EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
event_machine_core_mask.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015-2026, Nokia Solutions and Networks
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @file
33 *
34 * Event Machine core mask manipulation APIs
35 */
36
37#ifndef EVENT_MACHINE_CORE_MASK_H
38#define EVENT_MACHINE_CORE_MASK_H
39
40#pragma GCC visibility push(default)
41
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * EM core mask.
51 * Each bit represents one core, core 0 is the lsb (1 << em_core_id())
52 * Note, that EM will enumerate the core identifiers to always start from 0 and
53 * be contiguous meaning the core numbers are not necessarily physical.
54 *
55 * Use the functions in event_machine_core_mask.h to manipulate the
56 * core masks.
57 *
58 * @see em_queue_group_create()
59 */
60typedef struct {
61 odp_cpumask_t odp_cpumask;
63
64/** Number of chars needed to hold core mask as a string:'0xcoremask' + '\0' */
65#define EM_CORE_MASK_STRLEN ((EM_MAX_CORES + 3) / 4 + 3)
66
67/**
68 * Zero the whole mask.
69 *
70 * @param[out] mask Core mask to zero (clear)
71 */
73
74/**
75 * Set a bit in the mask.
76 *
77 * @param core Core id
78 * @param[out] mask Core mask
79 */
80void em_core_mask_set(int core, em_core_mask_t *mask);
81
82/**
83 * Clear a bit in the mask.
84 *
85 * @param core Core id
86 * @param[out] mask Core mask
87 */
88void em_core_mask_clr(int core, em_core_mask_t *mask);
89
90/**
91 * Test if a bit is set in the mask.
92 *
93 * @param core Core id
94 * @param mask Core mask
95 *
96 * @return Non-zero if core id is set in the mask
97 */
98int em_core_mask_isset(int core, const em_core_mask_t *mask);
99
100/**
101 * Test if the mask is all zero.
102 *
103 * @param mask Core mask
104 *
105 * @return Non-zero if the mask is all zero
106 */
107int em_core_mask_iszero(const em_core_mask_t *mask);
108
109/**
110 * Test if two masks are equal
111 *
112 * @param mask1 First core mask
113 * @param mask2 Second core mask
114 *
115 * @return Non-zero if the two masks are equal
116 */
117int em_core_mask_equal(const em_core_mask_t *mask1,
118 const em_core_mask_t *mask2);
119
120/**
121 * Set a range (0...count-1) of bits in the mask.
122 *
123 * @param count Number of bits to set
124 * @param[out] mask Core mask
125 */
126void em_core_mask_set_count(int count, em_core_mask_t *mask);
127
128/**
129 * Copy core mask
130 *
131 * @param[out] dst Destination core mask
132 * @param src Source core mask
133 */
134void em_core_mask_copy(em_core_mask_t *dst, const em_core_mask_t *src);
135
136/**
137 * Count the number of bits set in the mask.
138 *
139 * @param mask Core mask
140 *
141 * @return Number of bits set
142 */
143int em_core_mask_count(const em_core_mask_t *mask);
144
145/**
146 * Set specified bits from 'bits[]' in core mask.
147 *
148 * core 0: bits[0] = 0x1 (len = 1)
149 * core 1: bits[0] = 0x2 (len = 1)
150 * ...
151 * core 64: bits[0] = 0x0, bits[1] = 0x1 (len = 2)
152 * core 65: bits[0] = 0x0, bits[1] = 0x2 (len = 2)
153 * ...
154 * cores 0-127: bits[0]=0xffffffffffffffff, bits[1]=0xffffffffffffffff (len=2)
155 * ...
156 * @param bits Array of uint64_t:s with the bits to set in the core mask
157 * @param len Number of array elements in bits[].
158 * @param[out] mask Core mask to set.
159 *
160 * @note bits ar 'or'ed into mask, so any previously set bits will remain set.
161 */
162void em_core_mask_set_bits(const uint64_t bits[], int len,
163 em_core_mask_t *mask);
164
165/**
166 * Get core mask, stored in a uint64_t array for the user
167 *
168 * core 0: bits[0] = 0x1 (len = 1)
169 * core 1: bits[0] = 0x2 (len = 1)
170 * ...
171 * core 64: bits[0] = 0x0, bits[1] = 0x1 (len = 2)
172 * core 65: bits[0] = 0x0, bits[1] = 0x2 (len = 2)
173 * ...
174 * cores 0-127: bits[0]=0xffffffffffffffff, bits[1]=0xffffffffffffffff (len=2)
175 * ...
176 * @param[out] bits Array of uint64_t:s that the core mask will be stored in.
177 * @param len Number of array elements in bits[].
178 * @param mask Core mask to get bits from.
179 *
180 * @return The number of uint64_t:s written into bits[].
181 */
182int em_core_mask_bits(uint64_t bits[/*out*/], int len,
183 const em_core_mask_t *mask);
184
185/* Backwards compatible naming ("get") */
186#define em_core_mask_get_bits em_core_mask_bits
187
188/**
189 * Set bits in a mask according to a given string.
190 *
191 * @param mask_str String containing '0xcoremask' to set
192 * @param[out] mask Core mask to set
193 *
194 * @return Zero (0) on success, non-zero on error.
195 *
196 * @note bits ar 'or'ed into mask, so any previously set bits will remain set.
197 */
198int em_core_mask_set_str(const char *mask_str, em_core_mask_t *mask);
199
200/**
201 * Get core mask in string format
202 *
203 * @param[out] mask_str String into which the core mask will be printed
204 * @param len Length of 'mask_str'
205 * @param mask Core mask to convert to string format
206 */
207void em_core_mask_tostr(char *mask_str /*out*/, int len,
208 const em_core_mask_t *mask);
209
210/**
211 * Return the index (position) of the Nth set bit in the core mask
212 *
213 * @param n Nth set bit, note n=1 means first set bit, n=[1...MaxCores]
214 * @param mask Core mask
215 *
216 * @return Index of the Nth set bit
217 * @retval <0 if no Nth bit set
218 */
219int em_core_mask_idx(int n, const em_core_mask_t *mask);
220
221/**
222 * Return the index of the first set bit in the core mask
223 *
224 * @param mask Core mask
225 *
226 * @return Index of the first set bit
227 * @retval <0 if no bit set
228 */
229int em_core_mask_first(const em_core_mask_t *mask);
230
231/**
232 * Return the index of the last set bit in the core mask
233 *
234 * @param mask Core mask
235 *
236 * @return Index of the last set bit
237 * @retval <0 if no bit set
238 */
239int em_core_mask_last(const em_core_mask_t *mask);
240
241/**
242 * Return the index of the next set bit in the core mask
243 *
244 * Finds the next index in the core mask, starting after the index passed.
245 * Use with em_core_mask_first() to traverse a core mask, e.g.
246 *
247 * int idx = em_core_mask_first(&mask);
248 * while (idx >= 0) {
249 * ...
250 * idx = em_core_mask_next(&mask, idx);
251 * }
252 *
253 * @param mask Core mask
254 * @param idx Index after which to look for the next set bit
255 *
256 * @return Index of the next set bit
257 * @retval <0 if no next set bit found
258 *
259 * @see em_core_mask_first()
260 */
261int em_core_mask_next(const em_core_mask_t *mask, int idx);
262
263/**
264 * Bitwise AND operation on two masks, store the result in 'dst'
265 *
266 * dst = src1 & src2
267 *
268 * @param[out] dst Destination core mask, result is stored here
269 * @param src1 Source mask #1
270 * @param src2 Source mask #2
271 */
272void em_core_mask_and(em_core_mask_t *dst, const em_core_mask_t *src1,
273 const em_core_mask_t *src2);
274
275/**
276 * Bitwise OR operation on two masks, store the result in 'dst'
277 *
278 * dst = src1 | src2
279 *
280 * @param[out] dst Destination core mask, result is stored here
281 * @param src1 Source mask #1
282 * @param src2 Source mask #2
283 */
284void em_core_mask_or(em_core_mask_t *dst, const em_core_mask_t *src1,
285 const em_core_mask_t *src2);
286
287/**
288 * Bitwise XOR operation on two masks, store the result in 'dst'
289 *
290 * dst = src1 ^ src2
291 *
292 * @param[out] dst Destination core mask, result is stored here
293 * @param src1 Source mask #1
294 * @param src2 Source mask #2
295 */
296void em_core_mask_xor(em_core_mask_t *dst, const em_core_mask_t *src1,
297 const em_core_mask_t *src2);
298
299#ifdef __cplusplus
300}
301#endif
302
303#pragma GCC visibility pop
304#endif /* EVENT_MACHINE_CORE_MASK_H */
void em_core_mask_or(em_core_mask_t *dst, const em_core_mask_t *src1, const em_core_mask_t *src2)
int em_core_mask_equal(const em_core_mask_t *mask1, const em_core_mask_t *mask2)
int em_core_mask_count(const em_core_mask_t *mask)
void em_core_mask_tostr(char *mask_str, int len, const em_core_mask_t *mask)
int em_core_mask_first(const em_core_mask_t *mask)
int em_core_mask_iszero(const em_core_mask_t *mask)
void em_core_mask_copy(em_core_mask_t *dst, const em_core_mask_t *src)
int em_core_mask_set_str(const char *mask_str, em_core_mask_t *mask)
void em_core_mask_set(int core, em_core_mask_t *mask)
void em_core_mask_clr(int core, em_core_mask_t *mask)
int em_core_mask_idx(int n, const em_core_mask_t *mask)
int em_core_mask_bits(uint64_t bits[], int len, const em_core_mask_t *mask)
int em_core_mask_isset(int core, const em_core_mask_t *mask)
void em_core_mask_set_count(int count, em_core_mask_t *mask)
int em_core_mask_last(const em_core_mask_t *mask)
void em_core_mask_and(em_core_mask_t *dst, const em_core_mask_t *src1, const em_core_mask_t *src2)
void em_core_mask_set_bits(const uint64_t bits[], int len, em_core_mask_t *mask)
int em_core_mask_next(const em_core_mask_t *mask, int idx)
void em_core_mask_zero(em_core_mask_t *mask)
void em_core_mask_xor(em_core_mask_t *dst, const em_core_mask_t *src1, const em_core_mask_t *src2)