drop logging when blkdev invalidation failed on unsupported platforms
[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
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
907249cf
JA
33typedef off_t off64_t;
34
63820495
BC
35typedef cpuset_t os_cpu_mask_t;
36
37#define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
38#define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
50b5860b 39#define fio_cpu_isset(mask, cpu) CPU_ISSET((cpu), (mask))
d004a209 40#define fio_cpu_count(mask) CPU_COUNT((mask))
63820495
BC
41
42static inline int fio_cpuset_init(os_cpu_mask_t *mask)
43{
44 CPU_ZERO(mask);
45 return 0;
46}
47
48static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
49{
50 return 0;
51}
52
53static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
54{
55 return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask);
56}
57
58static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
59{
60 return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask);
61}
62
63#define FIO_MAX_CPUS CPU_SETSIZE
64
ecc314ba 65static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
aa5e69b2
JA
66{
67 off_t size;
68
ecc314ba 69 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
aa5e69b2
JA
70 *bytes = size;
71 return 0;
72 }
73
2fa55e93 74 *bytes = 0;
aa5e69b2
JA
75 return errno;
76}
77
ecc314ba 78static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
4ccdccd1 79{
9b836561 80 return blockdev_size(f, bytes);
4ccdccd1
JA
81}
82
ecc314ba 83static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4 84{
22de5d77 85 return ENOTSUP;
ebac4655
JA
86}
87
32cd46a0
JA
88static inline unsigned long long os_phys_mem(void)
89{
90 int mib[2] = { CTL_HW, HW_PHYSMEM };
91 unsigned long long mem;
92 size_t len = sizeof(mem);
93
94 sysctl(mib, 2, &mem, &len, NULL, 0);
95 return mem;
96}
97
e8d588e4
JA
98static inline int gettid(void)
99{
100 long lwpid;
101
102 thr_self(&lwpid);
103 return (int) lwpid;
104}
105
c08ad04c 106static inline unsigned long long get_fs_free_size(const char *path)
60f840a8
TK
107{
108 unsigned long long ret;
109 struct statvfs s;
110
111 if (statvfs(path, &s) < 0)
112 return -1ULL;
113
114 ret = s.f_frsize;
115 ret *= (unsigned long long) s.f_bfree;
116 return ret;
117}
118
0bf31987
TK
119static inline int os_trim(int fd, unsigned long long start,
120 unsigned long long len)
121{
122 off_t range[2];
123
124 range[0] = start;
125 range[1] = len;
126
127 if (!ioctl(fd, DIOCGDELETE, range))
128 return 0;
129
130 return errno;
131}
132
a1c58075
JA
133#ifdef MADV_FREE
134#define FIO_MADV_FREE MADV_FREE
135#endif
136
0cfe2089
TK
137static inline int shm_attach_to_open_removed(void)
138{
139 int x;
140 size_t len = sizeof(x);
141
142 if (sysctlbyname("kern.ipc.shm_allow_removed", &x, &len, NULL, 0) < 0)
143 return 0;
144
145 return x > 0 ? 1 : 0;
146}
147
ebac4655 148#endif