tsc.h 1.3 KB
Newer Older
1
/*
T
Thomas Gleixner 已提交
2
 * x86 TSC related functions
3
 */
H
H. Peter Anvin 已提交
4 5
#ifndef _ASM_X86_TSC_H
#define _ASM_X86_TSC_H
6 7 8

#include <asm/processor.h>

T
Thomas Gleixner 已提交
9 10 11
#define NS_SCALE	10 /* 2^10, carefully chosen */
#define US_SCALE	32 /* 2^32, arbitralrily chosen */

12 13 14 15 16 17 18
/*
 * Standard way to access the cycle counter.
 */
typedef unsigned long long cycles_t;

extern unsigned int cpu_khz;
extern unsigned int tsc_khz;
19 20

extern void disable_TSC(void);
21 22 23 24 25 26 27 28 29 30

static inline cycles_t get_cycles(void)
{
	unsigned long long ret = 0;

#ifndef CONFIG_X86_TSC
	if (!cpu_has_tsc)
		return 0;
#endif
	rdtscll(ret);
I
Ingo Molnar 已提交
31

32 33 34
	return ret;
}

35
static __always_inline cycles_t vget_cycles(void)
36
{
37 38
	cycles_t cycles;

39
	/*
A
Andi Kleen 已提交
40 41
	 * We only do VDSOs on TSC capable CPUs, so this shouldnt
	 * access boot_cpu_data (which is not VDSO-safe):
42
	 */
A
Andi Kleen 已提交
43 44 45
#ifndef CONFIG_X86_TSC
	if (!cpu_has_tsc)
		return 0;
46
#endif
47 48 49 50 51
	rdtsc_barrier();
	cycles = (cycles_t)__native_read_tsc();
	rdtsc_barrier();

	return cycles;
A
Andi Kleen 已提交
52
}
53

54
extern void tsc_init(void);
55
extern void mark_tsc_unstable(char *reason);
56
extern int unsynchronized_tsc(void);
R
Rusty Russell 已提交
57
int check_tsc_unstable(void);
58 59 60 61 62 63 64 65

/*
 * Boot-time check whether the TSCs are synchronized across
 * all CPUs/cores:
 */
extern void check_tsc_sync_source(int cpu);
extern void check_tsc_sync_target(void);

66
extern int notsc_setup(char *);
67

H
H. Peter Anvin 已提交
68
#endif /* _ASM_X86_TSC_H */