1 #ifndef FIO_OS_OPENBSD_H
2 #define FIO_OS_OPENBSD_H
3
4 #define FIO_OS os_openbsd
5
6 #include <errno.h>
7 #include <sys/param.h>
8 #include <sys/statvfs.h>
9 #include <sys/ioctl.h>
10 #include <sys/dkio.h>
11 #include <sys/disklabel.h>
12 #include <sys/utsname.h>
13 /* XXX hack to avoid conflicts between rbtree.h and <sys/tree.h> */
14 #include <sys/sysctl.h>
15 #undef RB_BLACK
16 #undef RB_RED
17 #undef RB_ROOT
18
19 #include "../file.h"
20
21 #undef FIO_HAVE_ODIRECT
22 #define FIO_USE_GENERIC_RAND
23 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
24 #define FIO_HAVE_FS_STAT
25 #define FIO_HAVE_GETTID
26 #define FIO_HAVE_SHM_ATTACH_REMOVED
27
28 #undef FIO_HAVE_CPU_AFFINITY /* doesn't exist */
29
30 #define OS_MAP_ANON MAP_ANON
31
32 #ifndef PTHREAD_STACK_MIN
33 #define PTHREAD_STACK_MIN 4096
34 #endif
35
36 #define fio_swap16(x) bswap16(x)
37 #define fio_swap32(x) bswap32(x)
38 #define fio_swap64(x) bswap64(x)
39
40 typedef off_t off64_t;
41
blockdev_size(struct fio_file * f,unsigned long long * bytes)42 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
43 {
44 struct disklabel dl;
45
46 if (!ioctl(f->fd, DIOCGDINFO, &dl)) {
47 *bytes = ((unsigned long long)dl.d_secperunit) * dl.d_secsize;
48 return 0;
49 }
50
51 *bytes = 0;
52 return errno;
53 }
54
blockdev_invalidate_cache(struct fio_file * f)55 static inline int blockdev_invalidate_cache(struct fio_file *f)
56 {
57 return ENOTSUP;
58 }
59
os_phys_mem(void)60 static inline unsigned long long os_phys_mem(void)
61 {
62 int mib[2] = { CTL_HW, HW_PHYSMEM64 };
63 uint64_t mem;
64 size_t len = sizeof(mem);
65
66 sysctl(mib, 2, &mem, &len, NULL, 0);
67 return mem;
68 }
69
gettid(void)70 static inline int gettid(void)
71 {
72 return (int)(intptr_t) pthread_self();
73 }
74
get_fs_free_size(const char * path)75 static inline unsigned long long get_fs_free_size(const char *path)
76 {
77 unsigned long long ret;
78 struct statvfs s;
79
80 if (statvfs(path, &s) < 0)
81 return -1ULL;
82
83 ret = s.f_frsize;
84 ret *= (unsigned long long) s.f_bfree;
85 return ret;
86 }
87
88 #ifdef MADV_FREE
89 #define FIO_MADV_FREE MADV_FREE
90 #endif
91
shm_attach_to_open_removed(void)92 static inline int shm_attach_to_open_removed(void)
93 {
94 struct utsname uts;
95 int major, minor;
96
97 if (uname(&uts) == -1)
98 return 0;
99
100 /*
101 * Return 1 if >= OpenBSD 5.1 according to 97900ebf,
102 * assuming both major/minor versions are < 10.
103 */
104 if (uts.release[0] > '9' || uts.release[0] < '0')
105 return 0;
106 if (uts.release[1] != '.')
107 return 0;
108 if (uts.release[2] > '9' || uts.release[2] < '0')
109 return 0;
110
111 major = uts.release[0] - '0';
112 minor = uts.release[2] - '0';
113
114 if (major > 5)
115 return 1;
116 if (major == 5 && minor >= 1)
117 return 1;
118
119 return 0;
120 }
121
122 #endif
123