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