sifadil / pcsx2-playground

Automatically exported from code.google.com/p/pcsx2-playground
2 stars 0 forks source link

Patch to Improve Overall Timeslicing behavior (Win32 only) #29

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This is a simple patch I did that helps improve PCSX2's performance
slightly, primarily when using the FrameLimiter.  So all it means for most
folks is to help maintain a little smoother overall FPS on games that run
at full FPS (shouldn't affect games that run slower).

One positive side effect is that PCSX2 will no longer trigger certain types
of background processes when running with the FrameLimiter enabled.  My
Google Desktop and Avast scanner kept thinking that "now" was a good time
to resume indexing/scanning, thanks to that Sleep(1); call in the
FrameLimiter.  Likewise, PCSX2 will be a little less likely to give up
valuable timeslices to other semi-idle background processes in general
(especially if the user opts for high priority mode).

The patch should also have a positive impact on emulation performance for
Laptop users, since the Windows install on many laptops likes to use a
low-resolution timeslicer (for longer battery life), and use of Sleep(1)
often leads to the CPU shifting into lower speeds.

Attached patch is against r236.

Original issue reported on code.google.com by Jake.Stine on 24 Oct 2008 at 11:32

Attachments:

GoogleCodeExporter commented 8 years ago
In case anyone wonders: There are some online blogs and benchmarks that 
discourage
the use of Sleep(0).  It's bogus information.

On Win95/98 systems Sleep(0) was indeed bad news.  It would behave erratically
(although with timeBeginPeriod(1) was usually ok).  Still, Sleep(1) yielded more
consistent results and so it was preferred.  Win95 is dead.  We don't care.

Windows XP introduces a new quirk.  XP has an auto-adjusting priority 
scheduler, and
it *will* throttle threads into lower priority ratings if those threads are 
spending
a lot of time sleeping.  XP counts Sleep(1) as "more idle" than Sleep(0), and 
thus
much more likely to be throttled.  This is why my "only run when the system is 
idle"
processes would start running while I was playing a non-intensive game under 
PCSX2
(ie, one that runs full framerate with plenty of cycles to spare).  This is 
also when
laptops throttle their CPU into low-speed mode.

Thus Sleep(0) is good, especially with the timeBeginPeriod set.

Concerning laptops: Every laptop I've used (which are only three, admittedly) 
had
kernel timeslice resolutions in excess of 20ms.  Even a basic idle wait loop 
couldn't
maintain a consistent 60fps rate, and it usually liked to wreak havoc on the 
audio
too (+/-20ms is an eternity in directsound latency terms).  I'm pretty sure most
modern laptops still follow the same practice, because it's really good at 
conserving
battery life while still maintaining high performance on dedicated single-thread
activities.  And when you kick up to play a DVD movie or what not, the player 
and/or
drivers just up the timeslice resolution while they're running.  Now PCSX2 can 
do the
same. :)

... just make sure the heating vents on your laptop are unobstructed before 
settling
in for a long emulation session. heh.

Original comment by Jake.Stine on 25 Oct 2008 at 9:49

GoogleCodeExporter commented 8 years ago
I'll run a few tests with this when I'm back at my beefy home pc :p
I can imagine this is the cause for the sporadically different benchmarks 
results I
always have.

Original comment by ramapcsx2 on 25 Oct 2008 at 10:13

GoogleCodeExporter commented 8 years ago
Ok, this is helping SPU2Ghz, it's helping the sync when speedhacks are enabled
(Persona3 videos work better). 
And it'll help when other processes want to "steal" cpu for themselves.
This is a keeper :p

Original comment by ramapcsx2 on 25 Oct 2008 at 1:29