| 1 | #ifndef FIO_OS_SOLARIS_H |
| 2 | #define FIO_OS_SOLARIS_H |
| 3 | |
| 4 | #include <errno.h> |
| 5 | #include <malloc.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/fcntl.h> |
| 8 | #include <sys/pset.h> |
| 9 | #include <sys/mman.h> |
| 10 | #include <sys/dkio.h> |
| 11 | |
| 12 | #include "../file.h" |
| 13 | |
| 14 | #define FIO_HAVE_POSIXAIO |
| 15 | #define FIO_HAVE_SOLARISAIO |
| 16 | #define FIO_HAVE_POSIXAIO_FSYNC |
| 17 | #define FIO_HAVE_CPU_AFFINITY |
| 18 | #define FIO_HAVE_PSHARED_MUTEX |
| 19 | #define FIO_HAVE_FDATASYNC |
| 20 | #define FIO_HAVE_CHARDEV_SIZE |
| 21 | #define FIO_USE_GENERIC_BDEV_SIZE |
| 22 | #define FIO_HAVE_GETTID |
| 23 | |
| 24 | #define OS_MAP_ANON MAP_ANON |
| 25 | #define OS_RAND_MAX 2147483648UL |
| 26 | |
| 27 | struct solaris_rand_seed { |
| 28 | unsigned short r[3]; |
| 29 | }; |
| 30 | |
| 31 | #ifndef POSIX_MADV_SEQUENTIAL |
| 32 | #define posix_madvise madvise |
| 33 | #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL |
| 34 | #define POSIX_MADV_DONTNEED MADV_DONTNEED |
| 35 | #define POSIX_MADV_RANDOM MADV_RANDOM |
| 36 | #endif |
| 37 | |
| 38 | typedef psetid_t os_cpu_mask_t; |
| 39 | typedef struct solaris_rand_seed os_random_state_t; |
| 40 | |
| 41 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
| 42 | { |
| 43 | struct dk_minfo info; |
| 44 | |
| 45 | *bytes = 0; |
| 46 | |
| 47 | if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0) |
| 48 | return errno; |
| 49 | |
| 50 | *bytes = info.dki_lbsize * info.dki_capacity; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
| 55 | { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static inline unsigned long long os_phys_mem(void) |
| 60 | { |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) |
| 65 | { |
| 66 | rs->r[0] = seed & 0xffff; |
| 67 | seed >>= 16; |
| 68 | rs->r[1] = seed & 0xffff; |
| 69 | seed >>= 16; |
| 70 | rs->r[2] = seed & 0xffff; |
| 71 | seed48(rs->r); |
| 72 | } |
| 73 | |
| 74 | static inline long os_random_long(os_random_state_t *rs) |
| 75 | { |
| 76 | return nrand48(rs->r); |
| 77 | } |
| 78 | |
| 79 | #define FIO_OS_DIRECTIO |
| 80 | extern int directio(int, int); |
| 81 | static inline int fio_set_odirect(int fd) |
| 82 | { |
| 83 | if (directio(fd, DIRECTIO_ON) < 0) |
| 84 | return errno; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * pset binding hooks for fio |
| 91 | */ |
| 92 | #define fio_setaffinity(pid, cpumask) \ |
| 93 | pset_bind((cpumask), P_PID, (pid), NULL) |
| 94 | #define fio_getaffinity(pid, ptr) ({ 0; }) |
| 95 | |
| 96 | #define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL) |
| 97 | #define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL) |
| 98 | |
| 99 | static inline int fio_cpuset_init(os_cpu_mask_t *mask) |
| 100 | { |
| 101 | int ret; |
| 102 | |
| 103 | if (pset_create(mask) < 0) { |
| 104 | ret = errno; |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static inline int fio_cpuset_exit(os_cpu_mask_t *mask) |
| 112 | { |
| 113 | int ret; |
| 114 | |
| 115 | if (pset_destroy(*mask) < 0) { |
| 116 | ret = errno; |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static inline int gettid(void) |
| 124 | { |
| 125 | return pthread_self(); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Should be enough, not aware of what (if any) restrictions Solaris has |
| 130 | */ |
| 131 | #define FIO_MAX_CPUS 16384 |
| 132 | |
| 133 | #ifdef MADV_FREE |
| 134 | #define FIO_MADV_FREE MADV_FREE |
| 135 | #endif |
| 136 | |
| 137 | #endif |