tsc.h 1.5 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
	/*
L
Lucas De Marchi 已提交
38
	 * We only do VDSOs on TSC capable CPUs, so this shouldn't
A
Andi Kleen 已提交
39
	 * access boot_cpu_data (which is not VDSO-safe):
40
	 */
A
Andi Kleen 已提交
41 42 43
#ifndef CONFIG_X86_TSC
	if (!cpu_has_tsc)
		return 0;
44
#endif
I
Ingo Molnar 已提交
45
	return (cycles_t)__native_read_tsc();
A
Andi Kleen 已提交
46
}
47

48
extern void tsc_init(void);
49
extern void mark_tsc_unstable(char *reason);
50
extern int unsynchronized_tsc(void);
51
extern int check_tsc_unstable(void);
52
extern int check_tsc_disabled(void);
53
extern unsigned long native_calibrate_tsc(void);
54

55 56
extern int tsc_clocksource_reliable;

57 58 59 60 61 62 63
/*
 * 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);

64
extern int notsc_setup(char *);
65 66
extern void tsc_save_sched_clock_state(void);
extern void tsc_restore_sched_clock_state(void);
67

68 69 70
/* MSR based TSC calibration for Intel Atom SoC platforms */
int try_msr_calibrate_tsc(unsigned long *fast_calibrate);

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