Fix whitespace issues in previous commit
[fio.git] / os / os-solaris.h
... / ...
CommitLineData
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#include <sys/statvfs.h>
16#include <pthread.h>
17
18#include "../file.h"
19#include "../lib/types.h"
20
21#define FIO_HAVE_CPU_AFFINITY
22#define FIO_HAVE_CHARDEV_SIZE
23#define FIO_USE_GENERIC_BDEV_SIZE
24#define FIO_HAVE_FS_STAT
25#define FIO_USE_GENERIC_INIT_RANDOM_STATE
26#define FIO_HAVE_GETTID
27
28#define OS_MAP_ANON MAP_ANON
29#define OS_RAND_MAX 2147483648UL
30
31#define fio_swap16(x) BSWAP_16(x)
32#define fio_swap32(x) BSWAP_32(x)
33#define fio_swap64(x) BSWAP_64(x)
34
35struct solaris_rand_seed {
36 unsigned short r[3];
37};
38
39#ifndef POSIX_MADV_SEQUENTIAL
40#define posix_madvise madvise
41#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
42#define POSIX_MADV_DONTNEED MADV_DONTNEED
43#define POSIX_MADV_RANDOM MADV_RANDOM
44#endif
45
46#define os_ctime_r(x, y, z) ctime_r((x), (y), (z))
47#define FIO_OS_HAS_CTIME_R
48
49typedef psetid_t os_cpu_mask_t;
50typedef struct solaris_rand_seed os_random_state_t;
51
52static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
53{
54 struct dk_minfo info;
55
56 *bytes = 0;
57
58 if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
59 return errno;
60
61 *bytes = info.dki_lbsize * info.dki_capacity;
62 return 0;
63}
64
65static inline int blockdev_invalidate_cache(struct fio_file *f)
66{
67 return ENOTSUP;
68}
69
70static inline unsigned long long os_phys_mem(void)
71{
72 long pagesize, pages;
73
74 pagesize = sysconf(_SC_PAGESIZE);
75 pages = sysconf(_SC_PHYS_PAGES);
76 if (pages == -1 || pagesize == -1)
77 return 0;
78
79 return (unsigned long long) pages * (unsigned long long) pagesize;
80}
81
82static inline unsigned long long get_fs_free_size(const char *path)
83{
84 unsigned long long ret;
85 struct statvfs s;
86
87 if (statvfs(path, &s) < 0)
88 return -1ULL;
89
90 ret = s.f_frsize;
91 ret *= (unsigned long long) s.f_bfree;
92 return ret;
93}
94
95static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
96{
97 rs->r[0] = seed & 0xffff;
98 seed >>= 16;
99 rs->r[1] = seed & 0xffff;
100 seed >>= 16;
101 rs->r[2] = seed & 0xffff;
102 seed48(rs->r);
103}
104
105static inline long os_random_long(os_random_state_t *rs)
106{
107 return nrand48(rs->r);
108}
109
110#define FIO_OS_DIRECTIO
111extern int directio(int, int);
112static inline int fio_set_odirect(struct fio_file *f)
113{
114 if (directio(f->fd, DIRECTIO_ON) < 0)
115 return errno;
116
117 return 0;
118}
119
120/*
121 * pset binding hooks for fio
122 */
123#define fio_setaffinity(pid, cpumask) \
124 pset_bind((cpumask), P_LWPID, (pid), NULL)
125#define fio_getaffinity(pid, ptr) ({ 0; })
126
127#define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
128#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
129
130static inline bool fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
131{
132 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
133 unsigned int num_cpus;
134 processorid_t *cpus;
135 bool ret;
136 int i;
137
138 cpus = malloc(sizeof(*cpus) * max_cpus);
139
140 if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
141 free(cpus);
142 return false;
143 }
144
145 ret = false;
146 for (i = 0; i < num_cpus; i++) {
147 if (cpus[i] == cpu) {
148 ret = true;
149 break;
150 }
151 }
152
153 free(cpus);
154 return ret;
155}
156
157static inline int fio_cpu_count(os_cpu_mask_t *mask)
158{
159 unsigned int num_cpus;
160
161 if (pset_info(*mask, NULL, &num_cpus, NULL) < 0)
162 return 0;
163
164 return num_cpus;
165}
166
167static inline int fio_cpuset_init(os_cpu_mask_t *mask)
168{
169 if (pset_create(mask) < 0)
170 return -1;
171
172 return 0;
173}
174
175static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
176{
177 if (pset_destroy(*mask) < 0)
178 return -1;
179
180 return 0;
181}
182
183static inline int gettid(void)
184{
185 return pthread_self();
186}
187
188/*
189 * Should be enough, not aware of what (if any) restrictions Solaris has
190 */
191#define FIO_MAX_CPUS 16384
192
193#ifdef MADV_FREE
194#define FIO_MADV_FREE MADV_FREE
195#endif
196
197#endif