Merge branch 'overlap' of https://github.com/bvanassche/fio
[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
6f7024e4 49typedef psetid_t os_cpu_mask_t;
2c0ecd28 50
08987f0e
JA
51static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
52{
53 struct dk_minfo info;
54
55 *bytes = 0;
56
57 if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
58 return errno;
59
60 *bytes = info.dki_lbsize * info.dki_capacity;
61 return 0;
62}
63
9b836561 64static inline int blockdev_invalidate_cache(struct fio_file *f)
e5b401d4 65{
22de5d77 66 return ENOTSUP;
2c0ecd28
JA
67}
68
69static inline unsigned long long os_phys_mem(void)
70{
f1ee6158
TK
71 long pagesize, pages;
72
73 pagesize = sysconf(_SC_PAGESIZE);
74 pages = sysconf(_SC_PHYS_PAGES);
75 if (pages == -1 || pagesize == -1)
76 return 0;
77
78 return (unsigned long long) pages * (unsigned long long) pagesize;
2c0ecd28
JA
79}
80
8d9f8d0f
TK
81static inline unsigned long long get_fs_free_size(const char *path)
82{
83 unsigned long long ret;
84 struct statvfs s;
85
86 if (statvfs(path, &s) < 0)
87 return -1ULL;
88
89 ret = s.f_frsize;
90 ret *= (unsigned long long) s.f_bfree;
91 return ret;
92}
93
e116f2b9
JA
94#define FIO_OS_DIRECTIO
95extern int directio(int, int);
2905de74 96static inline int fio_set_odirect(struct fio_file *f)
e116f2b9 97{
2905de74 98 if (directio(f->fd, DIRECTIO_ON) < 0)
e116f2b9
JA
99 return errno;
100
101 return 0;
102}
103
6f7024e4
JA
104/*
105 * pset binding hooks for fio
106 */
e8462bd8 107#define fio_setaffinity(pid, cpumask) \
dffccf56 108 pset_bind((cpumask), P_LWPID, (pid), NULL)
39555d03 109#define fio_getaffinity(pid, ptr) ({ 0; })
6f7024e4 110
39555d03
JA
111#define fio_cpu_clear(mask, cpu) pset_assign(PS_NONE, (cpu), NULL)
112#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), NULL)
d2ce18b5 113
52fd65f4 114static inline bool fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
50b5860b 115{
96ed30ce
JA
116 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
117 unsigned int num_cpus;
50b5860b 118 processorid_t *cpus;
52fd65f4
JA
119 bool ret;
120 int i;
50b5860b
JA
121
122 cpus = malloc(sizeof(*cpus) * max_cpus);
123
124 if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
125 free(cpus);
52fd65f4 126 return false;
50b5860b
JA
127 }
128
52fd65f4 129 ret = false;
96ed30ce 130 for (i = 0; i < num_cpus; i++) {
50b5860b 131 if (cpus[i] == cpu) {
52fd65f4 132 ret = true;
50b5860b
JA
133 break;
134 }
135 }
136
137 free(cpus);
138 return ret;
139}
140
96ed30ce 141static inline int fio_cpu_count(os_cpu_mask_t *mask)
c2acfbac
JA
142{
143 unsigned int num_cpus;
144
145 if (pset_info(*mask, NULL, &num_cpus, NULL) < 0)
146 return 0;
147
148 return num_cpus;
149}
150
96ed30ce
JA
151static inline int fio_cpuset_init(os_cpu_mask_t *mask)
152{
153 if (pset_create(mask) < 0)
154 return -1;
155
156 return 0;
157}
158
d2ce18b5
JA
159static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
160{
e721c57f 161 if (pset_destroy(*mask) < 0)
d2ce18b5 162 return -1;
d2ce18b5
JA
163
164 return 0;
165}
6f7024e4 166
de5ed0e4 167#ifndef CONFIG_HAVE_GETTID
e8d588e4
JA
168static inline int gettid(void)
169{
170 return pthread_self();
171}
de5ed0e4 172#endif
e8d588e4 173
6f7024e4
JA
174/*
175 * Should be enough, not aware of what (if any) restrictions Solaris has
176 */
177#define FIO_MAX_CPUS 16384
178
a1c58075
JA
179#ifdef MADV_FREE
180#define FIO_MADV_FREE MADV_FREE
181#endif
182
2c0ecd28 183#endif