tsc.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * x86 TSC related functions
  3. */
  4. #ifndef _ASM_X86_TSC_H
  5. #define _ASM_X86_TSC_H
  6. #include <asm/processor.h>
  7. #define NS_SCALE 10 /* 2^10, carefully chosen */
  8. #define US_SCALE 32 /* 2^32, arbitralrily chosen */
  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. extern void disable_TSC(void);
  16. static inline cycles_t get_cycles(void)
  17. {
  18. unsigned long long ret = 0;
  19. #ifndef CONFIG_X86_TSC
  20. if (!cpu_has_tsc)
  21. return 0;
  22. #endif
  23. rdtscll(ret);
  24. return ret;
  25. }
  26. static __always_inline cycles_t vget_cycles(void)
  27. {
  28. /*
  29. * We only do VDSOs on TSC capable CPUs, so this shouldnt
  30. * access boot_cpu_data (which is not VDSO-safe):
  31. */
  32. #ifndef CONFIG_X86_TSC
  33. if (!cpu_has_tsc)
  34. return 0;
  35. #endif
  36. return (cycles_t)__native_read_tsc();
  37. }
  38. extern void tsc_init(void);
  39. extern void mark_tsc_unstable(char *reason);
  40. extern int unsynchronized_tsc(void);
  41. extern void init_tsc_clocksource(void);
  42. int check_tsc_unstable(void);
  43. /*
  44. * Boot-time check whether the TSCs are synchronized across
  45. * all CPUs/cores:
  46. */
  47. extern void check_tsc_sync_source(int cpu);
  48. extern void check_tsc_sync_target(void);
  49. extern void tsc_calibrate(void);
  50. extern int notsc_setup(char *);
  51. #endif