[SDL] framerate counter

David Olofson david.olofson at reologica.se
Thu Apr 5 09:00:38 PDT 2001


On Thursday 05 April 2001 15:27, Timo K Suoranta wrote:
> timing information. Which is provided by performance counter (is it
> available in linux in any form?).

Sure (on x86 at least); it's a CPU core feature of the x86. It's a 64 bit 
counter that counts core clock cycles.


__inline__ unsigned long long int rdtsc(void)
{
	unsigned long long int x;
	__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
	return x;
}


For conversion into more useful units, you can do something like this:

f = fopen("/proc/cpuinfo","r");
if(f)
{
	while(1)
	{
		if(!fgets(s1, 100, f))
			break;
		if(!memcmp(s1, "cpu MHz", 7))
		{
			cpu_hz = atof(&s1[10])*1000000.0;
			break;
		}
	}
	fclose(f);
}


//David

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------> http://www.linuxaudiodev.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`--------------------------------------> david at linuxdj.com -'



More information about the SDL mailing list