RTEMS
processormask.h
Go to the documentation of this file.
1 
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 
54 typedef BITSET_DEFINE( Processor_mask, CPU_MAXIMUM_PROCESSORS ) Processor_mask;
55 
61 RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask *mask )
62 {
63  BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask );
64 }
65 
74 RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask *mask )
75 {
76  return BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask );
77 }
78 
84 RTEMS_INLINE_ROUTINE void _Processor_mask_Fill( Processor_mask *mask )
85 {
86  BIT_FILL( CPU_MAXIMUM_PROCESSORS, mask );
87 }
88 
96  Processor_mask *dst, const Processor_mask *src
97 )
98 {
99  BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst );
100 }
101 
109  Processor_mask *mask,
110  uint32_t index
111 )
112 {
113  BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask );
114 }
115 
123  Processor_mask *mask,
124  uint32_t index
125 )
126 {
127  BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask );
128 }
129 
140  const Processor_mask *mask,
141  uint32_t index
142 )
143 {
144  return BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask );
145 }
146 
157  const Processor_mask *a,
158  const Processor_mask *b
159 )
160 {
161  return !BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b );
162 }
163 
175  const Processor_mask *a,
176  const Processor_mask *b
177 )
178 {
179  return BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b );
180 }
181 
193  const Processor_mask *big,
194  const Processor_mask *small
195 )
196 {
197  return BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small );
198 }
199 
208  Processor_mask *a,
209  const Processor_mask *b,
210  const Processor_mask *c
211 )
212 {
213  BIT_AND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
214 }
215 
224  Processor_mask *a,
225  const Processor_mask *b,
226  const Processor_mask *c
227 )
228 {
229  BIT_NAND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
230 }
231 
240  Processor_mask *a,
241  const Processor_mask *b,
242  const Processor_mask *c
243 )
244 {
245  BIT_OR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
246 }
247 
256  Processor_mask *a,
257  const Processor_mask *b,
258  const Processor_mask *c
259 )
260 {
261  BIT_XOR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
262 }
263 
271 RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Count( const Processor_mask *a )
272 {
273  return (uint32_t) BIT_COUNT( CPU_MAXIMUM_PROCESSORS, a );
274 }
275 
283 RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Find_last_set( const Processor_mask *a )
284 {
285  return (uint32_t) BIT_FLS( CPU_MAXIMUM_PROCESSORS, a );
286 }
287 
298  const Processor_mask *mask,
299  uint32_t index
300 )
301 {
302  long bits = mask->__bits[ __bitset_words( index ) ];
303 
304  return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32));
305 }
306 
316  Processor_mask *mask,
317  uint32_t bits,
318  uint32_t index
319 )
320 {
321  _Processor_mask_Zero( mask );
322  mask->__bits[ __bitset_words( index ) ] = ((long) bits) << (32 * (index % _BITSET_BITS) / 32);
323 }
324 
332  Processor_mask *mask,
333  uint32_t index
334 )
335 {
336  BIT_SETOF( CPU_MAXIMUM_PROCESSORS, (int) index, mask );
337 }
338 
339 typedef enum {
340  PROCESSOR_MASK_COPY_LOSSLESS,
341  PROCESSOR_MASK_COPY_PARTIAL_LOSS,
342  PROCESSOR_MASK_COPY_COMPLETE_LOSS,
343  PROCESSOR_MASK_COPY_INVALID_SIZE
344 } Processor_mask_Copy_status;
345 
355  Processor_mask_Copy_status status
356 )
357 {
358  return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS;
359 }
360 
378 Processor_mask_Copy_status _Processor_mask_Copy(
379  long *dst,
380  size_t dst_size,
381  const long *src,
382  size_t src_size
383 );
384 
402  const Processor_mask *src,
403  size_t dst_size,
404  cpu_set_t *dst
405 )
406 {
407  return _Processor_mask_Copy(
408  &dst->__bits[ 0 ],
409  dst_size,
410  &src->__bits[ 0 ],
411  sizeof( *src )
412  );
413 }
414 
432  Processor_mask *dst,
433  size_t src_size,
434  const cpu_set_t *src
435 )
436 {
437  return _Processor_mask_Copy(
438  &dst->__bits[ 0 ],
439  sizeof( *dst ),
440  &src->__bits[ 0 ],
441  src_size
442  );
443 }
444 
445 extern const Processor_mask _Processor_mask_The_one_and_only;
446 
449 #ifdef __cplusplus
450 }
451 #endif /* __cplusplus */
452 
453 #endif /* _RTEMS_SCORE_PROCESSORMASK_H */
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_at_most_partial_loss(Processor_mask_Copy_status status)
Checks if the copy status guarantees at most partial loss.
RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(Processor_mask *dst, size_t src_size, const cpu_set_t *src)
Copies one mask to another.
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero(const Processor_mask *mask)
Checks if the mask is zero, also considers CPU_MAXIMUM_PROCESSORS.
Definition: processormask.h:74
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_equal(const Processor_mask *a, const Processor_mask *b)
Checks if the processor sets a and b are equal.
RTEMS_INLINE_ROUTINE void _Processor_mask_Or(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b | c.
RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Count(const Processor_mask *a)
Gets the number of set bits in the processor mask.
RTEMS_INLINE_ROUTINE void _Processor_mask_Clear(Processor_mask *mask, uint32_t index)
Clears the specified index bit of the mask.
RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_To_cpu_set_t(const Processor_mask *src, size_t dst_size, cpu_set_t *dst)
Copies one mask to another.
RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_To_uint32_t(const Processor_mask *mask, uint32_t index)
Returns the subset of 32 processors containing the specified index as an unsigned 32-bit integer...
RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Find_last_set(const Processor_mask *a)
Finds the last set of the processor mask.
Processor_mask_Copy_status _Processor_mask_Copy(long *dst, size_t dst_size, const long *src, size_t src_size)
Copies one mask to another.
typedef BITSET_DEFINE(Processor_mask, CPU_MAXIMUM_PROCESSORS) Processor_mask
A bit map which is large enough to provide one bit for each processor in the system.
RTEMS_INLINE_ROUTINE bool _Processor_mask_Has_overlap(const Processor_mask *a, const Processor_mask *b)
Checks if the intersection of the processor sets a and b is non-empty.
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_set(const Processor_mask *mask, uint32_t index)
Checks if the specified index bit of the mask is set.
RTEMS_INLINE_ROUTINE void _Processor_mask_Xor(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b ^ c.
RTEMS_INLINE_ROUTINE void _Processor_mask_Zero(Processor_mask *mask)
Sets the bits of the mask to zero, also considers CPU_MAXIMUM_PROCESSORS.
Definition: processormask.h:61
RTEMS_INLINE_ROUTINE void _Processor_mask_And(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b & c.
RTEMS_INLINE_ROUTINE void _Processor_mask_Nand(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b & ~c.
RTEMS_INLINE_ROUTINE void _Processor_mask_From_uint32_t(Processor_mask *mask, uint32_t bits, uint32_t index)
Creates a processor set from an unsigned 32-bit integer relative to the specified index...
RTEMS_INLINE_ROUTINE void _Processor_mask_From_index(Processor_mask *mask, uint32_t index)
Creates a processor set from the specified index.
SPARC CPU Department Source.
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_subset(const Processor_mask *big, const Processor_mask *small)
Checks if the processor set small is a subset of processor set big.
RTEMS_INLINE_ROUTINE void _Processor_mask_Assign(Processor_mask *dst, const Processor_mask *src)
Copies the mask to another mask, also considers CPU_MAXIMUM_PROCESSORS.
Definition: processormask.h:95
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
RTEMS_INLINE_ROUTINE void _Processor_mask_Fill(Processor_mask *mask)
Fills the mask, also considers CPU_MAXIMUM_PROCESSORS.
Definition: processormask.h:84
RTEMS_INLINE_ROUTINE void _Processor_mask_Set(Processor_mask *mask, uint32_t index)
Sets the specified index bit of the mask.