1#ifndef FIO_OS_FREEBSD_H 2#define FIO_OS_FREEBSD_H 3 4#define FIO_OS os_freebsd 5 6#include <errno.h> 7#include <sys/sysctl.h> 8#include <sys/disk.h> 9#include <sys/thr.h> 10#include <sys/socket.h> 11#include <sys/param.h> 12#include <sys/cpuset.h> 13#include <sys/statvfs.h> 14 15#include "../file.h" 16 17#define FIO_HAVE_ODIRECT 18#define FIO_USE_GENERIC_RAND 19#define FIO_USE_GENERIC_INIT_RANDOM_STATE 20#define FIO_HAVE_CHARDEV_SIZE 21#define FIO_HAVE_FS_STAT 22#define FIO_HAVE_TRIM 23#define FIO_HAVE_GETTID 24#define FIO_HAVE_CPU_AFFINITY 25#define FIO_HAVE_SHM_ATTACH_REMOVED 26 27#define OS_MAP_ANON MAP_ANON 28 29#define fio_swap16(x) bswap16(x) 30#define fio_swap32(x) bswap32(x) 31#define fio_swap64(x) bswap64(x) 32 33typedef off_t off64_t; 34 35typedef cpuset_t os_cpu_mask_t; 36 37#define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask)) 38#define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask)) 39#define fio_cpu_isset(mask, cpu) CPU_ISSET((cpu), (mask)) 40#define fio_cpu_count(mask) CPU_COUNT((mask)) 41 42static inline int fio_cpuset_init(os_cpu_mask_t *mask) 43{ 44 CPU_ZERO(mask); 45 return 0; 46} 47 48static inline int fio_cpuset_exit(os_cpu_mask_t *mask) 49{ 50 return 0; 51} 52 53static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask) 54{ 55 return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask); 56} 57 58static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask) 59{ 60 return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask); 61} 62 63#define FIO_MAX_CPUS CPU_SETSIZE 64 65static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) 66{ 67 off_t size; 68 69 if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) { 70 *bytes = size; 71 return 0; 72 } 73 74 *bytes = 0; 75 return errno; 76} 77 78static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) 79{ 80 return blockdev_size(f, bytes); 81} 82 83static inline int blockdev_invalidate_cache(struct fio_file *f) 84{ 85 return ENOTSUP; 86} 87 88static inline unsigned long long os_phys_mem(void) 89{ 90 int mib[2] = { CTL_HW, HW_PHYSMEM }; 91 unsigned long long mem; 92 size_t len = sizeof(mem); 93 94 sysctl(mib, 2, &mem, &len, NULL, 0); 95 return mem; 96} 97 98static inline int gettid(void) 99{ 100 long lwpid; 101 102 thr_self(&lwpid); 103 return (int) lwpid; 104} 105 106static inline unsigned long long get_fs_free_size(const char *path) 107{ 108 unsigned long long ret; 109 struct statvfs s; 110 111 if (statvfs(path, &s) < 0) 112 return -1ULL; 113 114 ret = s.f_frsize; 115 ret *= (unsigned long long) s.f_bfree; 116 return ret; 117} 118 119static inline int os_trim(int fd, unsigned long long start, 120 unsigned long long len) 121{ 122 off_t range[2]; 123 124 range[0] = start; 125 range[1] = len; 126 127 if (!ioctl(fd, DIOCGDELETE, range)) 128 return 0; 129 130 return errno; 131} 132 133#ifdef MADV_FREE 134#define FIO_MADV_FREE MADV_FREE 135#endif 136 137static inline int shm_attach_to_open_removed(void) 138{ 139 int x; 140 size_t len = sizeof(x); 141 142 if (sysctlbyname("kern.ipc.shm_allow_removed", &x, &len, NULL, 0) < 0) 143 return 0; 144 145 return x > 0 ? 1 : 0; 146} 147 148#endif 149