1 #ifndef FIO_OS_FREEBSD_H
2 #define FIO_OS_FREEBSD_H
4 #define FIO_OS os_freebsd
7 #include <sys/sysctl.h>
9 #include <sys/endian.h>
11 #include <sys/socket.h>
12 #include <sys/param.h>
13 #include <sys/cpuset.h>
14 #include <sys/statvfs.h>
18 #define FIO_HAVE_ODIRECT
19 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
20 #define FIO_HAVE_CHARDEV_SIZE
21 #define FIO_HAVE_FS_STAT
23 #define FIO_HAVE_GETTID
24 #define FIO_HAVE_CPU_AFFINITY
25 #define FIO_HAVE_SHM_ATTACH_REMOVED
27 #define OS_MAP_ANON MAP_ANON
29 #define fio_swap16(x) bswap16(x)
30 #define fio_swap32(x) bswap32(x)
31 #define fio_swap64(x) bswap64(x)
33 typedef cpuset_t os_cpu_mask_t;
35 #define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
36 #define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
37 #define fio_cpu_isset(mask, cpu) (CPU_ISSET((cpu), (mask)) != 0)
38 #define fio_cpu_count(mask) CPU_COUNT((mask))
40 #ifdef CONFIG_PTHREAD_GETAFFINITY
41 #define FIO_HAVE_GET_THREAD_AFFINITY
42 #define fio_get_thread_affinity(mask) \
43 pthread_getaffinity_np(pthread_self(), sizeof(mask), &(mask))
46 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
52 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
57 static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
59 return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask);
62 static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
64 return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask);
67 #define FIO_MAX_CPUS CPU_SETSIZE
69 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
73 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
82 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
84 return blockdev_size(f, bytes);
87 static inline int blockdev_invalidate_cache(struct fio_file *f)
92 static inline unsigned long long os_phys_mem(void)
94 int mib[2] = { CTL_HW, HW_PHYSMEM };
95 unsigned long long mem;
96 size_t len = sizeof(mem);
98 sysctl(mib, 2, &mem, &len, NULL, 0);
102 static inline int gettid(void)
110 static inline unsigned long long get_fs_free_size(const char *path)
112 unsigned long long ret;
115 if (statvfs(path, &s) < 0)
119 ret *= (unsigned long long) s.f_bfree;
123 static inline int os_trim(struct fio_file *f, unsigned long long start,
124 unsigned long long len)
131 if (!ioctl(f->fd, DIOCGDELETE, range))
138 #define FIO_MADV_FREE MADV_FREE
141 static inline int shm_attach_to_open_removed(void)
144 size_t len = sizeof(x);
146 if (sysctlbyname("kern.ipc.shm_allow_removed", &x, &len, NULL, 0) < 0)
149 return x > 0 ? 1 : 0;