Not all platforms have MSG_DONTWAIT
[fio.git] / os / os.h
... / ...
CommitLineData
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(__NetBSD__)
12#include "os-netbsd.h"
13#elif defined(__sun__)
14#include "os-solaris.h"
15#elif defined(__APPLE__)
16#include "os-mac.h"
17#else
18#error "unsupported os"
19#endif
20
21#ifdef FIO_HAVE_LIBAIO
22#include <libaio.h>
23#endif
24
25#ifdef FIO_HAVE_POSIXAIO
26#include <aio.h>
27#endif
28
29#ifdef FIO_HAVE_SGIO
30#include <linux/fs.h>
31#include <scsi/sg.h>
32#endif
33
34#ifndef FIO_HAVE_STRSEP
35#include "../lib/strsep.h"
36#endif
37
38#ifndef FIO_HAVE_FADVISE
39#define fadvise(fd, off, len, advice) (0)
40
41#ifndef POSIX_FADV_DONTNEED
42#define POSIX_FADV_DONTNEED (0)
43#define POSIX_FADV_SEQUENTIAL (0)
44#define POSIX_FADV_RANDOM (0)
45#endif
46#endif /* FIO_HAVE_FADVISE */
47
48#ifndef FIO_HAVE_CPU_AFFINITY
49#define fio_setaffinity(pid, mask) (0)
50#define fio_getaffinity(pid, mask) do { } while (0)
51#define fio_cpu_clear(mask, cpu) do { } while (0)
52#define fio_cpuset_exit(mask) (-1)
53typedef unsigned long os_cpu_mask_t;
54#endif
55
56#ifndef FIO_HAVE_IOPRIO
57#define ioprio_set(which, who, prio) (0)
58#endif
59
60#ifndef FIO_HAVE_ODIRECT
61#define OS_O_DIRECT 0
62#else
63#define OS_O_DIRECT O_DIRECT
64#endif
65
66#ifndef FIO_HAVE_HUGETLB
67#define SHM_HUGETLB 0
68#ifndef FIO_HUGE_PAGE
69#define FIO_HUGE_PAGE 0
70#endif
71#else
72#ifndef FIO_HUGE_PAGE
73#define FIO_HUGE_PAGE 4194304
74#endif
75#endif
76
77#ifndef FIO_O_NOATIME
78#define FIO_O_NOATIME 0
79#endif
80
81#ifndef OS_RAND_MAX
82#define OS_RAND_MAX RAND_MAX
83#endif
84
85#ifndef FIO_HAVE_RAWBIND
86#define fio_lookup_raw(dev, majdev, mindev) 1
87#endif
88
89#ifndef FIO_HAVE_BLKTRACE
90static inline int is_blktrace(const char *fname)
91{
92 return 0;
93}
94struct thread_data;
95static inline int load_blktrace(struct thread_data *td, const char *fname)
96{
97 return 1;
98}
99#endif
100
101#define FIO_DEF_CL_SIZE 128
102
103static inline int os_cache_line_size(void)
104{
105#ifdef FIO_HAVE_CL_SIZE
106 int ret = arch_cache_line_size();
107
108 if (ret <= 0)
109 return FIO_DEF_CL_SIZE;
110
111 return ret;
112#else
113 return FIO_DEF_CL_SIZE;
114#endif
115}
116
117#ifdef FIO_USE_GENERIC_BDEV_SIZE
118static inline int blockdev_size(int fd, unsigned long long *bytes)
119{
120 off_t end;
121
122 *bytes = 0;
123
124 end = lseek(fd, 0, SEEK_END);
125 if (end < 0)
126 return errno;
127
128 *bytes = end;
129 return 0;
130}
131#endif
132
133#ifdef FIO_USE_GENERIC_RAND
134typedef unsigned int os_random_state_t;
135
136static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
137{
138 srand(seed);
139}
140
141static inline long os_random_long(os_random_state_t *rs)
142{
143 long val;
144
145 val = rand_r(rs);
146 return val;
147}
148#endif
149
150#ifndef FIO_HAVE_FS_STAT
151static inline unsigned long long get_fs_size(const char *path)
152{
153 return 0;
154}
155#endif
156
157#endif