fio: ioengine flag cleanup
[fio.git] / arch / arch-x86-common.h
CommitLineData
fa80feae
JA
1#ifndef FIO_ARCH_X86_COMMON
2#define FIO_ARCH_X86_COMMON
3
7189c969
JA
4#include <string.h>
5
7189c969
JA
6static inline void cpuid(unsigned int op,
7 unsigned int *eax, unsigned int *ebx,
8 unsigned int *ecx, unsigned int *edx)
9{
10 *eax = op;
11 *ecx = 0;
12 do_cpuid(eax, ebx, ecx, edx);
13}
14
fa80feae 15#define ARCH_HAVE_INIT
7189c969 16
24575392 17extern bool tsc_reliable;
16dc0710 18extern int arch_random;
7189c969 19
ce892609 20static inline void arch_init_intel(void)
fa80feae 21{
267339ff 22 unsigned int eax, ebx, ecx = 0, edx;
fa80feae
JA
23
24 /*
25 * Check for TSC
26 */
27 eax = 1;
28 do_cpuid(&eax, &ebx, &ecx, &edx);
29 if (!(edx & (1U << 4)))
16dc0710 30 return;
fa80feae
JA
31
32 /*
33 * Check for constant rate and synced (across cores) TSC
34 */
35 eax = 0x80000007;
36 do_cpuid(&eax, &ebx, &ecx, &edx);
16dc0710
JA
37 tsc_reliable = (edx & (1U << 8)) != 0;
38
39 /*
40 * Check for FDRAND
41 */
42 eax = 0x1;
43 do_cpuid(&eax, &ebx, &ecx, &edx);
44 arch_random = (ecx & (1U << 30)) != 0;
7189c969
JA
45}
46
ce892609 47static inline void arch_init_amd(void)
7189c969
JA
48{
49 unsigned int eax, ebx, ecx, edx;
50
51 cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
52 if (eax < 0x80000007)
16dc0710 53 return;
7189c969
JA
54
55 cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
16dc0710 56 tsc_reliable = (edx & (1U << 8)) != 0;
7189c969
JA
57}
58
16dc0710 59static inline void arch_init(char *envp[])
7189c969
JA
60{
61 unsigned int level;
81fa6e06 62 char str[13];
7189c969 63
16dc0710
JA
64 arch_random = tsc_reliable = 0;
65
7189c969
JA
66 cpuid(0, &level, (unsigned int *) &str[0],
67 (unsigned int *) &str[8],
68 (unsigned int *) &str[4]);
69
81fa6e06 70 str[12] = '\0';
7189c969 71 if (!strcmp(str, "GenuineIntel"))
ce892609 72 arch_init_intel();
c3e028ca 73 else if (!strcmp(str, "AuthenticAMD") || !strcmp(str, "HygonGenuine"))
ce892609 74 arch_init_amd();
fa80feae
JA
75}
76
77#endif