os.h should include headers it needs by itself
[fio.git] / os / os.h
1 #ifndef FIO_OS_H
2 #define FIO_OS_H
3
4 #include <sys/types.h>
5 #include <unistd.h>
6
7 #if defined(__linux__)
8 #include "os-linux.h"
9 #elif defined(__FreeBSD__)
10 #include "os-freebsd.h"
11 #elif defined(__sun__)
12 #include "os-solaris.h"
13 #elif defined(__APPLE__)
14 #include "os-mac.h"
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
32 #ifndef FIO_HAVE_STRSEP
33 #include "../lib/strsep.h"
34 #endif
35
36 #ifndef FIO_HAVE_FADVISE
37 #define fadvise(fd, off, len, advice)   (0)
38
39 #ifndef POSIX_FADV_DONTNEED
40 #define POSIX_FADV_DONTNEED     (0)
41 #define POSIX_FADV_SEQUENTIAL   (0)
42 #define POSIX_FADV_RANDOM       (0)
43 #endif
44 #endif /* FIO_HAVE_FADVISE */
45
46 #ifndef FIO_HAVE_CPU_AFFINITY
47 #define fio_setaffinity(pid, mask)      (0)
48 #define fio_getaffinity(pid, mask)      do { } while (0)
49 #define fio_cpu_clear(mask, cpu)        do { } while (0)
50 #define fio_cpuset_exit(mask)           (-1)
51 #endif
52
53 #ifndef FIO_HAVE_IOPRIO
54 #define ioprio_set(which, who, prio)    (0)
55 #endif
56
57 #ifndef FIO_HAVE_ODIRECT
58 #define OS_O_DIRECT                     0
59 #else
60 #define OS_O_DIRECT                     O_DIRECT
61 #endif
62
63 #ifndef FIO_HAVE_HUGETLB
64 #define SHM_HUGETLB                     0
65 #ifndef FIO_HUGE_PAGE
66 #define FIO_HUGE_PAGE                   0
67 #endif
68 #else
69 #ifndef FIO_HUGE_PAGE
70 #define FIO_HUGE_PAGE                   4194304
71 #endif
72 #endif
73
74 #ifndef FIO_O_NOATIME
75 #define FIO_O_NOATIME                   0
76 #endif
77
78 #ifndef OS_RAND_MAX
79 #define OS_RAND_MAX                     RAND_MAX
80 #endif
81
82 #ifndef FIO_HAVE_RAWBIND
83 #define fio_lookup_raw(dev, majdev, mindev)     1
84 #endif
85
86 #ifndef FIO_HAVE_BLKTRACE
87 static inline int is_blktrace(const char *fname)
88 {
89         return 0;
90 }
91 struct thread_data;
92 static inline int load_blktrace(struct thread_data *td, const char *fname)
93 {
94         return 1;
95 }
96 #endif
97
98 #define FIO_DEF_CL_SIZE         128
99
100 static 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
114 #ifdef FIO_USE_GENERIC_BDEV_SIZE
115 static inline int blockdev_size(int fd, unsigned long long *bytes)
116 {
117         off_t end;
118
119         *bytes = 0;
120
121         end = lseek(fd, 0, SEEK_END);
122         if (end < 0)
123                 return errno;
124
125         *bytes = end;
126         return 0;
127 }
128 #endif
129
130 #ifdef FIO_USE_GENERIC_RAND
131 typedef unsigned int os_random_state_t;
132
133 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
134 {
135         srand(seed);
136 }
137
138 static 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
147 #endif