tsc.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef CONFIG_X86_TSC
  19. if (!boot_cpu_has(X86_FEATURE_TSC))
  20. return 0;
  21. #endif
  22. return rdtsc();
  23. }
  24. extern struct system_counterval_t convert_art_to_tsc(u64 art);
  25. extern void tsc_init(void);
  26. extern void mark_tsc_unstable(char *reason);
  27. extern int unsynchronized_tsc(void);
  28. extern int check_tsc_unstable(void);
  29. extern unsigned long native_calibrate_cpu(void);
  30. extern unsigned long native_calibrate_tsc(void);
  31. extern unsigned long long native_sched_clock_from_tsc(u64 tsc);
  32. extern int tsc_clocksource_reliable;
  33. /*
  34. * Boot-time check whether the TSCs are synchronized across
  35. * all CPUs/cores:
  36. */
  37. #ifdef CONFIG_X86_TSC
  38. extern bool tsc_store_and_check_tsc_adjust(bool bootcpu);
  39. extern void tsc_verify_tsc_adjust(bool resume);
  40. extern void check_tsc_sync_source(int cpu);
  41. extern void check_tsc_sync_target(void);
  42. #else
  43. static inline bool tsc_store_and_check_tsc_adjust(bool bootcpu) { return false; }
  44. static inline void tsc_verify_tsc_adjust(bool resume) { }
  45. static inline void check_tsc_sync_source(int cpu) { }
  46. static inline void check_tsc_sync_target(void) { }
  47. #endif
  48. extern int notsc_setup(char *);
  49. extern void tsc_save_sched_clock_state(void);
  50. extern void tsc_restore_sched_clock_state(void);
  51. unsigned long cpu_khz_from_msr(void);
  52. #endif /* _ASM_X86_TSC_H */