Commit | Line | Data |
---|---|---|
ebac4655 JA |
1 | #ifndef FIO_OS_FREEBSD_H |
2 | #define FIO_OS_FREEBSD_H | |
3 | ||
cca84643 JA |
4 | #define FIO_OS os_freebsd |
5 | ||
690dec6e | 6 | #include <errno.h> |
5c4e1dbc | 7 | #include <sys/sysctl.h> |
aa5e69b2 | 8 | #include <sys/disk.h> |
b939683e | 9 | #include <sys/thr.h> |
f1415a9f | 10 | #include <sys/socket.h> |
63820495 BC |
11 | #include <sys/param.h> |
12 | #include <sys/cpuset.h> | |
5c4e1dbc | 13 | |
e2e58886 JA |
14 | #include "../file.h" |
15 | ||
2c0ecd28 | 16 | #define FIO_HAVE_ODIRECT |
53531370 | 17 | #define FIO_USE_GENERIC_RAND |
93bcfd20 | 18 | #define FIO_USE_GENERIC_INIT_RANDOM_STATE |
4ccdccd1 | 19 | #define FIO_HAVE_CHARDEV_SIZE |
e8d588e4 | 20 | #define FIO_HAVE_GETTID |
63820495 | 21 | #define FIO_HAVE_CPU_AFFINITY |
ebac4655 | 22 | |
dc873b6f | 23 | #define OS_MAP_ANON MAP_ANON |
ebac4655 | 24 | |
232f9b73 JA |
25 | #define fio_swap16(x) bswap16(x) |
26 | #define fio_swap32(x) bswap32(x) | |
27 | #define fio_swap64(x) bswap64(x) | |
28 | ||
907249cf JA |
29 | typedef off_t off64_t; |
30 | ||
63820495 BC |
31 | typedef cpuset_t os_cpu_mask_t; |
32 | ||
33 | #define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask)) | |
34 | #define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask)) | |
c2acfbac | 35 | #define fio_cpu_count(maks) CPU_COUNT((mask)) |
63820495 BC |
36 | |
37 | static inline int fio_cpuset_init(os_cpu_mask_t *mask) | |
38 | { | |
39 | CPU_ZERO(mask); | |
40 | return 0; | |
41 | } | |
42 | ||
43 | static inline int fio_cpuset_exit(os_cpu_mask_t *mask) | |
44 | { | |
45 | return 0; | |
46 | } | |
47 | ||
48 | static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask) | |
49 | { | |
50 | return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask); | |
51 | } | |
52 | ||
53 | static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask) | |
54 | { | |
55 | return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask); | |
56 | } | |
57 | ||
58 | #define FIO_MAX_CPUS CPU_SETSIZE | |
59 | ||
ecc314ba | 60 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) |
aa5e69b2 JA |
61 | { |
62 | off_t size; | |
63 | ||
ecc314ba | 64 | if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) { |
aa5e69b2 JA |
65 | *bytes = size; |
66 | return 0; | |
67 | } | |
68 | ||
2fa55e93 | 69 | *bytes = 0; |
aa5e69b2 JA |
70 | return errno; |
71 | } | |
72 | ||
ecc314ba | 73 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
4ccdccd1 | 74 | { |
9b836561 | 75 | return blockdev_size(f, bytes); |
4ccdccd1 JA |
76 | } |
77 | ||
ecc314ba | 78 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
e5b401d4 JA |
79 | { |
80 | return EINVAL; | |
ebac4655 JA |
81 | } |
82 | ||
32cd46a0 JA |
83 | static inline unsigned long long os_phys_mem(void) |
84 | { | |
85 | int mib[2] = { CTL_HW, HW_PHYSMEM }; | |
86 | unsigned long long mem; | |
87 | size_t len = sizeof(mem); | |
88 | ||
89 | sysctl(mib, 2, &mem, &len, NULL, 0); | |
90 | return mem; | |
91 | } | |
92 | ||
e8d588e4 JA |
93 | static inline int gettid(void) |
94 | { | |
95 | long lwpid; | |
96 | ||
97 | thr_self(&lwpid); | |
98 | return (int) lwpid; | |
99 | } | |
100 | ||
a1c58075 JA |
101 | #ifdef MADV_FREE |
102 | #define FIO_MADV_FREE MADV_FREE | |
103 | #endif | |
104 | ||
ebac4655 | 105 | #endif |