Makefile: update libzbc git repository
[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 9#include <sys/types.h>
8393ca93 10#include <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>
8d9f8d0f 15#include <sys/statvfs.h>
978536ff 16#include <pthread.h>
e116f2b9 17
e2e58886 18#include "../file.h"
52fd65f4 19#include "../lib/types.h"
e2e58886 20
6f7024e4 21#define FIO_HAVE_CPU_AFFINITY
08987f0e
JA
22#define FIO_HAVE_CHARDEV_SIZE
23#define FIO_USE_GENERIC_BDEV_SIZE
8d9f8d0f 24#define FIO_HAVE_FS_STAT
93bcfd20 25#define FIO_USE_GENERIC_INIT_RANDOM_STATE
862745bf 26#define FIO_HAVE_GETTID
2c0ecd28 27
dc873b6f
JA
28#define OS_MAP_ANON MAP_ANON
29#define OS_RAND_MAX 2147483648UL
2c0ecd28 30
232f9b73
JA
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
f022ddb7
JA
35struct solaris_rand_seed {
36 unsigned short r[3];
37};
38
3f77f723 39#ifndef POSIX_MADV_SEQUENTIAL
08987f0e 40#define posix_madvise madvise
08987f0e 41#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
3f77f723 42#define POSIX_MADV_DONTNEED MADV_DONTNEED
08987f0e 43#define POSIX_MADV_RANDOM MADV_RANDOM
3f77f723 44#endif
08987f0e 45
45054cbe
SD
46#define os_ctime_r(x, y, z) ctime_r((x), (y), (z))
47#define FIO_OS_HAS_CTIME_R
48
e9d2a04d
TK
49#ifdef CONFIG_PTHREAD_GETAFFINITY
50#define FIO_HAVE_GET_THREAD_AFFINITY
51#define fio_get_thread_affinity(mask) \
52 pthread_getaffinity_np(pthread_self(), sizeof(mask), &(mask))
53#endif
54
6f7024e4 55typedef psetid_t os_cpu_mask_t;
2c0ecd28 56
08987f0e
JA
57static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
58{
59 struct dk_minfo info;
60
61 *bytes = 0;
62
63 if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
64 return errno;
65
66 *bytes = info.dki_lbsize * info.dki_capacity;
67 return 0;
68}
69
9b836561 70static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4 71{
22de5d77 72 return ENOTSUP;
2c0ecd28
JA
73}
74
75static inline unsigned long long os_phys_mem(void)
76{
f1ee6158
TK
77 long pagesize, pages;
78
79 pagesize = sysconf(_SC_PAGESIZE);
80 pages = sysconf(_SC_PHYS_PAGES);
81 if (pages == -1 || pagesize == -1)
82 return 0;
83
84 return (unsigned long long) pages * (unsigned long long) pagesize;
2c0ecd28
JA
85}
86
8d9f8d0f
TK
87static inline unsigned long long get_fs_free_size(const char *path)
88{
89 unsigned long long ret;
90 struct statvfs s;
91
92 if (statvfs(path, &s) < 0)
93 return -1ULL;
94
95 ret = s.f_frsize;
96 ret *= (unsigned long long) s.f_bfree;
97 return ret;
98}
99
e116f2b9
JA
100#define FIO_OS_DIRECTIO
101extern int directio(int, int);
2905de74 102static inline int fio_set_odirect(struct fio_file *f)
e116f2b9 103{
2905de74 104 if (directio(f->fd, DIRECTIO_ON) < 0)
e116f2b9
JA
105 return errno;
106
107 return 0;
108}
109
6f7024e4
JA
110/*
111 * pset binding hooks for fio
112 */
e8462bd8 113#define fio_setaffinity(pid, cpumask) \
dffccf56 114 pset_bind((cpumask), P_LWPID, (pid), NULL)
39555d03 115#define fio_getaffinity(pid, ptr) ({ 0; })
6f7024e4 116
39555d03
JA
117#define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
118#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
d2ce18b5 119
52fd65f4 120static inline bool fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
50b5860b 121{
96ed30ce
JA
122 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
123 unsigned int num_cpus;
50b5860b 124 processorid_t *cpus;
52fd65f4
JA
125 bool ret;
126 int i;
50b5860b
JA
127
128 cpus = malloc(sizeof(*cpus) * max_cpus);
129
130 if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
131 free(cpus);
52fd65f4 132 return false;
50b5860b
JA
133 }
134
52fd65f4 135 ret = false;
96ed30ce 136 for (i = 0; i < num_cpus; i++) {
50b5860b 137 if (cpus[i] == cpu) {
52fd65f4 138 ret = true;
50b5860b
JA
139 break;
140 }
141 }
142
143 free(cpus);
144 return ret;
145}
146
96ed30ce 147static inline int fio_cpu_count(os_cpu_mask_t *mask)
c2acfbac
JA
148{
149 unsigned int num_cpus;
150
151 if (pset_info(*mask, NULL, &num_cpus, NULL) < 0)
152 return 0;
153
154 return num_cpus;
155}
156
96ed30ce
JA
157static inline int fio_cpuset_init(os_cpu_mask_t *mask)
158{
159 if (pset_create(mask) < 0)
160 return -1;
161
162 return 0;
163}
164
d2ce18b5
JA
165static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
166{
e721c57f 167 if (pset_destroy(*mask) < 0)
d2ce18b5 168 return -1;
d2ce18b5
JA
169
170 return 0;
171}
6f7024e4 172
de5ed0e4 173#ifndef CONFIG_HAVE_GETTID
e8d588e4
JA
174static inline int gettid(void)
175{
176 return pthread_self();
177}
de5ed0e4 178#endif
e8d588e4 179
6f7024e4
JA
180/*
181 * Should be enough, not aware of what (if any) restrictions Solaris has
182 */
183#define FIO_MAX_CPUS 16384
184
a1c58075
JA
185#ifdef MADV_FREE
186#define FIO_MADV_FREE MADV_FREE
187#endif
188
2c0ecd28 189#endif