| 1 | #ifndef FIO_OS_H |
| 2 | #define FIO_OS_H |
| 3 | |
| 4 | #if defined(__linux__) |
| 5 | #include "os-linux.h" |
| 6 | #elif defined(__FreeBSD__) |
| 7 | #include "os-freebsd.h" |
| 8 | #elif defined(__sun__) |
| 9 | #include "os-solaris.h" |
| 10 | #elif defined(__APPLE__) |
| 11 | #include "os-mac.h" |
| 12 | #else |
| 13 | #error "unsupported os" |
| 14 | #endif |
| 15 | |
| 16 | #ifdef FIO_HAVE_LIBAIO |
| 17 | #include <libaio.h> |
| 18 | #endif |
| 19 | |
| 20 | #ifdef FIO_HAVE_POSIXAIO |
| 21 | #include <aio.h> |
| 22 | #endif |
| 23 | |
| 24 | #ifdef FIO_HAVE_SGIO |
| 25 | #include <linux/fs.h> |
| 26 | #include <scsi/sg.h> |
| 27 | #endif |
| 28 | |
| 29 | #ifndef FIO_HAVE_STRSEP |
| 30 | #include "../lib/strsep.h" |
| 31 | #endif |
| 32 | |
| 33 | #ifndef FIO_HAVE_FADVISE |
| 34 | #define fadvise(fd, off, len, advice) (0) |
| 35 | |
| 36 | #ifndef POSIX_FADV_DONTNEED |
| 37 | #define POSIX_FADV_DONTNEED (0) |
| 38 | #define POSIX_FADV_SEQUENTIAL (0) |
| 39 | #define POSIX_FADV_RANDOM (0) |
| 40 | #endif |
| 41 | #endif /* FIO_HAVE_FADVISE */ |
| 42 | |
| 43 | #ifndef FIO_HAVE_CPU_AFFINITY |
| 44 | #define fio_setaffinity(pid, mask) (0) |
| 45 | #define fio_getaffinity(pid, mask) do { } while (0) |
| 46 | #define fio_cpu_clear(mask, cpu) do { } while (0) |
| 47 | #define fio_cpuset_exit(mask) (-1) |
| 48 | #endif |
| 49 | |
| 50 | #ifndef FIO_HAVE_IOPRIO |
| 51 | #define ioprio_set(which, who, prio) (0) |
| 52 | #endif |
| 53 | |
| 54 | #ifndef FIO_HAVE_ODIRECT |
| 55 | #define OS_O_DIRECT 0 |
| 56 | #else |
| 57 | #define OS_O_DIRECT O_DIRECT |
| 58 | #endif |
| 59 | |
| 60 | #ifndef FIO_HAVE_HUGETLB |
| 61 | #define SHM_HUGETLB 0 |
| 62 | #ifndef FIO_HUGE_PAGE |
| 63 | #define FIO_HUGE_PAGE 0 |
| 64 | #endif |
| 65 | #else |
| 66 | #ifndef FIO_HUGE_PAGE |
| 67 | #define FIO_HUGE_PAGE 4194304 |
| 68 | #endif |
| 69 | #endif |
| 70 | |
| 71 | #ifndef FIO_O_NOATIME |
| 72 | #define FIO_O_NOATIME 0 |
| 73 | #endif |
| 74 | |
| 75 | #ifndef OS_RAND_MAX |
| 76 | #define OS_RAND_MAX RAND_MAX |
| 77 | #endif |
| 78 | |
| 79 | #ifndef FIO_HAVE_RAWBIND |
| 80 | #define fio_lookup_raw(dev, majdev, mindev) 1 |
| 81 | #endif |
| 82 | |
| 83 | #ifndef FIO_HAVE_BLKTRACE |
| 84 | static inline int is_blktrace(const char *fname) |
| 85 | { |
| 86 | return 0; |
| 87 | } |
| 88 | struct thread_data; |
| 89 | static inline int load_blktrace(struct thread_data *td, const char *fname) |
| 90 | { |
| 91 | return 1; |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #define FIO_DEF_CL_SIZE 128 |
| 96 | |
| 97 | static inline int os_cache_line_size(void) |
| 98 | { |
| 99 | #ifdef FIO_HAVE_CL_SIZE |
| 100 | int ret = arch_cache_line_size(); |
| 101 | |
| 102 | if (ret <= 0) |
| 103 | return FIO_DEF_CL_SIZE; |
| 104 | |
| 105 | return ret; |
| 106 | #else |
| 107 | return FIO_DEF_CL_SIZE; |
| 108 | #endif |
| 109 | } |
| 110 | |
| 111 | #ifdef FIO_USE_GENERIC_BDEV_SIZE |
| 112 | static inline int blockdev_size(int fd, unsigned long long *bytes) |
| 113 | { |
| 114 | off_t end; |
| 115 | |
| 116 | *bytes = 0; |
| 117 | |
| 118 | end = lseek(fd, 0, SEEK_END); |
| 119 | if (end < 0) |
| 120 | return errno; |
| 121 | |
| 122 | *bytes = end; |
| 123 | return 0; |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | #ifdef FIO_USE_GENERIC_RAND |
| 128 | typedef unsigned int os_random_state_t; |
| 129 | |
| 130 | static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) |
| 131 | { |
| 132 | srand(seed); |
| 133 | } |
| 134 | |
| 135 | static inline long os_random_long(os_random_state_t *rs) |
| 136 | { |
| 137 | long val; |
| 138 | |
| 139 | val = rand_r(rs); |
| 140 | return val; |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | #endif |