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