Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1 | #ifndef FIO_OS_FREEBSD_H |
| 2 | #define FIO_OS_FREEBSD_H |
| 3 | |
Jens Axboe | cca8464 | 2011-10-07 12:47:57 +0200 | [diff] [blame] | 4 | #define FIO_OS os_freebsd |
| 5 | |
Jens Axboe | 690dec6 | 2009-01-06 14:22:30 +0100 | [diff] [blame] | 6 | #include <errno.h> |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 7 | #include <sys/sysctl.h> |
Jens Axboe | aa5e69b | 2010-06-24 09:25:15 +0200 | [diff] [blame] | 8 | #include <sys/disk.h> |
Jens Axboe | b939683 | 2011-07-30 13:29:58 +0200 | [diff] [blame] | 9 | #include <sys/thr.h> |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 10 | #include <sys/endian.h> |
Bruce Cran | f1415a9 | 2011-10-08 18:50:34 +0200 | [diff] [blame] | 11 | #include <sys/socket.h> |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 12 | |
Jens Axboe | e2e5888 | 2011-01-04 08:36:06 +0100 | [diff] [blame] | 13 | #include "../file.h" |
| 14 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 15 | #define FIO_HAVE_POSIXAIO |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 16 | #define FIO_HAVE_ODIRECT |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 17 | #define FIO_HAVE_STRSEP |
Jens Axboe | 5353137 | 2009-12-15 10:28:37 +0100 | [diff] [blame] | 18 | #define FIO_USE_GENERIC_RAND |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 19 | #define FIO_USE_GENERIC_INIT_RANDOM_STATE |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 20 | #define FIO_HAVE_CHARDEV_SIZE |
Jens Axboe | e8d588e | 2011-07-12 22:33:53 +0200 | [diff] [blame] | 21 | #define FIO_HAVE_GETTID |
Jens Axboe | b4c1fb3 | 2012-02-16 22:22:46 +0100 | [diff] [blame] | 22 | #define FIO_HAVE_CLOCK_MONOTONIC |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 23 | |
Jens Axboe | dc873b6 | 2008-06-04 20:13:04 +0200 | [diff] [blame] | 24 | #define OS_MAP_ANON MAP_ANON |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 25 | |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 26 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 27 | #define FIO_LITTLE_ENDIAN |
| 28 | #else |
| 29 | #define FIO_BIG_ENDIAN |
| 30 | #endif |
| 31 | |
| 32 | #define fio_swap16(x) bswap16(x) |
| 33 | #define fio_swap32(x) bswap32(x) |
| 34 | #define fio_swap64(x) bswap64(x) |
| 35 | |
Jens Axboe | 907249c | 2010-06-22 10:30:11 +0200 | [diff] [blame] | 36 | typedef off_t off64_t; |
| 37 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 38 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) |
Jens Axboe | aa5e69b | 2010-06-24 09:25:15 +0200 | [diff] [blame] | 39 | { |
| 40 | off_t size; |
| 41 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 42 | if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) { |
Jens Axboe | aa5e69b | 2010-06-24 09:25:15 +0200 | [diff] [blame] | 43 | *bytes = size; |
| 44 | return 0; |
| 45 | } |
| 46 | |
Jens Axboe | 2fa55e9 | 2010-06-24 09:36:11 +0200 | [diff] [blame] | 47 | *bytes = 0; |
Jens Axboe | aa5e69b | 2010-06-24 09:25:15 +0200 | [diff] [blame] | 48 | return errno; |
| 49 | } |
| 50 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 51 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 52 | { |
Bruce Cran | 9b83656 | 2011-01-08 19:49:54 +0100 | [diff] [blame] | 53 | return blockdev_size(f, bytes); |
Jens Axboe | 4ccdccd | 2010-06-24 10:27:22 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 56 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 57 | { |
| 58 | return EINVAL; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Jens Axboe | 32cd46a | 2006-06-07 13:40:40 +0200 | [diff] [blame] | 61 | static inline unsigned long long os_phys_mem(void) |
| 62 | { |
| 63 | int mib[2] = { CTL_HW, HW_PHYSMEM }; |
| 64 | unsigned long long mem; |
| 65 | size_t len = sizeof(mem); |
| 66 | |
| 67 | sysctl(mib, 2, &mem, &len, NULL, 0); |
| 68 | return mem; |
| 69 | } |
| 70 | |
Jens Axboe | e8d588e | 2011-07-12 22:33:53 +0200 | [diff] [blame] | 71 | static inline int gettid(void) |
| 72 | { |
| 73 | long lwpid; |
| 74 | |
| 75 | thr_self(&lwpid); |
| 76 | return (int) lwpid; |
| 77 | } |
| 78 | |
Jens Axboe | a1c5807 | 2009-08-04 23:17:02 +0200 | [diff] [blame] | 79 | #ifdef MADV_FREE |
| 80 | #define FIO_MADV_FREE MADV_FREE |
| 81 | #endif |
| 82 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 83 | #endif |