blob: 2701d221583a26071b16c1caf1d34b3de7c7b007 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andres Salomon2272b0e2007-03-06 01:42:05 -08002/*
Thomas Gleixner2f0798a2007-10-12 23:04:23 +02003 * x86 TSC related functions
Andres Salomon2272b0e2007-03-06 01:42:05 -08004 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07005#ifndef _ASM_X86_TSC_H
6#define _ASM_X86_TSC_H
Andres Salomon2272b0e2007-03-06 01:42:05 -08007
8#include <asm/processor.h>
9
Thomas Gleixner2f0798a2007-10-12 23:04:23 +020010#define NS_SCALE 10 /* 2^10, carefully chosen */
11#define US_SCALE 32 /* 2^32, arbitralrily chosen */
12
Andres Salomon2272b0e2007-03-06 01:42:05 -080013/*
14 * Standard way to access the cycle counter.
15 */
16typedef unsigned long long cycles_t;
17
18extern unsigned int cpu_khz;
19extern unsigned int tsc_khz;
Glauber de Oliveira Costa73018a62008-01-30 13:31:26 +010020
21extern void disable_TSC(void);
Andres Salomon2272b0e2007-03-06 01:42:05 -080022
23static inline cycles_t get_cycles(void)
24{
Andres Salomon2272b0e2007-03-06 01:42:05 -080025#ifndef CONFIG_X86_TSC
Borislav Petkov59e21e32016-04-04 22:24:59 +020026 if (!boot_cpu_has(X86_FEATURE_TSC))
Andres Salomon2272b0e2007-03-06 01:42:05 -080027 return 0;
28#endif
Ingo Molnar75f2ce02008-01-30 13:33:24 +010029
Andy Lutomirski4ea16362015-06-25 18:44:07 +020030 return rdtsc();
Andi Kleen6d63de82008-01-30 13:32:39 +010031}
Glauber de Oliveira Costa4e871732008-01-30 13:31:03 +010032
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010033extern struct system_counterval_t convert_art_to_tsc(u64 art);
Rajvi Jingarfc804f62018-03-08 09:28:36 -080034extern struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns);
Christopher S. Hallf9677e02016-02-29 06:33:47 -080035
Dou Liyangeb496062017-07-14 11:34:06 +080036extern void tsc_early_delay_calibrate(void);
Andres Salomon2272b0e2007-03-06 01:42:05 -080037extern void tsc_init(void);
john stultz5a90cf22007-05-02 19:27:08 +020038extern void mark_tsc_unstable(char *reason);
Andres Salomon2272b0e2007-03-06 01:42:05 -080039extern int unsynchronized_tsc(void);
Thomas Gleixner2d826402009-08-20 17:06:25 +020040extern int check_tsc_unstable(void);
mike.travis@hpe.com341102c2017-10-12 11:32:02 -050041extern void mark_tsc_async_resets(char *reason);
Len Brownaa297292016-06-17 01:22:51 -040042extern unsigned long native_calibrate_cpu(void);
Thomas Gleixner2d826402009-08-20 17:06:25 +020043extern unsigned long native_calibrate_tsc(void);
Andi Kleena94cab22015-05-10 12:22:39 -070044extern unsigned long long native_sched_clock_from_tsc(u64 tsc);
Andres Salomon2272b0e2007-03-06 01:42:05 -080045
Suresh Siddha28a00182011-11-04 15:42:17 -070046extern int tsc_clocksource_reliable;
Thomas Gleixnerc0fc9b12017-10-17 08:49:37 +020047#ifdef CONFIG_X86_TSC
mike.travis@hpe.com341102c2017-10-12 11:32:02 -050048extern bool tsc_async_resets;
Thomas Gleixnerc0fc9b12017-10-17 08:49:37 +020049#else
50# define tsc_async_resets false
51#endif
Suresh Siddha28a00182011-11-04 15:42:17 -070052
Andres Salomon2272b0e2007-03-06 01:42:05 -080053/*
54 * Boot-time check whether the TSCs are synchronized across
55 * all CPUs/cores:
56 */
Thomas Gleixner8b223bc2016-11-19 13:47:36 +000057#ifdef CONFIG_X86_TSC
Thomas Gleixner5bae1562016-12-13 13:14:17 +000058extern bool tsc_store_and_check_tsc_adjust(bool bootcpu);
Thomas Gleixner6a369582016-12-13 13:14:17 +000059extern void tsc_verify_tsc_adjust(bool resume);
Thomas Gleixnerb8365542016-11-29 20:28:31 +010060extern void check_tsc_sync_source(int cpu);
61extern void check_tsc_sync_target(void);
Thomas Gleixner8b223bc2016-11-19 13:47:36 +000062#else
Thomas Gleixner5bae1562016-12-13 13:14:17 +000063static inline bool tsc_store_and_check_tsc_adjust(bool bootcpu) { return false; }
Thomas Gleixner6a369582016-12-13 13:14:17 +000064static inline void tsc_verify_tsc_adjust(bool resume) { }
Thomas Gleixnerb8365542016-11-29 20:28:31 +010065static inline void check_tsc_sync_source(int cpu) { }
66static inline void check_tsc_sync_target(void) { }
Thomas Gleixner8b223bc2016-11-19 13:47:36 +000067#endif
68
Thomas Gleixner80ca9c92008-01-30 13:30:18 +010069extern int notsc_setup(char *);
Marcelo Tosattib74f05d62012-02-13 11:07:27 -020070extern void tsc_save_sched_clock_state(void);
71extern void tsc_restore_sched_clock_state(void);
Thomas Gleixnerd3716982007-10-12 23:04:06 +020072
Len Brown02c0cd22016-06-17 01:22:50 -040073unsigned long cpu_khz_from_msr(void);
Bin Gao7da7c152013-10-21 09:16:33 -070074
H. Peter Anvin1965aae2008-10-22 22:26:29 -070075#endif /* _ASM_X86_TSC_H */