shm: have os remove shared memory if fio dies unexpectedly
[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>
b939683e 9#include <sys/thr.h>
f1415a9f 10#include <sys/socket.h>
63820495
BC
11#include <sys/param.h>
12#include <sys/cpuset.h>
60f840a8 13#include <sys/statvfs.h>
5c4e1dbc 14
e2e58886
JA
15#include "../file.h"
16
2c0ecd28 17#define FIO_HAVE_ODIRECT
53531370 18#define FIO_USE_GENERIC_RAND
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
97900ebf
SW
25/* Only have attach-to-open-removed when kern.ipc.shm_allow_removed is 1 */
26#undef FIO_HAVE_SHM_ATTACH_REMOVED
27
ebac4655 28
dc873b6f 29#define OS_MAP_ANON MAP_ANON
ebac4655 30
232f9b73
JA
31#define fio_swap16(x) bswap16(x)
32#define fio_swap32(x) bswap32(x)
33#define fio_swap64(x) bswap64(x)
34
907249cf
JA
35typedef off_t off64_t;
36
63820495
BC
37typedef cpuset_t os_cpu_mask_t;
38
39#define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
40#define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
50b5860b 41#define fio_cpu_isset(mask, cpu) CPU_ISSET((cpu), (mask))
d004a209 42#define fio_cpu_count(mask) CPU_COUNT((mask))
63820495
BC
43
44static inline int fio_cpuset_init(os_cpu_mask_t *mask)
45{
46 CPU_ZERO(mask);
47 return 0;
48}
49
50static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
51{
52 return 0;
53}
54
55static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
56{
57 return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask);
58}
59
60static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
61{
62 return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask);
63}
64
65#define FIO_MAX_CPUS CPU_SETSIZE
66
ecc314ba 67static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
aa5e69b2
JA
68{
69 off_t size;
70
ecc314ba 71 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
aa5e69b2
JA
72 *bytes = size;
73 return 0;
74 }
75
2fa55e93 76 *bytes = 0;
aa5e69b2
JA
77 return errno;
78}
79
ecc314ba 80static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
4ccdccd1 81{
9b836561 82 return blockdev_size(f, bytes);
4ccdccd1
JA
83}
84
ecc314ba 85static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4
JA
86{
87 return EINVAL;
ebac4655
JA
88}
89
32cd46a0
JA
90static inline unsigned long long os_phys_mem(void)
91{
92 int mib[2] = { CTL_HW, HW_PHYSMEM };
93 unsigned long long mem;
94 size_t len = sizeof(mem);
95
96 sysctl(mib, 2, &mem, &len, NULL, 0);
97 return mem;
98}
99
e8d588e4
JA
100static inline int gettid(void)
101{
102 long lwpid;
103
104 thr_self(&lwpid);
105 return (int) lwpid;
106}
107
c08ad04c 108static inline unsigned long long get_fs_free_size(const char *path)
60f840a8
TK
109{
110 unsigned long long ret;
111 struct statvfs s;
112
113 if (statvfs(path, &s) < 0)
114 return -1ULL;
115
116 ret = s.f_frsize;
117 ret *= (unsigned long long) s.f_bfree;
118 return ret;
119}
120
0bf31987
TK
121static inline int os_trim(int fd, unsigned long long start,
122 unsigned long long len)
123{
124 off_t range[2];
125
126 range[0] = start;
127 range[1] = len;
128
129 if (!ioctl(fd, DIOCGDELETE, range))
130 return 0;
131
132 return errno;
133}
134
a1c58075
JA
135#ifdef MADV_FREE
136#define FIO_MADV_FREE MADV_FREE
137#endif
138
ebac4655 139#endif