Makefile: Suppress `-Wimplicit-fallthrough` when compiling `lex.yy`
[fio.git] / os / os-freebsd.h
CommitLineData
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>
1236d61c 9#include <sys/endian.h>
b939683e 10#include <sys/thr.h>
f1415a9f 11#include <sys/socket.h>
63820495
BC
12#include <sys/param.h>
13#include <sys/cpuset.h>
60f840a8 14#include <sys/statvfs.h>
5c4e1dbc 15
e2e58886
JA
16#include "../file.h"
17
2c0ecd28 18#define FIO_HAVE_ODIRECT
93bcfd20 19#define FIO_USE_GENERIC_INIT_RANDOM_STATE
4ccdccd1 20#define FIO_HAVE_CHARDEV_SIZE
60f840a8 21#define FIO_HAVE_FS_STAT
0bf31987 22#define FIO_HAVE_TRIM
e8d588e4 23#define FIO_HAVE_GETTID
63820495 24#define FIO_HAVE_CPU_AFFINITY
0cfe2089 25#define FIO_HAVE_SHM_ATTACH_REMOVED
ebac4655 26
dc873b6f 27#define OS_MAP_ANON MAP_ANON
ebac4655 28
232f9b73
JA
29#define fio_swap16(x) bswap16(x)
30#define fio_swap32(x) bswap32(x)
31#define fio_swap64(x) bswap64(x)
32
63820495
BC
33typedef cpuset_t os_cpu_mask_t;
34
35#define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
36#define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
52fd65f4 37#define fio_cpu_isset(mask, cpu) (CPU_ISSET((cpu), (mask)) != 0)
d004a209 38#define fio_cpu_count(mask) CPU_COUNT((mask))
63820495 39
e9d2a04d
TK
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))
44#endif
45
63820495
BC
46static inline int fio_cpuset_init(os_cpu_mask_t *mask)
47{
48 CPU_ZERO(mask);
49 return 0;
50}
51
52static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
53{
54 return 0;
55}
56
57static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
58{
59 return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask);
60}
61
62static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
63{
64 return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask);
65}
66
67#define FIO_MAX_CPUS CPU_SETSIZE
68
ecc314ba 69static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
aa5e69b2
JA
70{
71 off_t size;
72
ecc314ba 73 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
aa5e69b2
JA
74 *bytes = size;
75 return 0;
76 }
77
2fa55e93 78 *bytes = 0;
aa5e69b2
JA
79 return errno;
80}
81
ecc314ba 82static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
4ccdccd1 83{
9b836561 84 return blockdev_size(f, bytes);
4ccdccd1
JA
85}
86
ecc314ba 87static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4 88{
22de5d77 89 return ENOTSUP;
ebac4655
JA
90}
91
32cd46a0
JA
92static inline unsigned long long os_phys_mem(void)
93{
94 int mib[2] = { CTL_HW, HW_PHYSMEM };
95 unsigned long long mem;
96 size_t len = sizeof(mem);
97
98 sysctl(mib, 2, &mem, &len, NULL, 0);
99 return mem;
100}
101
e8d588e4
JA
102static inline int gettid(void)
103{
104 long lwpid;
105
106 thr_self(&lwpid);
107 return (int) lwpid;
108}
109
c08ad04c 110static inline unsigned long long get_fs_free_size(const char *path)
60f840a8
TK
111{
112 unsigned long long ret;
113 struct statvfs s;
114
115 if (statvfs(path, &s) < 0)
116 return -1ULL;
117
118 ret = s.f_frsize;
119 ret *= (unsigned long long) s.f_bfree;
120 return ret;
121}
122
496b1f9e 123static inline int os_trim(struct fio_file *f, unsigned long long start,
0bf31987
TK
124 unsigned long long len)
125{
126 off_t range[2];
127
128 range[0] = start;
129 range[1] = len;
130
496b1f9e 131 if (!ioctl(f->fd, DIOCGDELETE, range))
0bf31987
TK
132 return 0;
133
134 return errno;
135}
136
a1c58075
JA
137#ifdef MADV_FREE
138#define FIO_MADV_FREE MADV_FREE
139#endif
140
0cfe2089
TK
141static inline int shm_attach_to_open_removed(void)
142{
143 int x;
144 size_t len = sizeof(x);
145
146 if (sysctlbyname("kern.ipc.shm_allow_removed", &x, &len, NULL, 0) < 0)
147 return 0;
148
149 return x > 0 ? 1 : 0;
150}
151
ebac4655 152#endif