RTEMS 6.1-rc1
processormask.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2016, 2017 embedded brains GmbH & Co. KG
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 * Recent Newlib versions provide the bitset defines in the system reserved
52 * namespace.
53 */
54#ifndef __BIT_AND2
55#define __BIT_AND2 BIT_AND2
56#endif
57#ifndef __BIT_CLR
58#define __BIT_CLR BIT_CLR
59#endif
60#ifndef __BIT_CMP
61#define __BIT_CMP BIT_CMP
62#endif
63#ifndef __BIT_COPY
64#define __BIT_COPY BIT_COPY
65#endif
66#ifndef __BIT_COUNT
67#define __BIT_COUNT BIT_COUNT
68#endif
69#ifndef __BITSET_DEFINE
70#define __BITSET_DEFINE BITSET_DEFINE
71#endif
72#ifndef __BIT_EMPTY
73#define __BIT_EMPTY BIT_EMPTY
74#endif
75#ifndef __BIT_FILL
76#define __BIT_FILL BIT_FILL
77#endif
78#ifndef __BIT_FLS
79#define __BIT_FLS BIT_FLS
80#endif
81#ifndef __BIT_ISSET
82#define __BIT_ISSET BIT_ISSET
83#endif
84#ifndef __BIT_OR2
85#define __BIT_OR2 BIT_OR2
86#endif
87#ifndef __BIT_OVERLAP
88#define __BIT_OVERLAP BIT_OVERLAP
89#endif
90#ifndef __BIT_SET
91#define __BIT_SET BIT_SET
92#endif
93#ifndef __BIT_SETOF
94#define __BIT_SETOF BIT_SETOF
95#endif
96#ifndef __BIT_SUBSET
97#define __BIT_SUBSET BIT_SUBSET
98#endif
99#ifndef __BIT_XOR2
100#define __BIT_XOR2 BIT_XOR2
101#endif
102#ifndef __BIT_ZERO
103#define __BIT_ZERO BIT_ZERO
104#endif
105
124typedef __BITSET_DEFINE( Processor_mask, CPU_MAXIMUM_PROCESSORS ) Processor_mask;
125
131static inline void _Processor_mask_Zero( Processor_mask *mask )
132{
133 __BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask );
134}
135
144static inline bool _Processor_mask_Is_zero( const Processor_mask *mask )
145{
146 return __BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask );
147}
148
154static inline void _Processor_mask_Fill( Processor_mask *mask )
155{
156 __BIT_FILL( CPU_MAXIMUM_PROCESSORS, mask );
157}
158
165static inline void _Processor_mask_Assign(
166 Processor_mask *dst, const Processor_mask *src
167)
168{
169 __BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst );
170}
171
178static inline void _Processor_mask_Set(
179 Processor_mask *mask,
180 uint32_t index
181)
182{
183 __BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask );
184}
185
192static inline void _Processor_mask_Clear(
193 Processor_mask *mask,
194 uint32_t index
195)
196{
197 __BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask );
198}
199
209static inline bool _Processor_mask_Is_set(
210 const Processor_mask *mask,
211 uint32_t index
212)
213{
214 return __BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask );
215}
216
226static inline bool _Processor_mask_Is_equal(
227 const Processor_mask *a,
228 const Processor_mask *b
229)
230{
231 return !__BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b );
232}
233
244static inline bool _Processor_mask_Has_overlap(
245 const Processor_mask *a,
246 const Processor_mask *b
247)
248{
249 return __BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b );
250}
251
262static inline bool _Processor_mask_Is_subset(
263 const Processor_mask *big,
264 const Processor_mask *small
265)
266{
267 return __BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small );
268}
269
277static inline void _Processor_mask_And(
278 Processor_mask *a,
279 const Processor_mask *b,
280 const Processor_mask *c
281)
282{
283 __BIT_AND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
284}
285
293static inline void _Processor_mask_Or(
294 Processor_mask *a,
295 const Processor_mask *b,
296 const Processor_mask *c
297)
298{
299 __BIT_OR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
300}
301
309static inline void _Processor_mask_Xor(
310 Processor_mask *a,
311 const Processor_mask *b,
312 const Processor_mask *c
313)
314{
315 __BIT_XOR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
316}
317
325static inline uint32_t _Processor_mask_Count( const Processor_mask *a )
326{
327 return (uint32_t) __BIT_COUNT( CPU_MAXIMUM_PROCESSORS, a );
328}
329
337static inline uint32_t _Processor_mask_Find_last_set( const Processor_mask *a )
338{
339 return (uint32_t) __BIT_FLS( CPU_MAXIMUM_PROCESSORS, a );
340}
341
351static inline uint32_t _Processor_mask_To_uint32_t(
352 const Processor_mask *mask,
353 uint32_t index
354)
355{
356 long bits = mask->__bits[ index / _BITSET_BITS ];
357
358 return (uint32_t) ( bits >> ( 32 * ( ( index % _BITSET_BITS ) / 32 ) ) );
359}
360
369static inline void _Processor_mask_From_uint32_t(
370 Processor_mask *mask,
371 uint32_t bits,
372 uint32_t index
373)
374{
375 _Processor_mask_Zero( mask );
376 mask->__bits[ __bitset_words( index ) ] = ((long) bits) << (32 * (index % _BITSET_BITS) / 32);
377}
378
385static inline void _Processor_mask_From_index(
386 Processor_mask *mask,
387 uint32_t index
388)
389{
390 __BIT_SETOF( CPU_MAXIMUM_PROCESSORS, (int) index, mask );
391}
392
393typedef enum {
394 PROCESSOR_MASK_COPY_LOSSLESS,
395 PROCESSOR_MASK_COPY_PARTIAL_LOSS,
396 PROCESSOR_MASK_COPY_COMPLETE_LOSS,
397 PROCESSOR_MASK_COPY_INVALID_SIZE
398} Processor_mask_Copy_status;
399
408static inline bool _Processor_mask_Is_at_most_partial_loss(
409 Processor_mask_Copy_status status
410)
411{
412 return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS;
413}
414
432Processor_mask_Copy_status _Processor_mask_Copy(
433 long *dst,
434 size_t dst_size,
435 const long *src,
436 size_t src_size
437);
438
455static inline Processor_mask_Copy_status _Processor_mask_To_cpu_set_t(
456 const Processor_mask *src,
457 size_t dst_size,
458 cpu_set_t *dst
459)
460{
462 &dst->__bits[ 0 ],
463 dst_size,
464 &src->__bits[ 0 ],
465 sizeof( *src )
466 );
467}
468
485static inline Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(
486 Processor_mask *dst,
487 size_t src_size,
488 const cpu_set_t *src
489)
490{
492 &dst->__bits[ 0 ],
493 sizeof( *dst ),
494 &src->__bits[ 0 ],
495 src_size
496 );
497}
498
499extern const Processor_mask _Processor_mask_The_one_and_only;
500
503#ifdef __cplusplus
504}
505#endif /* __cplusplus */
506
507#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.
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.
Definition: processormaskcopy.c:46
#define CPU_MAXIMUM_PROCESSORS
Maximum number of processors of all systems supported by this CPU port.
Definition: cpu.h:269