summaryrefslogtreecommitdiff
path: root/arch/arch-x86-common.h
blob: 1e62354418c01d41e5bc2bf975617fbad314d315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef FIO_ARCH_X86_COMMON
#define FIO_ARCH_X86_COMMON

static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
			    unsigned int *ecx, unsigned int *edx)
{
	unsigned int id = *eax;

	asm("movl %4, %%eax;"
	    "cpuid;"
	    "movl %%eax, %0;"
	    "movl %%ebx, %1;"
	    "movl %%ecx, %2;"
	    "movl %%edx, %3;"
		: "=r" (*eax), "=r" (*ebx), "=r" (*ecx), "=r" (*edx)
		: "r" (id)
		: "eax", "ebx", "ecx", "edx");
}

#define ARCH_HAVE_INIT
extern int tsc_reliable;
static inline int arch_init(char *envp[])
{
	unsigned int eax, ebx, ecx, edx;

	/*
	 * Check for TSC
	 */
	eax = 1;
	do_cpuid(&eax, &ebx, &ecx, &edx);
	if (!(edx & (1U << 4)))
		return 0;

	/*
	 * Check for constant rate and synced (across cores) TSC
	 */
	eax = 0x80000007;
	do_cpuid(&eax, &ebx, &ecx, &edx);
	tsc_reliable = edx & (1U << 8);
	return 0;
}

#endif