t/nvmept_trim: increase transfer size for some tests
[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 <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
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
55typedef psetid_t os_cpu_mask_t;
56
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
70static inline int blockdev_invalidate_cache(struct fio_file *f)
71{
72 return ENOTSUP;
73}
74
75static inline unsigned long long os_phys_mem(void)
76{
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;
85}
86
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
100#define FIO_OS_DIRECTIO
101extern int directio(int, int);
102static inline int fio_set_odirect(struct fio_file *f)
103{
104 if (directio(f->fd, DIRECTIO_ON) < 0)
105 return errno;
106
107 return 0;
108}
109
110/*
111 * pset binding hooks for fio
112 */
113#define fio_setaffinity(pid, cpumask) \
114 pset_bind((cpumask), P_LWPID, (pid), NULL)
115#define fio_getaffinity(pid, ptr) ({ 0; })
116
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)
119
120static inline bool fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
121{
122 const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
123 unsigned int num_cpus;
124 processorid_t *cpus;
125 bool ret;
126 int i;
127
128 cpus = malloc(sizeof(*cpus) * max_cpus);
129
130 if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
131 free(cpus);
132 return false;
133 }
134
135 ret = false;
136 for (i = 0; i < num_cpus; i++) {
137 if (cpus[i] == cpu) {
138 ret = true;
139 break;
140 }
141 }
142
143 free(cpus);
144 return ret;
145}
146
147static inline int fio_cpu_count(os_cpu_mask_t *mask)
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
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
165static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
166{
167 if (pset_destroy(*mask) < 0)
168 return -1;
169
170 return 0;
171}
172
173#ifndef CONFIG_HAVE_GETTID
174static inline int gettid(void)
175{
176 return pthread_self();
177}
178#endif
179
180/*
181 * Should be enough, not aware of what (if any) restrictions Solaris has
182 */
183#define FIO_MAX_CPUS 16384
184
185#ifdef MADV_FREE
186#define FIO_MADV_FREE MADV_FREE
187#endif
188
189#endif