I am trying to measure a difference of clock counters between two time points at a kernel module. I use the following function named get_ccnt()
to get a clock counter value at a certain time:
static __inline__ long long int get_ccnt(void)
{
#if defined(__i386__)
long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
#elif defined(__x86_64__)
unsigned int hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ( (long long int)lo)|( ((long long int)hi)<<32 );
#endif
}
What I concern is, I am using HP EliteBook 2530p in which Intel Core 2 Duo SL9400 (spec. reference)
I heard that CPUs after Nehalem
has a consistent clock counter over all cores. (If I get wrong, please point it out.) But, Intel Core 2 Duo SL 9400 has a code name Penryn
.
Thus, I think if a kernel module moves from one core to another between two time points, then consistency between two cores is compromised and I can't get a right clock difference.
Is it right what I am thinking? If it is, is there a way to fix it (e.g. fix a kernel module not to move a core to a core?)
One of the comments linked mentions that setting the process affinity can achieve what you want. I would also suggest making a custom version of get_ccnt()
whereby replacing RDTSC with RDTSCP. The latter is a variant of the former which also returns the cpuid with the cycle counter. You could check that your initial measurement's cpuid is equal to the final measurement's cpuid.
Have a look at Section 3.2 of this Intel manual. Be sure to make a test first to verify that your processor supports this instruction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With