From d72cacbdd49fe19ea903cd01477acdf31ca04448 Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Sat, 25 Oct 2008 13:37:48 +0000 Subject: [PATCH] Changed the Sleep() behavior as posted by Jake.Stine in Issue 29. Improves smoothness in games running fullspeed, and lets pcsx2 use the cpu time it needs :) (Note: You'll see constantly 100% cpu usage now, but pcsx2 doesn't do any "more" work.) git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@237 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/Counters.c | 2 +- pcsx2/FiFo.c | 6 +----- pcsx2/GS.cpp | 41 +++++++++-------------------------------- pcsx2/Misc.h | 10 ++++++++++ pcsx2/windows/WinMain.c | 13 +++++++++++-- 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/pcsx2/Counters.c b/pcsx2/Counters.c index ad769e6992..17015a360a 100644 --- a/pcsx2/Counters.c +++ b/pcsx2/Counters.c @@ -175,7 +175,7 @@ void FrameLimiter() if ((diff>>3)>iTicks) iExpectedEnd=iEnd; } else do { - Sleep(1); + _TIMESLICE(); iEnd = GetCPUTicks(); } while (iEnd= tempbuf || (writepos+size == GS_RINGBUFFEREND && tempbuf == GS_RINGBUFFERBASE)) ) { if( !CHECK_DUALCORE ) { GS_SETEVENT(); -#ifdef _WIN32 - Sleep(1); -#else - usleep(500); -#endif + _TIMESLICE(); } tempbuf = *(volatile PU8*)&g_pGSRingPos; @@ -373,11 +357,7 @@ void GSRingBufSimplePacket(int type, int data0, int data1, int data2) do { if( !CHECK_DUALCORE ) { GS_SETEVENT(); -#ifdef _WIN32 - Sleep(1); -#else - usleep(500); -#endif + _TIMESLICE(); } tempbuf = *(volatile PU8*)&g_pGSRingPos; @@ -397,11 +377,7 @@ void GSRingBufSimplePacket(int type, int data0, int data1, int data2) while(tempbuf == GS_RINGBUFFERBASE && tempbuf != *(volatile PU8*)&g_pGSWritePos) { if( !CHECK_DUALCORE ) { GS_SETEVENT(); -#ifdef _WIN32 - Sleep(1); -#else - usleep(500); -#endif + _TIMESLICE(); } tempbuf = *(volatile PU8*)&g_pGSRingPos; @@ -1471,6 +1447,7 @@ int HasToExit() } #if defined(_WIN32) && !defined(WIN32_PTHREADS) +//#pragma optimize ("",off) //needed for a working PGO build DWORD WINAPI GSThreadProc(LPVOID lpParam) { HANDLE handles[2] = { g_hGsEvent, g_hVuGSExit }; @@ -1744,7 +1721,7 @@ ExitGS: GSclose(); return 0; } - +//#pragma optimize ("",on) //needed for a working PGO build int gsFreeze(gzFile f, int Mode) { gzfreeze(PS2MEM_GS, 0x2000); @@ -1836,4 +1813,4 @@ void RunGSState(gzFile f) #endif -#undef GIFchain \ No newline at end of file +#undef GIFchain diff --git a/pcsx2/Misc.h b/pcsx2/Misc.h index 53425ad126..7660806d21 100644 --- a/pcsx2/Misc.h +++ b/pcsx2/Misc.h @@ -363,5 +363,15 @@ extern __forceinline long InterlockedExchangeAdd(long volatile* Addend, long Val //#define InterlockedExchangePointerAdd InterlockedExchangeAdd //#endif +// Timeslice releaser for those many idle loop spots through out PCSX2. +static __forceinline void _TIMESLICE() +{ +#ifdef _WIN32 + Sleep(0); +#else + usleep(500); +#endif +} + #endif /* __MISC_H__ */ diff --git a/pcsx2/windows/WinMain.c b/pcsx2/windows/WinMain.c index d62558d76b..d5744cbda8 100644 --- a/pcsx2/windows/WinMain.c +++ b/pcsx2/windows/WinMain.c @@ -140,7 +140,16 @@ void RunExecute(int run) { if( GSsetGameCRC != NULL ) GSsetGameCRC(ElfCRC, g_ZeroGSOptions); - if (run) Cpu->Execute(); + if (run) + { + // This makes sure the Windows Kernel is using high resolution + // timeslices for Sleep calls. + // (may not make much difference on most desktops but + // can improve performance a lot on laptops). + timeBeginPeriod( 1 ); + Cpu->Execute(); + timeEndPeriod( 1 ); + } } int Slots[5] = { -1, -1, -1, -1, -1 }; @@ -419,7 +428,7 @@ BOOL SysLoggedSetLockPagesPrivilege ( HANDLE hProcess, BOOL bEnable); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char *lang; int i; - + #ifdef PCSX2_VIRTUAL_MEM LPVOID lpMemReserved; #endif