Fix aiocb compile warnings on HPUX
[fio.git] / os / os.h
1 #ifndef FIO_OS_H
2 #define FIO_OS_H
3
4 #include <sys/types.h>
5 #include <pthread.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8
9 #if defined(__linux__)
10 #include "os-linux.h"
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__)
18 #include "os-mac.h"
19 #elif defined(_AIX)
20 #include "os-aix.h"
21 #elif defined(__hpux)
22 #include "os-hpux.h"
23 #elif defined(__CYGWIN__)
24 #include "os-windows.h"
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>
35 #ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
36 typedef struct aiocb os_aiocb_t;
37 #endif
38 #endif
39
40 #ifdef FIO_HAVE_SGIO
41 #include <linux/fs.h>
42 #include <scsi/sg.h>
43 #endif
44
45 #ifndef FIO_HAVE_STRSEP
46 #include "../lib/strsep.h"
47 #endif
48
49 #ifdef MSG_DONTWAIT
50 #define OS_MSG_DONTWAIT MSG_DONTWAIT
51 #endif
52
53 #ifndef FIO_HAVE_FADVISE
54 #define posix_fadvise(fd, off, len, advice)     (0)
55
56 #ifndef POSIX_FADV_DONTNEED
57 #define POSIX_FADV_DONTNEED     (0)
58 #define POSIX_FADV_SEQUENTIAL   (0)
59 #define POSIX_FADV_RANDOM       (0)
60 #endif
61 #endif /* FIO_HAVE_FADVISE */
62
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;
69 #endif
70
71 #ifndef FIO_HAVE_IOPRIO
72 #define ioprio_set(which, who, prio)    (0)
73 #endif
74
75 #ifndef FIO_HAVE_ODIRECT
76 #define OS_O_DIRECT                     0
77 #else
78 #define OS_O_DIRECT                     O_DIRECT
79 #endif
80
81 #ifndef FIO_HAVE_HUGETLB
82 #define SHM_HUGETLB                     0
83 #ifndef FIO_HUGE_PAGE
84 #define FIO_HUGE_PAGE                   0
85 #endif
86 #else
87 #ifndef FIO_HUGE_PAGE
88 #define FIO_HUGE_PAGE                   4194304
89 #endif
90 #endif
91
92 #ifndef FIO_O_NOATIME
93 #define FIO_O_NOATIME                   0
94 #endif
95
96 #ifndef OS_RAND_MAX
97 #define OS_RAND_MAX                     RAND_MAX
98 #endif
99
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
106 #ifndef FIO_HAVE_RAWBIND
107 #define fio_lookup_raw(dev, majdev, mindev)     1
108 #endif
109
110 #ifndef FIO_PREFERRED_ENGINE
111 #define FIO_PREFERRED_ENGINE    "sync"
112 #endif
113
114 #ifndef FIO_MAX_JOBS
115 #define FIO_MAX_JOBS            2048
116 #endif
117
118 #ifndef FIO_HAVE_BLKTRACE
119 static inline int is_blktrace(const char *fname)
120 {
121         return 0;
122 }
123 struct thread_data;
124 static inline int load_blktrace(struct thread_data *td, const char *fname)
125 {
126         return 1;
127 }
128 #endif
129
130 #define FIO_DEF_CL_SIZE         128
131
132 static inline int os_cache_line_size(void)
133 {
134 #ifdef FIO_HAVE_CL_SIZE
135         int ret = arch_cache_line_size();
136
137         if (ret <= 0)
138                 return FIO_DEF_CL_SIZE;
139
140         return ret;
141 #else
142         return FIO_DEF_CL_SIZE;
143 #endif
144 }
145
146 #ifdef FIO_USE_GENERIC_BDEV_SIZE
147 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
148 {
149         off_t end;
150
151         *bytes = 0;
152
153         end = lseek(f->fd, 0, SEEK_END);
154         if (end < 0)
155                 return errno;
156
157         *bytes = end;
158         return 0;
159 }
160 #endif
161
162 #ifdef FIO_USE_GENERIC_RAND
163 typedef unsigned int os_random_state_t;
164
165 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
166 {
167         srand(seed);
168 }
169
170 static inline long os_random_long(os_random_state_t *rs)
171 {
172         long val;
173
174         val = rand_r(rs);
175         return val;
176 }
177 #endif
178
179 #ifndef FIO_HAVE_FS_STAT
180 static inline unsigned long long get_fs_size(const char *path)
181 {
182         return 0;
183 }
184 #endif
185
186 #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
187 static inline unsigned int cpus_online(void)
188 {
189         return sysconf(_SC_NPROCESSORS_ONLN);
190 }
191 #endif
192
193 #ifndef FIO_HAVE_GETTID
194 static inline int gettid(void)
195 {
196         return getpid();
197 }
198 #endif
199
200 #endif