blob: 0434bd8349a7456f27f8ca95c18b472e07c1ba8e [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 */
Thomas Gleixner2f0798a2007-10-12 23:04:23 +02004#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);
Erik Bosman529e25f2008-04-14 00:24:18 +020021extern void enable_TSC(void);
Andres Salomon2272b0e2007-03-06 01:42:05 -080022
23static inline cycles_t get_cycles(void)
24{
25 unsigned long long ret = 0;
26
27#ifndef CONFIG_X86_TSC
28 if (!cpu_has_tsc)
29 return 0;
30#endif
Andres Salomon2272b0e2007-03-06 01:42:05 -080031 rdtscll(ret);
Ingo Molnar75f2ce02008-01-30 13:33:24 +010032
Andres Salomon2272b0e2007-03-06 01:42:05 -080033 return ret;
34}
35
Andi Kleen6d63de82008-01-30 13:32:39 +010036static inline cycles_t vget_cycles(void)
Andres Salomon2272b0e2007-03-06 01:42:05 -080037{
Andres Salomon2272b0e2007-03-06 01:42:05 -080038 /*
Andi Kleen6d63de82008-01-30 13:32:39 +010039 * We only do VDSOs on TSC capable CPUs, so this shouldnt
40 * access boot_cpu_data (which is not VDSO-safe):
Andi Kleenc5bcb562007-05-02 19:27:21 +020041 */
Andi Kleen6d63de82008-01-30 13:32:39 +010042#ifndef CONFIG_X86_TSC
43 if (!cpu_has_tsc)
44 return 0;
Glauber de Oliveira Costa4e871732008-01-30 13:31:03 +010045#endif
Joe Perches2d86e632008-03-23 01:03:47 -070046 return (cycles_t)__native_read_tsc();
Andi Kleen6d63de82008-01-30 13:32:39 +010047}
Glauber de Oliveira Costa4e871732008-01-30 13:31:03 +010048
Andres Salomon2272b0e2007-03-06 01:42:05 -080049extern void tsc_init(void);
john stultz5a90cf22007-05-02 19:27:08 +020050extern void mark_tsc_unstable(char *reason);
Andres Salomon2272b0e2007-03-06 01:42:05 -080051extern int unsynchronized_tsc(void);
52extern void init_tsc_clocksource(void);
Rusty Russelld7e28ff2007-07-19 01:49:23 -070053int check_tsc_unstable(void);
Andres Salomon2272b0e2007-03-06 01:42:05 -080054
55/*
56 * Boot-time check whether the TSCs are synchronized across
57 * all CPUs/cores:
58 */
59extern void check_tsc_sync_source(int cpu);
60extern void check_tsc_sync_target(void);
61
Thomas Gleixnerd3716982007-10-12 23:04:06 +020062extern void tsc_calibrate(void);
Thomas Gleixner80ca9c92008-01-30 13:30:18 +010063extern int notsc_setup(char *);
Thomas Gleixnerd3716982007-10-12 23:04:06 +020064
Andres Salomon2272b0e2007-03-06 01:42:05 -080065#endif