RTEMS 6.1-rc6
Loading...
Searching...
No Matches
processormaskimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2016, 2023 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_PROCESSORMASKIMPL_H
38#define _RTEMS_SCORE_PROCESSORMASKIMPL_H
39
41
42#include <sys/cpuset.h>
43
44#include <strings.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif /* __cplusplus */
49
61static inline void _Processor_mask_Zero( Processor_mask *mask )
62{
63 __BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask );
64}
65
74static inline bool _Processor_mask_Is_zero( const Processor_mask *mask )
75{
76 return __BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask );
77}
78
84static inline void _Processor_mask_Fill( Processor_mask *mask )
85{
86 __BIT_FILL( CPU_MAXIMUM_PROCESSORS, mask );
87}
88
95static inline void _Processor_mask_Assign(
96 Processor_mask *dst, const Processor_mask *src
97)
98{
99 __BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst );
100}
101
108static inline void _Processor_mask_Set(
109 Processor_mask *mask,
110 uint32_t index
111)
112{
113 __BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask );
114}
115
122static inline void _Processor_mask_Clear(
123 Processor_mask *mask,
124 uint32_t index
125)
126{
127 __BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask );
128}
129
139static inline bool _Processor_mask_Is_set(
140 const Processor_mask *mask,
141 uint32_t index
142)
143{
144 return __BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask );
145}
146
156static inline bool _Processor_mask_Is_equal(
157 const Processor_mask *a,
158 const Processor_mask *b
159)
160{
161 return !__BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b );
162}
163
174static inline bool _Processor_mask_Has_overlap(
175 const Processor_mask *a,
176 const Processor_mask *b
177)
178{
179 return __BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b );
180}
181
192static inline bool _Processor_mask_Is_subset(
193 const Processor_mask *big,
194 const Processor_mask *small
195)
196{
197 return __BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small );
198}
199
207static inline void _Processor_mask_And(
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
223static inline void _Processor_mask_And_not(
224 Processor_mask *a,
225 const Processor_mask *b,
226 const Processor_mask *c
227)
228{
229 __BIT_ANDNOT2( CPU_MAXIMUM_PROCESSORS, a, b, c );
230}
231
239static inline void _Processor_mask_Or(
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
255static inline void _Processor_mask_Xor(
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
271static inline uint32_t _Processor_mask_Count( const Processor_mask *a )
272{
273 return (uint32_t) __BIT_COUNT( CPU_MAXIMUM_PROCESSORS, a );
274}
275
283static inline uint32_t _Processor_mask_Find_last_set( const Processor_mask *a )
284{
285 return (uint32_t) __BIT_FLS( CPU_MAXIMUM_PROCESSORS, a );
286}
287
297static inline uint32_t _Processor_mask_To_uint32_t(
298 const Processor_mask *mask,
299 uint32_t index
300)
301{
302 long bits = mask->__bits[ index / _BITSET_BITS ];
303
304 return (uint32_t) ( bits >> ( 32 * ( ( index % _BITSET_BITS ) / 32 ) ) );
305}
306
315static inline void _Processor_mask_From_uint32_t(
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
331static inline void _Processor_mask_From_index(
332 Processor_mask *mask,
333 uint32_t index
334)
335{
336 __BIT_SETOF( CPU_MAXIMUM_PROCESSORS, (int) index, mask );
337}
338
339typedef 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
354static inline bool _Processor_mask_Is_at_most_partial_loss(
355 Processor_mask_Copy_status status
356)
357{
358 return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS;
359}
360
378Processor_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
401static inline Processor_mask_Copy_status _Processor_mask_To_cpu_set_t(
402 const Processor_mask *src,
403 size_t dst_size,
404 cpu_set_t *dst
405)
406{
408 &dst->__bits[ 0 ],
409 dst_size,
410 &src->__bits[ 0 ],
411 sizeof( *src )
412 );
413}
414
431static inline Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(
432 Processor_mask *dst,
433 size_t src_size,
434 const cpu_set_t *src
435)
436{
438 &dst->__bits[ 0 ],
439 sizeof( *dst ),
440 &src->__bits[ 0 ],
441 src_size
442 );
443}
444
445extern const Processor_mask _Processor_mask_The_one_and_only;
446
449#ifdef __cplusplus
450}
451#endif /* __cplusplus */
452
453#endif /* _RTEMS_SCORE_PROCESSORMASKIMPL_H */
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
This header file provides the interfaces of the Processor Mask.