blob: 875de9642b436dbc7f7ca4c2c28d97853edf5959 [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>
Jens Axboe5c4e1db2006-06-07 14:17:08 +020011
Jens Axboee2e58882011-01-04 08:36:06 +010012#include "../file.h"
13
Jens Axboeebac4652005-12-08 15:25:21 +010014#define FIO_HAVE_POSIXAIO
Jens Axboe2c0ecd22006-06-08 13:25:41 +020015#define FIO_HAVE_ODIRECT
Bruce Cranecc314b2011-01-04 10:59:30 +010016#define FIO_HAVE_STRSEP
Jens Axboe53531372009-12-15 10:28:37 +010017#define FIO_USE_GENERIC_RAND
Jens Axboe4ccdccd2010-06-24 10:27:22 +020018#define FIO_HAVE_CHARDEV_SIZE
Bruce Cranecc314b2011-01-04 10:59:30 +010019#define FIO_HAVE_CLOCK_MONOTONIC
Jens Axboee8d588e2011-07-12 22:33:53 +020020#define FIO_HAVE_GETTID
Jens Axboeebac4652005-12-08 15:25:21 +010021
Jens Axboedc873b62008-06-04 20:13:04 +020022#define OS_MAP_ANON MAP_ANON
Jens Axboeebac4652005-12-08 15:25:21 +010023
Jens Axboe232f9b72011-10-04 14:45:20 +020024#if BYTE_ORDER == LITTLE_ENDIAN
25#define FIO_LITTLE_ENDIAN
26#else
27#define FIO_BIG_ENDIAN
28#endif
29
30#define fio_swap16(x) bswap16(x)
31#define fio_swap32(x) bswap32(x)
32#define fio_swap64(x) bswap64(x)
33
Jens Axboe907249c2010-06-22 10:30:11 +020034typedef off_t off64_t;
35
Bruce Cranecc314b2011-01-04 10:59:30 +010036static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboeaa5e69b2010-06-24 09:25:15 +020037{
38 off_t size;
39
Bruce Cranecc314b2011-01-04 10:59:30 +010040 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
Jens Axboeaa5e69b2010-06-24 09:25:15 +020041 *bytes = size;
42 return 0;
43 }
44
Jens Axboe2fa55e92010-06-24 09:36:11 +020045 *bytes = 0;
Jens Axboeaa5e69b2010-06-24 09:25:15 +020046 return errno;
47}
48
Bruce Cranecc314b2011-01-04 10:59:30 +010049static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboe4ccdccd2010-06-24 10:27:22 +020050{
Bruce Cran9b836562011-01-08 19:49:54 +010051 return blockdev_size(f, bytes);
Jens Axboe4ccdccd2010-06-24 10:27:22 +020052}
53
Bruce Cranecc314b2011-01-04 10:59:30 +010054static inline int blockdev_invalidate_cache(struct fio_file *f)
Jens Axboee5b401d2006-10-18 16:03:40 +020055{
56 return EINVAL;
Jens Axboeebac4652005-12-08 15:25:21 +010057}
58
Jens Axboe32cd46a2006-06-07 13:40:40 +020059static inline unsigned long long os_phys_mem(void)
60{
61 int mib[2] = { CTL_HW, HW_PHYSMEM };
62 unsigned long long mem;
63 size_t len = sizeof(mem);
64
65 sysctl(mib, 2, &mem, &len, NULL, 0);
66 return mem;
67}
68
Jens Axboee8d588e2011-07-12 22:33:53 +020069static inline int gettid(void)
70{
71 long lwpid;
72
73 thr_self(&lwpid);
74 return (int) lwpid;
75}
76
Jens Axboea1c58072009-08-04 23:17:02 +020077#ifdef MADV_FREE
78#define FIO_MADV_FREE MADV_FREE
79#endif
80
Jens Axboeebac4652005-12-08 15:25:21 +010081#endif