tsc.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /* flag for disabling the tsc */
  16. extern int tsc_disable;
  17. extern void disable_TSC(void);
  18. static inline cycles_t get_cycles(void)
  19. {
  20. unsigned long long ret = 0;
  21. #ifndef CONFIG_X86_TSC
  22. if (!cpu_has_tsc)
  23. return 0;
  24. #endif
  25. #if defined(CONFIG_X86_GENERIC) || defined(CONFIG_X86_TSC)
  26. rdtscll(ret);
  27. #endif
  28. return ret;
  29. }
  30. static inline cycles_t vget_cycles(void)
  31. {
  32. /*
  33. * We only do VDSOs on TSC capable CPUs, so this shouldnt
  34. * access boot_cpu_data (which is not VDSO-safe):
  35. */
  36. #ifndef CONFIG_X86_TSC
  37. if (!cpu_has_tsc)
  38. return 0;
  39. #endif
  40. return (cycles_t) __native_read_tsc();
  41. }
  42. extern void tsc_init(void);
  43. extern void mark_tsc_unstable(char *reason);
  44. extern int unsynchronized_tsc(void);
  45. extern void init_tsc_clocksource(void);
  46. int check_tsc_unstable(void);
  47. /*
  48. * Boot-time check whether the TSCs are synchronized across
  49. * all CPUs/cores:
  50. */
  51. extern void check_tsc_sync_source(int cpu);
  52. extern void check_tsc_sync_target(void);
  53. extern void tsc_calibrate(void);
  54. extern int notsc_setup(char *);
  55. #endif