Endian sanity check
[fio.git] / os / os.h
CommitLineData
ebac4655
JA
1#ifndef FIO_OS_H
2#define FIO_OS_H
3
a14ca44a 4#include <sys/types.h>
03e20d68 5#include <pthread.h>
a14ca44a 6#include <unistd.h>
ecc314ba 7#include <stdlib.h>
a14ca44a 8
ebac4655
JA
9#if defined(__linux__)
10#include "os-linux.h"
11#elif defined(__FreeBSD__)
12#include "os-freebsd.h"
7452440e
YT
13#elif defined(__NetBSD__)
14#include "os-netbsd.h"
2c0ecd28
JA
15#elif defined(__sun__)
16#include "os-solaris.h"
2afd826b
JA
17#elif defined(__APPLE__)
18#include "os-mac.h"
bf2e821a
CC
19#elif defined(_AIX)
20#include "os-aix.h"
c00a2289
JA
21#elif defined(__hpux)
22#include "os-hpux.h"
03e20d68
BC
23#elif defined(__CYGWIN__)
24#include "os-windows.h"
ebac4655
JA
25#else
26#error "unsupported os"
27#endif
28
29#ifdef FIO_HAVE_LIBAIO
30#include <libaio.h>
31#endif
32
33#ifdef FIO_HAVE_POSIXAIO
34#include <aio.h>
e97c1442
JA
35#ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
36typedef struct aiocb os_aiocb_t;
37#endif
ebac4655
JA
38#endif
39
40#ifdef FIO_HAVE_SGIO
41#include <linux/fs.h>
42#include <scsi/sg.h>
43#endif
44
5921e80c 45#ifndef FIO_HAVE_STRSEP
00fb3c8d 46#include "../lib/strsep.h"
5921e80c
JA
47#endif
48
8e239cae
JA
49#ifdef MSG_DONTWAIT
50#define OS_MSG_DONTWAIT MSG_DONTWAIT
51#endif
52
ebac4655 53#ifndef FIO_HAVE_FADVISE
ecc314ba 54#define posix_fadvise(fd, off, len, advice) (0)
ebac4655 55
4d8947de 56#ifndef POSIX_FADV_DONTNEED
ebac4655
JA
57#define POSIX_FADV_DONTNEED (0)
58#define POSIX_FADV_SEQUENTIAL (0)
59#define POSIX_FADV_RANDOM (0)
4d8947de 60#endif
ebac4655
JA
61#endif /* FIO_HAVE_FADVISE */
62
63#ifndef FIO_HAVE_CPU_AFFINITY
e8462bd8 64#define fio_setaffinity(pid, mask) (0)
be4ecfdf
JA
65#define fio_getaffinity(pid, mask) do { } while (0)
66#define fio_cpu_clear(mask, cpu) do { } while (0)
85daf2c1 67#define fio_cpuset_exit(mask) (-1)
7452440e 68typedef unsigned long os_cpu_mask_t;
ebac4655
JA
69#endif
70
71#ifndef FIO_HAVE_IOPRIO
72#define ioprio_set(which, who, prio) (0)
73#endif
74
2c0ecd28 75#ifndef FIO_HAVE_ODIRECT
7d424763
JA
76#define OS_O_DIRECT 0
77#else
78#define OS_O_DIRECT O_DIRECT
2c0ecd28
JA
79#endif
80
74b025b0
JA
81#ifndef FIO_HAVE_HUGETLB
82#define SHM_HUGETLB 0
4d8947de 83#ifndef FIO_HUGE_PAGE
74b025b0 84#define FIO_HUGE_PAGE 0
4d8947de 85#endif
74b025b0 86#else
cb25df61 87#ifndef FIO_HUGE_PAGE
ee0e0a71 88#define FIO_HUGE_PAGE 4194304
74b025b0 89#endif
cb25df61 90#endif
74b025b0 91
5921e80c
JA
92#ifndef FIO_O_NOATIME
93#define FIO_O_NOATIME 0
94#endif
95
dc873b6f
JA
96#ifndef OS_RAND_MAX
97#define OS_RAND_MAX RAND_MAX
98#endif
99
ecc314ba
BC
100#ifdef FIO_HAVE_CLOCK_MONOTONIC
101#define FIO_TIMER_CLOCK CLOCK_MONOTONIC
102#else
103#define FIO_TIMER_CLOCK CLOCK_REALTIME
104#endif
105
07e5b264 106#ifndef FIO_HAVE_RAWBIND
8cc7afa9 107#define fio_lookup_raw(dev, majdev, mindev) 1
07e5b264
JA
108#endif
109
58483fa4
JA
110#ifndef FIO_PREFERRED_ENGINE
111#define FIO_PREFERRED_ENGINE "sync"
112#endif
113
fca70358
JA
114#ifndef FIO_MAX_JOBS
115#define FIO_MAX_JOBS 2048
116#endif
117
5ba13ea6
JA
118#ifndef FIO_OS_HAVE_SOCKLEN_T
119typedef socklen_t fio_socklen_t;
120#endif
121
901ebe18 122#ifdef FIO_USE_GENERIC_SWAP
9677bec3 123static inline uint16_t fio_swap16(uint16_t val)
232f9b73
JA
124{
125 return (val << 8) | (val >> 8);
126}
127
901ebe18 128static inline uint32_t fio_swap32(uint32_t val)
232f9b73
JA
129{
130 val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
131
132 return (val >> 16) | (val << 16);
133}
134
901ebe18 135static inline uint64_t fio_swap64(uint64_t val)
232f9b73
JA
136{
137 val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
138 ((val & 0x00ff00ff00ff00ffULL) << 8);
139 val = ((val & 0xffff0000ffff0000ULL) >> 16) |
140 ((val & 0x0000ffff0000ffffULL) << 16);
141
142 return (val >> 32) | (val << 32);
143}
144#endif
145
5e62c22a
JA
146#ifndef FIO_HAVE_BLKTRACE
147static inline int is_blktrace(const char *fname)
148{
149 return 0;
150}
5921e80c 151struct thread_data;
5e62c22a
JA
152static inline int load_blktrace(struct thread_data *td, const char *fname)
153{
154 return 1;
155}
156#endif
157
eb7ccf38
JA
158#define FIO_DEF_CL_SIZE 128
159
160static inline int os_cache_line_size(void)
161{
162#ifdef FIO_HAVE_CL_SIZE
163 int ret = arch_cache_line_size();
164
165 if (ret <= 0)
166 return FIO_DEF_CL_SIZE;
167
168 return ret;
169#else
170 return FIO_DEF_CL_SIZE;
171#endif
172}
173
792d5517 174#ifdef FIO_USE_GENERIC_BDEV_SIZE
ecc314ba 175static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
792d5517 176{
3b2e1464 177 off_t end;
792d5517 178
3b2e1464
JA
179 *bytes = 0;
180
ecc314ba 181 end = lseek(f->fd, 0, SEEK_END);
792d5517
JA
182 if (end < 0)
183 return errno;
184
185 *bytes = end;
186 return 0;
187}
188#endif
189
53531370
JA
190#ifdef FIO_USE_GENERIC_RAND
191typedef unsigned int os_random_state_t;
192
193static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
194{
195 srand(seed);
196}
197
198static inline long os_random_long(os_random_state_t *rs)
199{
200 long val;
201
202 val = rand_r(rs);
203 return val;
204}
205#endif
206
2e3bd4c2
JA
207#ifndef FIO_HAVE_FS_STAT
208static inline unsigned long long get_fs_size(const char *path)
209{
210 return 0;
211}
212#endif
213
c00a2289
JA
214#ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
215static inline unsigned int cpus_online(void)
216{
217 return sysconf(_SC_NPROCESSORS_ONLN);
218}
219#endif
220
47f767c1
JA
221#ifndef FIO_HAVE_GETTID
222static inline int gettid(void)
223{
224 return getpid();
225}
226#endif
227
ebac4655 228#endif