Merge branch 'minor_fixes' of https://github.com/sitsofe/fio
[fio.git] / os / os-netbsd.h
1 #ifndef FIO_OS_NETBSD_H
2 #define FIO_OS_NETBSD_H
3
4 #define FIO_OS  os_netbsd
5
6 #include <errno.h>
7 #include <lwp.h>
8 #include <sys/param.h>
9 #include <sys/statvfs.h>
10 #include <sys/ioctl.h>
11 #include <sys/dkio.h>
12 #include <sys/disklabel.h>
13 #include <sys/endian.h>
14 /* XXX hack to avoid confilcts between rbtree.h and <sys/rb.h> */
15 #define rb_node _rb_node
16 #include <sys/sysctl.h>
17 #undef rb_node
18 #undef rb_left
19 #undef rb_right
20
21 #include "../file.h"
22
23 #define FIO_HAVE_ODIRECT
24 #define FIO_USE_GENERIC_RAND
25 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
26 #define FIO_HAVE_FS_STAT
27 #define FIO_HAVE_GETTID
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
41 typedef off_t off64_t;
42
43 static 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
56 static inline int blockdev_invalidate_cache(struct fio_file *f)
57 {
58         return ENOTSUP;
59 }
60
61 static 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
71 static inline int gettid(void)
72 {
73         return (int) _lwp_self();
74 }
75
76 static 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
93 #endif