/* x86_rdtscp_siewior1.c */ /* Results: root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1 CPU : 0 CPUv2: 0 TS 0x1896116ed97bec root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1 CPU : 0 CPUv2: 0 TS 0x189611d176dccc root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1 CPU : 0 CPUv2: 0 TS 0x1896121adfeb94 root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1 CPU : 1 CPUv2: 0 TS 0x189612ab407b60 root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1 CPU : 1 CPUv2: 0 TS 0x189613730e0678 root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1 CPU : 0 CPUv2: 0 TS 0x189613e707ae7c */ #define _GNU_SOURCE 1 #include #include static inline unsigned int rdtscp(unsigned long long *ts) { unsigned int eax, edx; unsigned int cpuid; __asm__ __volatile__("rdtscp" : "=a"(eax), "=d"(edx), "=c"(cpuid)); *ts = ((unsigned long long)edx) << 32 | eax; return cpuid; } int main(void) { unsigned int cpu; unsigned long long tsc; unsigned int cpu_v2; cpu = sched_getcpu(); cpu_v2 = rdtscp(&tsc); printf("CPU : %u\n", cpu); printf("CPUv2: %u TS 0x%llx\n", cpu_v2, tsc); return 0; }