tsc.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * linux/include/asm-i386/tsc.h
  3. *
  4. * i386 TSC related functions
  5. */
  6. #ifndef _ASM_i386_TSC_H
  7. #define _ASM_i386_TSC_H
  8. #include <asm/processor.h>
  9. /*
  10. * Standard way to access the cycle counter.
  11. */
  12. typedef unsigned long long cycles_t;
  13. extern unsigned int cpu_khz;
  14. extern unsigned int tsc_khz;
  15. static inline cycles_t get_cycles(void)
  16. {
  17. unsigned long long ret = 0;
  18. #ifndef CONFIG_X86_TSC
  19. if (!cpu_has_tsc)
  20. return 0;
  21. #endif
  22. #if defined(CONFIG_X86_GENERIC) || defined(CONFIG_X86_TSC)
  23. rdtscll(ret);
  24. #endif
  25. return ret;
  26. }
  27. /* Like get_cycles, but make sure the CPU is synchronized. */
  28. static __always_inline cycles_t get_cycles_sync(void)
  29. {
  30. unsigned long long ret;
  31. unsigned eax;
  32. /*
  33. * Use RDTSCP if possible; it is guaranteed to be synchronous
  34. * and doesn't cause a VMEXIT on Hypervisors
  35. */
  36. alternative_io(ASM_NOP3, ".byte 0x0f,0x01,0xf9", X86_FEATURE_RDTSCP,
  37. "=A" (ret), "0" (0ULL) : "ecx", "memory");
  38. if (ret)
  39. return ret;
  40. /*
  41. * Don't do an additional sync on CPUs where we know
  42. * RDTSC is already synchronous:
  43. */
  44. alternative_io("cpuid", ASM_NOP2, X86_FEATURE_SYNC_RDTSC,
  45. "=a" (eax), "0" (1) : "ebx","ecx","edx","memory");
  46. rdtscll(ret);
  47. return ret;
  48. }
  49. extern void tsc_init(void);
  50. extern void mark_tsc_unstable(char *reason);
  51. extern int unsynchronized_tsc(void);
  52. extern void init_tsc_clocksource(void);
  53. /*
  54. * Boot-time check whether the TSCs are synchronized across
  55. * all CPUs/cores:
  56. */
  57. extern void check_tsc_sync_source(int cpu);
  58. extern void check_tsc_sync_target(void);
  59. #endif