RTEMS  5.0.0
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 
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 
105  const Processor_mask *a,
106  const Processor_mask *b
107 )
108 {
109  return !BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b );
110 }
111 
117  const Processor_mask *a,
118  const Processor_mask *b
119 )
120 {
121  return BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b );
122 }
123 
129  const Processor_mask *big,
130  const Processor_mask *small
131 )
132 {
133  return BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small );
134 }
135 
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 
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 
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 
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 
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 
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 
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 
286 #ifdef __cplusplus
287 }
288 #endif /* __cplusplus */
289 
290 #endif /* _RTEMS_SCORE_PROCESSORMASK_H */
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.
#define CPU_MAXIMUM_PROCESSORS
Maximum number of processors of all systems supported by this CPU port.
Definition: cpu.h:250
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
RTEMS_INLINE_ROUTINE void _Processor_mask_Or(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b | c.
Definition: processormask.h:163
RTEMS_INLINE_ROUTINE bool _Processor_mask_Has_overlap(const Processor_mask *a, const Processor_mask *b)
Returns true if the intersection of the processor sets a and b is non-empty, and false otherwise...
Definition: processormask.h:116
RTEMS_INLINE_ROUTINE void _Processor_mask_From_index(Processor_mask *mask, uint32_t index)
Creates a processor set from the specified index.
Definition: processormask.h:225
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_subset(const Processor_mask *big, const Processor_mask *small)
Returns true if the processor set small is a subset of processor set big, and false otherwise...
Definition: processormask.h:128
RTEMS_INLINE_ROUTINE void _Processor_mask_Nand(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b & ~c.
Definition: processormask.h:151
RTEMS_INLINE_ROUTINE void _Processor_mask_Xor(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b ^ c.
Definition: processormask.h:175
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...
Definition: processormask.h:212
RTEMS_INLINE_ROUTINE void _Processor_mask_And(Processor_mask *a, const Processor_mask *b, const Processor_mask *c)
Performs a bitwise a = b & c.
Definition: processormask.h:139
RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_equal(const Processor_mask *a, const Processor_mask *b)
Returns true if the processor sets a and b are equal, and false otherwise.
Definition: processormask.h:104
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...
Definition: processormask.h:198