5efd7ac1e96481ec4ed0645c2c2bb88a66cbdf6d
[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 <sys/types.h>
9 #include <sys/fcntl.h>
10 #include <sys/pset.h>
11 #include <sys/mman.h>
12 #include <sys/dkio.h>
13 #include <sys/byteorder.h>
14
15 #include "../file.h"
16
17 #define FIO_HAVE_POSIXAIO
18 #define FIO_HAVE_SOLARISAIO
19 #define FIO_HAVE_POSIXAIO_FSYNC
20 #define FIO_HAVE_CPU_AFFINITY
21 #define FIO_HAVE_PSHARED_MUTEX
22 #define FIO_HAVE_FDATASYNC
23 #define FIO_HAVE_CHARDEV_SIZE
24 #define FIO_USE_GENERIC_BDEV_SIZE
25 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
26 #define FIO_HAVE_GETTID
27 #define FIO_HAVE_FADVISE
28
29 #define OS_MAP_ANON             MAP_ANON
30 #define OS_RAND_MAX             2147483648UL
31
32 #if defined(_BIG_ENDIAN)
33 #define FIO_BIG_ENDIAN
34 #else
35 #define FIO_LITTLE_ENDIAN
36 #endif
37
38 #define fio_swap16(x)   BSWAP_16(x)
39 #define fio_swap32(x)   BSWAP_32(x)
40 #define fio_swap64(x)   BSWAP_64(x)
41
42 struct solaris_rand_seed {
43         unsigned short r[3];
44 };
45
46 #ifndef POSIX_MADV_SEQUENTIAL
47 #define posix_madvise   madvise
48 #define POSIX_MADV_SEQUENTIAL   MADV_SEQUENTIAL
49 #define POSIX_MADV_DONTNEED     MADV_DONTNEED
50 #define POSIX_MADV_RANDOM       MADV_RANDOM
51 #endif
52
53 #define os_ctime_r(x, y, z)     ctime_r((x), (y), (z))
54 #define FIO_OS_HAS_CTIME_R
55
56 typedef psetid_t os_cpu_mask_t;
57 typedef struct solaris_rand_seed os_random_state_t;
58
59 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
60 {
61         struct dk_minfo info;
62
63         *bytes = 0;
64
65         if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
66                 return errno;
67
68         *bytes = info.dki_lbsize * info.dki_capacity;
69         return 0;
70 }
71
72 static inline int blockdev_invalidate_cache(struct fio_file *f)
73 {
74         return 0;
75 }
76
77 static inline unsigned long long os_phys_mem(void)
78 {
79         return 0;
80 }
81
82 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
83 {
84         rs->r[0] = seed & 0xffff;
85         seed >>= 16;
86         rs->r[1] = seed & 0xffff;
87         seed >>= 16;
88         rs->r[2] = seed & 0xffff;
89         seed48(rs->r);
90 }
91
92 static inline long os_random_long(os_random_state_t *rs)
93 {
94         return nrand48(rs->r);
95 }
96
97 #define FIO_OS_DIRECTIO
98 extern int directio(int, int);
99 static inline int fio_set_odirect(int fd)
100 {
101         if (directio(fd, DIRECTIO_ON) < 0)
102                 return errno;
103
104         return 0;
105 }
106
107 /*
108  * pset binding hooks for fio
109  */
110 #define fio_setaffinity(pid, cpumask)           \
111         pset_bind((cpumask), P_PID, (pid), NULL)
112 #define fio_getaffinity(pid, ptr)       ({ 0; })
113
114 #define fio_cpu_clear(mask, cpu)        pset_assign(PS_NONE, (cpu), NULL)
115 #define fio_cpu_set(mask, cpu)          pset_assign(*(mask), (cpu), NULL)
116
117 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
118 {
119         if (pset_create(mask) < 0)
120                 return -1;
121
122         return 0;
123 }
124
125 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
126 {
127         if (pset_destroy(*mask) < 0)
128                 return -1;
129
130         return 0;
131 }
132
133 static inline int gettid(void)
134 {
135         return pthread_self();
136 }
137
138 /*
139  * Should be enough, not aware of what (if any) restrictions Solaris has
140  */
141 #define FIO_MAX_CPUS                    16384
142
143 #ifdef MADV_FREE
144 #define FIO_MADV_FREE   MADV_FREE
145 #endif
146
147 #endif