1 #ifndef FIO_OS_SOLARIS_H
2 #define FIO_OS_SOLARIS_H
3 
4 #define	FIO_OS	os_solaris
5 
6 #include <errno.h>
7 #include <malloc.h>
8 #include <unistd.h>
9 #include <sys/types.h>
10 #include <sys/fcntl.h>
11 #include <sys/pset.h>
12 #include <sys/mman.h>
13 #include <sys/dkio.h>
14 #include <sys/byteorder.h>
15 
16 #include "../file.h"
17 
18 #define FIO_HAVE_CPU_AFFINITY
19 #define FIO_HAVE_PSHARED_MUTEX
20 #define FIO_HAVE_CHARDEV_SIZE
21 #define FIO_USE_GENERIC_BDEV_SIZE
22 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
23 #define FIO_HAVE_GETTID
24 
25 #define OS_MAP_ANON		MAP_ANON
26 #define OS_RAND_MAX		2147483648UL
27 
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 
32 struct solaris_rand_seed {
33 	unsigned short r[3];
34 };
35 
36 #ifndef POSIX_MADV_SEQUENTIAL
37 #define posix_madvise	madvise
38 #define POSIX_MADV_SEQUENTIAL	MADV_SEQUENTIAL
39 #define POSIX_MADV_DONTNEED	MADV_DONTNEED
40 #define POSIX_MADV_RANDOM	MADV_RANDOM
41 #endif
42 
43 #define os_ctime_r(x, y, z)     ctime_r((x), (y), (z))
44 #define FIO_OS_HAS_CTIME_R
45 
46 typedef psetid_t os_cpu_mask_t;
47 typedef struct solaris_rand_seed os_random_state_t;
48 
chardev_size(struct fio_file * f,unsigned long long * bytes)49 static 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 
blockdev_invalidate_cache(struct fio_file * f)62 static inline int blockdev_invalidate_cache(struct fio_file *f)
63 {
64 	return 0;
65 }
66 
os_phys_mem(void)67 static inline unsigned long long os_phys_mem(void)
68 {
69 	return 0;
70 }
71 
os_random_seed(unsigned long seed,os_random_state_t * rs)72 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
73 {
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);
80 }
81 
os_random_long(os_random_state_t * rs)82 static inline long os_random_long(os_random_state_t *rs)
83 {
84 	return nrand48(rs->r);
85 }
86 
87 #define FIO_OS_DIRECTIO
88 extern int directio(int, int);
fio_set_odirect(int fd)89 static inline int fio_set_odirect(int fd)
90 {
91 	if (directio(fd, DIRECTIO_ON) < 0)
92 		return errno;
93 
94 	return 0;
95 }
96 
97 /*
98  * pset binding hooks for fio
99  */
100 #define fio_setaffinity(pid, cpumask)		\
101 	pset_bind((cpumask), P_PID, (pid), NULL)
102 #define fio_getaffinity(pid, ptr)	({ 0; })
103 
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)
106 
fio_cpu_isset(os_cpu_mask_t * mask,int cpu)107 static inline int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
108 {
109 	const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
110 	unsigned int num_cpus;
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;
122 	for (i = 0; i < num_cpus; i++) {
123 		if (cpus[i] == cpu) {
124 			ret = 1;
125 			break;
126 		}
127 	}
128 
129 	free(cpus);
130 	return ret;
131 }
132 
fio_cpu_count(os_cpu_mask_t * mask)133 static inline int fio_cpu_count(os_cpu_mask_t *mask)
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 
fio_cpuset_init(os_cpu_mask_t * mask)143 static 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 
fio_cpuset_exit(os_cpu_mask_t * mask)151 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
152 {
153 	if (pset_destroy(*mask) < 0)
154 		return -1;
155 
156 	return 0;
157 }
158 
gettid(void)159 static inline int gettid(void)
160 {
161 	return pthread_self();
162 }
163 
164 /*
165  * Should be enough, not aware of what (if any) restrictions Solaris has
166  */
167 #define FIO_MAX_CPUS			16384
168 
169 #ifdef MADV_FREE
170 #define FIO_MADV_FREE	MADV_FREE
171 #endif
172 
173 #endif
174