How to convert RDTSC Clock ticks to Real Time in C or C++?

1k Views Asked by At

This is the code I am using in C to convert RDTSC clock ticks to time in usec. Assembly code to read the TSC. To covert RDTSC clock ticks to time, need to divide it with CPU clock frequency in GHz. CPU Frequency = 0.963 is in GHz. I don't know where am I wrong in the conversion?

static inline uint64_t RDTSC()
{
 unsigned int hi, lo;
 __asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));
 return ((uint64_t)hi << 32) | lo;
}
start = RDTSC();
end = RDTSC();
printf("\n-%.4f us-",((double)(end-start)/(double)0.963)/1000);



 

   

    
0

There are 0 best solutions below