Define OS preferred IO engine
[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"
03e20d68
BC
21#elif defined(__CYGWIN__)
22#include "os-windows.h"
ebac4655
JA
23#else
24#error "unsupported os"
25#endif
26
27#ifdef FIO_HAVE_LIBAIO
28#include <libaio.h>
29#endif
30
31#ifdef FIO_HAVE_POSIXAIO
32#include <aio.h>
33#endif
34
35#ifdef FIO_HAVE_SGIO
36#include <linux/fs.h>
37#include <scsi/sg.h>
38#endif
39
5921e80c 40#ifndef FIO_HAVE_STRSEP
00fb3c8d 41#include "../lib/strsep.h"
5921e80c
JA
42#endif
43
8e239cae
JA
44#ifdef MSG_DONTWAIT
45#define OS_MSG_DONTWAIT MSG_DONTWAIT
46#endif
47
ebac4655 48#ifndef FIO_HAVE_FADVISE
ecc314ba 49#define posix_fadvise(fd, off, len, advice) (0)
ebac4655 50
4d8947de 51#ifndef POSIX_FADV_DONTNEED
ebac4655
JA
52#define POSIX_FADV_DONTNEED (0)
53#define POSIX_FADV_SEQUENTIAL (0)
54#define POSIX_FADV_RANDOM (0)
4d8947de 55#endif
ebac4655
JA
56#endif /* FIO_HAVE_FADVISE */
57
58#ifndef FIO_HAVE_CPU_AFFINITY
e8462bd8 59#define fio_setaffinity(pid, mask) (0)
be4ecfdf
JA
60#define fio_getaffinity(pid, mask) do { } while (0)
61#define fio_cpu_clear(mask, cpu) do { } while (0)
85daf2c1 62#define fio_cpuset_exit(mask) (-1)
7452440e 63typedef unsigned long os_cpu_mask_t;
ebac4655
JA
64#endif
65
66#ifndef FIO_HAVE_IOPRIO
67#define ioprio_set(which, who, prio) (0)
68#endif
69
2c0ecd28 70#ifndef FIO_HAVE_ODIRECT
7d424763
JA
71#define OS_O_DIRECT 0
72#else
73#define OS_O_DIRECT O_DIRECT
2c0ecd28
JA
74#endif
75
74b025b0
JA
76#ifndef FIO_HAVE_HUGETLB
77#define SHM_HUGETLB 0
4d8947de 78#ifndef FIO_HUGE_PAGE
74b025b0 79#define FIO_HUGE_PAGE 0
4d8947de 80#endif
74b025b0 81#else
cb25df61 82#ifndef FIO_HUGE_PAGE
ee0e0a71 83#define FIO_HUGE_PAGE 4194304
74b025b0 84#endif
cb25df61 85#endif
74b025b0 86
5921e80c
JA
87#ifndef FIO_O_NOATIME
88#define FIO_O_NOATIME 0
89#endif
90
dc873b6f
JA
91#ifndef OS_RAND_MAX
92#define OS_RAND_MAX RAND_MAX
93#endif
94
ecc314ba
BC
95#ifdef FIO_HAVE_CLOCK_MONOTONIC
96#define FIO_TIMER_CLOCK CLOCK_MONOTONIC
97#else
98#define FIO_TIMER_CLOCK CLOCK_REALTIME
99#endif
100
07e5b264 101#ifndef FIO_HAVE_RAWBIND
8cc7afa9 102#define fio_lookup_raw(dev, majdev, mindev) 1
07e5b264
JA
103#endif
104
58483fa4
JA
105#ifndef FIO_PREFERRED_ENGINE
106#define FIO_PREFERRED_ENGINE "sync"
107#endif
108
5e62c22a
JA
109#ifndef FIO_HAVE_BLKTRACE
110static inline int is_blktrace(const char *fname)
111{
112 return 0;
113}
5921e80c 114struct thread_data;
5e62c22a
JA
115static inline int load_blktrace(struct thread_data *td, const char *fname)
116{
117 return 1;
118}
119#endif
120
eb7ccf38
JA
121#define FIO_DEF_CL_SIZE 128
122
123static inline int os_cache_line_size(void)
124{
125#ifdef FIO_HAVE_CL_SIZE
126 int ret = arch_cache_line_size();
127
128 if (ret <= 0)
129 return FIO_DEF_CL_SIZE;
130
131 return ret;
132#else
133 return FIO_DEF_CL_SIZE;
134#endif
135}
136
792d5517 137#ifdef FIO_USE_GENERIC_BDEV_SIZE
ecc314ba 138static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
792d5517 139{
3b2e1464 140 off_t end;
792d5517 141
3b2e1464
JA
142 *bytes = 0;
143
ecc314ba 144 end = lseek(f->fd, 0, SEEK_END);
792d5517
JA
145 if (end < 0)
146 return errno;
147
148 *bytes = end;
149 return 0;
150}
151#endif
152
53531370
JA
153#ifdef FIO_USE_GENERIC_RAND
154typedef unsigned int os_random_state_t;
155
156static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
157{
158 srand(seed);
159}
160
161static inline long os_random_long(os_random_state_t *rs)
162{
163 long val;
164
165 val = rand_r(rs);
166 return val;
167}
168#endif
169
2e3bd4c2
JA
170#ifndef FIO_HAVE_FS_STAT
171static inline unsigned long long get_fs_size(const char *path)
172{
173 return 0;
174}
175#endif
176
ebac4655 177#endif