pastebin - collaborative debugging tool
rovema.kpaste.net RSS


x86_rdtscp_siewior1.c, try #001
Posted by Anonymous on Thu 17th Nov 2022 15:48
raw | new post

  1. /* x86_rdtscp_siewior1.c */
  2.  
  3. /*
  4. Results:
  5. root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1
  6. CPU  : 0
  7. CPUv2: 0 TS 0x1896116ed97bec
  8. root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1
  9. CPU  : 0
  10. CPUv2: 0 TS 0x189611d176dccc
  11. root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1
  12. CPU  : 0
  13. CPUv2: 0 TS 0x1896121adfeb94
  14. root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1
  15. CPU  : 1
  16. CPUv2: 0 TS 0x189612ab407b60
  17. root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1
  18. CPU  : 1
  19. CPUv2: 0 TS 0x189613730e0678
  20. root@EPU-102054501-AugustToepfer:~/x86_rdtscp# ./x86_rdtscp_siewior1
  21. CPU  : 0
  22. CPUv2: 0 TS 0x189613e707ae7c
  23. */
  24.  
  25. #define _GNU_SOURCE 1
  26.  
  27. #include <stdio.h>
  28. #include <sched.h>
  29.  
  30. static inline unsigned int rdtscp(unsigned long long *ts)
  31. {
  32.         unsigned int eax, edx;
  33.         unsigned int cpuid;
  34.  
  35.         __asm__ __volatile__("rdtscp" : "=a"(eax), "=d"(edx), "=c"(cpuid));
  36.         *ts = ((unsigned long long)edx) << 32 | eax;
  37.         return cpuid;
  38. }
  39.  
  40. int main(void)
  41. {
  42.         unsigned int cpu;
  43.         unsigned long long tsc;
  44.         unsigned int cpu_v2;
  45.  
  46.         cpu = sched_getcpu();
  47.         cpu_v2 = rdtscp(&tsc);
  48.         printf("CPU  : %u\n", cpu);
  49.         printf("CPUv2: %u TS 0x%llx\n", cpu_v2, tsc);
  50.         return 0;
  51. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at