aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/spec/cpumask.h
blob: 22d8e8f246f02aefee82fe099b57d6e5e625ad1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* Copyright (c) 2013, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */


/**
 * @file
 *
 * ODP CPU masks and enumeration
 */

#ifndef ODP_API_CPUMASK_H_
#define ODP_API_CPUMASK_H_
#include <odp/visibility_begin.h>

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup odp_cpumask ODP CPUMASK
 *  CPU mask operations.
 *  @{
 */

/**
 * @def ODP_CPUMASK_SIZE
 * Maximum cpumask size, this definition limits the number of individual CPUs
 * that can be accessed in this system.
 */

/**
 * @def ODP_CPUMASK_STR_SIZE
 * The maximum number of characters needed to record any CPU mask as
 * a string (output of odp_cpumask_to_str()).
 */

/**
 * Add CPU mask bits from a string
 *
 * Each bit set in the string represents a CPU to be added into the mask.
 * The string is null terminated and consists of hexadecimal digits. It may be
 * prepended with '0x' and may contain leading zeros (e.g. 0x0001, 0x1 or 1).
 * CPU #0 is located at the least significant bit (0x1).
 *
 * @param mask   CPU mask to modify
 * @param str    String of hexadecimal digits
 */
void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str);

/**
 * Format a string from CPU mask
 *
 * Output string format is defined in odp_cpumask_from_str() documentation,
 * except that the string is always prepended with '0x' and does not have any
 * leading zeros (e.g. outputs always 0x1 instead of 0x0001 or 1).
 *
 * @param      mask  CPU mask
 * @param[out] str   String pointer for output
 * @param      size  Size of output buffer. Buffer size ODP_CPUMASK_STR_SIZE
 *                   or larger will have enough space for any CPU mask.
 *
 * @return Number of characters written (including terminating null char)
 * @retval <0 on failure (e.g. buffer too small)
 */
int32_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int32_t size);

/**
 * Clear entire CPU mask
 * @param mask CPU mask to clear
 */
void odp_cpumask_zero(odp_cpumask_t *mask);

/**
 * Add CPU to mask
 * @param mask  CPU mask to update
 * @param cpu   CPU number
 */
void odp_cpumask_set(odp_cpumask_t *mask, int cpu);

/**
 * Set all CPUs in mask
 *
 * Set all possible CPUs in the mask. All CPUs from 0 to odp_cpumask_count()
 * minus one are set, regardless of which CPUs are actually available to
 * the application.
 *
 * @param mask  CPU mask to set
 */
void odp_cpumask_setall(odp_cpumask_t *mask);

/**
 * Remove CPU from mask
 * @param mask  CPU mask to update
 * @param cpu   CPU number
 */
void odp_cpumask_clr(odp_cpumask_t *mask, int cpu);

/**
 * Test if CPU is a member of mask
 *
 * @param mask  CPU mask to test
 * @param cpu   CPU number
 * @return      non-zero if set
 * @retval      0 if not set
 */
int odp_cpumask_isset(const odp_cpumask_t *mask, int cpu);

/**
 * Count number of CPUs set in mask
 *
 * @param mask  CPU mask
 * @return population count
 */
int odp_cpumask_count(const odp_cpumask_t *mask);

/**
 * Member-wise AND over two CPU masks
 *
 * @param dest    Destination CPU mask (may be one of the source masks)
 * @param src1    Source CPU mask 1
 * @param src2    Source CPU mask 2
 */
void odp_cpumask_and(odp_cpumask_t *dest, const odp_cpumask_t *src1,
		     const odp_cpumask_t *src2);

/**
 * Member-wise OR over two CPU masks
 *
 * @param dest    Destination CPU mask (may be one of the source masks)
 * @param src1    Source CPU mask 1
 * @param src2    Source CPU mask 2
 */
void odp_cpumask_or(odp_cpumask_t *dest, const odp_cpumask_t *src1,
		    const odp_cpumask_t *src2);

/**
 * Member-wise XOR over two CPU masks
 *
 * @param dest    Destination CPU mask (may be one of the source masks)
 * @param src1    Source CPU mask 1
 * @param src2    Source CPU mask 2
 */
void odp_cpumask_xor(odp_cpumask_t *dest, const odp_cpumask_t *src1,
		     const odp_cpumask_t *src2);

/**
 * Test if two CPU masks contain the same CPUs
 *
 * @param mask1    CPU mask 1
 * @param mask2    CPU mask 2
 *
 * @retval non-zero if CPU masks equal
 * @retval 0 if CPU masks not equal
 */
int odp_cpumask_equal(const odp_cpumask_t *mask1,
		      const odp_cpumask_t *mask2);

/**
 * Copy a CPU mask
 *
 * @param dest    Destination CPU mask
 * @param src     Source CPU mask
 */
void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src);

/**
 * Find first set CPU in mask
 *
 * @param mask    CPU mask
 *
 * @return cpu number
 * @retval <0 if no CPU found
 */
int odp_cpumask_first(const odp_cpumask_t *mask);

/**
 * Find last set CPU in mask
 *
 * @param mask    CPU mask
 *
 * @return cpu number
 * @retval <0 if no CPU found
 */
int odp_cpumask_last(const odp_cpumask_t *mask);

/**
 * Find next set CPU in mask
 *
 * Finds the next CPU in the CPU mask, starting at the CPU passed.
 * Use with odp_cpumask_first to traverse a CPU mask, e.g.
 *
 * int cpu = odp_cpumask_first(&mask);
 * while (0 <= cpu) {
 *     ...
 *     ...
 *     cpu = odp_cpumask_next(&mask, cpu);
 * }
 *
 * @param mask        CPU mask
 * @param cpu         CPU to start from
 *
 * @return cpu number
 * @retval <0 if no CPU found
 *
 * @see odp_cpumask_first()
 */
int odp_cpumask_next(const odp_cpumask_t *mask, int cpu);

/**
 * Default cpumask for worker threads
 *
 * Initializes cpumask with CPUs available for worker threads. Sets up to 'num'
 * CPUs and returns the count actually set. Use zero for all available CPUs.
 *
 * @param[out] mask      CPU mask to initialize
 * @param      num       Number of worker threads, zero for all available CPUs
 * @return Actual number of CPUs used to create the mask
 */
int odp_cpumask_default_worker(odp_cpumask_t *mask, int num);

/**
 * Default cpumask for control threads
 *
 * Initializes cpumask with CPUs available for control threads. Sets up to 'num'
 * CPUs and returns the count actually set. Use zero for all available CPUs.
 *
 * @param[out] mask      CPU mask to initialize
 * @param      num       Number of control threads, zero for all available CPUs
 * @return Actual number of CPUs used to create the mask
 */
int odp_cpumask_default_control(odp_cpumask_t *mask, int num);

/**
 * Report all the available CPUs
 *
 * All the available CPUs include both worker CPUs and control CPUs
 *
 * @param[out] mask    CPU mask to hold all available CPUs
 * @return cpu number of all available CPUs
 */
int odp_cpumask_all_available(odp_cpumask_t *mask);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#include <odp/visibility_end.h>
#endif