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