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