blob: 92b6950d305d077261633723b181f35e273b33ae [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001#ifndef FIO_OS_H
2#define FIO_OS_H
3
Jens Axboea14ca442009-12-20 22:24:10 +01004#include <sys/types.h>
Bruce Cran03e20d62011-01-02 20:14:54 +01005#include <pthread.h>
Jens Axboea14ca442009-12-20 22:24:10 +01006#include <unistd.h>
Bruce Cranecc314b2011-01-04 10:59:30 +01007#include <stdlib.h>
Jens Axboea14ca442009-12-20 22:24:10 +01008
Jens Axboeebac4652005-12-08 15:25:21 +01009#if defined(__linux__)
10#include "os-linux.h"
11#elif defined(__FreeBSD__)
12#include "os-freebsd.h"
YAMAMOTO Takashi74524402010-05-12 15:06:46 +020013#elif defined(__NetBSD__)
14#include "os-netbsd.h"
Jens Axboe2c0ecd22006-06-08 13:25:41 +020015#elif defined(__sun__)
16#include "os-solaris.h"
Jens Axboe2afd8262009-12-14 23:08:42 +010017#elif defined(__APPLE__)
18#include "os-mac.h"
Cigy Cyriacbf2e8212010-08-10 19:51:11 -040019#elif defined(_AIX)
20#include "os-aix.h"
Bruce Cran03e20d62011-01-02 20:14:54 +010021#elif defined(__CYGWIN__)
22#include "os-windows.h"
Jens Axboeebac4652005-12-08 15:25:21 +010023#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
Jens Axboe5921e802008-05-30 15:02:38 +020040#ifndef FIO_HAVE_STRSEP
Jens Axboe00fb3c82008-05-30 22:17:45 +020041#include "../lib/strsep.h"
Jens Axboe5921e802008-05-30 15:02:38 +020042#endif
43
Jens Axboe8e239ca2010-08-11 10:29:12 -040044#ifdef MSG_DONTWAIT
45#define OS_MSG_DONTWAIT MSG_DONTWAIT
46#endif
47
Jens Axboeebac4652005-12-08 15:25:21 +010048#ifndef FIO_HAVE_FADVISE
Bruce Cranecc314b2011-01-04 10:59:30 +010049#define posix_fadvise(fd, off, len, advice) (0)
Jens Axboeebac4652005-12-08 15:25:21 +010050
Shawn Lewis4d8947d2007-07-25 07:51:58 +020051#ifndef POSIX_FADV_DONTNEED
Jens Axboeebac4652005-12-08 15:25:21 +010052#define POSIX_FADV_DONTNEED (0)
53#define POSIX_FADV_SEQUENTIAL (0)
54#define POSIX_FADV_RANDOM (0)
Shawn Lewis4d8947d2007-07-25 07:51:58 +020055#endif
Jens Axboeebac4652005-12-08 15:25:21 +010056#endif /* FIO_HAVE_FADVISE */
57
58#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboee8462bd2009-07-06 12:59:04 +020059#define fio_setaffinity(pid, mask) (0)
Jens Axboebe4ecfd2008-12-08 14:10:52 +010060#define fio_getaffinity(pid, mask) do { } while (0)
61#define fio_cpu_clear(mask, cpu) do { } while (0)
Jens Axboe85daf2c2009-01-05 09:40:13 +010062#define fio_cpuset_exit(mask) (-1)
YAMAMOTO Takashi74524402010-05-12 15:06:46 +020063typedef unsigned long os_cpu_mask_t;
Jens Axboeebac4652005-12-08 15:25:21 +010064#endif
65
66#ifndef FIO_HAVE_IOPRIO
67#define ioprio_set(which, who, prio) (0)
68#endif
69
Jens Axboe2c0ecd22006-06-08 13:25:41 +020070#ifndef FIO_HAVE_ODIRECT
Jens Axboe7d424762006-06-08 13:26:31 +020071#define OS_O_DIRECT 0
72#else
73#define OS_O_DIRECT O_DIRECT
Jens Axboe2c0ecd22006-06-08 13:25:41 +020074#endif
75
Jens Axboe74b025b2006-12-19 15:18:14 +010076#ifndef FIO_HAVE_HUGETLB
77#define SHM_HUGETLB 0
Shawn Lewis4d8947d2007-07-25 07:51:58 +020078#ifndef FIO_HUGE_PAGE
Jens Axboe74b025b2006-12-19 15:18:14 +010079#define FIO_HUGE_PAGE 0
Shawn Lewis4d8947d2007-07-25 07:51:58 +020080#endif
Jens Axboe74b025b2006-12-19 15:18:14 +010081#else
Jens Axboecb25df62007-03-23 08:23:30 +010082#ifndef FIO_HUGE_PAGE
Jens Axboeee0e0a72007-03-19 10:50:47 +010083#define FIO_HUGE_PAGE 4194304
Jens Axboe74b025b2006-12-19 15:18:14 +010084#endif
Jens Axboecb25df62007-03-23 08:23:30 +010085#endif
Jens Axboe74b025b2006-12-19 15:18:14 +010086
Jens Axboe5921e802008-05-30 15:02:38 +020087#ifndef FIO_O_NOATIME
88#define FIO_O_NOATIME 0
89#endif
90
Jens Axboedc873b62008-06-04 20:13:04 +020091#ifndef OS_RAND_MAX
92#define OS_RAND_MAX RAND_MAX
93#endif
94
Bruce Cranecc314b2011-01-04 10:59:30 +010095#ifdef FIO_HAVE_CLOCK_MONOTONIC
96#define FIO_TIMER_CLOCK CLOCK_MONOTONIC
97#else
98#define FIO_TIMER_CLOCK CLOCK_REALTIME
99#endif
100
Jens Axboe07e5b262007-04-02 14:46:07 +0200101#ifndef FIO_HAVE_RAWBIND
Jens Axboe8cc7afa2007-04-17 09:06:43 +0200102#define fio_lookup_raw(dev, majdev, mindev) 1
Jens Axboe07e5b262007-04-02 14:46:07 +0200103#endif
104
Jens Axboe5e62c222007-05-22 13:27:30 +0200105#ifndef FIO_HAVE_BLKTRACE
106static inline int is_blktrace(const char *fname)
107{
108 return 0;
109}
Jens Axboe5921e802008-05-30 15:02:38 +0200110struct thread_data;
Jens Axboe5e62c222007-05-22 13:27:30 +0200111static inline int load_blktrace(struct thread_data *td, const char *fname)
112{
113 return 1;
114}
115#endif
116
Jens Axboeeb7ccf32009-04-29 09:48:04 +0200117#define FIO_DEF_CL_SIZE 128
118
119static inline int os_cache_line_size(void)
120{
121#ifdef FIO_HAVE_CL_SIZE
122 int ret = arch_cache_line_size();
123
124 if (ret <= 0)
125 return FIO_DEF_CL_SIZE;
126
127 return ret;
128#else
129 return FIO_DEF_CL_SIZE;
130#endif
131}
132
Jens Axboe792d5512009-09-22 17:12:29 +0200133#ifdef FIO_USE_GENERIC_BDEV_SIZE
Bruce Cranecc314b2011-01-04 10:59:30 +0100134static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboe792d5512009-09-22 17:12:29 +0200135{
Jens Axboe3b2e1462009-12-15 08:58:10 +0100136 off_t end;
Jens Axboe792d5512009-09-22 17:12:29 +0200137
Jens Axboe3b2e1462009-12-15 08:58:10 +0100138 *bytes = 0;
139
Bruce Cranecc314b2011-01-04 10:59:30 +0100140 end = lseek(f->fd, 0, SEEK_END);
Jens Axboe792d5512009-09-22 17:12:29 +0200141 if (end < 0)
142 return errno;
143
144 *bytes = end;
145 return 0;
146}
147#endif
148
Jens Axboe53531372009-12-15 10:28:37 +0100149#ifdef FIO_USE_GENERIC_RAND
150typedef unsigned int os_random_state_t;
151
152static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
153{
154 srand(seed);
155}
156
157static inline long os_random_long(os_random_state_t *rs)
158{
159 long val;
160
161 val = rand_r(rs);
162 return val;
163}
164#endif
165
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200166#ifndef FIO_HAVE_FS_STAT
167static inline unsigned long long get_fs_size(const char *path)
168{
169 return 0;
170}
171#endif
172
Jens Axboeebac4652005-12-08 15:25:21 +0100173#endif