| 1 | #ifndef ARCH_X86_64_H |
| 2 | #define ARCH_X86_64_H |
| 3 | |
| 4 | #ifndef __NR_sys_io_uring_setup |
| 5 | #define __NR_sys_io_uring_setup 335 |
| 6 | #endif |
| 7 | #ifndef __NR_sys_io_uring_enter |
| 8 | #define __NR_sys_io_uring_enter 336 |
| 9 | #endif |
| 10 | #ifndef __NR_sys_io_uring_register |
| 11 | #define __NR_sys_io_uring_register 337 |
| 12 | #endif |
| 13 | |
| 14 | static inline void do_cpuid(unsigned int *eax, unsigned int *ebx, |
| 15 | unsigned int *ecx, unsigned int *edx) |
| 16 | { |
| 17 | asm volatile("cpuid" |
| 18 | : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) |
| 19 | : "0" (*eax), "2" (*ecx) |
| 20 | : "memory"); |
| 21 | } |
| 22 | |
| 23 | #include "arch-x86-common.h" /* IWYU pragma: export */ |
| 24 | |
| 25 | #define FIO_ARCH (arch_x86_64) |
| 26 | |
| 27 | #define FIO_HUGE_PAGE 2097152 |
| 28 | |
| 29 | #define nop __asm__ __volatile__("rep;nop": : :"memory") |
| 30 | #define read_barrier() __asm__ __volatile__("lfence":::"memory") |
| 31 | #define write_barrier() __asm__ __volatile__("sfence":::"memory") |
| 32 | |
| 33 | static inline unsigned long arch_ffz(unsigned long bitmask) |
| 34 | { |
| 35 | __asm__("bsf %1,%0" :"=r" (bitmask) :"r" (~bitmask)); |
| 36 | return bitmask; |
| 37 | } |
| 38 | |
| 39 | static inline unsigned long long get_cpu_clock(void) |
| 40 | { |
| 41 | unsigned int lo, hi; |
| 42 | |
| 43 | __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi)); |
| 44 | return ((unsigned long long) hi << 32ULL) | lo; |
| 45 | } |
| 46 | |
| 47 | #define ARCH_HAVE_FFZ |
| 48 | #define ARCH_HAVE_SSE4_2 |
| 49 | #define ARCH_HAVE_CPU_CLOCK |
| 50 | #define ARCH_HAVE_IOURING |
| 51 | |
| 52 | #define RDRAND_LONG ".byte 0x48,0x0f,0xc7,0xf0" |
| 53 | #define RDSEED_LONG ".byte 0x48,0x0f,0xc7,0xf8" |
| 54 | #define RDRAND_RETRY 100 |
| 55 | |
| 56 | static inline int arch_rand_long(unsigned long *val) |
| 57 | { |
| 58 | int ok; |
| 59 | |
| 60 | asm volatile("1: " RDRAND_LONG "\n\t" |
| 61 | "jc 2f\n\t" |
| 62 | "decl %0\n\t" |
| 63 | "jnz 1b\n\t" |
| 64 | "2:" |
| 65 | : "=r" (ok), "=a" (*val) |
| 66 | : "0" (RDRAND_RETRY)); |
| 67 | |
| 68 | return ok; |
| 69 | } |
| 70 | |
| 71 | static inline int arch_rand_seed(unsigned long *seed) |
| 72 | { |
| 73 | unsigned char ok; |
| 74 | |
| 75 | asm volatile(RDSEED_LONG "\n\t" |
| 76 | "setc %0" |
| 77 | : "=qm" (ok), "=a" (*seed)); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | #endif |