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