Add gettid() for FreeBSD/OSX/Solaris
[fio.git] / os / os-freebsd.h
CommitLineData
ebac4655
JA
1#ifndef FIO_OS_FREEBSD_H
2#define FIO_OS_FREEBSD_H
3
690dec6e 4#include <errno.h>
5c4e1dbc 5#include <sys/sysctl.h>
aa5e69b2 6#include <sys/disk.h>
5c4e1dbc 7
e2e58886
JA
8#include "../file.h"
9
ebac4655 10#define FIO_HAVE_POSIXAIO
2c0ecd28 11#define FIO_HAVE_ODIRECT
ecc314ba 12#define FIO_HAVE_STRSEP
53531370 13#define FIO_USE_GENERIC_RAND
4ccdccd1 14#define FIO_HAVE_CHARDEV_SIZE
ecc314ba 15#define FIO_HAVE_CLOCK_MONOTONIC
e8d588e4 16#define FIO_HAVE_GETTID
ebac4655 17
dc873b6f 18#define OS_MAP_ANON MAP_ANON
ebac4655 19
907249cf
JA
20typedef off_t off64_t;
21
ecc314ba 22static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
aa5e69b2
JA
23{
24 off_t size;
25
ecc314ba 26 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
aa5e69b2
JA
27 *bytes = size;
28 return 0;
29 }
30
2fa55e93 31 *bytes = 0;
aa5e69b2
JA
32 return errno;
33}
34
ecc314ba 35static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
4ccdccd1 36{
9b836561 37 return blockdev_size(f, bytes);
4ccdccd1
JA
38}
39
ecc314ba 40static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4
JA
41{
42 return EINVAL;
ebac4655
JA
43}
44
32cd46a0
JA
45static inline unsigned long long os_phys_mem(void)
46{
47 int mib[2] = { CTL_HW, HW_PHYSMEM };
48 unsigned long long mem;
49 size_t len = sizeof(mem);
50
51 sysctl(mib, 2, &mem, &len, NULL, 0);
52 return mem;
53}
54
e8d588e4
JA
55static inline int gettid(void)
56{
57 long lwpid;
58
59 thr_self(&lwpid);
60 return (int) lwpid;
61}
62
a1c58075
JA
63#ifdef MADV_FREE
64#define FIO_MADV_FREE MADV_FREE
65#endif
66
ebac4655 67#endif