Add tests from t/ to the Windows installer
[fio.git] / os / os-solaris.h
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
35 struct 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 typedef psetid_t os_cpu_mask_t;
50
51 static 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
64 static inline int blockdev_invalidate_cache(struct fio_file *f)
65 {
66         return ENOTSUP;
67 }
68
69 static inline unsigned long long os_phys_mem(void)
70 {
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;
79 }
80
81 static 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
94 #define FIO_OS_DIRECTIO
95 extern int directio(int, int);
96 static inline int fio_set_odirect(struct fio_file *f)
97 {
98         if (directio(f->fd, DIRECTIO_ON) < 0)
99                 return errno;
100
101         return 0;
102 }
103
104 /*
105  * pset binding hooks for fio
106  */
107 #define fio_setaffinity(pid, cpumask)           \
108         pset_bind((cpumask), P_LWPID, (pid), NULL)
109 #define fio_getaffinity(pid, ptr)       ({ 0; })
110
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)
113
114 static inline bool fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
115 {
116         const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
117         unsigned int num_cpus;
118         processorid_t *cpus;
119         bool ret;
120         int i;
121
122         cpus = malloc(sizeof(*cpus) * max_cpus);
123
124         if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
125                 free(cpus);
126                 return false;
127         }
128
129         ret = false;
130         for (i = 0; i < num_cpus; i++) {
131                 if (cpus[i] == cpu) {
132                         ret = true;
133                         break;
134                 }
135         }
136
137         free(cpus);
138         return ret;
139 }
140
141 static inline int fio_cpu_count(os_cpu_mask_t *mask)
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
151 static 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
159 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
160 {
161         if (pset_destroy(*mask) < 0)
162                 return -1;
163
164         return 0;
165 }
166
167 #ifndef CONFIG_HAVE_GETTID
168 static inline int gettid(void)
169 {
170         return pthread_self();
171 }
172 #endif
173
174 /*
175  * Should be enough, not aware of what (if any) restrictions Solaris has
176  */
177 #define FIO_MAX_CPUS                    16384
178
179 #ifdef MADV_FREE
180 #define FIO_MADV_FREE   MADV_FREE
181 #endif
182
183 #endif