aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86/tsc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-x86/tsc.h')
-rw-r--r--include/asm-x86/tsc.h40
1 files changed, 12 insertions, 28 deletions
diff --git a/include/asm-x86/tsc.h b/include/asm-x86/tsc.h
index 6baab30dc2c8..7d3e27f7d484 100644
--- a/include/asm-x86/tsc.h
+++ b/include/asm-x86/tsc.h
@@ -17,6 +17,8 @@ typedef unsigned long long cycles_t;
17extern unsigned int cpu_khz; 17extern unsigned int cpu_khz;
18extern unsigned int tsc_khz; 18extern unsigned int tsc_khz;
19 19
20extern void disable_TSC(void);
21
20static inline cycles_t get_cycles(void) 22static inline cycles_t get_cycles(void)
21{ 23{
22 unsigned long long ret = 0; 24 unsigned long long ret = 0;
@@ -25,39 +27,22 @@ static inline cycles_t get_cycles(void)
25 if (!cpu_has_tsc) 27 if (!cpu_has_tsc)
26 return 0; 28 return 0;
27#endif 29#endif
28
29#if defined(CONFIG_X86_GENERIC) || defined(CONFIG_X86_TSC)
30 rdtscll(ret); 30 rdtscll(ret);
31#endif 31
32 return ret; 32 return ret;
33} 33}
34 34
35/* Like get_cycles, but make sure the CPU is synchronized. */ 35static inline cycles_t vget_cycles(void)
36static __always_inline cycles_t get_cycles_sync(void)
37{ 36{
38 unsigned long long ret;
39 unsigned eax, edx;
40
41 /*
42 * Use RDTSCP if possible; it is guaranteed to be synchronous
43 * and doesn't cause a VMEXIT on Hypervisors
44 */
45 alternative_io(ASM_NOP3, ".byte 0x0f,0x01,0xf9", X86_FEATURE_RDTSCP,
46 ASM_OUTPUT2("=a" (eax), "=d" (edx)),
47 "a" (0U), "d" (0U) : "ecx", "memory");
48 ret = (((unsigned long long)edx) << 32) | ((unsigned long long)eax);
49 if (ret)
50 return ret;
51
52 /* 37 /*
53 * Don't do an additional sync on CPUs where we know 38 * We only do VDSOs on TSC capable CPUs, so this shouldnt
54 * RDTSC is already synchronous: 39 * access boot_cpu_data (which is not VDSO-safe):
55 */ 40 */
56 alternative_io("cpuid", ASM_NOP2, X86_FEATURE_SYNC_RDTSC, 41#ifndef CONFIG_X86_TSC
57 "=a" (eax), "0" (1) : "ebx","ecx","edx","memory"); 42 if (!cpu_has_tsc)
58 rdtscll(ret); 43 return 0;
59 44#endif
60 return ret; 45 return (cycles_t) __native_read_tsc();
61} 46}
62 47
63extern void tsc_init(void); 48extern void tsc_init(void);
@@ -73,8 +58,7 @@ int check_tsc_unstable(void);
73extern void check_tsc_sync_source(int cpu); 58extern void check_tsc_sync_source(int cpu);
74extern void check_tsc_sync_target(void); 59extern void check_tsc_sync_target(void);
75 60
76#ifdef CONFIG_X86_64
77extern void tsc_calibrate(void); 61extern void tsc_calibrate(void);
78#endif 62extern int notsc_setup(char *);
79 63
80#endif 64#endif