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>
14 #include <sys/resource.h>
18 #define FIO_HAVE_ODIRECT
19 #define FIO_USE_GENERIC_RAND
20 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
21 #define FIO_HAVE_FS_STAT
23 #define FIO_HAVE_CHARDEV_SIZE
24 #define FIO_HAVE_GETTID
25 #define FIO_HAVE_CPU_AFFINITY
26 #define FIO_HAVE_IOPRIO
28 #define OS_MAP_ANON MAP_ANON
30 #ifndef PTHREAD_STACK_MIN
31 #define PTHREAD_STACK_MIN 4096
34 #define fio_swap16(x) bswap16(x)
35 #define fio_swap32(x) bswap32(x)
36 #define fio_swap64(x) bswap64(x)
38 /* This is supposed to equal (sizeof(cpumask_t)*8) */
39 #define FIO_MAX_CPUS SMP_MAXCPU
41 typedef off_t off64_t;
42 typedef cpumask_t os_cpu_mask_t;
45 * These macros are copied from sys/cpu/x86_64/include/types.h.
46 * It's okay to copy from arch dependent header because x86_64 is the only
47 * supported arch, and no other arch is going to be supported any time soon.
49 * These are supposed to be able to be included from userspace by defining
50 * _KERNEL_STRUCTURES, however this scheme is badly broken that enabling it
51 * causes compile-time conflicts with other headers. Although the current
52 * upstream code no longer requires _KERNEL_STRUCTURES, they should be kept
53 * here for compatibility with older versions.
55 #ifndef CPUMASK_SIMPLE
56 #define CPUMASK_SIMPLE(cpu) ((uint64_t)1 << (cpu))
57 #define CPUMASK_TESTBIT(val, i) ((val).ary[((i) >> 6) & 3] & \
58 CPUMASK_SIMPLE((i) & 63))
59 #define CPUMASK_ORBIT(mask, i) ((mask).ary[((i) >> 6) & 3] |= \
60 CPUMASK_SIMPLE((i) & 63))
61 #define CPUMASK_NANDBIT(mask, i) ((mask).ary[((i) >> 6) & 3] &= \
62 ~CPUMASK_SIMPLE((i) & 63))
63 #define CPUMASK_ASSZERO(mask) do { \
72 * Define USCHED_GET_CPUMASK as the macro didn't exist until release 4.5.
73 * usched_set(2) returns EINVAL if the kernel doesn't support it.
75 * Also note usched_set(2) works only for the current thread regardless of
76 * the command type. It doesn't work against another thread regardless of
77 * a caller's privilege. A caller would generally specify 0 for pid for the
78 * current thread though that's the only choice. See BUGS in usched_set(2).
80 #ifndef USCHED_GET_CPUMASK
81 #define USCHED_GET_CPUMASK 5
84 /* No CPU_COUNT(), but use the default function defined in os/os.h */
85 #define fio_cpu_count(mask) CPU_COUNT((mask))
87 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
89 CPUMASK_ASSZERO(*mask);
93 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
98 static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu)
100 CPUMASK_NANDBIT(*mask, cpu);
103 static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu)
105 CPUMASK_ORBIT(*mask, cpu);
108 static inline int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
110 if (CPUMASK_TESTBIT(*mask, cpu))
116 static inline int fio_setaffinity(int pid, os_cpu_mask_t mask)
118 int i, firstcall = 1;
120 /* 0 for the current thread, see BUGS in usched_set(2) */
123 for (i = 0; i < FIO_MAX_CPUS; i++) {
124 if (!CPUMASK_TESTBIT(mask, i))
127 if (usched_set(pid, USCHED_SET_CPU, &i, sizeof(int)))
131 if (usched_set(pid, USCHED_ADD_CPU, &i, sizeof(int)))
139 static inline int fio_getaffinity(int pid, os_cpu_mask_t *mask)
141 /* 0 for the current thread, see BUGS in usched_set(2) */
144 if (usched_set(pid, USCHED_GET_CPUMASK, mask, sizeof(*mask)))
150 /* fio code is Linux based, so rename macros to Linux style */
151 #define IOPRIO_WHO_PROCESS PRIO_PROCESS
152 #define IOPRIO_WHO_PGRP PRIO_PGRP
153 #define IOPRIO_WHO_USER PRIO_USER
155 #define IOPRIO_MIN_PRIO 1 /* lowest priority */
156 #define IOPRIO_MAX_PRIO 10 /* highest priority */
159 * Prototypes declared in sys/sys/resource.h are preventing from defining
160 * ioprio_set() with 4 arguments, so define fio's ioprio_set() as a macro.
161 * Note that there is no idea of class within ioprio_set(2) unlike Linux.
163 #define ioprio_set(which, who, ioprio_class, ioprio) \
164 ioprio_set(which, who, ioprio)
166 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
170 if (!ioctl(f->fd, DIOCGPART, &pi)) {
171 *bytes = (unsigned long long) pi.media_size;
179 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
181 return blockdev_size(f, bytes);
184 static inline int blockdev_invalidate_cache(struct fio_file *f)
189 static inline unsigned long long os_phys_mem(void)
191 int mib[2] = { CTL_HW, HW_PHYSMEM };
193 size_t len = sizeof(mem);
195 sysctl(mib, 2, &mem, &len, NULL, 0);
199 static inline int gettid(void)
201 return (int) lwp_gettid();
204 static inline unsigned long long get_fs_free_size(const char *path)
206 unsigned long long ret;
209 if (statvfs(path, &s) < 0)
213 ret *= (unsigned long long) s.f_bfree;
217 static inline int os_trim(int fd, unsigned long long start,
218 unsigned long long len)
225 if (!ioctl(fd, IOCTLTRIM, range))
232 #define FIO_MADV_FREE MADV_FREE