| 1 | #ifndef FIO_ARCH_X86_COMMON |
| 2 | #define FIO_ARCH_X86_COMMON |
| 3 | |
| 4 | #include <string.h> |
| 5 | |
| 6 | #ifndef __NR_sys_io_uring_setup |
| 7 | #define __NR_sys_io_uring_setup 425 |
| 8 | #endif |
| 9 | #ifndef __NR_sys_io_uring_enter |
| 10 | #define __NR_sys_io_uring_enter 426 |
| 11 | #endif |
| 12 | #ifndef __NR_sys_io_uring_register |
| 13 | #define __NR_sys_io_uring_register 427 |
| 14 | #endif |
| 15 | |
| 16 | static inline void cpuid(unsigned int op, |
| 17 | unsigned int *eax, unsigned int *ebx, |
| 18 | unsigned int *ecx, unsigned int *edx) |
| 19 | { |
| 20 | *eax = op; |
| 21 | *ecx = 0; |
| 22 | do_cpuid(eax, ebx, ecx, edx); |
| 23 | } |
| 24 | |
| 25 | #define ARCH_HAVE_INIT |
| 26 | #define ARCH_HAVE_IOURING |
| 27 | |
| 28 | extern bool tsc_reliable; |
| 29 | extern int arch_random; |
| 30 | |
| 31 | static inline void arch_init_intel(void) |
| 32 | { |
| 33 | unsigned int eax, ebx, ecx = 0, edx; |
| 34 | |
| 35 | /* |
| 36 | * Check for TSC |
| 37 | */ |
| 38 | eax = 1; |
| 39 | do_cpuid(&eax, &ebx, &ecx, &edx); |
| 40 | if (!(edx & (1U << 4))) |
| 41 | return; |
| 42 | |
| 43 | /* |
| 44 | * Check for constant rate and synced (across cores) TSC |
| 45 | */ |
| 46 | eax = 0x80000007; |
| 47 | do_cpuid(&eax, &ebx, &ecx, &edx); |
| 48 | tsc_reliable = (edx & (1U << 8)) != 0; |
| 49 | |
| 50 | /* |
| 51 | * Check for FDRAND |
| 52 | */ |
| 53 | eax = 0x1; |
| 54 | do_cpuid(&eax, &ebx, &ecx, &edx); |
| 55 | arch_random = (ecx & (1U << 30)) != 0; |
| 56 | } |
| 57 | |
| 58 | static inline void arch_init_amd(void) |
| 59 | { |
| 60 | unsigned int eax, ebx, ecx, edx; |
| 61 | |
| 62 | cpuid(0x80000000, &eax, &ebx, &ecx, &edx); |
| 63 | if (eax < 0x80000007) |
| 64 | return; |
| 65 | |
| 66 | cpuid(0x80000007, &eax, &ebx, &ecx, &edx); |
| 67 | tsc_reliable = (edx & (1U << 8)) != 0; |
| 68 | } |
| 69 | |
| 70 | static inline void arch_init(char *envp[]) |
| 71 | { |
| 72 | unsigned int level; |
| 73 | char str[13]; |
| 74 | |
| 75 | arch_random = tsc_reliable = 0; |
| 76 | |
| 77 | cpuid(0, &level, (unsigned int *) &str[0], |
| 78 | (unsigned int *) &str[8], |
| 79 | (unsigned int *) &str[4]); |
| 80 | |
| 81 | str[12] = '\0'; |
| 82 | if (!strcmp(str, "GenuineIntel")) |
| 83 | arch_init_intel(); |
| 84 | else if (!strcmp(str, "AuthenticAMD")) |
| 85 | arch_init_amd(); |
| 86 | } |
| 87 | |
| 88 | #endif |