| 1 | #ifndef FIO_OS_FREEBSD_H |
| 2 | #define FIO_OS_FREEBSD_H |
| 3 | |
| 4 | #include <errno.h> |
| 5 | #include <sys/sysctl.h> |
| 6 | #include <sys/disk.h> |
| 7 | #include <sys/thr.h> |
| 8 | #include <sys/endian.h> |
| 9 | |
| 10 | #include "../file.h" |
| 11 | |
| 12 | #define FIO_HAVE_POSIXAIO |
| 13 | #define FIO_HAVE_ODIRECT |
| 14 | #define FIO_HAVE_STRSEP |
| 15 | #define FIO_USE_GENERIC_RAND |
| 16 | #define FIO_HAVE_CHARDEV_SIZE |
| 17 | #define FIO_HAVE_CLOCK_MONOTONIC |
| 18 | #define FIO_HAVE_GETTID |
| 19 | |
| 20 | #define OS_MAP_ANON MAP_ANON |
| 21 | |
| 22 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 23 | #define FIO_LITTLE_ENDIAN |
| 24 | #else |
| 25 | #define FIO_BIG_ENDIAN |
| 26 | #endif |
| 27 | |
| 28 | #define fio_swap16(x) bswap16(x) |
| 29 | #define fio_swap32(x) bswap32(x) |
| 30 | #define fio_swap64(x) bswap64(x) |
| 31 | |
| 32 | typedef off_t off64_t; |
| 33 | |
| 34 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) |
| 35 | { |
| 36 | off_t size; |
| 37 | |
| 38 | if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) { |
| 39 | *bytes = size; |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | *bytes = 0; |
| 44 | return errno; |
| 45 | } |
| 46 | |
| 47 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
| 48 | { |
| 49 | return blockdev_size(f, bytes); |
| 50 | } |
| 51 | |
| 52 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
| 53 | { |
| 54 | return EINVAL; |
| 55 | } |
| 56 | |
| 57 | static inline unsigned long long os_phys_mem(void) |
| 58 | { |
| 59 | int mib[2] = { CTL_HW, HW_PHYSMEM }; |
| 60 | unsigned long long mem; |
| 61 | size_t len = sizeof(mem); |
| 62 | |
| 63 | sysctl(mib, 2, &mem, &len, NULL, 0); |
| 64 | return mem; |
| 65 | } |
| 66 | |
| 67 | static inline int gettid(void) |
| 68 | { |
| 69 | long lwpid; |
| 70 | |
| 71 | thr_self(&lwpid); |
| 72 | return (int) lwpid; |
| 73 | } |
| 74 | |
| 75 | #ifdef MADV_FREE |
| 76 | #define FIO_MADV_FREE MADV_FREE |
| 77 | #endif |
| 78 | |
| 79 | #endif |