More minor improvements to cpuSpeed calculations, since my experimental fix apparently works. :)

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2364 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-12-20 01:28:23 +00:00
parent 84c7436d34
commit b45b91bf07
2 changed files with 22 additions and 5 deletions

View File

@ -88,8 +88,15 @@ SingleCoreAffinity::SingleCoreAffinity()
); );
} }
// Force Windows to timeslice (hoping this fixes some affinity issues)
Sleep( 2 ); Sleep( 2 );
// Sleep Explained: I arbitrarily pick Core 0 to lock to for running the CPU test. This
// means that the current thread will need to be switched to Core 0 if it's currently
// scheduled on a difference cpu/core. However, Windows does not necessarily perform
// that scheduling immediately upon the call to SetThreadAffinityMask (seems dependent
// on version: XP does, Win7 does not). So by issuing a Sleep here we give Win7 time
// to issue a timeslice and move our thread to Core 0. Without this, it tends to move
// the thread during the cpuSpeed test instead, causing totally wacky results.
}; };
SingleCoreAffinity::~SingleCoreAffinity() throw() SingleCoreAffinity::~SingleCoreAffinity() throw()

View File

@ -34,7 +34,7 @@ static const char* bool_to_char( bool testcond )
static s64 CPUSpeedHz( u64 time ) static s64 CPUSpeedHz( u64 time )
{ {
u64 timeStart, timeStop; u64 timeStart, timeStop;
s64 startTick, endTick; s64 startCycle, endCycle;
if( ! x86caps.hasTimeStampCounter ) if( ! x86caps.hasTimeStampCounter )
return 0; return 0;
@ -49,18 +49,28 @@ static s64 CPUSpeedHz( u64 time )
do do
{ {
timeStop = GetCPUTicks(); timeStop = GetCPUTicks();
startTick = __rdtsc(); startCycle = __rdtsc();
} while( ( timeStop - timeStart ) == 0 ); } while( ( timeStop - timeStart ) == 0 );
timeStart = timeStop; timeStart = timeStop;
do do
{ {
timeStop = GetCPUTicks(); timeStop = GetCPUTicks();
endTick = __rdtsc(); endCycle = __rdtsc();
} }
while( ( timeStop - timeStart ) < time ); while( ( timeStop - timeStart ) < time );
return (s64)( endTick - startTick ); s64 cycleCount = endCycle - startCycle;
s64 timeCount = timeStop - timeStart;
s64 overrun = timeCount - time;
if( !overrun ) return cycleCount;
// interference could cause us to overshoot the target time, compensate:
double cyclesPerTick = (double)cycleCount / (double)timeCount;
double newCycleCount = (double)cycleCount - (cyclesPerTick * overrun);
return (s64)newCycleCount;
} }
// Recompiled code buffer for SSE and MXCSR feature testing. // Recompiled code buffer for SSE and MXCSR feature testing.