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