I'm accessing the TSC register, and using usleep() function to calculate my clock frequency. Basically, I check the current clock, delay for 1 second, and then check the clock again to discover how many clock ticks occur in a second.
The only problem is - my result turns out to be a ridiculous (and inconsistent) number. It always very close to one of the two following numbers.
18446744072127.2 Mhz or 2712.6 Mhz
My question - Is this a result of having a multi-core processor? Or is my code/logic just plain wrong? I included the relevant sections of the code below.
typedef unsigned long long int UINT64;
UINT64 startTSC = 0;
UINT64 stopTSC = 0;
UINT64 cycleCnt = 0;
// Access TSC register to get current value
__asm__ volatile(".byte 0x0f,0x31" : "=A" (startTSC));
// Delay for 1*10^6 us (1 second)
usleep(1000000);
// Access TSC register to get new value
__asm__ volatile(".byte 0x0f,0x31" : "=A" (stopTSC));
// Calculate cycles that happened over the full second
cycleCnt = stopTSC-startTSC;