blob: 4bbdd623a987c174122b2577b2899332605a0a0c [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 Axboe58483fa2011-01-19 11:09:58 -0700105#ifndef FIO_PREFERRED_ENGINE
106#define FIO_PREFERRED_ENGINE "sync"
107#endif
108
Jens Axboefca70352011-07-06 20:12:54 +0200109#ifndef FIO_MAX_JOBS
110#define FIO_MAX_JOBS 2048
111#endif
112
Jens Axboe5e62c222007-05-22 13:27:30 +0200113#ifndef FIO_HAVE_BLKTRACE
114static inline int is_blktrace(const char *fname)
115{
116 return 0;
117}
Jens Axboe5921e802008-05-30 15:02:38 +0200118struct thread_data;
Jens Axboe5e62c222007-05-22 13:27:30 +0200119static inline int load_blktrace(struct thread_data *td, const char *fname)
120{
121 return 1;
122}
123#endif
124
Jens Axboeeb7ccf32009-04-29 09:48:04 +0200125#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
Jens Axboe792d5512009-09-22 17:12:29 +0200141#ifdef FIO_USE_GENERIC_BDEV_SIZE
Bruce Cranecc314b2011-01-04 10:59:30 +0100142static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboe792d5512009-09-22 17:12:29 +0200143{
Jens Axboe3b2e1462009-12-15 08:58:10 +0100144 off_t end;
Jens Axboe792d5512009-09-22 17:12:29 +0200145
Jens Axboe3b2e1462009-12-15 08:58:10 +0100146 *bytes = 0;
147
Bruce Cranecc314b2011-01-04 10:59:30 +0100148 end = lseek(f->fd, 0, SEEK_END);
Jens Axboe792d5512009-09-22 17:12:29 +0200149 if (end < 0)
150 return errno;
151
152 *bytes = end;
153 return 0;
154}
155#endif
156
Jens Axboe53531372009-12-15 10:28:37 +0100157#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
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200174#ifndef FIO_HAVE_FS_STAT
175static inline unsigned long long get_fs_size(const char *path)
176{
177 return 0;
178}
179#endif
180
Jens Axboeebac4652005-12-08 15:25:21 +0100181#endif