Get rid of Sys_GetClockticks() and Sys_ClockTicksPerSecond()

Now unused.
This commit is contained in:
dhewg 2011-12-21 17:00:56 +01:00
parent 2e3653ce9f
commit e2b46a5a34
8 changed files with 0 additions and 276 deletions

View file

@ -276,99 +276,6 @@ void Sys_FPE_handler( int signum, siginfo_t *info, void *context ) {
Sys_Printf( "FPE\n" );
}
/*
===============
Sys_GetClockticks
===============
*/
double Sys_GetClockTicks( void ) {
#if defined( __i386__ )
unsigned long lo, hi;
__asm__ __volatile__ (
"push %%ebx\n" \
"xor %%eax,%%eax\n" \
"cpuid\n" \
"rdtsc\n" \
"mov %%eax,%0\n" \
"mov %%edx,%1\n" \
"pop %%ebx\n"
: "=r" (lo), "=r" (hi) );
return (double) lo + (double) 0xFFFFFFFF * hi;
#else
return 0.0;
#endif
}
/*
===============
MeasureClockTicks
===============
*/
double MeasureClockTicks( void ) {
double t0, t1;
t0 = Sys_GetClockTicks( );
Sys_Sleep( 1000 );
t1 = Sys_GetClockTicks( );
return t1 - t0;
}
/*
===============
Sys_ClockTicksPerSecond
===============
*/
double Sys_ClockTicksPerSecond(void) {
static bool init = false;
static double ret;
int fd, len, pos, end;
char buf[ 4096 ];
if ( init ) {
return ret;
}
fd = open( "/proc/cpuinfo", O_RDONLY );
if ( fd == -1 ) {
common->Printf( "couldn't read /proc/cpuinfo\n" );
ret = MeasureClockTicks();
init = true;
common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 );
return ret;
}
len = read( fd, buf, 4096 );
close( fd );
pos = 0;
while ( pos < len ) {
if ( !idStr::Cmpn( buf + pos, "cpu MHz", 7 ) ) {
pos = strchr( buf + pos, ':' ) - buf + 2;
end = strchr( buf + pos, '\n' ) - buf;
if ( pos < len && end < len ) {
buf[end] = '\0';
ret = atof( buf + pos );
} else {
common->Printf( "failed parsing /proc/cpuinfo\n" );
ret = MeasureClockTicks();
init = true;
common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 );
return ret;
}
common->Printf( "/proc/cpuinfo CPU frequency: %g MHz\n", ret );
ret *= 1000000;
init = true;
return ret;
}
pos = strchr( buf + pos, '\n' ) - buf + 1;
}
common->Printf( "failed parsing /proc/cpuinfo\n" );
ret = MeasureClockTicks();
init = true;
common->Printf( "measured CPU frequency: %g MHz\n", ret / 1000000.0 );
return ret;
}
/*
================
Sys_GetSystemRam

View file

@ -641,79 +641,6 @@ void Sys_FPE_handler( int signum, siginfo_t *info, void *context ) {
#endif
}
/*
===============
Sys_GetClockTicks
===============
*/
double Sys_GetClockTicks( void ) {
// NOTE that this only affects idTimer atm, which is only used for performance timing during developement
#warning FIXME: implement Sys_GetClockTicks
return 0.0;
}
/*
===============
Sys_ClockTicksPerSecond
===============
*/
double Sys_ClockTicksPerSecond(void) {
// Our strategy is to query both Gestalt & IOKit and then take the larger of the two values.
long gestaltSpeed, ioKitSpeed = -1;
// GESTALT
// gestaltProcClkSpeedMHz available in 10.3 needs to be used because CPU speeds have now
// exceeded the signed long that Gestalt returns.
long osVers;
OSErr err;
Gestalt(gestaltSystemVersion, &osVers);
if (osVers >= 0x1030)
err = Gestalt(gestaltProcClkSpeedMHz, &gestaltSpeed);
else
{
err = Gestalt(gestaltProcClkSpeed, &gestaltSpeed);
if (err == noErr)
gestaltSpeed = gestaltSpeed / 1000000;
}
// IO KIT
mach_port_t masterPort;
CFMutableDictionaryRef matchDict = nil;
io_iterator_t itThis;
io_service_t service = nil;
if (IOMasterPort(MACH_PORT_NULL, &masterPort))
goto bail;
matchDict = IOServiceNameMatching("cpus");
if (IOServiceGetMatchingServices(masterPort, matchDict, &itThis))
goto bail;
service = IOIteratorNext(itThis);
while(service)
{
io_service_t ioCpu = NULL;
if (IORegistryEntryGetChildEntry(service, kIODeviceTreePlane, &ioCpu))
goto bail;
if (ioCpu)
{
CFDataRef data = (CFDataRef)IORegistryEntryCreateCFProperty(ioCpu, CFSTR("clock-frequency"),kCFAllocatorDefault,0);
if (data)
ioKitSpeed = *((unsigned long*)CFDataGetBytePtr(data)) / 1000000;
}
service = IOIteratorNext(itThis);
}
// Return the larger value
bail:
return ( ioKitSpeed > gestaltSpeed ? ioKitSpeed : gestaltSpeed ) * 1000000.f;
}
/*
================
Sys_GetSystemRam

View file

@ -45,14 +45,6 @@ unsigned int Sys_Milliseconds( void ) {
return frameNum * 16;
}
double Sys_GetClockTicks( void ) {
return frameNum * 16.0;
}
double Sys_ClockTicksPerSecond( void ) {
return 1000.0;
}
void Sys_Sleep( int msec ) {
}

View file

@ -57,14 +57,6 @@ unsigned int idSysLocal::GetMilliseconds( void ) {
return Sys_Milliseconds();
}
double idSysLocal::GetClockTicks( void ) {
return Sys_GetClockTicks();
}
double idSysLocal::ClockTicksPerSecond( void ) {
return Sys_ClockTicksPerSecond();
}
int idSysLocal::GetProcessorId( void ) {
return Sys_GetProcessorId();
}

View file

@ -46,8 +46,6 @@ public:
virtual void DebugVPrintf( const char *fmt, va_list arg );
virtual unsigned int GetMilliseconds( void );
virtual double GetClockTicks( void );
virtual double ClockTicksPerSecond( void );
virtual int GetProcessorId( void );
virtual const char * GetProcessorString( void );
virtual const char * FPU_GetState( void );

View file

@ -151,10 +151,6 @@ void Sys_Sleep( int msec );
// any game related timing information should come from event timestamps
unsigned int Sys_Milliseconds( void );
// for accurate performance testing
double Sys_GetClockTicks( void );
double Sys_ClockTicksPerSecond( void );
// returns a selection of the CPUID_* flags
int Sys_GetProcessorId( void );
const char * Sys_GetProcessorString( void );
@ -414,8 +410,6 @@ public:
virtual void DebugVPrintf( const char *fmt, va_list arg ) = 0;
virtual unsigned int GetMilliseconds( void ) = 0;
virtual double GetClockTicks( void ) = 0;
virtual double ClockTicksPerSecond( void ) = 0;
virtual int GetProcessorId( void ) = 0;
virtual const char * GetProcessorString( void ) = 0;
virtual const char * FPU_GetState( void ) = 0;

View file

@ -30,90 +30,6 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/win32/win_local.h"
/*
==============================================================
Clock ticks
==============================================================
*/
/*
================
Sys_GetClockTicks
================
*/
double Sys_GetClockTicks( void ) {
#ifndef _MSC_VER
LARGE_INTEGER li;
QueryPerformanceCounter( &li );
return (double ) li.LowPart + (double) 0xFFFFFFFF * li.HighPart;
#else
unsigned long lo, hi;
__asm {
push ebx
xor eax, eax
cpuid
rdtsc
mov lo, eax
mov hi, edx
pop ebx
}
return (double ) lo + (double) 0xFFFFFFFF * hi;
#endif
}
/*
================
Sys_ClockTicksPerSecond
================
*/
double Sys_ClockTicksPerSecond( void ) {
static double ticks = 0;
#ifndef _MSC_VER
if ( !ticks ) {
LARGE_INTEGER li;
QueryPerformanceFrequency( &li );
ticks = li.QuadPart;
}
#else
if ( !ticks ) {
HKEY hKey;
LPBYTE ProcSpeed;
DWORD buflen, ret;
if ( !RegOpenKeyEx( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey ) ) {
ProcSpeed = 0;
buflen = sizeof( ProcSpeed );
ret = RegQueryValueEx( hKey, "~MHz", NULL, NULL, (LPBYTE) &ProcSpeed, &buflen );
// If we don't succeed, try some other spellings.
if ( ret != ERROR_SUCCESS ) {
ret = RegQueryValueEx( hKey, "~Mhz", NULL, NULL, (LPBYTE) &ProcSpeed, &buflen );
}
if ( ret != ERROR_SUCCESS ) {
ret = RegQueryValueEx( hKey, "~mhz", NULL, NULL, (LPBYTE) &ProcSpeed, &buflen );
}
RegCloseKey( hKey );
if ( ret == ERROR_SUCCESS ) {
ticks = (double) ((unsigned long)ProcSpeed) * 1000000;
}
}
}
#endif
return ticks;
}
/*
==============================================================

View file

@ -852,8 +852,6 @@ void Sys_Init( void ) {
if ( !idStr::Icmp( win32.sys_cpustring.GetString(), "detect" ) ) {
idStr string;
common->Printf( "%1.0f MHz ", Sys_ClockTicksPerSecond() / 1000000.0f );
win32.cpuid = Sys_GetCPUId();
string.Clear();