summaryrefslogtreecommitdiffstats
path: root/newlib/libc/sys/rtems/include/sys/cpuset.h
blob: f928a37c7de73d5d0fd6c941141ae78510abd6b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*-
 * Copyright (c) 2008,	Jeffrey Roberson <jeff@freebsd.org>
 * All rights reserved.
 *
 * Copyright (c) 2008 Nokia Corporation
 * All rights reserved.
 *
 * Copyright (c) 2013 On-Line Applications Research Corporation.
 * All rights reserved.
 *
 *  On-Line Applications Research Corporation
 *  7047 Old Madison Pike Suite 320
 *  Huntsville Alabama 35806
 *  <info@oarcorp.com>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: head/sys/sys/cpuset.h 317756 2017-05-03 18:41:08Z cem $
 */

#ifndef _SYS_CPUSET_H_
#define	_SYS_CPUSET_H_

#include <sys/cdefs.h>
#include <sys/_cpuset.h>
#include <sys/bitset.h>

#define	_NCPUBITS	_BITSET_BITS
#define	_NCPUWORDS	__bitset_words(CPU_SETSIZE)

#define	CPUSETBUFSIZ	((2 + sizeof(long) * 2) * _NCPUWORDS)

#define	CPU_SETOF(n, p)			BIT_SETOF(_cpu_set_bits(setsize), n, p)
#define	CPU_ISFULLSET(p)		BIT_ISFULLSET(_cpu_set_bits(setsize), p)
#define	CPU_SUBSET(p, c)		BIT_SUBSET(_cpu_set_bits(setsize), p, c)
#define	CPU_OVERLAP(p, c)		BIT_OVERLAP(_cpu_set_bits(setsize), p, c)
#define	CPU_CLR_ATOMIC(n, p)		BIT_CLR_ATOMIC(_cpu_set_bits(setsize), n, p)
#define	CPU_SET_ATOMIC(n, p)		BIT_SET_ATOMIC(_cpu_set_bits(setsize), n, p)
#define	CPU_SET_ATOMIC_ACQ(n, p)	BIT_SET_ATOMIC_ACQ(_cpu_set_bits(setsize), n, p)
#define	CPU_AND_ATOMIC(n, p)		BIT_AND_ATOMIC(_cpu_set_bits(setsize), n, p)
#define	CPU_OR_ATOMIC(d, s)		BIT_OR_ATOMIC(_cpu_set_bits(setsize), d, s)
#define	CPU_COPY_STORE_REL(f, t)	BIT_COPY_STORE_REL(_cpu_set_bits(setsize), f, t)
#define	CPU_FFS(p)			BIT_FFS(_cpu_set_bits(setsize), p)
#define	CPUSET_FSET			BITSET_FSET(_NCPUWORDS)
#define	CPUSET_T_INITIALIZER		BITSET_T_INITIALIZER

typedef cpuset_t cpu_set_t;

#define	_cpu_set_bits(_setsize) (8 * (_setsize))

#define	CPU_ALLOC_SIZE(_num_cpus) (sizeof(long) * __bitset_words(_num_cpus))

__BEGIN_DECLS

cpu_set_t *__cpuset_alloc(int num_cpus);

void __cpuset_free(cpu_set_t *set);

static __inline cpu_set_t *CPU_ALLOC(int num_cpus)
{
  return __cpuset_alloc(num_cpus);
}

static __inline void CPU_FREE(cpu_set_t *set)
{
  __cpuset_free(set);
}

static __inline void CPU_ZERO_S(size_t setsize, cpu_set_t *set)
{
  BIT_ZERO(_cpu_set_bits(setsize), set);
}

static __inline void CPU_ZERO(cpu_set_t *set)
{
  CPU_ZERO_S(sizeof(*set), set);
}

static __inline void CPU_FILL_S(size_t setsize, cpu_set_t *set)
{
  BIT_FILL(_cpu_set_bits(setsize), set);
}

static __inline void CPU_FILL(cpu_set_t *set)
{
  CPU_FILL_S(sizeof(*set), set);
}

static __inline void CPU_SET_S(int cpu, size_t setsize, cpu_set_t *set)
{
  BIT_SET(_cpu_set_bits(setsize), cpu, set);
}

static __inline void CPU_SET(int cpu, cpu_set_t *set)
{
  CPU_SET_S(cpu, sizeof(*set), set);
}

static __inline void CPU_CLR_S(int cpu, size_t setsize, cpu_set_t *set)
{
  BIT_CLR(_cpu_set_bits(setsize), cpu, set);
}

static __inline void CPU_CLR(int cpu, cpu_set_t *set)
{
  CPU_CLR_S(cpu, sizeof(*set), set);
}

static __inline int CPU_ISSET_S(int cpu, size_t setsize, const cpu_set_t *set)
{
  return BIT_ISSET(_cpu_set_bits(setsize), cpu, set);
}

static __inline int CPU_ISSET(int cpu, const cpu_set_t *set)
{
  return CPU_ISSET_S(cpu, sizeof(*set), set);
}

static __inline void CPU_COPY(const cpu_set_t *src, cpu_set_t *dest)
{
  BIT_COPY(_cpu_set_bits(setsize), src, dest);
}

static __inline void CPU_AND_S(size_t setsize, cpu_set_t *destset,
  const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
  BIT_AND2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}

static __inline void CPU_AND(cpu_set_t *destset, const cpu_set_t *srcset1,
  const cpu_set_t *srcset2)
{
  CPU_AND_S(sizeof(*destset), destset, srcset1, srcset2);
}

static __inline void CPU_OR_S(size_t setsize, cpu_set_t *destset,
  const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
  BIT_OR2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}

static __inline void CPU_OR(cpu_set_t *destset, const cpu_set_t *srcset1,
  const cpu_set_t *srcset2)
{
  CPU_OR_S(sizeof(*destset), destset, srcset1, srcset2);
}

static __inline void CPU_XOR_S(size_t setsize, cpu_set_t *destset,
  const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
  BIT_XOR2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}

static __inline void CPU_XOR(cpu_set_t *destset, const cpu_set_t *srcset1,
  const cpu_set_t *srcset2)
{
  CPU_XOR_S(sizeof(*destset), destset, srcset1, srcset2);
}

static __inline void CPU_NAND_S(size_t setsize, cpu_set_t *destset,
  const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
  BIT_NAND2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}

static __inline void CPU_NAND(cpu_set_t *destset, const cpu_set_t *srcset1,
  const cpu_set_t *srcset2)
{
  CPU_NAND_S(sizeof(*destset), destset, srcset1, srcset2);
}

static __inline int CPU_COUNT_S(size_t setsize, const cpu_set_t *set)
{
  return BIT_COUNT(_cpu_set_bits(setsize), set);
}

static __inline int CPU_COUNT(const cpu_set_t *set)
{
  return CPU_COUNT_S(sizeof(*set), set);
}

static __inline int CPU_EQUAL_S(size_t setsize, const cpu_set_t *set1,
  const cpu_set_t *set2)
{
  return !BIT_CMP(_cpu_set_bits(setsize), set1, set2);
}

static __inline int CPU_EQUAL(const cpu_set_t *set1, const cpu_set_t *set2)
{
  return CPU_EQUAL_S(sizeof(*set1), set1, set2);
}

static __inline int CPU_CMP(const cpu_set_t *set1, const cpu_set_t *set2)
{
  return BIT_CMP(CPU_SETSIZE, set1, set2);
}

static __inline int CPU_EMPTY(const cpu_set_t *set)
{
  return BIT_EMPTY(_cpu_set_bits(sizeof(*set)), set);
}

__END_DECLS

#ifdef _KERNEL
/* Header file provided outside of Newlib */
#include <machine/_kernel_cpuset.h>
#endif
#endif /* !_SYS_CPUSET_H_ */