11 #elif defined(__FreeBSD__)
12 #include "os-freebsd.h"
13 #elif defined(__NetBSD__)
14 #include "os-netbsd.h"
15 #elif defined(__sun__)
16 #include "os-solaris.h"
17 #elif defined(__APPLE__)
23 #elif defined(__CYGWIN__)
24 #include "os-windows.h"
26 #error "unsupported os"
29 #ifdef FIO_HAVE_LIBAIO
33 #ifdef FIO_HAVE_POSIXAIO
35 #ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
36 typedef struct aiocb os_aiocb_t;
45 #ifndef FIO_HAVE_STRSEP
46 #include "../lib/strsep.h"
50 #define OS_MSG_DONTWAIT MSG_DONTWAIT
53 #ifndef FIO_HAVE_FADVISE
54 #define posix_fadvise(fd, off, len, advice) (0)
56 #ifndef POSIX_FADV_DONTNEED
57 #define POSIX_FADV_DONTNEED (0)
58 #define POSIX_FADV_SEQUENTIAL (0)
59 #define POSIX_FADV_RANDOM (0)
61 #endif /* FIO_HAVE_FADVISE */
63 #ifndef FIO_HAVE_CPU_AFFINITY
64 #define fio_setaffinity(pid, mask) (0)
65 #define fio_getaffinity(pid, mask) do { } while (0)
66 #define fio_cpu_clear(mask, cpu) do { } while (0)
67 #define fio_cpuset_exit(mask) (-1)
68 typedef unsigned long os_cpu_mask_t;
71 #ifndef FIO_HAVE_IOPRIO
72 #define ioprio_set(which, who, prio) (0)
75 #ifndef FIO_HAVE_ODIRECT
78 #define OS_O_DIRECT O_DIRECT
81 #ifndef FIO_HAVE_HUGETLB
84 #define FIO_HUGE_PAGE 0
88 #define FIO_HUGE_PAGE 4194304
93 #define FIO_O_NOATIME 0
97 #define OS_RAND_MAX RAND_MAX
100 #ifdef FIO_HAVE_CLOCK_MONOTONIC
101 #define FIO_TIMER_CLOCK CLOCK_MONOTONIC
103 #define FIO_TIMER_CLOCK CLOCK_REALTIME
106 #ifndef FIO_HAVE_RAWBIND
107 #define fio_lookup_raw(dev, majdev, mindev) 1
110 #ifndef FIO_PREFERRED_ENGINE
111 #define FIO_PREFERRED_ENGINE "sync"
115 #define FIO_MAX_JOBS 2048
118 #ifndef FIO_OS_HAVE_SOCKLEN_T
119 typedef socklen_t fio_socklen_t;
122 #ifdef FIO_USE_GENERIC_SWAP
123 static inline uint16_t fio_swap16(uint16_t val)
125 return (val << 8) | (val >> 8);
128 static inline uint32_t fio_swap32(uint32_t val)
130 val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
132 return (val >> 16) | (val << 16);
135 static inline uint64_t fio_swap64(uint64_t val)
137 val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
138 ((val & 0x00ff00ff00ff00ffULL) << 8);
139 val = ((val & 0xffff0000ffff0000ULL) >> 16) |
140 ((val & 0x0000ffff0000ffffULL) << 16);
142 return (val >> 32) | (val << 32);
146 #ifdef FIO_LITTLE_ENDIAN
147 #define __le16_to_cpu(x) (x)
148 #define __le32_to_cpu(x) (x)
149 #define __le64_to_cpu(x) (x)
150 #define __cpu_to_le16(x) (x)
151 #define __cpu_to_le32(x) (x)
152 #define __cpu_to_le64(x) (x)
154 #define __le16_to_cpu(x) fio_swap16(x)
155 #define __le32_to_cpu(x) fio_swap32(x)
156 #define __le64_to_cpu(x) fio_swap64(x)
157 #define __cpu_to_le16(x) fio_swap16(x)
158 #define __cpu_to_le32(x) fio_swap32(x)
159 #define __cpu_to_le64(x) fio_swap64(x)
162 #define le16_to_cpu(val) ({ \
163 uint16_t *__val = &(val); \
164 __le16_to_cpu(*__val); \
166 #define le32_to_cpu(val) ({ \
167 uint32_t *__val = &(val); \
168 __le32_to_cpu(*__val); \
170 #define le64_to_cpu(val) ({ \
171 uint64_t *__val = &(val); \
172 __le64_to_cpu(*__val); \
174 #define cpu_to_le16(val) ({ \
175 uint16_t *__val = &(val); \
176 __cpu_to_le16(*__val); \
178 #define cpu_to_le32(val) ({ \
179 uint32_t *__val = &(val); \
180 __cpu_to_le32(*__val); \
182 #define cpu_to_le64(val) ({ \
183 uint64_t *__val = &(val); \
184 __cpu_to_le64(*__val); \
187 #ifndef FIO_HAVE_BLKTRACE
188 static inline int is_blktrace(const char *fname)
193 static inline int load_blktrace(struct thread_data *td, const char *fname)
199 #define FIO_DEF_CL_SIZE 128
201 static inline int os_cache_line_size(void)
203 #ifdef FIO_HAVE_CL_SIZE
204 int ret = arch_cache_line_size();
207 return FIO_DEF_CL_SIZE;
211 return FIO_DEF_CL_SIZE;
215 #ifdef FIO_USE_GENERIC_BDEV_SIZE
216 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
222 end = lseek(f->fd, 0, SEEK_END);
231 #ifdef FIO_USE_GENERIC_RAND
232 typedef unsigned int os_random_state_t;
234 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
239 static inline long os_random_long(os_random_state_t *rs)
248 #ifndef FIO_HAVE_FS_STAT
249 static inline unsigned long long get_fs_size(const char *path)
255 #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
256 static inline unsigned int cpus_online(void)
258 return sysconf(_SC_NPROCESSORS_ONLN);
262 #ifndef FIO_HAVE_GETTID
263 static inline int gettid(void)