tsc.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * x86 TSC related functions
  4. */
  5. #ifndef _ASM_X86_TSC_H
  6. #define _ASM_X86_TSC_H
  7. #include <asm/processor.h>
  8. #include <asm/cpufeature.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. extern void disable_TSC(void);
  16. static inline cycles_t get_cycles(void)
  17. {
  18. if (!IS_ENABLED(CONFIG_X86_TSC) &&
  19. !cpu_feature_enabled(X86_FEATURE_TSC))
  20. return 0;
  21. return rdtsc();
  22. }
  23. #define get_cycles get_cycles
  24. extern struct system_counterval_t convert_art_to_tsc(u64 art);
  25. extern struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns);
  26. extern void tsc_early_init(void);
  27. extern void tsc_init(void);
  28. extern unsigned long calibrate_delay_is_known(void);
  29. extern void mark_tsc_unstable(char *reason);
  30. extern int unsynchronized_tsc(void);
  31. extern int check_tsc_unstable(void);
  32. extern void mark_tsc_async_resets(char *reason);
  33. extern unsigned long native_calibrate_cpu_early(void);
  34. extern unsigned long native_calibrate_tsc(void);
  35. extern unsigned long long native_sched_clock_from_tsc(u64 tsc);
  36. extern int tsc_clocksource_reliable;
  37. #ifdef CONFIG_X86_TSC
  38. extern bool tsc_async_resets;
  39. #else
  40. # define tsc_async_resets false
  41. #endif
  42. /*
  43. * Boot-time check whether the TSCs are synchronized across
  44. * all CPUs/cores:
  45. */
  46. #ifdef CONFIG_X86_TSC
  47. extern bool tsc_store_and_check_tsc_adjust(bool bootcpu);
  48. extern void tsc_verify_tsc_adjust(bool resume);
  49. extern void check_tsc_sync_source(int cpu);
  50. extern void check_tsc_sync_target(void);
  51. #else
  52. static inline bool tsc_store_and_check_tsc_adjust(bool bootcpu) { return false; }
  53. static inline void tsc_verify_tsc_adjust(bool resume) { }
  54. static inline void check_tsc_sync_source(int cpu) { }
  55. static inline void check_tsc_sync_target(void) { }
  56. #endif
  57. extern int notsc_setup(char *);
  58. extern void tsc_save_sched_clock_state(void);
  59. extern void tsc_restore_sched_clock_state(void);
  60. unsigned long cpu_khz_from_msr(void);
  61. #endif /* _ASM_X86_TSC_H */