Skip to content

Commit

Permalink
bugfix: CPU usage would climb to 100% when paused (fixes #1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Jan 16, 2025
1 parent 1bad27f commit e8ed4c8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,8 @@ bool handle_events()
sound_closed = 0;
was_paused = 0;
}

// Insert a 10ms delay to prevent 100% CPU usage
SDL_Delay(10);
return pause_emulation != 0;
}

Expand Down

3 comments on commit e8ed4c8

@giantclambake
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix, although addressing the issue at hand, comes with an unfortunate penalty ~ please view https://www.youtube.com/watch?v=fGrHc-u-78s

....as the ClassicWB-P96 instance boots up, the bootup time is very much extended, to the point that @0:12 in the video, you can see the gray CLI window briefly, just before the P96 screenmode kicks in ... Note: previously, the CLI window is never seen..ie; it boots too quickly to see it =)

Looking at the commit, I construe the 10ms wait is applying to the main loop, and this is responsible for the behavior.

Test:

Question ~ do we need 10ms to achieve the fix here?

Edit value to SDL_Delay(1); ~ recompile and retest... //decrement an order of ten

Result:

  • CPU usage works (decreases) as expected when emulation is in Pause state ...ie; still an effective fix to original issue
  • Boot-up time of emulation much closer to what it used to be, and I no longer see the aforementioned CLI window

Of course, if you put a stopwatch on it, bootup time will be a tiny bit longer (1ms per loop), but it's hardly discernible at the human, user level...if you get what I mean ;)

Might you please review/revisit this commit?

TIA

@midwan
Copy link
Collaborator Author

@midwan midwan commented on e8ed4c8 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not ideal indeed.
I'll do some tests to find a better solution.

@midwan
Copy link
Collaborator Author

@midwan midwan commented on e8ed4c8 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better fix is in, with e2feb3c

Please sign in to comment.