CPU set creation and destruction can fail on some platforms
[fio.git] / os / os-solaris.h
CommitLineData
2c0ecd28
JA
1#ifndef FIO_OS_SOLARIS_H
2#define FIO_OS_SOLARIS_H
3
e116f2b9
JA
4#include <sys/types.h>
5#include <sys/fcntl.h>
6f7024e4 6#include <sys/pset.h>
e116f2b9 7
2c0ecd28 8#define FIO_HAVE_POSIXAIO
417f0068 9#define FIO_HAVE_SOLARISAIO
fffca02d 10#define FIO_HAVE_FALLOCATE
207cb0f0 11#define FIO_HAVE_POSIXAIO_FSYNC
6f7024e4 12#define FIO_HAVE_CPU_AFFINITY
2c0ecd28 13
dc873b6f
JA
14#define OS_MAP_ANON MAP_ANON
15#define OS_RAND_MAX 2147483648UL
2c0ecd28 16
f022ddb7
JA
17struct solaris_rand_seed {
18 unsigned short r[3];
19};
20
6f7024e4 21typedef psetid_t os_cpu_mask_t;
f022ddb7 22typedef struct solaris_rand_seed os_random_state_t;
2c0ecd28
JA
23
24/*
25 * FIXME
26 */
27static inline int blockdev_size(int fd, unsigned long long *bytes)
28{
e5b401d4
JA
29 return EINVAL;
30}
31
32static inline int blockdev_invalidate_cache(int fd)
33{
34 return EINVAL;
2c0ecd28
JA
35}
36
37static inline unsigned long long os_phys_mem(void)
38{
2c0ecd28 39 return 0;
2c0ecd28
JA
40}
41
42static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
43{
f022ddb7
JA
44 rs->r[0] = seed & 0xffff;
45 seed >>= 16;
46 rs->r[1] = seed & 0xffff;
47 seed >>= 16;
48 rs->r[2] = seed & 0xffff;
49 seed48(rs->r);
2c0ecd28
JA
50}
51
52static inline long os_random_long(os_random_state_t *rs)
53{
f022ddb7 54 return nrand48(rs->r);
2c0ecd28
JA
55}
56
e116f2b9
JA
57#define FIO_OS_DIRECTIO
58extern int directio(int, int);
59static inline int fio_set_odirect(int fd)
60{
61 if (directio(fd, DIRECTIO_ON) < 0)
62 return errno;
63
64 return 0;
65}
66
6f7024e4
JA
67/*
68 * pset binding hooks for fio
69 */
70#define fio_setaffinity(td) \
71 pset_bind((td)->o.cpumask, P_PID, (td)->pid)
72#define fio_getaffinity(pid, ptr) \
73 sched_getaffinity((pid), sizeof(cpu_set_t), (ptr))
74
75#define fio_cpu_clear(mask, cpu) pset_assign(*(mask), (cpu), PS_NONE)
76#define fio_cpu_set(mask, cpu) pset_assign(*(mask), (cpu), PS_MYID)
d2ce18b5
JA
77
78static inline int fio_cpuset_init(os_cpu_mask_t *mask)
79{
80 int ret;
81
82 if (pset_create(mask) < 0) {
83 ret = errno;
84 return -1;
85 }
86
87 return 0;
88}
89
90static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
91{
92 int ret;
93
94 if (pset_destroy(*mask) < 0) {
95 ret = errno;
96 return -1;
97 }
98
99 return 0;
100}
6f7024e4
JA
101
102/*
103 * Should be enough, not aware of what (if any) restrictions Solaris has
104 */
105#define FIO_MAX_CPUS 16384
106
2c0ecd28 107#endif