1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Processor Mask API |
---|
5 | * |
---|
6 | * @ingroup ScoreProcessorMask |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2016, 2017 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_PROCESSORMASK_H |
---|
24 | #define _RTEMS_SCORE_PROCESSORMASK_H |
---|
25 | |
---|
26 | #include <rtems/score/cpu.h> |
---|
27 | |
---|
28 | #include <sys/cpuset.h> |
---|
29 | |
---|
30 | #include <strings.h> |
---|
31 | |
---|
32 | #ifdef __cplusplus |
---|
33 | extern "C" { |
---|
34 | #endif /* __cplusplus */ |
---|
35 | |
---|
36 | /** |
---|
37 | * @defgroup ScoreProcessorMask Processor Mask |
---|
38 | * |
---|
39 | * @ingroup Score |
---|
40 | * |
---|
41 | * The processor mask provides a bit map large enough to provide one bit for |
---|
42 | * each processor in the system. It is a fixed size internal data type |
---|
43 | * provided for efficiency in addition to the API level cpu_set_t. |
---|
44 | * |
---|
45 | * @{ |
---|
46 | */ |
---|
47 | |
---|
48 | /** |
---|
49 | * @brief A bit map which is large enough to provide one bit for each processor |
---|
50 | * in the system. |
---|
51 | */ |
---|
52 | typedef BITSET_DEFINE( Processor_mask, CPU_MAXIMUM_PROCESSORS ) Processor_mask; |
---|
53 | |
---|
54 | RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask *mask ) |
---|
55 | { |
---|
56 | BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask ); |
---|
57 | } |
---|
58 | |
---|
59 | RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask *mask ) |
---|
60 | { |
---|
61 | return BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask ); |
---|
62 | } |
---|
63 | |
---|
64 | RTEMS_INLINE_ROUTINE void _Processor_mask_Fill( Processor_mask *mask ) |
---|
65 | { |
---|
66 | BIT_FILL( CPU_MAXIMUM_PROCESSORS, mask ); |
---|
67 | } |
---|
68 | |
---|
69 | RTEMS_INLINE_ROUTINE void _Processor_mask_Assign( |
---|
70 | Processor_mask *dst, const Processor_mask *src |
---|
71 | ) |
---|
72 | { |
---|
73 | BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst ); |
---|
74 | } |
---|
75 | |
---|
76 | RTEMS_INLINE_ROUTINE void _Processor_mask_Set( |
---|
77 | Processor_mask *mask, |
---|
78 | uint32_t index |
---|
79 | ) |
---|
80 | { |
---|
81 | BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask ); |
---|
82 | } |
---|
83 | |
---|
84 | RTEMS_INLINE_ROUTINE void _Processor_mask_Clear( |
---|
85 | Processor_mask *mask, |
---|
86 | uint32_t index |
---|
87 | ) |
---|
88 | { |
---|
89 | BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask ); |
---|
90 | } |
---|
91 | |
---|
92 | RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_set( |
---|
93 | const Processor_mask *mask, |
---|
94 | uint32_t index |
---|
95 | ) |
---|
96 | { |
---|
97 | return BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask ); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * @brief Returns true if the processor sets a and b are equal, and false |
---|
102 | * otherwise. |
---|
103 | */ |
---|
104 | RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_equal( |
---|
105 | const Processor_mask *a, |
---|
106 | const Processor_mask *b |
---|
107 | ) |
---|
108 | { |
---|
109 | return !BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b ); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * @brief Returns true if the intersection of the processor sets a and b is |
---|
114 | * non-empty, and false otherwise. |
---|
115 | */ |
---|
116 | RTEMS_INLINE_ROUTINE bool _Processor_mask_Has_overlap( |
---|
117 | const Processor_mask *a, |
---|
118 | const Processor_mask *b |
---|
119 | ) |
---|
120 | { |
---|
121 | return BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b ); |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Returns true if the processor set small is a subset of processor set |
---|
126 | * big, and false otherwise. |
---|
127 | */ |
---|
128 | RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_subset( |
---|
129 | const Processor_mask *big, |
---|
130 | const Processor_mask *small |
---|
131 | ) |
---|
132 | { |
---|
133 | return BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small ); |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * @brief Performs a bitwise a = b & c. |
---|
138 | */ |
---|
139 | RTEMS_INLINE_ROUTINE void _Processor_mask_And( |
---|
140 | Processor_mask *a, |
---|
141 | const Processor_mask *b, |
---|
142 | const Processor_mask *c |
---|
143 | ) |
---|
144 | { |
---|
145 | BIT_AND2( CPU_MAXIMUM_PROCESSORS, a, b, c ); |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * @brief Performs a bitwise a = b & ~c. |
---|
150 | */ |
---|
151 | RTEMS_INLINE_ROUTINE void _Processor_mask_Nand( |
---|
152 | Processor_mask *a, |
---|
153 | const Processor_mask *b, |
---|
154 | const Processor_mask *c |
---|
155 | ) |
---|
156 | { |
---|
157 | BIT_NAND2( CPU_MAXIMUM_PROCESSORS, a, b, c ); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * @brief Performs a bitwise a = b | c. |
---|
162 | */ |
---|
163 | RTEMS_INLINE_ROUTINE void _Processor_mask_Or( |
---|
164 | Processor_mask *a, |
---|
165 | const Processor_mask *b, |
---|
166 | const Processor_mask *c |
---|
167 | ) |
---|
168 | { |
---|
169 | BIT_OR2( CPU_MAXIMUM_PROCESSORS, a, b, c ); |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * @brief Performs a bitwise a = b ^ c. |
---|
174 | */ |
---|
175 | RTEMS_INLINE_ROUTINE void _Processor_mask_Xor( |
---|
176 | Processor_mask *a, |
---|
177 | const Processor_mask *b, |
---|
178 | const Processor_mask *c |
---|
179 | ) |
---|
180 | { |
---|
181 | BIT_XOR2( CPU_MAXIMUM_PROCESSORS, a, b, c ); |
---|
182 | } |
---|
183 | |
---|
184 | RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Count( const Processor_mask *a ) |
---|
185 | { |
---|
186 | return (uint32_t) BIT_COUNT( CPU_MAXIMUM_PROCESSORS, a ); |
---|
187 | } |
---|
188 | |
---|
189 | RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Find_last_set( const Processor_mask *a ) |
---|
190 | { |
---|
191 | return (uint32_t) BIT_FLS( CPU_MAXIMUM_PROCESSORS, a ); |
---|
192 | } |
---|
193 | |
---|
194 | /** |
---|
195 | * @brief Returns the subset of 32 processors containing the specified index as |
---|
196 | * an unsigned 32-bit integer. |
---|
197 | */ |
---|
198 | RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_To_uint32_t( |
---|
199 | const Processor_mask *mask, |
---|
200 | uint32_t index |
---|
201 | ) |
---|
202 | { |
---|
203 | long bits = mask->__bits[ __bitset_words( index ) ]; |
---|
204 | |
---|
205 | return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32)); |
---|
206 | } |
---|
207 | |
---|
208 | /** |
---|
209 | * @brief Creates a processor set from an unsigned 32-bit integer relative to |
---|
210 | * the specified index. |
---|
211 | */ |
---|
212 | RTEMS_INLINE_ROUTINE void _Processor_mask_From_uint32_t( |
---|
213 | Processor_mask *mask, |
---|
214 | uint32_t bits, |
---|
215 | uint32_t index |
---|
216 | ) |
---|
217 | { |
---|
218 | _Processor_mask_Zero( mask ); |
---|
219 | mask->__bits[ __bitset_words( index ) ] = ((long) bits) << (32 * (index % _BITSET_BITS) / 32); |
---|
220 | } |
---|
221 | |
---|
222 | /** |
---|
223 | * @brief Creates a processor set from the specified index. |
---|
224 | */ |
---|
225 | RTEMS_INLINE_ROUTINE void _Processor_mask_From_index( |
---|
226 | Processor_mask *mask, |
---|
227 | uint32_t index |
---|
228 | ) |
---|
229 | { |
---|
230 | BIT_SETOF( CPU_MAXIMUM_PROCESSORS, (int) index, mask ); |
---|
231 | } |
---|
232 | |
---|
233 | typedef enum { |
---|
234 | PROCESSOR_MASK_COPY_LOSSLESS, |
---|
235 | PROCESSOR_MASK_COPY_PARTIAL_LOSS, |
---|
236 | PROCESSOR_MASK_COPY_COMPLETE_LOSS, |
---|
237 | PROCESSOR_MASK_COPY_INVALID_SIZE |
---|
238 | } Processor_mask_Copy_status; |
---|
239 | |
---|
240 | RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_at_most_partial_loss( |
---|
241 | Processor_mask_Copy_status status |
---|
242 | ) |
---|
243 | { |
---|
244 | return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS; |
---|
245 | } |
---|
246 | |
---|
247 | Processor_mask_Copy_status _Processor_mask_Copy( |
---|
248 | long *dst, |
---|
249 | size_t dst_size, |
---|
250 | const long *src, |
---|
251 | size_t src_size |
---|
252 | ); |
---|
253 | |
---|
254 | RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_To_cpu_set_t( |
---|
255 | const Processor_mask *src, |
---|
256 | size_t dst_size, |
---|
257 | cpu_set_t *dst |
---|
258 | ) |
---|
259 | { |
---|
260 | return _Processor_mask_Copy( |
---|
261 | &dst->__bits[ 0 ], |
---|
262 | dst_size, |
---|
263 | &src->__bits[ 0 ], |
---|
264 | sizeof( *src ) |
---|
265 | ); |
---|
266 | } |
---|
267 | |
---|
268 | RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t( |
---|
269 | Processor_mask *dst, |
---|
270 | size_t src_size, |
---|
271 | const cpu_set_t *src |
---|
272 | ) |
---|
273 | { |
---|
274 | return _Processor_mask_Copy( |
---|
275 | &dst->__bits[ 0 ], |
---|
276 | sizeof( *dst ), |
---|
277 | &src->__bits[ 0 ], |
---|
278 | src_size |
---|
279 | ); |
---|
280 | } |
---|
281 | |
---|
282 | extern const Processor_mask _Processor_mask_The_one_and_only; |
---|
283 | |
---|
284 | /** @} */ |
---|
285 | |
---|
286 | #ifdef __cplusplus |
---|
287 | } |
---|
288 | #endif /* __cplusplus */ |
---|
289 | |
---|
290 | #endif /* _RTEMS_SCORE_PROCESSORMASK_H */ |
---|