source: rtems/cpukit/include/rtems/score/processormask.h @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 12.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreProcessorMask
7 *
8 * @brief This header file provides the interfaces of the
9 *   @ref RTEMSScoreProcessorMask.
10 */
11
12/*
13 * Copyright (c) 2016, 2017 embedded brains GmbH.  All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_PROCESSORMASK_H
38#define _RTEMS_SCORE_PROCESSORMASK_H
39
40#include <rtems/score/cpu.h>
41
42#include <sys/cpuset.h>
43
44#include <strings.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif /* __cplusplus */
49
50/**
51 * @defgroup RTEMSScoreProcessorMask Processor Mask
52 *
53 * @ingroup RTEMSScore
54 *
55 * @brief This group contains the implementation to support processor masks.
56 *
57 * The processor mask provides a bit map large enough to provide one bit for
58 * each processor in the system.  It is a fixed size internal data type
59 * provided for efficiency in addition to the API level cpu_set_t.
60 *
61 * @{
62 */
63
64/**
65 * @brief A bit map which is large enough to provide one bit for each processor
66 * in the system.
67 */
68typedef BITSET_DEFINE( Processor_mask, CPU_MAXIMUM_PROCESSORS ) Processor_mask;
69
70/**
71 * @brief Sets the bits of the mask to zero, also considers CPU_MAXIMUM_PROCESSORS.
72 *
73 * @param[out] mask The mask to set to zero.
74 */
75RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask *mask )
76{
77  BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask );
78}
79
80/**
81 * @brief Checks if the mask is zero, also considers CPU_MAXIMUM_PROCESSORS.
82 *
83 * @param mask The mask to check whether is is zero
84 *
85 * @retval true The mask is zero.
86 * @retval false The mask is not zero.
87 */
88RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask *mask )
89{
90  return BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask );
91}
92
93/**
94 * @brief Fills the mask, also considers CPU_MAXIMUM_PROCESSORS.
95 *
96 * @param[out] mask The mask to fill
97 */
98RTEMS_INLINE_ROUTINE void _Processor_mask_Fill( Processor_mask *mask )
99{
100  BIT_FILL( CPU_MAXIMUM_PROCESSORS, mask );
101}
102
103/**
104 * @brief Copies the mask to another mask, also considers CPU_MAXIMUM_PROCESSORS.
105 *
106 * @param[out] dst The mask to copy @a src to.
107 * @param src The mask to copy to @a dst.
108 */
109RTEMS_INLINE_ROUTINE void _Processor_mask_Assign(
110  Processor_mask *dst, const Processor_mask *src
111)
112{
113  BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst );
114}
115
116/**
117 * @brief Sets the specified index bit of the mask.
118 *
119 * @param[out] mask The mask to set the bit of.
120 * @param index The index of the bit that shall be set.
121 */
122RTEMS_INLINE_ROUTINE void _Processor_mask_Set(
123  Processor_mask *mask,
124  uint32_t        index
125)
126{
127  BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask );
128}
129
130/**
131 * @brief Clears the specified index bit of the mask.
132 *
133 * @param[out] mask The mask to clear the bit of.
134 * @param index The index of the bit that shall be cleared.
135 */
136RTEMS_INLINE_ROUTINE void _Processor_mask_Clear(
137  Processor_mask *mask,
138  uint32_t        index
139)
140{
141  BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask );
142}
143
144/**
145 * @brief Checks if the specified index bit of the mask is set.
146 *
147 * @param mask The mask to check if the specified bit is set.
148 * @param index The index of the bit that is checked.
149 *
150 * @retval true The specified index bit is set.
151 * @retval false The specified index bit is not set.
152 */
153RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_set(
154  const Processor_mask *mask,
155  uint32_t              index
156)
157{
158  return BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask );
159}
160
161/**
162 * @brief Checks if the processor sets a and b are equal.
163 *
164 * @param a The first processor set.
165 * @param b The seconde processor set.
166 *
167 * @retval true The processor sets a and b are equal.
168 * @retval false The processor sets a and b are not equal.
169 */
170RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_equal(
171  const Processor_mask *a,
172  const Processor_mask *b
173)
174{
175  return !BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b );
176}
177
178/**
179 * @brief Checks if the intersection of the processor sets a and b is
180 * non-empty.
181 *
182 * @param a The first processor set.
183 * @param b The second processor set.
184 *
185 * @retval true The intersection of the processor sets a and b is non-empty.
186 * @retval false The intersection of the processor sets a and b is empty.
187 */
188RTEMS_INLINE_ROUTINE bool _Processor_mask_Has_overlap(
189  const Processor_mask *a,
190  const Processor_mask *b
191)
192{
193  return BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b );
194}
195
196/**
197 * @brief Checks if the processor set small is a subset of processor set
198 * big.
199 *
200 * @param big The bigger processor set.
201 * @param small The smaller processor set.
202 *
203 * @retval true @a small is a subset of @a big.
204 * @retval false @a small is not a subset of @a big.
205 */
206RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_subset(
207  const Processor_mask *big,
208  const Processor_mask *small
209)
210{
211  return BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small );
212}
213
214/**
215 * @brief Performs a bitwise a = b & c.
216 *
217 * @param[out] a The processor mask that is set by this operation.
218 * @param b The first parameter of the AND-operation.
219 * @param c The second parameter of the AND-operation.
220 */
221RTEMS_INLINE_ROUTINE void _Processor_mask_And(
222  Processor_mask       *a,
223  const Processor_mask *b,
224  const Processor_mask *c
225)
226{
227  BIT_AND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
228}
229
230/**
231 * @brief Performs a bitwise a = b & ~c.
232 *
233 * @param[out] a The processor mask that is set by this operation.
234 * @param b The first parameter of the operation.
235 * @param c The second parameter of the operation.
236 */
237RTEMS_INLINE_ROUTINE void _Processor_mask_Nand(
238  Processor_mask       *a,
239  const Processor_mask *b,
240  const Processor_mask *c
241)
242{
243  BIT_NAND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
244}
245
246/**
247 * @brief Performs a bitwise a = b | c.
248 *
249 * @param[out] a The processor mask that is set by this operation.
250 * @param b The first parameter of the OR-operation.
251 * @param c The second parameter of the OR-operation.
252 */
253RTEMS_INLINE_ROUTINE void _Processor_mask_Or(
254  Processor_mask       *a,
255  const Processor_mask *b,
256  const Processor_mask *c
257)
258{
259  BIT_OR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
260}
261
262/**
263 * @brief Performs a bitwise a = b ^ c.
264 *
265 * @param[out] a The processor mask that is set by this operation.
266 * @param b The first parameter of the XOR-operation.
267 * @param c The second parameter of the XOR-operation.
268 */
269RTEMS_INLINE_ROUTINE void _Processor_mask_Xor(
270  Processor_mask       *a,
271  const Processor_mask *b,
272  const Processor_mask *c
273)
274{
275  BIT_XOR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
276}
277
278/**
279 * @brief Gets the number of set bits in the processor mask.
280 *
281 * @param a The processor mask of which the set bits are counted.
282 *
283 * @return The number of set bits in @a a.
284 */
285RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Count( const Processor_mask *a )
286{
287  return (uint32_t) BIT_COUNT( CPU_MAXIMUM_PROCESSORS, a );
288}
289
290/**
291 * @brief Finds the last set of the processor mask.
292 *
293 * @param a The processor mask wo find the last set of.
294 *
295 * @return The last set of @a a.
296 */
297RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Find_last_set( const Processor_mask *a )
298{
299  return (uint32_t) BIT_FLS( CPU_MAXIMUM_PROCESSORS, a );
300}
301
302/**
303 * @brief Returns the subset of 32 processors containing the specified index as
304 * an unsigned 32-bit integer.
305 *
306 * @param mask The processor mask.
307 * @param index The specified index.
308 *
309 * @return The subset containing the specified index as an unsigned 32-bit integer.
310 */
311RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_To_uint32_t(
312  const Processor_mask *mask,
313  uint32_t              index
314)
315{
316  long bits = mask->__bits[ __bitset_words( index ) ];
317
318  return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32));
319}
320
321/**
322 * @brief Creates a processor set from an unsigned 32-bit integer relative to
323 * the specified index.
324 *
325 * @param[out] mask The mask that is created.
326 * @param bits The bits for creating the mask.
327 * @param index The index to which the mask is relative.
328 */
329RTEMS_INLINE_ROUTINE void _Processor_mask_From_uint32_t(
330  Processor_mask *mask,
331  uint32_t        bits,
332  uint32_t        index
333)
334{
335  _Processor_mask_Zero( mask );
336  mask->__bits[ __bitset_words( index ) ] = ((long) bits) << (32 * (index % _BITSET_BITS) / 32);
337}
338
339/**
340 * @brief Creates a processor set from the specified index.
341 *
342 * @param[out] The mask that is created.
343 * @param index The specified index.
344 */
345RTEMS_INLINE_ROUTINE void _Processor_mask_From_index(
346  Processor_mask *mask,
347  uint32_t        index
348)
349{
350  BIT_SETOF( CPU_MAXIMUM_PROCESSORS, (int) index, mask );
351}
352
353typedef enum {
354  PROCESSOR_MASK_COPY_LOSSLESS,
355  PROCESSOR_MASK_COPY_PARTIAL_LOSS,
356  PROCESSOR_MASK_COPY_COMPLETE_LOSS,
357  PROCESSOR_MASK_COPY_INVALID_SIZE
358} Processor_mask_Copy_status;
359
360/**
361 * @brief Checks if the copy status guarantees at most partial loss.
362 *
363 * @param status The copy status to check.
364 *
365 * @retval true At most partial loss can be guaranteed.
366 * @retval false The status indicates more than partial loss.
367 */
368RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_at_most_partial_loss(
369  Processor_mask_Copy_status status
370)
371{
372  return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS;
373}
374
375/**
376 * @brief Copies one mask to another.
377 *
378 * @param[out] dst The destination of the copy operation.
379 * @param dst_size The size of @a dst.
380 * @param src The source of the copy operation.
381 * @param src_size The size of @a src.
382 *
383 * @retval PROCESSOR_MASK_COPY_LOSSLESS It is guaranteed that the copy
384 *      operation is lossless.
385 * @retval PROCESSOR_MASK_COPY_PARTIAL_LOSS Partial loss happened due
386 *      to the sizes of @a src and @a dst.
387 * @retval PROCESSOR_MASK_COPY_COMPLETE_LOSS Complete loss happened due
388 *      to the sizes of @a src and @a dst.
389 * @retval PROCESSOR_MASK_COPY_INVALID_SIZE One of the arguments sizes
390 *      is invalid (bigger than the size of a long).
391 */
392Processor_mask_Copy_status _Processor_mask_Copy(
393  long       *dst,
394  size_t      dst_size,
395  const long *src,
396  size_t      src_size
397);
398
399/**
400 * @brief Copies one mask to another.
401 *
402 * @param src The source for the copy operation.
403 * @param dst_size The size of @a dst.
404 * @param[out] dst The destination for the copy operation.
405 *
406 * @retval PROCESSOR_MASK_COPY_LOSSLESS It is guaranteed that the copy
407 *      operation is lossless.
408 * @retval PROCESSOR_MASK_COPY_PARTIAL_LOSS Partial loss happened due
409 *      to the sizes of @a src and @a dst.
410 * @retval PROCESSOR_MASK_COPY_COMPLETE_LOSS Complete loss happened due
411 *      to the sizes of @a src and @a dst.
412 * @retval PROCESSOR_MASK_COPY_INVALID_SIZE One of the arguments sizes
413 *      is invalid (bigger than the size of a long).
414 */
415RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_To_cpu_set_t(
416  const Processor_mask *src,
417  size_t                dst_size,
418  cpu_set_t            *dst
419)
420{
421  return _Processor_mask_Copy(
422    &dst->__bits[ 0 ],
423    dst_size,
424    &src->__bits[ 0 ],
425    sizeof( *src )
426  );
427}
428
429/**
430 * @brief Copies one mask to another.
431 *
432 * @param src The source for the copy operation.
433 * @param src_size The size of @a src.
434 * @param[out] dst The destination for the copy operation.
435 *
436 * @retval PROCESSOR_MASK_COPY_LOSSLESS It is guaranteed that the copy
437 *      operation is lossless.
438 * @retval PROCESSOR_MASK_COPY_PARTIAL_LOSS Partial loss happened due
439 *      to the sizes of @a src and @a dst.
440 * @retval PROCESSOR_MASK_COPY_COMPLETE_LOSS Complete loss happened due
441 *      to the sizes of @a src and @a dst.
442 * @retval PROCESSOR_MASK_COPY_INVALID_SIZE One of the arguments sizes
443 *      is invalid (bigger than the size of a long).
444 */
445RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(
446  Processor_mask  *dst,
447  size_t           src_size,
448  const cpu_set_t *src
449)
450{
451  return _Processor_mask_Copy(
452    &dst->__bits[ 0 ],
453    sizeof( *dst ),
454    &src->__bits[ 0 ],
455    src_size
456  );
457}
458
459extern const Processor_mask _Processor_mask_The_one_and_only;
460
461/** @} */
462
463#ifdef __cplusplus
464}
465#endif /* __cplusplus */
466
467#endif /* _RTEMS_SCORE_PROCESSORMASK_H */
Note: See TracBrowser for help on using the repository browser.