tsc.h 1.16 KB
Newer Older
1
/*
Thomas Gleixner's avatar
Thomas Gleixner committed
2
 * x86 TSC related functions
3
 */
Thomas Gleixner's avatar
Thomas Gleixner committed
4 5
#ifndef _ASM_X86_TSC_H
#define _ASM_X86_TSC_H
6 7 8

#include <asm/processor.h>

Thomas Gleixner's avatar
Thomas Gleixner committed
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);
Ingo Molnar's avatar
Ingo Molnar committed
31

32 33 34
	return ret;
}

35
static __always_inline cycles_t vget_cycles(void)
36
{
37
	/*
Andi Kleen's avatar
Andi Kleen committed
38 39
	 * We only do VDSOs on TSC capable CPUs, so this shouldnt
	 * access boot_cpu_data (which is not VDSO-safe):
40
	 */
Andi Kleen's avatar
Andi Kleen committed
41 42 43
#ifndef CONFIG_X86_TSC
	if (!cpu_has_tsc)
		return 0;
44
#endif
45
	return (cycles_t)__native_read_tsc();
Andi Kleen's avatar
Andi Kleen committed
46
}
47

48
extern void tsc_init(void);
49
extern void mark_tsc_unstable(char *reason);
50
extern int unsynchronized_tsc(void);
Rusty Russell's avatar
Rusty Russell committed
51
int check_tsc_unstable(void);
52 53 54 55 56 57 58 59

/*
 * 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);

60
extern int notsc_setup(char *);
61

62
#endif