tsc.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifdef X86_FEATURE_SYNC_RDTSC
  32. unsigned eax;
  33. /*
  34. * Don't do an additional sync on CPUs where we know
  35. * RDTSC is already synchronous:
  36. */
  37. alternative_io("cpuid", ASM_NOP2, X86_FEATURE_SYNC_RDTSC,
  38. "=a" (eax), "0" (1) : "ebx","ecx","edx","memory");
  39. #else
  40. sync_core();
  41. #endif
  42. rdtscll(ret);
  43. return ret;
  44. }
  45. extern void tsc_init(void);
  46. extern void mark_tsc_unstable(void);
  47. extern int unsynchronized_tsc(void);
  48. extern void init_tsc_clocksource(void);
  49. /*
  50. * Boot-time check whether the TSCs are synchronized across
  51. * all CPUs/cores:
  52. */
  53. extern void check_tsc_sync_source(int cpu);
  54. extern void check_tsc_sync_target(void);
  55. #endif