blob: 2a7b7b327a83f6fb50eb7f1839108ca108b9e1ef [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001#ifndef FIO_OS_FREEBSD_H
2#define FIO_OS_FREEBSD_H
3
Jens Axboecca84642011-10-07 12:47:57 +02004#define FIO_OS os_freebsd
5
Jens Axboe690dec62009-01-06 14:22:30 +01006#include <errno.h>
Jens Axboe5c4e1db2006-06-07 14:17:08 +02007#include <sys/sysctl.h>
Jens Axboeaa5e69b2010-06-24 09:25:15 +02008#include <sys/disk.h>
Jens Axboeb9396832011-07-30 13:29:58 +02009#include <sys/thr.h>
Jens Axboe232f9b72011-10-04 14:45:20 +020010#include <sys/endian.h>
Bruce Cranf1415a92011-10-08 18:50:34 +020011#include <sys/socket.h>
Jens Axboe5c4e1db2006-06-07 14:17:08 +020012
Jens Axboee2e58882011-01-04 08:36:06 +010013#include "../file.h"
14
Jens Axboeebac4652005-12-08 15:25:21 +010015#define FIO_HAVE_POSIXAIO
Jens Axboe2c0ecd22006-06-08 13:25:41 +020016#define FIO_HAVE_ODIRECT
Bruce Cranecc314b2011-01-04 10:59:30 +010017#define FIO_HAVE_STRSEP
Jens Axboe53531372009-12-15 10:28:37 +010018#define FIO_USE_GENERIC_RAND
Bruce Cran93bcfd22012-02-20 20:18:19 +010019#define FIO_USE_GENERIC_INIT_RANDOM_STATE
Jens Axboe4ccdccd2010-06-24 10:27:22 +020020#define FIO_HAVE_CHARDEV_SIZE
Jens Axboee8d588e2011-07-12 22:33:53 +020021#define FIO_HAVE_GETTID
Jens Axboeb4c1fb32012-02-16 22:22:46 +010022#define FIO_HAVE_CLOCK_MONOTONIC
Jens Axboeebac4652005-12-08 15:25:21 +010023
Jens Axboedc873b62008-06-04 20:13:04 +020024#define OS_MAP_ANON MAP_ANON
Jens Axboeebac4652005-12-08 15:25:21 +010025
Jens Axboe232f9b72011-10-04 14:45:20 +020026#if BYTE_ORDER == LITTLE_ENDIAN
27#define FIO_LITTLE_ENDIAN
28#else
29#define FIO_BIG_ENDIAN
30#endif
31
32#define fio_swap16(x) bswap16(x)
33#define fio_swap32(x) bswap32(x)
34#define fio_swap64(x) bswap64(x)
35
Jens Axboe907249c2010-06-22 10:30:11 +020036typedef off_t off64_t;
37
Bruce Cranecc314b2011-01-04 10:59:30 +010038static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboeaa5e69b2010-06-24 09:25:15 +020039{
40 off_t size;
41
Bruce Cranecc314b2011-01-04 10:59:30 +010042 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
Jens Axboeaa5e69b2010-06-24 09:25:15 +020043 *bytes = size;
44 return 0;
45 }
46
Jens Axboe2fa55e92010-06-24 09:36:11 +020047 *bytes = 0;
Jens Axboeaa5e69b2010-06-24 09:25:15 +020048 return errno;
49}
50
Bruce Cranecc314b2011-01-04 10:59:30 +010051static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboe4ccdccd2010-06-24 10:27:22 +020052{
Bruce Cran9b836562011-01-08 19:49:54 +010053 return blockdev_size(f, bytes);
Jens Axboe4ccdccd2010-06-24 10:27:22 +020054}
55
Bruce Cranecc314b2011-01-04 10:59:30 +010056static inline int blockdev_invalidate_cache(struct fio_file *f)
Jens Axboee5b401d2006-10-18 16:03:40 +020057{
58 return EINVAL;
Jens Axboeebac4652005-12-08 15:25:21 +010059}
60
Jens Axboe32cd46a2006-06-07 13:40:40 +020061static inline unsigned long long os_phys_mem(void)
62{
63 int mib[2] = { CTL_HW, HW_PHYSMEM };
64 unsigned long long mem;
65 size_t len = sizeof(mem);
66
67 sysctl(mib, 2, &mem, &len, NULL, 0);
68 return mem;
69}
70
Jens Axboee8d588e2011-07-12 22:33:53 +020071static inline int gettid(void)
72{
73 long lwpid;
74
75 thr_self(&lwpid);
76 return (int) lwpid;
77}
78
Jens Axboea1c58072009-08-04 23:17:02 +020079#ifdef MADV_FREE
80#define FIO_MADV_FREE MADV_FREE
81#endif
82
Jens Axboeebac4652005-12-08 15:25:21 +010083#endif