Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1 | #ifndef FIO_OS_H |
| 2 | #define FIO_OS_H |
| 3 | |
Jens Axboe | a14ca44 | 2009-12-20 22:24:10 +0100 | [diff] [blame] | 4 | #include <sys/types.h> |
Bruce Cran | 203913e | 2011-10-18 12:20:56 +0200 | [diff] [blame] | 5 | #include <sys/socket.h> |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 6 | #include <fcntl.h> |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 7 | #include <pthread.h> |
Jens Axboe | a14ca44 | 2009-12-20 22:24:10 +0100 | [diff] [blame] | 8 | #include <unistd.h> |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 9 | #include <stdlib.h> |
Jens Axboe | a14ca44 | 2009-12-20 22:24:10 +0100 | [diff] [blame] | 10 | |
Jens Axboe | 836fcc0 | 2013-01-24 09:08:45 -0700 | [diff] [blame] | 11 | #include "../arch/arch.h" |
| 12 | |
Jens Axboe | cca8464 | 2011-10-07 12:47:57 +0200 | [diff] [blame] | 13 | enum { |
| 14 | os_linux = 1, |
| 15 | os_aix, |
| 16 | os_freebsd, |
| 17 | os_hpux, |
| 18 | os_mac, |
| 19 | os_netbsd, |
John | 3cd4c66 | 2013-12-29 19:20:35 -0700 | [diff] [blame] | 20 | os_openbsd, |
Jens Axboe | cca8464 | 2011-10-07 12:47:57 +0200 | [diff] [blame] | 21 | os_solaris, |
| 22 | os_windows, |
Aaron Carroll | ec5c6b1 | 2012-11-21 10:39:00 +0100 | [diff] [blame] | 23 | os_android, |
Jens Axboe | ec58c74 | 2014-11-04 19:53:04 -0700 | [diff] [blame] | 24 | os_dragonfly, |
Jens Axboe | cca8464 | 2011-10-07 12:47:57 +0200 | [diff] [blame] | 25 | |
| 26 | os_nr, |
| 27 | }; |
| 28 | |
Aaron Carroll | ec5c6b1 | 2012-11-21 10:39:00 +0100 | [diff] [blame] | 29 | #if defined(__ANDROID__) |
| 30 | #include "os-android.h" |
| 31 | #elif defined(__linux__) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 32 | #include "os-linux.h" |
| 33 | #elif defined(__FreeBSD__) |
| 34 | #include "os-freebsd.h" |
John | 3cd4c66 | 2013-12-29 19:20:35 -0700 | [diff] [blame] | 35 | #elif defined(__OpenBSD__) |
| 36 | #include "os-openbsd.h" |
YAMAMOTO Takashi | 7452440 | 2010-05-12 15:06:46 +0200 | [diff] [blame] | 37 | #elif defined(__NetBSD__) |
| 38 | #include "os-netbsd.h" |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 39 | #elif defined(__sun__) |
| 40 | #include "os-solaris.h" |
Jens Axboe | 2afd826 | 2009-12-14 23:08:42 +0100 | [diff] [blame] | 41 | #elif defined(__APPLE__) |
| 42 | #include "os-mac.h" |
Cigy Cyriac | bf2e821 | 2010-08-10 19:51:11 -0400 | [diff] [blame] | 43 | #elif defined(_AIX) |
| 44 | #include "os-aix.h" |
Jens Axboe | c00a228 | 2011-07-08 20:56:06 +0200 | [diff] [blame] | 45 | #elif defined(__hpux) |
| 46 | #include "os-hpux.h" |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 47 | #elif defined(WIN32) |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 48 | #include "os-windows.h" |
Jens Axboe | ec58c74 | 2014-11-04 19:53:04 -0700 | [diff] [blame] | 49 | #elif defined (__DragonFly__) |
| 50 | #include "os-dragonfly.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 51 | #else |
| 52 | #error "unsupported os" |
| 53 | #endif |
| 54 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 55 | #ifdef CONFIG_POSIXAIO |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 56 | #include <aio.h> |
Jens Axboe | e97c144 | 2011-09-21 09:38:01 +0200 | [diff] [blame] | 57 | #ifndef FIO_OS_HAVE_AIOCB_TYPEDEF |
| 58 | typedef struct aiocb os_aiocb_t; |
| 59 | #endif |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | #ifdef FIO_HAVE_SGIO |
| 63 | #include <linux/fs.h> |
| 64 | #include <scsi/sg.h> |
| 65 | #endif |
| 66 | |
Jens Axboe | 4feafb1 | 2013-01-24 23:07:55 -0700 | [diff] [blame] | 67 | #ifndef CONFIG_STRSEP |
Jens Axboe | 00fb3c8 | 2008-05-30 22:17:45 +0200 | [diff] [blame] | 68 | #include "../lib/strsep.h" |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 69 | #endif |
| 70 | |
Jens Axboe | 8e239ca | 2010-08-11 10:29:12 -0400 | [diff] [blame] | 71 | #ifdef MSG_DONTWAIT |
| 72 | #define OS_MSG_DONTWAIT MSG_DONTWAIT |
| 73 | #endif |
| 74 | |
Shawn Lewis | 4d8947d | 2007-07-25 07:51:58 +0200 | [diff] [blame] | 75 | #ifndef POSIX_FADV_DONTNEED |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 76 | #define POSIX_FADV_DONTNEED (0) |
| 77 | #define POSIX_FADV_SEQUENTIAL (0) |
| 78 | #define POSIX_FADV_RANDOM (0) |
Shawn Lewis | 4d8947d | 2007-07-25 07:51:58 +0200 | [diff] [blame] | 79 | #endif |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 80 | |
| 81 | #ifndef FIO_HAVE_CPU_AFFINITY |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 82 | #define fio_setaffinity(pid, mask) (0) |
Jens Axboe | be4ecfd | 2008-12-08 14:10:52 +0100 | [diff] [blame] | 83 | #define fio_getaffinity(pid, mask) do { } while (0) |
| 84 | #define fio_cpu_clear(mask, cpu) do { } while (0) |
Jens Axboe | 85daf2c | 2009-01-05 09:40:13 +0100 | [diff] [blame] | 85 | #define fio_cpuset_exit(mask) (-1) |
Jens Axboe | c2acfba | 2014-02-27 15:52:02 -0800 | [diff] [blame] | 86 | #define fio_cpus_split(mask, cpu) (0) |
YAMAMOTO Takashi | 7452440 | 2010-05-12 15:06:46 +0200 | [diff] [blame] | 87 | typedef unsigned long os_cpu_mask_t; |
Jens Axboe | c2acfba | 2014-02-27 15:52:02 -0800 | [diff] [blame] | 88 | #else |
| 89 | extern int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 90 | #endif |
| 91 | |
| 92 | #ifndef FIO_HAVE_IOPRIO |
Jens Axboe | 28727df | 2012-03-29 08:33:15 +0200 | [diff] [blame] | 93 | #define ioprio_set(which, who, prioclass, prio) (0) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 94 | #endif |
| 95 | |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 96 | #ifndef FIO_HAVE_ODIRECT |
Jens Axboe | 7d42476 | 2006-06-08 13:26:31 +0200 | [diff] [blame] | 97 | #define OS_O_DIRECT 0 |
| 98 | #else |
| 99 | #define OS_O_DIRECT O_DIRECT |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 100 | #endif |
| 101 | |
Chris Mason | d01612f | 2013-11-15 15:52:58 -0700 | [diff] [blame] | 102 | #ifdef OS_O_ATOMIC |
| 103 | #define FIO_O_ATOMIC OS_O_ATOMIC |
| 104 | #else |
| 105 | #define FIO_O_ATOMIC 0 |
| 106 | #endif |
| 107 | |
Jens Axboe | 74b025b | 2006-12-19 15:18:14 +0100 | [diff] [blame] | 108 | #ifndef FIO_HAVE_HUGETLB |
| 109 | #define SHM_HUGETLB 0 |
Jens Axboe | d6dc02f | 2012-11-20 13:39:59 +0100 | [diff] [blame] | 110 | #define MAP_HUGETLB 0 |
Shawn Lewis | 4d8947d | 2007-07-25 07:51:58 +0200 | [diff] [blame] | 111 | #ifndef FIO_HUGE_PAGE |
Jens Axboe | 74b025b | 2006-12-19 15:18:14 +0100 | [diff] [blame] | 112 | #define FIO_HUGE_PAGE 0 |
Shawn Lewis | 4d8947d | 2007-07-25 07:51:58 +0200 | [diff] [blame] | 113 | #endif |
Jens Axboe | 74b025b | 2006-12-19 15:18:14 +0100 | [diff] [blame] | 114 | #else |
Jens Axboe | cb25df6 | 2007-03-23 08:23:30 +0100 | [diff] [blame] | 115 | #ifndef FIO_HUGE_PAGE |
Jens Axboe | ee0e0a7 | 2007-03-19 10:50:47 +0100 | [diff] [blame] | 116 | #define FIO_HUGE_PAGE 4194304 |
Jens Axboe | 74b025b | 2006-12-19 15:18:14 +0100 | [diff] [blame] | 117 | #endif |
Jens Axboe | cb25df6 | 2007-03-23 08:23:30 +0100 | [diff] [blame] | 118 | #endif |
Jens Axboe | 74b025b | 2006-12-19 15:18:14 +0100 | [diff] [blame] | 119 | |
Jens Axboe | 39b9356 | 2012-11-27 08:27:50 +0100 | [diff] [blame] | 120 | #ifndef FIO_HAVE_MMAP_HUGE |
| 121 | #define MAP_HUGETLB 0 |
| 122 | #endif |
| 123 | |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 124 | #ifndef FIO_O_NOATIME |
| 125 | #define FIO_O_NOATIME 0 |
| 126 | #endif |
| 127 | |
Jens Axboe | dc873b6 | 2008-06-04 20:13:04 +0200 | [diff] [blame] | 128 | #ifndef OS_RAND_MAX |
| 129 | #define OS_RAND_MAX RAND_MAX |
| 130 | #endif |
| 131 | |
Jens Axboe | 07e5b26 | 2007-04-02 14:46:07 +0200 | [diff] [blame] | 132 | #ifndef FIO_HAVE_RAWBIND |
Jens Axboe | 8cc7afa | 2007-04-17 09:06:43 +0200 | [diff] [blame] | 133 | #define fio_lookup_raw(dev, majdev, mindev) 1 |
Jens Axboe | 07e5b26 | 2007-04-02 14:46:07 +0200 | [diff] [blame] | 134 | #endif |
| 135 | |
Jens Axboe | 58483fa | 2011-01-19 11:09:58 -0700 | [diff] [blame] | 136 | #ifndef FIO_PREFERRED_ENGINE |
| 137 | #define FIO_PREFERRED_ENGINE "sync" |
| 138 | #endif |
| 139 | |
Bruce Cran | b9fd788 | 2012-02-20 17:01:46 +0000 | [diff] [blame] | 140 | #ifndef FIO_OS_PATH_SEPARATOR |
| 141 | #define FIO_OS_PATH_SEPARATOR "/" |
| 142 | #endif |
| 143 | |
Bruce Cran | 16de1bf | 2012-02-20 17:07:32 +0000 | [diff] [blame] | 144 | #ifndef FIO_PREFERRED_CLOCK_SOURCE |
Bruce Cran | 86e5341 | 2013-02-02 20:54:36 +0000 | [diff] [blame] | 145 | #ifdef CONFIG_CLOCK_GETTIME |
Bruce Cran | 16de1bf | 2012-02-20 17:07:32 +0000 | [diff] [blame] | 146 | #define FIO_PREFERRED_CLOCK_SOURCE CS_CGETTIME |
Bruce Cran | 86e5341 | 2013-02-02 20:54:36 +0000 | [diff] [blame] | 147 | #else |
| 148 | #define FIO_PREFERRED_CLOCK_SOURCE CS_GTOD |
| 149 | #endif |
Bruce Cran | 16de1bf | 2012-02-20 17:07:32 +0000 | [diff] [blame] | 150 | #endif |
| 151 | |
Jens Axboe | fca7035 | 2011-07-06 20:12:54 +0200 | [diff] [blame] | 152 | #ifndef FIO_MAX_JOBS |
| 153 | #define FIO_MAX_JOBS 2048 |
| 154 | #endif |
| 155 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 156 | #ifndef CONFIG_SOCKLEN_T |
| 157 | typedef unsigned int socklen_t; |
Jens Axboe | 5ba13ea | 2011-10-04 23:50:28 +0200 | [diff] [blame] | 158 | #endif |
| 159 | |
Saurabh De | 45054cb | 2012-10-09 14:46:24 -0600 | [diff] [blame] | 160 | #ifndef FIO_OS_HAS_CTIME_R |
Jens Axboe | 1f81991 | 2013-01-23 17:21:41 -0700 | [diff] [blame] | 161 | #define os_ctime_r(x, y, z) (void) ctime_r((x), (y)) |
Saurabh De | 45054cb | 2012-10-09 14:46:24 -0600 | [diff] [blame] | 162 | #endif |
| 163 | |
Jens Axboe | 901ebe1 | 2011-10-04 23:31:00 +0200 | [diff] [blame] | 164 | #ifdef FIO_USE_GENERIC_SWAP |
Jens Axboe | 9677bec | 2011-10-04 16:02:51 +0200 | [diff] [blame] | 165 | static inline uint16_t fio_swap16(uint16_t val) |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 166 | { |
| 167 | return (val << 8) | (val >> 8); |
| 168 | } |
| 169 | |
Jens Axboe | 901ebe1 | 2011-10-04 23:31:00 +0200 | [diff] [blame] | 170 | static inline uint32_t fio_swap32(uint32_t val) |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 171 | { |
| 172 | val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8); |
| 173 | |
| 174 | return (val >> 16) | (val << 16); |
| 175 | } |
| 176 | |
Jens Axboe | 901ebe1 | 2011-10-04 23:31:00 +0200 | [diff] [blame] | 177 | static inline uint64_t fio_swap64(uint64_t val) |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 178 | { |
| 179 | val = ((val & 0xff00ff00ff00ff00ULL) >> 8) | |
| 180 | ((val & 0x00ff00ff00ff00ffULL) << 8); |
| 181 | val = ((val & 0xffff0000ffff0000ULL) >> 16) | |
| 182 | ((val & 0x0000ffff0000ffffULL) << 16); |
| 183 | |
| 184 | return (val >> 32) | (val << 32); |
| 185 | } |
| 186 | #endif |
| 187 | |
Aaron Carroll | ec5c6b1 | 2012-11-21 10:39:00 +0100 | [diff] [blame] | 188 | #ifndef FIO_HAVE_BYTEORDER_FUNCS |
Jens Axboe | 0dcebdf | 2013-01-23 15:42:16 -0700 | [diff] [blame] | 189 | #ifdef CONFIG_LITTLE_ENDIAN |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 190 | #define __le16_to_cpu(x) (x) |
| 191 | #define __le32_to_cpu(x) (x) |
| 192 | #define __le64_to_cpu(x) (x) |
| 193 | #define __cpu_to_le16(x) (x) |
| 194 | #define __cpu_to_le32(x) (x) |
| 195 | #define __cpu_to_le64(x) (x) |
| 196 | #else |
| 197 | #define __le16_to_cpu(x) fio_swap16(x) |
| 198 | #define __le32_to_cpu(x) fio_swap32(x) |
| 199 | #define __le64_to_cpu(x) fio_swap64(x) |
| 200 | #define __cpu_to_le16(x) fio_swap16(x) |
| 201 | #define __cpu_to_le32(x) fio_swap32(x) |
| 202 | #define __cpu_to_le64(x) fio_swap64(x) |
| 203 | #endif |
Aaron Carroll | ec5c6b1 | 2012-11-21 10:39:00 +0100 | [diff] [blame] | 204 | #endif /* FIO_HAVE_BYTEORDER_FUNCS */ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 205 | |
Daniel Gollub | 0bbe46e | 2014-05-01 14:07:04 +0200 | [diff] [blame] | 206 | #ifdef FIO_INTERNAL |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 207 | #define le16_to_cpu(val) ({ \ |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 208 | typecheck(uint16_t, val); \ |
Sébastien Bouchex Bellomié | c46fda9 | 2014-03-11 08:54:27 -0600 | [diff] [blame] | 209 | __le16_to_cpu(val); \ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 210 | }) |
| 211 | #define le32_to_cpu(val) ({ \ |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 212 | typecheck(uint32_t, val); \ |
Sébastien Bouchex Bellomié | c46fda9 | 2014-03-11 08:54:27 -0600 | [diff] [blame] | 213 | __le32_to_cpu(val); \ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 214 | }) |
| 215 | #define le64_to_cpu(val) ({ \ |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 216 | typecheck(uint64_t, val); \ |
| 217 | __le64_to_cpu(val); \ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 218 | }) |
Daniel Gollub | 0bbe46e | 2014-05-01 14:07:04 +0200 | [diff] [blame] | 219 | #endif |
| 220 | |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 221 | #define cpu_to_le16(val) ({ \ |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 222 | typecheck(uint16_t, val); \ |
Sébastien Bouchex Bellomié | c46fda9 | 2014-03-11 08:54:27 -0600 | [diff] [blame] | 223 | __cpu_to_le16(val); \ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 224 | }) |
| 225 | #define cpu_to_le32(val) ({ \ |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 226 | typecheck(uint32_t, val); \ |
Sébastien Bouchex Bellomié | c46fda9 | 2014-03-11 08:54:27 -0600 | [diff] [blame] | 227 | __cpu_to_le32(val); \ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 228 | }) |
| 229 | #define cpu_to_le64(val) ({ \ |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 230 | typecheck(uint64_t, val); \ |
Sébastien Bouchex Bellomié | c46fda9 | 2014-03-11 08:54:27 -0600 | [diff] [blame] | 231 | __cpu_to_le64(val); \ |
Jens Axboe | 8111092 | 2011-10-05 12:40:49 +0200 | [diff] [blame] | 232 | }) |
| 233 | |
Jens Axboe | 5e62c22 | 2007-05-22 13:27:30 +0200 | [diff] [blame] | 234 | #ifndef FIO_HAVE_BLKTRACE |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 235 | static inline int is_blktrace(const char *fname, int *need_swap) |
Jens Axboe | 5e62c22 | 2007-05-22 13:27:30 +0200 | [diff] [blame] | 236 | { |
| 237 | return 0; |
| 238 | } |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 239 | struct thread_data; |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 240 | static inline int load_blktrace(struct thread_data *td, const char *fname, |
| 241 | int need_swap) |
Jens Axboe | 5e62c22 | 2007-05-22 13:27:30 +0200 | [diff] [blame] | 242 | { |
| 243 | return 1; |
| 244 | } |
| 245 | #endif |
| 246 | |
Jens Axboe | eb7ccf3 | 2009-04-29 09:48:04 +0200 | [diff] [blame] | 247 | #define FIO_DEF_CL_SIZE 128 |
| 248 | |
| 249 | static inline int os_cache_line_size(void) |
| 250 | { |
| 251 | #ifdef FIO_HAVE_CL_SIZE |
| 252 | int ret = arch_cache_line_size(); |
| 253 | |
| 254 | if (ret <= 0) |
| 255 | return FIO_DEF_CL_SIZE; |
| 256 | |
| 257 | return ret; |
| 258 | #else |
| 259 | return FIO_DEF_CL_SIZE; |
| 260 | #endif |
| 261 | } |
| 262 | |
Jens Axboe | 792d551 | 2009-09-22 17:12:29 +0200 | [diff] [blame] | 263 | #ifdef FIO_USE_GENERIC_BDEV_SIZE |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 264 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) |
Jens Axboe | 792d551 | 2009-09-22 17:12:29 +0200 | [diff] [blame] | 265 | { |
Jens Axboe | 3b2e146 | 2009-12-15 08:58:10 +0100 | [diff] [blame] | 266 | off_t end; |
Jens Axboe | 792d551 | 2009-09-22 17:12:29 +0200 | [diff] [blame] | 267 | |
Jens Axboe | 3b2e146 | 2009-12-15 08:58:10 +0100 | [diff] [blame] | 268 | *bytes = 0; |
| 269 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 270 | end = lseek(f->fd, 0, SEEK_END); |
Jens Axboe | 792d551 | 2009-09-22 17:12:29 +0200 | [diff] [blame] | 271 | if (end < 0) |
| 272 | return errno; |
| 273 | |
| 274 | *bytes = end; |
| 275 | return 0; |
| 276 | } |
| 277 | #endif |
| 278 | |
Jens Axboe | 5353137 | 2009-12-15 10:28:37 +0100 | [diff] [blame] | 279 | #ifdef FIO_USE_GENERIC_RAND |
| 280 | typedef unsigned int os_random_state_t; |
| 281 | |
| 282 | static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) |
| 283 | { |
| 284 | srand(seed); |
| 285 | } |
| 286 | |
| 287 | static inline long os_random_long(os_random_state_t *rs) |
| 288 | { |
| 289 | long val; |
| 290 | |
| 291 | val = rand_r(rs); |
| 292 | return val; |
| 293 | } |
| 294 | #endif |
| 295 | |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 296 | #ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE |
| 297 | extern void td_fill_rand_seeds(struct thread_data *td); |
| 298 | /* |
| 299 | * Initialize the various random states we need (random io, block size ranges, |
| 300 | * read/write mix, etc). |
| 301 | */ |
| 302 | static inline int init_random_state(struct thread_data *td, unsigned long *rand_seeds, int size) |
| 303 | { |
| 304 | int fd; |
| 305 | |
| 306 | fd = open("/dev/urandom", O_RDONLY); |
| 307 | if (fd == -1) { |
| 308 | return 1; |
| 309 | } |
| 310 | |
| 311 | if (read(fd, rand_seeds, size) < size) { |
| 312 | close(fd); |
| 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | close(fd); |
| 317 | td_fill_rand_seeds(td); |
| 318 | return 0; |
| 319 | } |
| 320 | #endif |
| 321 | |
Jens Axboe | 2e3bd4c | 2010-05-17 12:29:57 +0200 | [diff] [blame] | 322 | #ifndef FIO_HAVE_FS_STAT |
| 323 | static inline unsigned long long get_fs_size(const char *path) |
| 324 | { |
| 325 | return 0; |
| 326 | } |
| 327 | #endif |
| 328 | |
Jens Axboe | c00a228 | 2011-07-08 20:56:06 +0200 | [diff] [blame] | 329 | #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF |
| 330 | static inline unsigned int cpus_online(void) |
| 331 | { |
| 332 | return sysconf(_SC_NPROCESSORS_ONLN); |
| 333 | } |
| 334 | #endif |
| 335 | |
Daniel Gollub | 7221da3 | 2014-05-01 14:07:01 +0200 | [diff] [blame] | 336 | #ifndef CPU_COUNT |
Jens Axboe | 6cf71c2 | 2014-03-05 15:49:54 -0700 | [diff] [blame] | 337 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 338 | static inline int CPU_COUNT(os_cpu_mask_t *mask) |
| 339 | { |
| 340 | int max_cpus = cpus_online(); |
| 341 | int nr_cpus, i; |
| 342 | |
| 343 | for (i = 0, nr_cpus = 0; i < max_cpus; i++) |
| 344 | if (fio_cpu_isset(mask, i)) |
| 345 | nr_cpus++; |
| 346 | |
| 347 | return nr_cpus; |
| 348 | } |
| 349 | #endif |
| 350 | #endif |
| 351 | |
Jens Axboe | 47f767c | 2011-07-12 21:17:49 +0200 | [diff] [blame] | 352 | #ifndef FIO_HAVE_GETTID |
| 353 | static inline int gettid(void) |
| 354 | { |
| 355 | return getpid(); |
| 356 | } |
| 357 | #endif |
| 358 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 359 | #endif |