blob: 174c4212780afde12200fd23a1dbc17a08f40309 [file] [log] [blame]
Andres Salomon2272b0e2007-03-06 01:42:05 -08001/*
Thomas Gleixner2f0798a2007-10-12 23:04:23 +02002 * x86 TSC related functions
Andres Salomon2272b0e2007-03-06 01:42:05 -08003 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07004#ifndef _ASM_X86_TSC_H
5#define _ASM_X86_TSC_H
Andres Salomon2272b0e2007-03-06 01:42:05 -08006
7#include <asm/processor.h>
8
Thomas Gleixner2f0798a2007-10-12 23:04:23 +02009#define NS_SCALE 10 /* 2^10, carefully chosen */
10#define US_SCALE 32 /* 2^32, arbitralrily chosen */
11
Andres Salomon2272b0e2007-03-06 01:42:05 -080012/*
13 * Standard way to access the cycle counter.
14 */
15typedef unsigned long long cycles_t;
16
17extern unsigned int cpu_khz;
18extern unsigned int tsc_khz;
Glauber de Oliveira Costa73018a62008-01-30 13:31:26 +010019
20extern void disable_TSC(void);
Andres Salomon2272b0e2007-03-06 01:42:05 -080021
22static inline cycles_t get_cycles(void)
23{
Andres Salomon2272b0e2007-03-06 01:42:05 -080024#ifndef CONFIG_X86_TSC
25 if (!cpu_has_tsc)
26 return 0;
27#endif
Ingo Molnar75f2ce02008-01-30 13:33:24 +010028
Andy Lutomirski4ea16362015-06-25 18:44:07 +020029 return rdtsc();
Andi Kleen6d63de82008-01-30 13:32:39 +010030}
Glauber de Oliveira Costa4e871732008-01-30 13:31:03 +010031
Christopher S. Hallf9677e02016-02-29 06:33:47 -080032extern struct system_counterval_t convert_art_to_tsc(cycle_t art);
33
Andres Salomon2272b0e2007-03-06 01:42:05 -080034extern void tsc_init(void);
john stultz5a90cf22007-05-02 19:27:08 +020035extern void mark_tsc_unstable(char *reason);
Andres Salomon2272b0e2007-03-06 01:42:05 -080036extern int unsynchronized_tsc(void);
Thomas Gleixner2d826402009-08-20 17:06:25 +020037extern int check_tsc_unstable(void);
Adrian Hunterc73deb62013-06-28 16:22:18 +030038extern int check_tsc_disabled(void);
Thomas Gleixner2d826402009-08-20 17:06:25 +020039extern unsigned long native_calibrate_tsc(void);
Andi Kleena94cab22015-05-10 12:22:39 -070040extern unsigned long long native_sched_clock_from_tsc(u64 tsc);
Andres Salomon2272b0e2007-03-06 01:42:05 -080041
Suresh Siddha28a00182011-11-04 15:42:17 -070042extern int tsc_clocksource_reliable;
43
Andres Salomon2272b0e2007-03-06 01:42:05 -080044/*
45 * Boot-time check whether the TSCs are synchronized across
46 * all CPUs/cores:
47 */
48extern void check_tsc_sync_source(int cpu);
49extern void check_tsc_sync_target(void);
50
Thomas Gleixner80ca9c92008-01-30 13:30:18 +010051extern int notsc_setup(char *);
Marcelo Tosattib74f05d2012-02-13 11:07:27 -020052extern void tsc_save_sched_clock_state(void);
53extern void tsc_restore_sched_clock_state(void);
Thomas Gleixnerd3716982007-10-12 23:04:06 +020054
Bin Gao7da7c152013-10-21 09:16:33 -070055/* MSR based TSC calibration for Intel Atom SoC platforms */
Thomas Gleixner5f0e0302014-02-19 13:52:29 +020056unsigned long try_msr_calibrate_tsc(void);
Bin Gao7da7c152013-10-21 09:16:33 -070057
H. Peter Anvin1965aae2008-10-22 22:26:29 -070058#endif /* _ASM_X86_TSC_H */