posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
cpuset.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
11#ifndef ZEPHYR_INCLUDE_POSIX_SYS_CPUSET_H_
12#define ZEPHYR_INCLUDE_POSIX_SYS_CPUSET_H_
13
14#include <stddef.h>
15#include <stdint.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#if !(defined(_CPU_SET_T_DECLARED) || defined(__cpu_set_t_defined)) || defined(__DOXYGEN__)
26#define CPU_SETSIZE 32
27
32typedef struct {
33 uint32_t __bits[CPU_SETSIZE / 32];
34} cpu_set_t;
35#define _CPU_SET_T_DECLARED
36#define __cpu_set_t_defined
37#endif
38
39static inline void __cpu_zero(cpu_set_t *set)
40{
41 for (size_t i = 0; i < CPU_SETSIZE / 32; ++i) {
42 set->__bits[i] = 0;
43 }
44}
45
46static inline int __cpu_count(const cpu_set_t *set)
47{
48 int count = 0;
49
50 for (size_t i = 0; i < CPU_SETSIZE / 32; ++i) {
51 count += __builtin_popcount(set->__bits[i]);
52 }
53
54 return count;
55}
56
57static inline int __cpu_equal(const cpu_set_t *a, const cpu_set_t *b)
58{
59 for (size_t i = 0; i < CPU_SETSIZE / 32; ++i) {
60 if (a->__bits[i] != b->__bits[i]) {
61 return 0;
62 }
63 }
64
65 return 1;
66}
67
68#define __CPU_WORD(cpu) ((size_t)(cpu) / 32)
69#define __CPU_BIT(cpu) (1U << ((size_t)(cpu) % 32))
70
75#define CPU_ZERO(set) __cpu_zero(set)
76
81#define CPU_SET(cpu, set) \
82 ((void)(((size_t)(cpu) < CPU_SETSIZE) \
83 ? ((set)->__bits[__CPU_WORD(cpu)] |= __CPU_BIT(cpu)) \
84 : 0U))
85
90#define CPU_CLR(cpu, set) \
91 ((void)(((size_t)(cpu) < CPU_SETSIZE) \
92 ? ((set)->__bits[__CPU_WORD(cpu)] &= ~__CPU_BIT(cpu)) \
93 : 0U))
94
99#define CPU_ISSET(cpu, set) \
100 (((size_t)(cpu) < CPU_SETSIZE) && (((set)->__bits[__CPU_WORD(cpu)] & __CPU_BIT(cpu)) != 0))
101
106#define CPU_COUNT(set) __cpu_count(set)
107
112#define CPU_EQUAL(a, b) __cpu_equal(a, b)
113
114#ifdef __cplusplus
115}
116#endif
117
118#endif /* ZEPHYR_INCLUDE_POSIX_SYS_CPUSET_H_ */
#define CPU_SETSIZE
Number of CPUs a cpu_set_t can name (GNU extension).
Definition cpuset.h:26
Set of CPUs for pthread_getaffinity_np() and pthread_setaffinity_np() (GNU extension).
Definition cpuset.h:32
uint32_t __bits[32/32]
One bit per CPU index.
Definition cpuset.h:33