os.h revision fca7035863bd570270376a0c06776e5549ff813e
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_MAX_JOBS
110#define FIO_MAX_JOBS		2048
111#endif
112
113#ifndef FIO_HAVE_BLKTRACE
114static inline int is_blktrace(const char *fname)
115{
116	return 0;
117}
118struct thread_data;
119static inline int load_blktrace(struct thread_data *td, const char *fname)
120{
121	return 1;
122}
123#endif
124
125#define FIO_DEF_CL_SIZE		128
126
127static inline int os_cache_line_size(void)
128{
129#ifdef FIO_HAVE_CL_SIZE
130	int ret = arch_cache_line_size();
131
132	if (ret <= 0)
133		return FIO_DEF_CL_SIZE;
134
135	return ret;
136#else
137	return FIO_DEF_CL_SIZE;
138#endif
139}
140
141#ifdef FIO_USE_GENERIC_BDEV_SIZE
142static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
143{
144	off_t end;
145
146	*bytes = 0;
147
148	end = lseek(f->fd, 0, SEEK_END);
149	if (end < 0)
150		return errno;
151
152	*bytes = end;
153	return 0;
154}
155#endif
156
157#ifdef FIO_USE_GENERIC_RAND
158typedef unsigned int os_random_state_t;
159
160static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
161{
162	srand(seed);
163}
164
165static inline long os_random_long(os_random_state_t *rs)
166{
167	long val;
168
169	val = rand_r(rs);
170	return val;
171}
172#endif
173
174#ifndef FIO_HAVE_FS_STAT
175static inline unsigned long long get_fs_size(const char *path)
176{
177	return 0;
178}
179#endif
180
181#endif
182