Changeset View
Standalone View
sys/sys/cpuset.h
Show All 30 Lines | |||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#ifndef _SYS_CPUSET_H_ | #ifndef _SYS_CPUSET_H_ | ||||
#define _SYS_CPUSET_H_ | #define _SYS_CPUSET_H_ | ||||
#include <sys/_cpuset.h> | #include <sys/_cpuset.h> | ||||
#include <sys/_bitset.h> | |||||
#include <sys/bitset.h> | #include <sys/bitset.h> | ||||
#define _NCPUBITS _BITSET_BITS | #define _NCPUBITS _BITSET_BITS | ||||
#define _NCPUWORDS __bitset_words(CPU_SETSIZE) | #define _NCPUWORDS __bitset_words(CPU_SETSIZE) | ||||
#define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS) | #define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS) | ||||
#define CPU_CLR(n, p) __BIT_CLR(CPU_SETSIZE, n, p) | #define CPU_CLR(n, p) __BIT_CLR(CPU_SETSIZE, n, p) | ||||
#define CPU_COPY(f, t) __BIT_COPY(CPU_SETSIZE, f, t) | #define CPU_COPY(f, t) __BIT_COPY(CPU_SETSIZE, f, t) | ||||
#define CPU_ISSET(n, p) __BIT_ISSET(CPU_SETSIZE, n, p) | #define CPU_ISSET(n, p) __BIT_ISSET(CPU_SETSIZE, n, p) | ||||
#define CPU_SET(n, p) __BIT_SET(CPU_SETSIZE, n, p) | #define CPU_SET(n, p) __BIT_SET(CPU_SETSIZE, n, p) | ||||
#define CPU_ZERO(p) __BIT_ZERO(CPU_SETSIZE, p) | #define CPU_ZERO(p) __BIT_ZERO(CPU_SETSIZE, p) | ||||
#define CPU_FILL(p) __BIT_FILL(CPU_SETSIZE, p) | #define CPU_FILL(p) __BIT_FILL(CPU_SETSIZE, p) | ||||
#define CPU_SETOF(n, p) __BIT_SETOF(CPU_SETSIZE, n, p) | #define CPU_SETOF(n, p) __BIT_SETOF(CPU_SETSIZE, n, p) | ||||
#define CPU_EQUAL(p, c) (__BIT_CMP(CPU_SETSIZE, p, c) == 0) | #define CPU_EQUAL(p, c) (__BIT_CMP(CPU_SETSIZE, p, c) == 0) | ||||
#define CPU_EMPTY(p) __BIT_EMPTY(CPU_SETSIZE, p) | #define CPU_EMPTY(p) __BIT_EMPTY(CPU_SETSIZE, p) | ||||
#define CPU_ISFULLSET(p) __BIT_ISFULLSET(CPU_SETSIZE, p) | #define CPU_ISFULLSET(p) __BIT_ISFULLSET(CPU_SETSIZE, p) | ||||
#define CPU_SUBSET(p, c) __BIT_SUBSET(CPU_SETSIZE, p, c) | #define CPU_SUBSET(p, c) __BIT_SUBSET(CPU_SETSIZE, p, c) | ||||
#define CPU_OVERLAP(p, c) __BIT_OVERLAP(CPU_SETSIZE, p, c) | #define CPU_OVERLAP(p, c) __BIT_OVERLAP(CPU_SETSIZE, p, c) | ||||
#define CPU_CMP(p, c) __BIT_CMP(CPU_SETSIZE, p, c) | #define CPU_CMP(p, c) __BIT_CMP(CPU_SETSIZE, p, c) | ||||
#define CPU_OR(d, s) __BIT_OR(CPU_SETSIZE, d, s) | #define CPU_OR(d, s1, s2) __BIT_OR2(CPU_SETSIZE, d, s1, s2) | ||||
#define CPU_AND(d, s) __BIT_AND(CPU_SETSIZE, d, s) | #define CPU_AND(d, s1, s2) __BIT_AND2(CPU_SETSIZE, d, s1, s2) | ||||
#define CPU_ANDNOT(d, s) __BIT_ANDNOT(CPU_SETSIZE, d, s) | #define CPU_ANDNOT(d, s1, s2) __BIT_ANDNOT2(CPU_SETSIZE, d, s1, s2) | ||||
#define CPU_XOR(d, s1, s2) __BIT_XOR2(CPU_SETSIZE, d, s1, s2) | |||||
#define CPU_CLR_ATOMIC(n, p) __BIT_CLR_ATOMIC(CPU_SETSIZE, n, p) | #define CPU_CLR_ATOMIC(n, p) __BIT_CLR_ATOMIC(CPU_SETSIZE, n, p) | ||||
#define CPU_SET_ATOMIC(n, p) __BIT_SET_ATOMIC(CPU_SETSIZE, n, p) | #define CPU_SET_ATOMIC(n, p) __BIT_SET_ATOMIC(CPU_SETSIZE, n, p) | ||||
#define CPU_SET_ATOMIC_ACQ(n, p) __BIT_SET_ATOMIC_ACQ(CPU_SETSIZE, n, p) | #define CPU_SET_ATOMIC_ACQ(n, p) __BIT_SET_ATOMIC_ACQ(CPU_SETSIZE, n, p) | ||||
#define CPU_AND_ATOMIC(n, p) __BIT_AND_ATOMIC(CPU_SETSIZE, n, p) | #define CPU_AND_ATOMIC(n, p) __BIT_AND_ATOMIC(CPU_SETSIZE, n, p) | ||||
#define CPU_OR_ATOMIC(d, s) __BIT_OR_ATOMIC(CPU_SETSIZE, d, s) | #define CPU_OR_ATOMIC(d, s) __BIT_OR_ATOMIC(CPU_SETSIZE, d, s) | ||||
#define CPU_COPY_STORE_REL(f, t) __BIT_COPY_STORE_REL(CPU_SETSIZE, f, t) | #define CPU_COPY_STORE_REL(f, t) __BIT_COPY_STORE_REL(CPU_SETSIZE, f, t) | ||||
#define CPU_FFS(p) __BIT_FFS(CPU_SETSIZE, p) | #define CPU_FFS(p) __BIT_FFS(CPU_SETSIZE, p) | ||||
#define CPU_FLS(p) __BIT_FLS(CPU_SETSIZE, p) | #define CPU_FLS(p) __BIT_FLS(CPU_SETSIZE, p) | ||||
#define CPU_FOREACH_ISSET(i, p) __BIT_FOREACH_ISSET(CPU_SETSIZE, i, p) | #define CPU_FOREACH_ISSET(i, p) __BIT_FOREACH_ISSET(CPU_SETSIZE, i, p) | ||||
#define CPU_FOREACH_ISCLR(i, p) __BIT_FOREACH_ISCLR(CPU_SETSIZE, i, p) | #define CPU_FOREACH_ISCLR(i, p) __BIT_FOREACH_ISCLR(CPU_SETSIZE, i, p) | ||||
#define CPU_COUNT(p) ((int)__BIT_COUNT(CPU_SETSIZE, p)) | #define CPU_COUNT(p) ((int)__BIT_COUNT(CPU_SETSIZE, p)) | ||||
#define CPUSET_FSET __BITSET_FSET(_NCPUWORDS) | #define CPUSET_FSET __BITSET_FSET(_NCPUWORDS) | ||||
#define CPUSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x) | #define CPUSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x) | ||||
#if !defined(_KERNEL) | |||||
kib: This is WIP, at best, right? | |||||
Done Inline ActionsYes, as I wrote in the comment to this review, this is a WIP state, just what I had after test building lang/gcc11 with the static inline implementation of CPU_ALLOC(). se: Yes, as I wrote in the comment to this review, this is a WIP state, just what I had after test… | |||||
#define CPU_ALLOC(_s) __BITSET_ALLOC(_s) | |||||
Done Inline ActionsI suspect this is a namespace pollution, POSIX does not allow inclusion of cpuset.h expose stdlib symbols. kib: I suspect this is a namespace pollution, POSIX does not allow inclusion of cpuset.h expose… | |||||
Done Inline ActionsNo, this was just a quick hack to make lang/gcc11 build with static inline CPU_ALLOC(), obviously not acceptable for a final commit. se: No, this was just a quick hack to make lang/gcc11 build with static inline CPU_ALLOC()… | |||||
#define CPU_ALLOC_SIZE(_s) __BITSET_SIZE(_s) | |||||
#define CPU_FREE(p) __BITSET_FREE(p) | |||||
Done Inline ActionsAnd this is the reason for stdlib.h inclusion, right? This is why a lot of stuff are macros and not inlines. kib: And this is the reason for stdlib.h inclusion, right? This is why a lot of stuff are macros… | |||||
Done Inline ActionsThe problem is that GCC poisons references to malloc(), even if it is only used to define some macro like CPU_ALLOC() which is never used in GCC. This is just one example of a port that uses GLIBC specific CPU_* functions. I'm wondering whether we need to provide both FreeBSD and GLIBC style implementations of those functions, the latter e.g. selected by _GNU_SOURCE being defined. The changes that I committed to sys/bitset.h et.al. where a result of my question, whether we should try to provide GLIBC compatible BIT_*/BITSET_* macros, and you were correct to point out that __BIT* names could be used to prevent namespace pollution and to allow GLIBC BIT* macros in usermode code. I'm afraid that this will not work well for the CPU_* macros, and one solution might be a similar approach to that used in sys/bitset.h, i.e. CPU_* defined as __CPU_* and aliased back for the kernel and FreeBSD code in base, and GLIBC compatible macros for ports that define _GNU_SOURCE. You do probably know that GLIBC uses CPU_AND() for FreeBSD's CPU_AND2(), for example, but GNU programs have to #define _GNU_SOURCE to make these GLIBC CPU_* macros visible. se: The problem is that GCC poisons references to malloc(), even if it is only used to define some… | |||||
Not Done Inline ActionsThis must be __cpuset_free(), to not depend on the user symbol. Also for symmetry if somebody needs to override. kib: This must be __cpuset_free(), to not depend on the user symbol. Also for symmetry if somebody… | |||||
#define CPU_ISSET_S(n, _s, p) __BIT_ISSET(_s, n, p) | |||||
#define CPU_SET_S(n, _s, p) __BIT_SET(_s, n, p) | |||||
#define CPU_ZERO_S(_s, p) __BIT_ZERO(_s, p) | |||||
#define CPU_OR_S(_s, d, s1, s2) __BIT_OR2(_s, d, s1, s2) | |||||
#define CPU_AND_S(_s, d, s1, s2) __BIT_AND2(_s, d, s1, s2) | |||||
#define CPU_XOR_S(_s, d, s1, s2) __BIT_XOR2(_s, d, s1, s2) | |||||
#endif | |||||
/* | /* | ||||
* Valid cpulevel_t values. | * Valid cpulevel_t values. | ||||
*/ | */ | ||||
#define CPU_LEVEL_ROOT 1 /* All system cpus. */ | #define CPU_LEVEL_ROOT 1 /* All system cpus. */ | ||||
#define CPU_LEVEL_CPUSET 2 /* Available cpus for which. */ | #define CPU_LEVEL_CPUSET 2 /* Available cpus for which. */ | ||||
#define CPU_LEVEL_WHICH 3 /* Actual mask/id for which. */ | #define CPU_LEVEL_WHICH 3 /* Actual mask/id for which. */ | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |
This is WIP, at best, right?