Fix typo in fio_cpu_count()
[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>
5c4e1dbc 13
e2e58886
JA
14#include "../file.h"
15
2c0ecd28 16#define FIO_HAVE_ODIRECT
53531370 17#define FIO_USE_GENERIC_RAND
93bcfd20 18#define FIO_USE_GENERIC_INIT_RANDOM_STATE
4ccdccd1 19#define FIO_HAVE_CHARDEV_SIZE
e8d588e4 20#define FIO_HAVE_GETTID
63820495 21#define FIO_HAVE_CPU_AFFINITY
ebac4655 22
dc873b6f 23#define OS_MAP_ANON MAP_ANON
ebac4655 24
232f9b73
JA
25#define fio_swap16(x) bswap16(x)
26#define fio_swap32(x) bswap32(x)
27#define fio_swap64(x) bswap64(x)
28
907249cf
JA
29typedef off_t off64_t;
30
63820495
BC
31typedef cpuset_t os_cpu_mask_t;
32
33#define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
34#define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
50b5860b 35#define fio_cpu_isset(mask, cpu) CPU_ISSET((cpu), (mask))
d004a209 36#define fio_cpu_count(mask) CPU_COUNT((mask))
63820495
BC
37
38static inline int fio_cpuset_init(os_cpu_mask_t *mask)
39{
40 CPU_ZERO(mask);
41 return 0;
42}
43
44static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
45{
46 return 0;
47}
48
49static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
50{
51 return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask);
52}
53
54static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
55{
56 return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask);
57}
58
59#define FIO_MAX_CPUS CPU_SETSIZE
60
ecc314ba 61static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
aa5e69b2
JA
62{
63 off_t size;
64
ecc314ba 65 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
aa5e69b2
JA
66 *bytes = size;
67 return 0;
68 }
69
2fa55e93 70 *bytes = 0;
aa5e69b2
JA
71 return errno;
72}
73
ecc314ba 74static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
4ccdccd1 75{
9b836561 76 return blockdev_size(f, bytes);
4ccdccd1
JA
77}
78
ecc314ba 79static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4
JA
80{
81 return EINVAL;
ebac4655
JA
82}
83
32cd46a0
JA
84static inline unsigned long long os_phys_mem(void)
85{
86 int mib[2] = { CTL_HW, HW_PHYSMEM };
87 unsigned long long mem;
88 size_t len = sizeof(mem);
89
90 sysctl(mib, 2, &mem, &len, NULL, 0);
91 return mem;
92}
93
e8d588e4
JA
94static inline int gettid(void)
95{
96 long lwpid;
97
98 thr_self(&lwpid);
99 return (int) lwpid;
100}
101
a1c58075
JA
102#ifdef MADV_FREE
103#define FIO_MADV_FREE MADV_FREE
104#endif
105
ebac4655 106#endif