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