blob: 5b78cc2cc43cb384fb8d5e6e1f952bd6f618c1b6 [file] [log] [blame]
Jens Axboe2c0ecd22006-06-08 13:25:41 +02001#ifndef FIO_OS_SOLARIS_H
2#define FIO_OS_SOLARIS_H
3
Jens Axboecca84642011-10-07 12:47:57 +02004#define FIO_OS os_solaris
5
Jens Axboe690dec62009-01-06 14:22:30 +01006#include <errno.h>
Jens Axboef8ed6d82009-12-16 09:50:05 +01007#include <malloc.h>
Jens Axboe96ed30c2014-03-03 13:55:44 -07008#include <unistd.h>
Jens Axboee116f2b2008-06-04 15:14:24 +02009#include <sys/types.h>
10#include <sys/fcntl.h>
Jens Axboe6f7024e2008-12-12 20:42:26 +010011#include <sys/pset.h>
Jens Axboe08987f02011-01-26 20:43:50 +010012#include <sys/mman.h>
13#include <sys/dkio.h>
Jens Axboe232f9b72011-10-04 14:45:20 +020014#include <sys/byteorder.h>
Jens Axboee116f2b2008-06-04 15:14:24 +020015
Jens Axboee2e58882011-01-04 08:36:06 +010016#include "../file.h"
17
Jens Axboe6f7024e2008-12-12 20:42:26 +010018#define FIO_HAVE_CPU_AFFINITY
Jens Axboef356d012009-01-05 09:56:29 +010019#define FIO_HAVE_PSHARED_MUTEX
Jens Axboe08987f02011-01-26 20:43:50 +010020#define FIO_HAVE_CHARDEV_SIZE
21#define FIO_USE_GENERIC_BDEV_SIZE
Bruce Cran93bcfd22012-02-20 20:18:19 +010022#define FIO_USE_GENERIC_INIT_RANDOM_STATE
Jens Axboe862745b2011-07-19 16:27:43 +020023#define FIO_HAVE_GETTID
Jens Axboe2c0ecd22006-06-08 13:25:41 +020024
Jens Axboedc873b62008-06-04 20:13:04 +020025#define OS_MAP_ANON MAP_ANON
26#define OS_RAND_MAX 2147483648UL
Jens Axboe2c0ecd22006-06-08 13:25:41 +020027
Jens Axboe232f9b72011-10-04 14:45:20 +020028#define fio_swap16(x) BSWAP_16(x)
29#define fio_swap32(x) BSWAP_32(x)
30#define fio_swap64(x) BSWAP_64(x)
31
Jens Axboef022ddb2008-06-04 19:55:58 +020032struct solaris_rand_seed {
33 unsigned short r[3];
34};
35
Jens Axboe3f77f722011-01-27 10:10:07 +010036#ifndef POSIX_MADV_SEQUENTIAL
Jens Axboe08987f02011-01-26 20:43:50 +010037#define posix_madvise madvise
Jens Axboe08987f02011-01-26 20:43:50 +010038#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
Jens Axboe3f77f722011-01-27 10:10:07 +010039#define POSIX_MADV_DONTNEED MADV_DONTNEED
Jens Axboe08987f02011-01-26 20:43:50 +010040#define POSIX_MADV_RANDOM MADV_RANDOM
Jens Axboe3f77f722011-01-27 10:10:07 +010041#endif
Jens Axboe08987f02011-01-26 20:43:50 +010042
Saurabh De45054cb2012-10-09 14:46:24 -060043#define os_ctime_r(x, y, z) ctime_r((x), (y), (z))
44#define FIO_OS_HAS_CTIME_R
45
Jens Axboe6f7024e2008-12-12 20:42:26 +010046typedef psetid_t os_cpu_mask_t;
Jens Axboef022ddb2008-06-04 19:55:58 +020047typedef struct solaris_rand_seed os_random_state_t;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020048
Jens Axboe08987f02011-01-26 20:43:50 +010049static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
50{
51 struct dk_minfo info;
52
53 *bytes = 0;
54
55 if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
56 return errno;
57
58 *bytes = info.dki_lbsize * info.dki_capacity;
59 return 0;
60}
61
Bruce Cran9b836562011-01-08 19:49:54 +010062static inline int blockdev_invalidate_cache(struct fio_file *f)
Jens Axboee5b401d2006-10-18 16:03:40 +020063{
Jens Axboe08987f02011-01-26 20:43:50 +010064 return 0;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020065}
66
67static inline unsigned long long os_phys_mem(void)
68{
Jens Axboe2c0ecd22006-06-08 13:25:41 +020069 return 0;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020070}
71
72static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
73{
Jens Axboef022ddb2008-06-04 19:55:58 +020074 rs->r[0] = seed & 0xffff;
75 seed >>= 16;
76 rs->r[1] = seed & 0xffff;
77 seed >>= 16;
78 rs->r[2] = seed & 0xffff;
79 seed48(rs->r);
Jens Axboe2c0ecd22006-06-08 13:25:41 +020080}
81
82static inline long os_random_long(os_random_state_t *rs)
83{
Jens Axboef022ddb2008-06-04 19:55:58 +020084 return nrand48(rs->r);
Jens Axboe2c0ecd22006-06-08 13:25:41 +020085}
86
Jens Axboee116f2b2008-06-04 15:14:24 +020087#define FIO_OS_DIRECTIO
88extern int directio(int, int);
89static inline int fio_set_odirect(int fd)
90{
91 if (directio(fd, DIRECTIO_ON) < 0)
92 return errno;
93
94 return 0;
95}
96
Jens Axboe6f7024e2008-12-12 20:42:26 +010097/*
98 * pset binding hooks for fio
99 */
Jens Axboee8462bd2009-07-06 12:59:04 +0200100#define fio_setaffinity(pid, cpumask) \
Jens Axboef2b7ce12009-08-03 10:54:41 +0200101 pset_bind((cpumask), P_PID, (pid), NULL)
Jens Axboe39555d02008-12-22 11:28:26 +0100102#define fio_getaffinity(pid, ptr) ({ 0; })
Jens Axboe6f7024e2008-12-12 20:42:26 +0100103
Jens Axboe39555d02008-12-22 11:28:26 +0100104#define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
105#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100106
Jens Axboe50b58602014-02-28 15:08:25 -0800107static inline int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
108{
Jens Axboe96ed30c2014-03-03 13:55:44 -0700109 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
110 unsigned int num_cpus;
Jens Axboe50b58602014-02-28 15:08:25 -0800111 processorid_t *cpus;
112 int i, ret;
113
114 cpus = malloc(sizeof(*cpus) * max_cpus);
115
116 if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
117 free(cpus);
118 return 0;
119 }
120
121 ret = 0;
Jens Axboe96ed30c2014-03-03 13:55:44 -0700122 for (i = 0; i < num_cpus; i++) {
Jens Axboe50b58602014-02-28 15:08:25 -0800123 if (cpus[i] == cpu) {
124 ret = 1;
125 break;
126 }
127 }
128
129 free(cpus);
130 return ret;
131}
132
Jens Axboe96ed30c2014-03-03 13:55:44 -0700133static inline int fio_cpu_count(os_cpu_mask_t *mask)
Jens Axboec2acfba2014-02-27 15:52:02 -0800134{
135 unsigned int num_cpus;
136
137 if (pset_info(*mask, NULL, &num_cpus, NULL) < 0)
138 return 0;
139
140 return num_cpus;
141}
142
Jens Axboe96ed30c2014-03-03 13:55:44 -0700143static inline int fio_cpuset_init(os_cpu_mask_t *mask)
144{
145 if (pset_create(mask) < 0)
146 return -1;
147
148 return 0;
149}
150
Jens Axboed2ce18b2008-12-12 20:51:40 +0100151static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
152{
Jens Axboee721c572012-02-09 20:55:29 +0100153 if (pset_destroy(*mask) < 0)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100154 return -1;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100155
156 return 0;
157}
Jens Axboe6f7024e2008-12-12 20:42:26 +0100158
Jens Axboee8d588e2011-07-12 22:33:53 +0200159static inline int gettid(void)
160{
161 return pthread_self();
162}
163
Jens Axboe6f7024e2008-12-12 20:42:26 +0100164/*
165 * Should be enough, not aware of what (if any) restrictions Solaris has
166 */
167#define FIO_MAX_CPUS 16384
168
Jens Axboea1c58072009-08-04 23:17:02 +0200169#ifdef MADV_FREE
170#define FIO_MADV_FREE MADV_FREE
171#endif
172
Jens Axboe2c0ecd22006-06-08 13:25:41 +0200173#endif