source: rtems/cpukit/score/include/rtems/score/processormask.h @ 7851555

5
Last change on this file since 7851555 was 7851555, checked in by Sebastian Huber <sebastian.huber@…>, on 07/03/17 at 12:05:26

score: Move processor affinity to Thread_Control

Update #3059.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Processor Mask API
5 *
6 * @ingroup ScoreProcessorMask
7 */
8
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#ifdef __cplusplus
31extern "C" {
32#endif /* __cplusplus */
33
34/**
35 * @defgroup ScoreProcessorMask Processor Mask
36 *
37 * @ingroup Score
38 *
39 * The processor mask provides a bit map large enough to provide one bit for
40 * each processor in the system.  It is a fixed size internal data type
41 * provided for efficiency in addition to the API level cpu_set_t.
42 *
43 * @{
44 */
45
46/**
47 * @brief A bit map which is large enough to provide one bit for each processor
48 * in the system.
49 */
50typedef BITSET_DEFINE( Processor_mask, CPU_MAXIMUM_PROCESSORS ) Processor_mask;
51
52RTEMS_INLINE_ROUTINE void _Processor_mask_Zero( Processor_mask *mask )
53{
54  BIT_ZERO( CPU_MAXIMUM_PROCESSORS, mask );
55}
56
57RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_zero( const Processor_mask *mask )
58{
59  return BIT_EMPTY( CPU_MAXIMUM_PROCESSORS, mask );
60}
61
62RTEMS_INLINE_ROUTINE void _Processor_mask_Fill( Processor_mask *mask )
63{
64  BIT_FILL( CPU_MAXIMUM_PROCESSORS, mask );
65}
66
67RTEMS_INLINE_ROUTINE void _Processor_mask_Assign(
68  Processor_mask *dst, const Processor_mask *src
69)
70{
71  BIT_COPY( CPU_MAXIMUM_PROCESSORS, src, dst );
72}
73
74RTEMS_INLINE_ROUTINE void _Processor_mask_Set(
75  Processor_mask *mask,
76  uint32_t        index
77)
78{
79  BIT_SET( CPU_MAXIMUM_PROCESSORS, index, mask );
80}
81
82RTEMS_INLINE_ROUTINE void _Processor_mask_Clear(
83  Processor_mask *mask,
84  uint32_t        index
85)
86{
87  BIT_CLR( CPU_MAXIMUM_PROCESSORS, index, mask );
88}
89
90RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_set(
91  const Processor_mask *mask,
92  uint32_t              index
93)
94{
95  return BIT_ISSET( CPU_MAXIMUM_PROCESSORS, index, mask );
96}
97
98/**
99 * @brief Returns true if the processor sets a and b are equal, and false
100 * otherwise.
101 */
102RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_equal(
103  const Processor_mask *a,
104  const Processor_mask *b
105)
106{
107  return !BIT_CMP( CPU_MAXIMUM_PROCESSORS, a, b );
108}
109
110/**
111 * @brief Returns true if the intersection of the processor sets a and b is
112 * non-empty, and false otherwise.
113 */
114RTEMS_INLINE_ROUTINE bool _Processor_mask_Has_overlap(
115  const Processor_mask *a,
116  const Processor_mask *b
117)
118{
119  return BIT_OVERLAP( CPU_MAXIMUM_PROCESSORS, a, b );
120}
121
122/**
123 * @brief Returns true if the processor set small is a subset of processor set
124 * big, and false otherwise.
125 */
126RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_subset(
127  const Processor_mask *big,
128  const Processor_mask *small
129)
130{
131  return BIT_SUBSET( CPU_MAXIMUM_PROCESSORS, big, small );
132}
133
134/**
135 * @brief Performs a bitwise a = b & c.
136 */
137RTEMS_INLINE_ROUTINE void _Processor_mask_And(
138  Processor_mask       *a,
139  const Processor_mask *b,
140  const Processor_mask *c
141)
142{
143  BIT_AND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
144}
145
146/**
147 * @brief Performs a bitwise a = b & ~c.
148 */
149RTEMS_INLINE_ROUTINE void _Processor_mask_Nand(
150  Processor_mask       *a,
151  const Processor_mask *b,
152  const Processor_mask *c
153)
154{
155  BIT_NAND2( CPU_MAXIMUM_PROCESSORS, a, b, c );
156}
157
158/**
159 * @brief Performs a bitwise a = b | c.
160 */
161RTEMS_INLINE_ROUTINE void _Processor_mask_Or(
162  Processor_mask       *a,
163  const Processor_mask *b,
164  const Processor_mask *c
165)
166{
167  BIT_OR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
168}
169
170/**
171 * @brief Performs a bitwise a = b ^ c.
172 */
173RTEMS_INLINE_ROUTINE void _Processor_mask_Xor(
174  Processor_mask       *a,
175  const Processor_mask *b,
176  const Processor_mask *c
177)
178{
179  BIT_XOR2( CPU_MAXIMUM_PROCESSORS, a, b, c );
180}
181
182RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Count( const Processor_mask *a )
183{
184  return (uint32_t) BIT_COUNT( CPU_MAXIMUM_PROCESSORS, a );
185}
186
187RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_Find_last_set( const Processor_mask *a )
188{
189  return (uint32_t) BIT_FLS( CPU_MAXIMUM_PROCESSORS, a );
190}
191
192/**
193 * @brief Returns the subset of 32 processors containing the specified index as
194 * an unsigned 32-bit integer.
195 */
196RTEMS_INLINE_ROUTINE uint32_t _Processor_mask_To_uint32_t(
197  const Processor_mask *mask,
198  uint32_t              index
199)
200{
201  long bits = mask->__bits[ __bitset_words( index ) ];
202
203  return (uint32_t) (bits >> (32 * (index % _BITSET_BITS) / 32));
204}
205
206typedef enum {
207  PROCESSOR_MASK_COPY_LOSSLESS,
208  PROCESSOR_MASK_COPY_PARTIAL_LOSS,
209  PROCESSOR_MASK_COPY_COMPLETE_LOSS,
210  PROCESSOR_MASK_COPY_INVALID_SIZE
211} Processor_mask_Copy_status;
212
213RTEMS_INLINE_ROUTINE bool _Processor_mask_Is_at_most_partial_loss(
214  Processor_mask_Copy_status status
215)
216{
217  return (unsigned int) status <= PROCESSOR_MASK_COPY_PARTIAL_LOSS;
218}
219
220Processor_mask_Copy_status _Processor_mask_Copy(
221  long       *dst,
222  size_t      dst_size,
223  const long *src,
224  size_t      src_size
225);
226
227RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_To_cpu_set_t(
228  const Processor_mask *src,
229  size_t                dst_size,
230  cpu_set_t            *dst
231)
232{
233  return _Processor_mask_Copy(
234    &dst->__bits[ 0 ],
235    dst_size,
236    &src->__bits[ 0 ],
237    sizeof( *src )
238  );
239}
240
241RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(
242  Processor_mask  *dst,
243  size_t           src_size,
244  const cpu_set_t *src
245)
246{
247  return _Processor_mask_Copy(
248    &dst->__bits[ 0 ],
249    sizeof( *dst ),
250    &src->__bits[ 0 ],
251    src_size
252  );
253}
254
255extern const Processor_mask _Processor_mask_The_one_and_only;
256
257/** @} */
258
259#ifdef __cplusplus
260}
261#endif /* __cplusplus */
262
263#endif /* _RTEMS_SCORE_PROCESSORMASK_H */
Note: See TracBrowser for help on using the repository browser.