solaris: #include <pthread.h>
[fio.git] / os / os-solaris.h
CommitLineData
2c0ecd28
JA
1#ifndef FIO_OS_SOLARIS_H
2#define FIO_OS_SOLARIS_H
3
cca84643
JA
4#define FIO_OS os_solaris
5
690dec6e 6#include <errno.h>
f8ed6d89 7#include <malloc.h>
96ed30ce 8#include <unistd.h>
e116f2b9
JA
9#include <sys/types.h>
10#include <sys/fcntl.h>
6f7024e4 11#include <sys/pset.h>
08987f0e
JA
12#include <sys/mman.h>
13#include <sys/dkio.h>
232f9b73 14#include <sys/byteorder.h>
978536ff 15#include <pthread.h>
e116f2b9 16
e2e58886
JA
17#include "../file.h"
18
6f7024e4 19#define FIO_HAVE_CPU_AFFINITY
08987f0e
JA
20#define FIO_HAVE_CHARDEV_SIZE
21#define FIO_USE_GENERIC_BDEV_SIZE
93bcfd20 22#define FIO_USE_GENERIC_INIT_RANDOM_STATE
862745bf 23#define FIO_HAVE_GETTID
2c0ecd28 24
dc873b6f
JA
25#define OS_MAP_ANON MAP_ANON
26#define OS_RAND_MAX 2147483648UL
2c0ecd28 27
232f9b73
JA
28#define fio_swap16(x) BSWAP_16(x)
29#define fio_swap32(x) BSWAP_32(x)
30#define fio_swap64(x) BSWAP_64(x)
31
f022ddb7
JA
32struct solaris_rand_seed {
33 unsigned short r[3];
34};
35
3f77f723 36#ifndef POSIX_MADV_SEQUENTIAL
08987f0e 37#define posix_madvise madvise
08987f0e 38#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
3f77f723 39#define POSIX_MADV_DONTNEED MADV_DONTNEED
08987f0e 40#define POSIX_MADV_RANDOM MADV_RANDOM
3f77f723 41#endif
08987f0e 42
45054cbe
SD
43#define os_ctime_r(x, y, z) ctime_r((x), (y), (z))
44#define FIO_OS_HAS_CTIME_R
45
6f7024e4 46typedef psetid_t os_cpu_mask_t;
f022ddb7 47typedef struct solaris_rand_seed os_random_state_t;
2c0ecd28 48
08987f0e
JA
49static 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
9b836561 62static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4 63{
22de5d77 64 return ENOTSUP;
2c0ecd28
JA
65}
66
67static inline unsigned long long os_phys_mem(void)
68{
2c0ecd28 69 return 0;
2c0ecd28
JA
70}
71
72static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
73{
f022ddb7
JA
74 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);
2c0ecd28
JA
80}
81
82static inline long os_random_long(os_random_state_t *rs)
83{
f022ddb7 84 return nrand48(rs->r);
2c0ecd28
JA
85}
86
e116f2b9
JA
87#define FIO_OS_DIRECTIO
88extern int directio(int, int);
2905de74 89static inline int fio_set_odirect(struct fio_file *f)
e116f2b9 90{
2905de74 91 if (directio(f->fd, DIRECTIO_ON) < 0)
e116f2b9
JA
92 return errno;
93
94 return 0;
95}
96
6f7024e4
JA
97/*
98 * pset binding hooks for fio
99 */
e8462bd8 100#define fio_setaffinity(pid, cpumask) \
dffccf56 101 pset_bind((cpumask), P_LWPID, (pid), NULL)
39555d03 102#define fio_getaffinity(pid, ptr) ({ 0; })
6f7024e4 103
39555d03
JA
104#define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
105#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
d2ce18b5 106
50b5860b
JA
107static inline int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
108{
96ed30ce
JA
109 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
110 unsigned int num_cpus;
50b5860b
JA
111 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;
96ed30ce 122 for (i = 0; i < num_cpus; i++) {
50b5860b
JA
123 if (cpus[i] == cpu) {
124 ret = 1;
125 break;
126 }
127 }
128
129 free(cpus);
130 return ret;
131}
132
96ed30ce 133static inline int fio_cpu_count(os_cpu_mask_t *mask)
c2acfbac
JA
134{
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
96ed30ce
JA
143static 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
d2ce18b5
JA
151static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
152{
e721c57f 153 if (pset_destroy(*mask) < 0)
d2ce18b5 154 return -1;
d2ce18b5
JA
155
156 return 0;
157}
6f7024e4 158
e8d588e4
JA
159static inline int gettid(void)
160{
161 return pthread_self();
162}
163
6f7024e4
JA
164/*
165 * Should be enough, not aware of what (if any) restrictions Solaris has
166 */
167#define FIO_MAX_CPUS 16384
168
a1c58075
JA
169#ifdef MADV_FREE
170#define FIO_MADV_FREE MADV_FREE
171#endif
172
2c0ecd28 173#endif