Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 1 | #ifndef FIO_OS_SOLARIS_H |
| 2 | #define FIO_OS_SOLARIS_H |
| 3 | |
Jens Axboe | cca8464 | 2011-10-07 12:47:57 +0200 | [diff] [blame] | 4 | #define FIO_OS os_solaris |
| 5 | |
Jens Axboe | 690dec6 | 2009-01-06 14:22:30 +0100 | [diff] [blame] | 6 | #include <errno.h> |
Jens Axboe | f8ed6d8 | 2009-12-16 09:50:05 +0100 | [diff] [blame] | 7 | #include <malloc.h> |
Jens Axboe | e116f2b | 2008-06-04 15:14:24 +0200 | [diff] [blame] | 8 | #include <sys/types.h> |
| 9 | #include <sys/fcntl.h> |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 10 | #include <sys/pset.h> |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 11 | #include <sys/mman.h> |
| 12 | #include <sys/dkio.h> |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 13 | #include <sys/byteorder.h> |
Jens Axboe | e116f2b | 2008-06-04 15:14:24 +0200 | [diff] [blame] | 14 | |
Jens Axboe | e2e5888 | 2011-01-04 08:36:06 +0100 | [diff] [blame] | 15 | #include "../file.h" |
| 16 | |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 17 | #define FIO_HAVE_CPU_AFFINITY |
Jens Axboe | f356d01 | 2009-01-05 09:56:29 +0100 | [diff] [blame] | 18 | #define FIO_HAVE_PSHARED_MUTEX |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 19 | #define FIO_HAVE_CHARDEV_SIZE |
| 20 | #define FIO_USE_GENERIC_BDEV_SIZE |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 21 | #define FIO_USE_GENERIC_INIT_RANDOM_STATE |
Jens Axboe | 862745b | 2011-07-19 16:27:43 +0200 | [diff] [blame] | 22 | #define FIO_HAVE_GETTID |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 23 | |
Jens Axboe | dc873b6 | 2008-06-04 20:13:04 +0200 | [diff] [blame] | 24 | #define OS_MAP_ANON MAP_ANON |
| 25 | #define OS_RAND_MAX 2147483648UL |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 26 | |
Jens Axboe | 232f9b7 | 2011-10-04 14:45:20 +0200 | [diff] [blame] | 27 | #define fio_swap16(x) BSWAP_16(x) |
| 28 | #define fio_swap32(x) BSWAP_32(x) |
| 29 | #define fio_swap64(x) BSWAP_64(x) |
| 30 | |
Jens Axboe | f022ddb | 2008-06-04 19:55:58 +0200 | [diff] [blame] | 31 | struct solaris_rand_seed { |
| 32 | unsigned short r[3]; |
| 33 | }; |
| 34 | |
Jens Axboe | 3f77f72 | 2011-01-27 10:10:07 +0100 | [diff] [blame] | 35 | #ifndef POSIX_MADV_SEQUENTIAL |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 36 | #define posix_madvise madvise |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 37 | #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL |
Jens Axboe | 3f77f72 | 2011-01-27 10:10:07 +0100 | [diff] [blame] | 38 | #define POSIX_MADV_DONTNEED MADV_DONTNEED |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 39 | #define POSIX_MADV_RANDOM MADV_RANDOM |
Jens Axboe | 3f77f72 | 2011-01-27 10:10:07 +0100 | [diff] [blame] | 40 | #endif |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 41 | |
Saurabh De | 45054cb | 2012-10-09 14:46:24 -0600 | [diff] [blame] | 42 | #define os_ctime_r(x, y, z) ctime_r((x), (y), (z)) |
| 43 | #define FIO_OS_HAS_CTIME_R |
| 44 | |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 45 | typedef psetid_t os_cpu_mask_t; |
Jens Axboe | f022ddb | 2008-06-04 19:55:58 +0200 | [diff] [blame] | 46 | typedef struct solaris_rand_seed os_random_state_t; |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 47 | |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 48 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
| 49 | { |
| 50 | struct dk_minfo info; |
| 51 | |
| 52 | *bytes = 0; |
| 53 | |
| 54 | if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0) |
| 55 | return errno; |
| 56 | |
| 57 | *bytes = info.dki_lbsize * info.dki_capacity; |
| 58 | return 0; |
| 59 | } |
| 60 | |
Bruce Cran | 9b83656 | 2011-01-08 19:49:54 +0100 | [diff] [blame] | 61 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
Jens Axboe | e5b401d | 2006-10-18 16:03:40 +0200 | [diff] [blame] | 62 | { |
Jens Axboe | 08987f0 | 2011-01-26 20:43:50 +0100 | [diff] [blame] | 63 | return 0; |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static inline unsigned long long os_phys_mem(void) |
| 67 | { |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 68 | return 0; |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) |
| 72 | { |
Jens Axboe | f022ddb | 2008-06-04 19:55:58 +0200 | [diff] [blame] | 73 | rs->r[0] = seed & 0xffff; |
| 74 | seed >>= 16; |
| 75 | rs->r[1] = seed & 0xffff; |
| 76 | seed >>= 16; |
| 77 | rs->r[2] = seed & 0xffff; |
| 78 | seed48(rs->r); |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline long os_random_long(os_random_state_t *rs) |
| 82 | { |
Jens Axboe | f022ddb | 2008-06-04 19:55:58 +0200 | [diff] [blame] | 83 | return nrand48(rs->r); |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Jens Axboe | e116f2b | 2008-06-04 15:14:24 +0200 | [diff] [blame] | 86 | #define FIO_OS_DIRECTIO |
| 87 | extern int directio(int, int); |
| 88 | static inline int fio_set_odirect(int fd) |
| 89 | { |
| 90 | if (directio(fd, DIRECTIO_ON) < 0) |
| 91 | return errno; |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 96 | /* |
| 97 | * pset binding hooks for fio |
| 98 | */ |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 99 | #define fio_setaffinity(pid, cpumask) \ |
Jens Axboe | f2b7ce1 | 2009-08-03 10:54:41 +0200 | [diff] [blame] | 100 | pset_bind((cpumask), P_PID, (pid), NULL) |
Jens Axboe | 39555d0 | 2008-12-22 11:28:26 +0100 | [diff] [blame] | 101 | #define fio_getaffinity(pid, ptr) ({ 0; }) |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 102 | |
Jens Axboe | 39555d0 | 2008-12-22 11:28:26 +0100 | [diff] [blame] | 103 | #define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL) |
| 104 | #define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL) |
Jens Axboe | d2ce18b | 2008-12-12 20:51:40 +0100 | [diff] [blame] | 105 | |
| 106 | static inline int fio_cpuset_init(os_cpu_mask_t *mask) |
| 107 | { |
Jens Axboe | e721c57 | 2012-02-09 20:55:29 +0100 | [diff] [blame] | 108 | if (pset_create(mask) < 0) |
Jens Axboe | d2ce18b | 2008-12-12 20:51:40 +0100 | [diff] [blame] | 109 | return -1; |
Jens Axboe | d2ce18b | 2008-12-12 20:51:40 +0100 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static inline int fio_cpuset_exit(os_cpu_mask_t *mask) |
| 115 | { |
Jens Axboe | e721c57 | 2012-02-09 20:55:29 +0100 | [diff] [blame] | 116 | if (pset_destroy(*mask) < 0) |
Jens Axboe | d2ce18b | 2008-12-12 20:51:40 +0100 | [diff] [blame] | 117 | return -1; |
Jens Axboe | d2ce18b | 2008-12-12 20:51:40 +0100 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 121 | |
Jens Axboe | e8d588e | 2011-07-12 22:33:53 +0200 | [diff] [blame] | 122 | static inline int gettid(void) |
| 123 | { |
| 124 | return pthread_self(); |
| 125 | } |
| 126 | |
Jens Axboe | 6f7024e | 2008-12-12 20:42:26 +0100 | [diff] [blame] | 127 | /* |
| 128 | * Should be enough, not aware of what (if any) restrictions Solaris has |
| 129 | */ |
| 130 | #define FIO_MAX_CPUS 16384 |
| 131 | |
Jens Axboe | a1c5807 | 2009-08-04 23:17:02 +0200 | [diff] [blame] | 132 | #ifdef MADV_FREE |
| 133 | #define FIO_MADV_FREE MADV_FREE |
| 134 | #endif |
| 135 | |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 136 | #endif |