Define OS preferred IO engine
[fio.git] / os / os.h
... / ...
CommitLineData
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(__CYGWIN__)
22#include "os-windows.h"
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
40#ifndef FIO_HAVE_STRSEP
41#include "../lib/strsep.h"
42#endif
43
44#ifdef MSG_DONTWAIT
45#define OS_MSG_DONTWAIT MSG_DONTWAIT
46#endif
47
48#ifndef FIO_HAVE_FADVISE
49#define posix_fadvise(fd, off, len, advice) (0)
50
51#ifndef POSIX_FADV_DONTNEED
52#define POSIX_FADV_DONTNEED (0)
53#define POSIX_FADV_SEQUENTIAL (0)
54#define POSIX_FADV_RANDOM (0)
55#endif
56#endif /* FIO_HAVE_FADVISE */
57
58#ifndef FIO_HAVE_CPU_AFFINITY
59#define fio_setaffinity(pid, mask) (0)
60#define fio_getaffinity(pid, mask) do { } while (0)
61#define fio_cpu_clear(mask, cpu) do { } while (0)
62#define fio_cpuset_exit(mask) (-1)
63typedef unsigned long os_cpu_mask_t;
64#endif
65
66#ifndef FIO_HAVE_IOPRIO
67#define ioprio_set(which, who, prio) (0)
68#endif
69
70#ifndef FIO_HAVE_ODIRECT
71#define OS_O_DIRECT 0
72#else
73#define OS_O_DIRECT O_DIRECT
74#endif
75
76#ifndef FIO_HAVE_HUGETLB
77#define SHM_HUGETLB 0
78#ifndef FIO_HUGE_PAGE
79#define FIO_HUGE_PAGE 0
80#endif
81#else
82#ifndef FIO_HUGE_PAGE
83#define FIO_HUGE_PAGE 4194304
84#endif
85#endif
86
87#ifndef FIO_O_NOATIME
88#define FIO_O_NOATIME 0
89#endif
90
91#ifndef OS_RAND_MAX
92#define OS_RAND_MAX RAND_MAX
93#endif
94
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
101#ifndef FIO_HAVE_RAWBIND
102#define fio_lookup_raw(dev, majdev, mindev) 1
103#endif
104
105#ifndef FIO_PREFERRED_ENGINE
106#define FIO_PREFERRED_ENGINE "sync"
107#endif
108
109#ifndef FIO_HAVE_BLKTRACE
110static inline int is_blktrace(const char *fname)
111{
112 return 0;
113}
114struct thread_data;
115static inline int load_blktrace(struct thread_data *td, const char *fname)
116{
117 return 1;
118}
119#endif
120
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
137#ifdef FIO_USE_GENERIC_BDEV_SIZE
138static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
139{
140 off_t end;
141
142 *bytes = 0;
143
144 end = lseek(f->fd, 0, SEEK_END);
145 if (end < 0)
146 return errno;
147
148 *bytes = end;
149 return 0;
150}
151#endif
152
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
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
177#endif