1 #ifndef FIO_OS_DRAGONFLY_H
2 #define FIO_OS_DRAGONFLY_H
4 #define FIO_OS os_dragonfly
9 #include <sys/sysctl.h>
10 #include <sys/statvfs.h>
11 #include <sys/diskslice.h>
12 #include <sys/ioctl_compat.h>
13 #include <sys/usched.h>
17 #define FIO_HAVE_ODIRECT
18 #define FIO_USE_GENERIC_RAND
19 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
20 #define FIO_HAVE_FS_STAT
22 #define FIO_HAVE_CHARDEV_SIZE
23 #define FIO_HAVE_GETTID
24 #define FIO_HAVE_CPU_AFFINITY
26 #define OS_MAP_ANON MAP_ANON
28 #ifndef PTHREAD_STACK_MIN
29 #define PTHREAD_STACK_MIN 4096
32 #define fio_swap16(x) bswap16(x)
33 #define fio_swap32(x) bswap32(x)
34 #define fio_swap64(x) bswap64(x)
36 /* This is supposed to equal (sizeof(cpumask_t)*8) */
37 #define FIO_MAX_CPUS SMP_MAXCPU
39 typedef off_t off64_t;
40 typedef cpumask_t os_cpu_mask_t;
43 * These macros are copied from sys/cpu/x86_64/include/types.h.
44 * It's okay to copy from arch dependent header because x86_64 is the only
45 * supported arch, and no other arch is going to be supported any time soon.
47 * These are supposed to be able to be included from userspace by defining
48 * _KERNEL_STRUCTURES, however this scheme is badly broken that enabling it
49 * causes compile-time conflicts with other headers. Although the current
50 * upstream code no longer requires _KERNEL_STRUCTURES, they should be kept
51 * here for compatibility with older versions.
53 #ifndef CPUMASK_SIMPLE
54 #define CPUMASK_SIMPLE(cpu) ((uint64_t)1 << (cpu))
55 #define CPUMASK_TESTBIT(val, i) ((val).ary[((i) >> 6) & 3] & \
56 CPUMASK_SIMPLE((i) & 63))
57 #define CPUMASK_ORBIT(mask, i) ((mask).ary[((i) >> 6) & 3] |= \
58 CPUMASK_SIMPLE((i) & 63))
59 #define CPUMASK_NANDBIT(mask, i) ((mask).ary[((i) >> 6) & 3] &= \
60 ~CPUMASK_SIMPLE((i) & 63))
61 #define CPUMASK_ASSZERO(mask) do { \
70 * Define USCHED_GET_CPUMASK as the macro didn't exist until release 4.5.
71 * usched_set(2) returns EINVAL if the kernel doesn't support it, though
72 * fio_getaffinity() returns void.
74 * Also note usched_set(2) works only for the current thread regardless of
75 * the command type. It doesn't work against another thread regardless of
76 * a caller's privilege. A caller would generally specify 0 for pid for the
77 * current thread though that's the only choice. See BUGS in usched_set(2).
79 #ifndef USCHED_GET_CPUMASK
80 #define USCHED_GET_CPUMASK 5
83 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
85 CPUMASK_ASSZERO(*mask);
89 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
94 static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu)
96 CPUMASK_NANDBIT(*mask, cpu);
99 static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu)
101 CPUMASK_ORBIT(*mask, cpu);
104 static inline int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
106 if (CPUMASK_TESTBIT(*mask, cpu))
112 static inline int fio_cpu_count(os_cpu_mask_t *mask)
116 for (i = 0; i < FIO_MAX_CPUS; i++)
117 if (CPUMASK_TESTBIT(*mask, i))
123 static inline int fio_setaffinity(int pid, os_cpu_mask_t mask)
125 int i, firstcall = 1;
127 /* 0 for the current thread, see BUGS in usched_set(2) */
130 for (i = 0; i < FIO_MAX_CPUS; i++) {
131 if (!CPUMASK_TESTBIT(mask, i))
134 if (usched_set(pid, USCHED_SET_CPU, &i, sizeof(int)))
138 if (usched_set(pid, USCHED_ADD_CPU, &i, sizeof(int)))
146 static inline void fio_getaffinity(int pid, os_cpu_mask_t *mask)
148 /* 0 for the current thread, see BUGS in usched_set(2) */
151 usched_set(pid, USCHED_GET_CPUMASK, mask, sizeof(*mask));
154 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
158 if (!ioctl(f->fd, DIOCGPART, &pi)) {
159 *bytes = (unsigned long long) pi.media_size;
167 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
169 return blockdev_size(f, bytes);
172 static inline int blockdev_invalidate_cache(struct fio_file *f)
177 static inline unsigned long long os_phys_mem(void)
179 int mib[2] = { CTL_HW, HW_PHYSMEM };
181 size_t len = sizeof(mem);
183 sysctl(mib, 2, &mem, &len, NULL, 0);
187 static inline int gettid(void)
189 return (int) lwp_gettid();
192 static inline unsigned long long get_fs_free_size(const char *path)
194 unsigned long long ret;
197 if (statvfs(path, &s) < 0)
201 ret *= (unsigned long long) s.f_bfree;
205 static inline int os_trim(int fd, unsigned long long start,
206 unsigned long long len)
213 if (!ioctl(fd, IOCTLTRIM, range))
220 #define FIO_MADV_FREE MADV_FREE