blob: e6612118ace4baf7afcae38eb9a7126ca45af10e [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 Axboee116f2b2008-06-04 15:14:24 +02008#include <sys/types.h>
9#include <sys/fcntl.h>
Jens Axboe6f7024e2008-12-12 20:42:26 +010010#include <sys/pset.h>
Jens Axboe08987f02011-01-26 20:43:50 +010011#include <sys/mman.h>
12#include <sys/dkio.h>
Jens Axboe232f9b72011-10-04 14:45:20 +020013#include <sys/byteorder.h>
Jens Axboee116f2b2008-06-04 15:14:24 +020014
Jens Axboee2e58882011-01-04 08:36:06 +010015#include "../file.h"
16
Jens Axboe6f7024e2008-12-12 20:42:26 +010017#define FIO_HAVE_CPU_AFFINITY
Jens Axboef356d012009-01-05 09:56:29 +010018#define FIO_HAVE_PSHARED_MUTEX
Jens Axboe08987f02011-01-26 20:43:50 +010019#define FIO_HAVE_CHARDEV_SIZE
20#define FIO_USE_GENERIC_BDEV_SIZE
Bruce Cran93bcfd22012-02-20 20:18:19 +010021#define FIO_USE_GENERIC_INIT_RANDOM_STATE
Jens Axboe862745b2011-07-19 16:27:43 +020022#define FIO_HAVE_GETTID
Jens Axboe2c0ecd22006-06-08 13:25:41 +020023
Jens Axboedc873b62008-06-04 20:13:04 +020024#define OS_MAP_ANON MAP_ANON
25#define OS_RAND_MAX 2147483648UL
Jens Axboe2c0ecd22006-06-08 13:25:41 +020026
Jens Axboe232f9b72011-10-04 14:45:20 +020027#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 Axboef022ddb2008-06-04 19:55:58 +020031struct solaris_rand_seed {
32 unsigned short r[3];
33};
34
Jens Axboe3f77f722011-01-27 10:10:07 +010035#ifndef POSIX_MADV_SEQUENTIAL
Jens Axboe08987f02011-01-26 20:43:50 +010036#define posix_madvise madvise
Jens Axboe08987f02011-01-26 20:43:50 +010037#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
Jens Axboe3f77f722011-01-27 10:10:07 +010038#define POSIX_MADV_DONTNEED MADV_DONTNEED
Jens Axboe08987f02011-01-26 20:43:50 +010039#define POSIX_MADV_RANDOM MADV_RANDOM
Jens Axboe3f77f722011-01-27 10:10:07 +010040#endif
Jens Axboe08987f02011-01-26 20:43:50 +010041
Saurabh De45054cb2012-10-09 14:46:24 -060042#define os_ctime_r(x, y, z) ctime_r((x), (y), (z))
43#define FIO_OS_HAS_CTIME_R
44
Jens Axboe6f7024e2008-12-12 20:42:26 +010045typedef psetid_t os_cpu_mask_t;
Jens Axboef022ddb2008-06-04 19:55:58 +020046typedef struct solaris_rand_seed os_random_state_t;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020047
Jens Axboe08987f02011-01-26 20:43:50 +010048static 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 Cran9b836562011-01-08 19:49:54 +010061static inline int blockdev_invalidate_cache(struct fio_file *f)
Jens Axboee5b401d2006-10-18 16:03:40 +020062{
Jens Axboe08987f02011-01-26 20:43:50 +010063 return 0;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020064}
65
66static inline unsigned long long os_phys_mem(void)
67{
Jens Axboe2c0ecd22006-06-08 13:25:41 +020068 return 0;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020069}
70
71static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
72{
Jens Axboef022ddb2008-06-04 19:55:58 +020073 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 Axboe2c0ecd22006-06-08 13:25:41 +020079}
80
81static inline long os_random_long(os_random_state_t *rs)
82{
Jens Axboef022ddb2008-06-04 19:55:58 +020083 return nrand48(rs->r);
Jens Axboe2c0ecd22006-06-08 13:25:41 +020084}
85
Jens Axboee116f2b2008-06-04 15:14:24 +020086#define FIO_OS_DIRECTIO
87extern int directio(int, int);
88static 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 Axboe6f7024e2008-12-12 20:42:26 +010096/*
97 * pset binding hooks for fio
98 */
Jens Axboee8462bd2009-07-06 12:59:04 +020099#define fio_setaffinity(pid, cpumask) \
Jens Axboef2b7ce12009-08-03 10:54:41 +0200100 pset_bind((cpumask), P_PID, (pid), NULL)
Jens Axboe39555d02008-12-22 11:28:26 +0100101#define fio_getaffinity(pid, ptr) ({ 0; })
Jens Axboe6f7024e2008-12-12 20:42:26 +0100102
Jens Axboe39555d02008-12-22 11:28:26 +0100103#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 Axboed2ce18b2008-12-12 20:51:40 +0100105
106static inline int fio_cpuset_init(os_cpu_mask_t *mask)
107{
Jens Axboee721c572012-02-09 20:55:29 +0100108 if (pset_create(mask) < 0)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100109 return -1;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100110
111 return 0;
112}
113
114static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
115{
Jens Axboee721c572012-02-09 20:55:29 +0100116 if (pset_destroy(*mask) < 0)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100117 return -1;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100118
119 return 0;
120}
Jens Axboe6f7024e2008-12-12 20:42:26 +0100121
Jens Axboee8d588e2011-07-12 22:33:53 +0200122static inline int gettid(void)
123{
124 return pthread_self();
125}
126
Jens Axboe6f7024e2008-12-12 20:42:26 +0100127/*
128 * Should be enough, not aware of what (if any) restrictions Solaris has
129 */
130#define FIO_MAX_CPUS 16384
131
Jens Axboea1c58072009-08-04 23:17:02 +0200132#ifdef MADV_FREE
133#define FIO_MADV_FREE MADV_FREE
134#endif
135
Jens Axboe2c0ecd22006-06-08 13:25:41 +0200136#endif