tsc.h 1.4 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. 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 shouldn't
  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 int check_tsc_unstable(void);
  42. extern unsigned long native_calibrate_tsc(void);
  43. extern int tsc_clocksource_reliable;
  44. /*
  45. * Boot-time check whether the TSCs are synchronized across
  46. * all CPUs/cores:
  47. */
  48. extern void check_tsc_sync_source(int cpu);
  49. extern void check_tsc_sync_target(void);
  50. extern int notsc_setup(char *);
  51. extern void tsc_save_sched_clock_state(void);
  52. extern void tsc_restore_sched_clock_state(void);
  53. #endif /* _ASM_X86_TSC_H */