Multi-core Clock Consistency

I am trying to measure the difference of hour counters between two time points in a kernel module. I use the following function named get_ccnt() to get the hour counter value at a specific 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 touch, I use the HP EliteBook 2530p in which the Intel Core 2 Duo SL9400 ( link specification )

I heard that processors after Nehalem have a consistent hour counter across all cores. (If I am mistaken, indicate this.) But the Intel Core 2 Duo SL 9400 has the code name Penryn .

Thus, I think that if a core module moves from one core to another between two time points, then the consistency between the two cores is compromised, and I cannot get the correct clock difference.

Is what I think right? If so, is there a way to fix it (for example, fix the kernel module so as not to move the kernel to the kernel?)

+6
source share
1 answer

One related note mentions that setting affinity for a process can achieve what you want. I would also suggest making a custom version of get_ccnt() , replacing RDTSC with RDTSCP . The latter is a variant of the former, which also returns cpuid with a loop counter. You can verify that your initial measuring cpuid is equal to the final measuring cpuid.

Take a look at section 3.2 of this Intel manual . Be sure to take a test first to make sure your processor supports this instruction.

+1
source

Source: https://habr.com/ru/post/989133/


All Articles