Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 1 | /* |
Thomas Gleixner | 2f0798a | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 2 | * x86 TSC related functions |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 3 | */ |
Thomas Gleixner | 2f0798a | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 4 | #ifndef _ASM_X86_TSC_H |
| 5 | #define _ASM_X86_TSC_H |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 6 | |
| 7 | #include <asm/processor.h> |
| 8 | |
Thomas Gleixner | 2f0798a | 2007-10-12 23:04:23 +0200 | [diff] [blame] | 9 | #define NS_SCALE 10 /* 2^10, carefully chosen */ |
| 10 | #define US_SCALE 32 /* 2^32, arbitralrily chosen */ |
| 11 | |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 12 | /* |
| 13 | * Standard way to access the cycle counter. |
| 14 | */ |
| 15 | typedef unsigned long long cycles_t; |
| 16 | |
| 17 | extern unsigned int cpu_khz; |
| 18 | extern unsigned int tsc_khz; |
Glauber de Oliveira Costa | 73018a6 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 19 | /* flag for disabling the tsc */ |
| 20 | extern int tsc_disable; |
| 21 | |
| 22 | extern void disable_TSC(void); |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 23 | |
| 24 | static inline cycles_t get_cycles(void) |
| 25 | { |
| 26 | unsigned long long ret = 0; |
| 27 | |
| 28 | #ifndef CONFIG_X86_TSC |
| 29 | if (!cpu_has_tsc) |
| 30 | return 0; |
| 31 | #endif |
| 32 | |
| 33 | #if defined(CONFIG_X86_GENERIC) || defined(CONFIG_X86_TSC) |
| 34 | rdtscll(ret); |
| 35 | #endif |
| 36 | return ret; |
| 37 | } |
| 38 | |
Andi Kleen | 6d63de8 | 2008-01-30 13:32:39 +0100 | [diff] [blame^] | 39 | static inline cycles_t vget_cycles(void) |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 40 | { |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 41 | /* |
Andi Kleen | 6d63de8 | 2008-01-30 13:32:39 +0100 | [diff] [blame^] | 42 | * We only do VDSOs on TSC capable CPUs, so this shouldnt |
| 43 | * access boot_cpu_data (which is not VDSO-safe): |
Andi Kleen | c5bcb56 | 2007-05-02 19:27:21 +0200 | [diff] [blame] | 44 | */ |
Andi Kleen | 6d63de8 | 2008-01-30 13:32:39 +0100 | [diff] [blame^] | 45 | #ifndef CONFIG_X86_TSC |
| 46 | if (!cpu_has_tsc) |
| 47 | return 0; |
Glauber de Oliveira Costa | 4e87173 | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 48 | #endif |
Andi Kleen | 6d63de8 | 2008-01-30 13:32:39 +0100 | [diff] [blame^] | 49 | return (cycles_t) native_read_tsc(); |
| 50 | } |
Glauber de Oliveira Costa | 4e87173 | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 51 | |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 52 | extern void tsc_init(void); |
john stultz | 5a90cf2 | 2007-05-02 19:27:08 +0200 | [diff] [blame] | 53 | extern void mark_tsc_unstable(char *reason); |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 54 | extern int unsynchronized_tsc(void); |
| 55 | extern void init_tsc_clocksource(void); |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 56 | int check_tsc_unstable(void); |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Boot-time check whether the TSCs are synchronized across |
| 60 | * all CPUs/cores: |
| 61 | */ |
| 62 | extern void check_tsc_sync_source(int cpu); |
| 63 | extern void check_tsc_sync_target(void); |
| 64 | |
Thomas Gleixner | d371698 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 65 | extern void tsc_calibrate(void); |
Thomas Gleixner | 80ca9c9 | 2008-01-30 13:30:18 +0100 | [diff] [blame] | 66 | extern int notsc_setup(char *); |
Thomas Gleixner | d371698 | 2007-10-12 23:04:06 +0200 | [diff] [blame] | 67 | |
Andres Salomon | 2272b0e | 2007-03-06 01:42:05 -0800 | [diff] [blame] | 68 | #endif |