1 #ifndef FIO_OS_SOLARIS_H
2 #define FIO_OS_SOLARIS_H
4 #define FIO_OS os_solaris
14 #include <sys/byteorder.h>
15 #include <sys/statvfs.h>
19 #include "../lib/types.h"
21 #define FIO_HAVE_CPU_AFFINITY
22 #define FIO_HAVE_CHARDEV_SIZE
23 #define FIO_USE_GENERIC_BDEV_SIZE
24 #define FIO_HAVE_FS_STAT
25 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
26 #define FIO_HAVE_GETTID
28 #define OS_MAP_ANON MAP_ANON
29 #define OS_RAND_MAX 2147483648UL
31 #define fio_swap16(x) BSWAP_16(x)
32 #define fio_swap32(x) BSWAP_32(x)
33 #define fio_swap64(x) BSWAP_64(x)
35 struct solaris_rand_seed {
39 #ifndef POSIX_MADV_SEQUENTIAL
40 #define posix_madvise madvise
41 #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
42 #define POSIX_MADV_DONTNEED MADV_DONTNEED
43 #define POSIX_MADV_RANDOM MADV_RANDOM
46 #define os_ctime_r(x, y, z) ctime_r((x), (y), (z))
47 #define FIO_OS_HAS_CTIME_R
49 typedef psetid_t os_cpu_mask_t;
50 typedef struct solaris_rand_seed os_random_state_t;
52 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
58 if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
61 *bytes = info.dki_lbsize * info.dki_capacity;
65 static inline int blockdev_invalidate_cache(struct fio_file *f)
70 static inline unsigned long long os_phys_mem(void)
74 pagesize = sysconf(_SC_PAGESIZE);
75 pages = sysconf(_SC_PHYS_PAGES);
76 if (pages == -1 || pagesize == -1)
79 return (unsigned long long) pages * (unsigned long long) pagesize;
82 static inline unsigned long long get_fs_free_size(const char *path)
84 unsigned long long ret;
87 if (statvfs(path, &s) < 0)
91 ret *= (unsigned long long) s.f_bfree;
95 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
97 rs->r[0] = seed & 0xffff;
99 rs->r[1] = seed & 0xffff;
101 rs->r[2] = seed & 0xffff;
105 static inline long os_random_long(os_random_state_t *rs)
107 return nrand48(rs->r);
110 #define FIO_OS_DIRECTIO
111 extern int directio(int, int);
112 static inline int fio_set_odirect(struct fio_file *f)
114 if (directio(f->fd, DIRECTIO_ON) < 0)
121 * pset binding hooks for fio
123 #define fio_setaffinity(pid, cpumask) \
124 pset_bind((cpumask), P_LWPID, (pid), NULL)
125 #define fio_getaffinity(pid, ptr) ({ 0; })
127 #define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
128 #define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
130 static inline bool fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
132 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
133 unsigned int num_cpus;
138 cpus = malloc(sizeof(*cpus) * max_cpus);
140 if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
146 for (i = 0; i < num_cpus; i++) {
147 if (cpus[i] == cpu) {
157 static inline int fio_cpu_count(os_cpu_mask_t *mask)
159 unsigned int num_cpus;
161 if (pset_info(*mask, NULL, &num_cpus, NULL) < 0)
167 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
169 if (pset_create(mask) < 0)
175 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
177 if (pset_destroy(*mask) < 0)
183 static inline int gettid(void)
185 return pthread_self();
189 * Should be enough, not aware of what (if any) restrictions Solaris has
191 #define FIO_MAX_CPUS 16384
194 #define FIO_MADV_FREE MADV_FREE