blob: d97643d02c71394211e915e429ee91b1d6addf1f [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 Axboe2c0ecd22006-06-08 13:25:41 +020017#define FIO_HAVE_POSIXAIO
Jens Axboe417f0062008-06-02 11:59:30 +020018#define FIO_HAVE_SOLARISAIO
Jens Axboe207cb0f2008-06-02 12:28:02 +020019#define FIO_HAVE_POSIXAIO_FSYNC
Jens Axboe6f7024e2008-12-12 20:42:26 +010020#define FIO_HAVE_CPU_AFFINITY
Jens Axboef356d012009-01-05 09:56:29 +010021#define FIO_HAVE_PSHARED_MUTEX
Jens Axboec36d16f2009-12-20 22:29:10 +010022#define FIO_HAVE_FDATASYNC
Jens Axboe08987f02011-01-26 20:43:50 +010023#define FIO_HAVE_CHARDEV_SIZE
24#define FIO_USE_GENERIC_BDEV_SIZE
Bruce Cran93bcfd22012-02-20 20:18:19 +010025#define FIO_USE_GENERIC_INIT_RANDOM_STATE
Jens Axboe862745b2011-07-19 16:27:43 +020026#define FIO_HAVE_GETTID
Jens Axboe2c0ecd22006-06-08 13:25:41 +020027
Jens Axboedc873b62008-06-04 20:13:04 +020028#define OS_MAP_ANON MAP_ANON
29#define OS_RAND_MAX 2147483648UL
Jens Axboe2c0ecd22006-06-08 13:25:41 +020030
Jens Axboe232f9b72011-10-04 14:45:20 +020031#if defined(_BIG_ENDIAN)
32#define FIO_BIG_ENDIAN
33#else
34#define FIO_LITTLE_ENDIAN
35#endif
36
37#define fio_swap16(x) BSWAP_16(x)
38#define fio_swap32(x) BSWAP_32(x)
39#define fio_swap64(x) BSWAP_64(x)
40
Jens Axboef022ddb2008-06-04 19:55:58 +020041struct solaris_rand_seed {
42 unsigned short r[3];
43};
44
Jens Axboe3f77f722011-01-27 10:10:07 +010045#ifndef POSIX_MADV_SEQUENTIAL
Jens Axboe08987f02011-01-26 20:43:50 +010046#define posix_madvise madvise
Jens Axboe08987f02011-01-26 20:43:50 +010047#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
Jens Axboe3f77f722011-01-27 10:10:07 +010048#define POSIX_MADV_DONTNEED MADV_DONTNEED
Jens Axboe08987f02011-01-26 20:43:50 +010049#define POSIX_MADV_RANDOM MADV_RANDOM
Jens Axboe3f77f722011-01-27 10:10:07 +010050#endif
Jens Axboe08987f02011-01-26 20:43:50 +010051
Jens Axboe6f7024e2008-12-12 20:42:26 +010052typedef psetid_t os_cpu_mask_t;
Jens Axboef022ddb2008-06-04 19:55:58 +020053typedef struct solaris_rand_seed os_random_state_t;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020054
Jens Axboe08987f02011-01-26 20:43:50 +010055static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
56{
57 struct dk_minfo info;
58
59 *bytes = 0;
60
61 if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
62 return errno;
63
64 *bytes = info.dki_lbsize * info.dki_capacity;
65 return 0;
66}
67
Bruce Cran9b836562011-01-08 19:49:54 +010068static inline int blockdev_invalidate_cache(struct fio_file *f)
Jens Axboee5b401d2006-10-18 16:03:40 +020069{
Jens Axboe08987f02011-01-26 20:43:50 +010070 return 0;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020071}
72
73static inline unsigned long long os_phys_mem(void)
74{
Jens Axboe2c0ecd22006-06-08 13:25:41 +020075 return 0;
Jens Axboe2c0ecd22006-06-08 13:25:41 +020076}
77
78static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
79{
Jens Axboef022ddb2008-06-04 19:55:58 +020080 rs->r[0] = seed & 0xffff;
81 seed >>= 16;
82 rs->r[1] = seed & 0xffff;
83 seed >>= 16;
84 rs->r[2] = seed & 0xffff;
85 seed48(rs->r);
Jens Axboe2c0ecd22006-06-08 13:25:41 +020086}
87
88static inline long os_random_long(os_random_state_t *rs)
89{
Jens Axboef022ddb2008-06-04 19:55:58 +020090 return nrand48(rs->r);
Jens Axboe2c0ecd22006-06-08 13:25:41 +020091}
92
Jens Axboee116f2b2008-06-04 15:14:24 +020093#define FIO_OS_DIRECTIO
94extern int directio(int, int);
95static inline int fio_set_odirect(int fd)
96{
97 if (directio(fd, DIRECTIO_ON) < 0)
98 return errno;
99
100 return 0;
101}
102
Jens Axboe6f7024e2008-12-12 20:42:26 +0100103/*
104 * pset binding hooks for fio
105 */
Jens Axboee8462bd2009-07-06 12:59:04 +0200106#define fio_setaffinity(pid, cpumask) \
Jens Axboef2b7ce12009-08-03 10:54:41 +0200107 pset_bind((cpumask), P_PID, (pid), NULL)
Jens Axboe39555d02008-12-22 11:28:26 +0100108#define fio_getaffinity(pid, ptr) ({ 0; })
Jens Axboe6f7024e2008-12-12 20:42:26 +0100109
Jens Axboe39555d02008-12-22 11:28:26 +0100110#define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
111#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100112
113static inline int fio_cpuset_init(os_cpu_mask_t *mask)
114{
Jens Axboee721c572012-02-09 20:55:29 +0100115 if (pset_create(mask) < 0)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100116 return -1;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100117
118 return 0;
119}
120
121static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
122{
Jens Axboee721c572012-02-09 20:55:29 +0100123 if (pset_destroy(*mask) < 0)
Jens Axboed2ce18b2008-12-12 20:51:40 +0100124 return -1;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100125
126 return 0;
127}
Jens Axboe6f7024e2008-12-12 20:42:26 +0100128
Jens Axboee8d588e2011-07-12 22:33:53 +0200129static inline int gettid(void)
130{
131 return pthread_self();
132}
133
Jens Axboe6f7024e2008-12-12 20:42:26 +0100134/*
135 * Should be enough, not aware of what (if any) restrictions Solaris has
136 */
137#define FIO_MAX_CPUS 16384
138
Jens Axboea1c58072009-08-04 23:17:02 +0200139#ifdef MADV_FREE
140#define FIO_MADV_FREE MADV_FREE
141#endif
142
Jens Axboe2c0ecd22006-06-08 13:25:41 +0200143#endif