Date: Mon, 6 Feb 2023 19:07:43 GMT From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 669dc70e40ff - stable/13 - sched.h: Fix _S macros for better compatibility with glibc. Message-ID: <202302061907.316J7hwD076856@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=669dc70e40ff68e6d58df84ce21c175fe6c6321f commit 669dc70e40ff68e6d58df84ce21c175fe6c6321f Author: Dmitry Chagin <dchagin@FreeBSD.org> AuthorDate: 2023-01-29 12:34:10 +0000 Commit: Dmitry Chagin <dchagin@FreeBSD.org> CommitDate: 2023-02-06 19:06:30 +0000 sched.h: Fix _S macros for better compatibility with glibc. In e2650af157 was added "_S" macros for compatibility with glibc, but it's still incompatible as under glibc the macros whose names end with "_S" operate on the dynamically allocated CPU set(s) whose size is in bytes, not in bits. While here remove limiting ifdef to non-kernel case. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D38110 MFC after: 1 week (cherry picked from commit 02f7670ed243498aea96150962c2c9916bab7c98) --- sys/sys/cpuset.h | 20 ++++++------- tests/sys/kern/sched_affinity.c | 62 ++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h index 5df5cff6497b..601da08a46a8 100644 --- a/sys/sys/cpuset.h +++ b/sys/sys/cpuset.h @@ -75,23 +75,21 @@ #define CPUSET_FSET __BITSET_FSET(_NCPUWORDS) #define CPUSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x) -#if !defined(_KERNEL) #define CPU_ALLOC_SIZE(_s) __BITSET_SIZE(_s) #define CPU_ALLOC(_s) __cpuset_alloc(_s) #define CPU_FREE(p) __cpuset_free(p) -#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_CLR_S(n, _s, p) __BIT_CLR(_s, n, p) -#define CPU_ZERO_S(_s, p) __BIT_ZERO(_s, p) +#define CPU_ISSET_S(n, _s, p) __BIT_ISSET((_s) * 8, n, p) +#define CPU_SET_S(n, _s, p) __BIT_SET((_s) * 8, n, p) +#define CPU_CLR_S(n, _s, p) __BIT_CLR((_s) * 8, n, p) +#define CPU_ZERO_S(_s, p) __BIT_ZERO((_s) * 8, 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) +#define CPU_OR_S(_s, d, s1, s2) __BIT_OR2((_s) * 8, d, s1, s2) +#define CPU_AND_S(_s, d, s1, s2) __BIT_AND2((_s) * 8, d, s1, s2) +#define CPU_XOR_S(_s, d, s1, s2) __BIT_XOR2((_s) * 8, d, s1, s2) -#define CPU_COUNT_S(_s, p) ((int)__BIT_COUNT(_s, p)) -#define CPU_EQUAL_S(_s, p, c) (__BIT_CMP(_s, p, c) == 0) -#endif +#define CPU_COUNT_S(_s, p) ((int)__BIT_COUNT((_s) * 8, p)) +#define CPU_EQUAL_S(_s, p, c) (__BIT_CMP((_s) * 8, p, c) == 0) /* * Valid cpulevel_t values. diff --git a/tests/sys/kern/sched_affinity.c b/tests/sys/kern/sched_affinity.c index 0c864342ff01..db8d9132550c 100644 --- a/tests/sys/kern/sched_affinity.c +++ b/tests/sys/kern/sched_affinity.c @@ -50,7 +50,7 @@ support_getmaxcpuid(void) setsize = CPU_ALLOC_SIZE(i); set = CPU_ALLOC(i); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(i, set); + CPU_ZERO_S(setsize, set); rv = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, setsize, set); if (rv == 0) { @@ -73,18 +73,18 @@ ATF_TC_BODY(test_setinvalidcpu, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpuid + 1); set = CPU_ALLOC(maxcpuid + 1); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpuid + 1, set); - CPU_SET_S(maxcpuid + 1, maxcpuid + 1, set); - CPU_SET_S(maxcpuid - 1, maxcpuid + 1, set); + CPU_ZERO_S(cpusetsize, set); + CPU_SET_S(maxcpuid + 1, cpusetsize, set); + CPU_SET_S(maxcpuid - 1, cpusetsize, set); ATF_REQUIRE(sched_setaffinity(0, cpusetsize, set) == 0); CPU_FREE(set); cpusetsize = CPU_ALLOC_SIZE(maxcpus + 1); set = CPU_ALLOC(maxcpus + 1); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpus + 1, set); - CPU_SET_S(maxcpuid + 1, maxcpus + 1, set); - CPU_SET_S(maxcpuid - 1, maxcpus + 1, set); + CPU_ZERO_S(cpusetsize, set); + CPU_SET_S(maxcpuid + 1, cpusetsize, set); + CPU_SET_S(maxcpuid - 1, cpusetsize, set); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == -1); ATF_REQUIRE_EQ(errno, EINVAL); @@ -104,8 +104,8 @@ ATF_TC_BODY(test_setvalidcpu, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpus + 1); set = CPU_ALLOC(maxcpus + 1); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpus + 1, set); - CPU_SET_S(cpu, maxcpus + 1, set); + CPU_ZERO_S(cpusetsize, set); + CPU_SET_S(cpu, cpusetsize, set); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == 0); ATF_REQUIRE_EQ(cpu, sched_getcpu()); @@ -121,7 +121,7 @@ ATF_TC_BODY(test_setzeroset1, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpuid + 1); set = CPU_ALLOC(maxcpuid + 1); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpuid + 1, set); + CPU_ZERO_S(cpusetsize, set); ATF_REQUIRE(sched_setaffinity(0, cpusetsize, set) == -1); ATF_REQUIRE_EQ(errno, EINVAL); CPU_FREE(set); @@ -136,7 +136,7 @@ ATF_TC_BODY(test_setzeroset2, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpuid + 1); set = CPU_ALLOC(maxcpuid + 1); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpuid + 1, set); + CPU_ZERO_S(cpusetsize, set); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == -1); ATF_REQUIRE_EQ(errno, EDEADLK); @@ -152,20 +152,20 @@ ATF_TC_BODY(test_setmaxsetsize, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpus * 2); set = CPU_ALLOC(maxcpus * 2); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpus * 2, set); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 0); - CPU_SET_S(0, maxcpus * 2, set); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 1); + CPU_ZERO_S(cpusetsize, set); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 0); + CPU_SET_S(0, cpusetsize, set); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 1); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == 0); - CPU_ZERO_S(maxcpus * 2, set); - CPU_SET_S(maxcpuid, maxcpus * 2, set); + CPU_ZERO_S(cpusetsize, set); + CPU_SET_S(maxcpuid, cpusetsize, set); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == 0); - CPU_ZERO_S(maxcpus * 2, set); - CPU_SET_S(maxcpuid + 1, maxcpus * 2, set); + CPU_ZERO_S(cpusetsize, set); + CPU_SET_S(maxcpuid + 1, cpusetsize, set); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == -1); ATF_REQUIRE_EQ(errno, EINVAL); @@ -212,7 +212,7 @@ ATF_TC_BODY(test_getsetsize, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpuid + 1); set = CPU_ALLOC(maxcpuid + 1); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpuid + 1, set); + CPU_ZERO_S(cpusetsize, set); ATF_REQUIRE(cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == 0); CPU_FREE(set); @@ -227,26 +227,26 @@ ATF_TC_BODY(test_holes, tc) cpusetsize = CPU_ALLOC_SIZE(maxcpus * 2); set = CPU_ALLOC(maxcpus * 2); ATF_REQUIRE(set != NULL); - CPU_ZERO_S(maxcpus * 2, set); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 0); - CPU_SET_S(maxcpuid, maxcpus * 2, set); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 1); + CPU_ZERO_S(cpusetsize, set); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 0); + CPU_SET_S(maxcpuid, cpusetsize, set); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 1); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == 0); - CPU_ZERO_S(maxcpus * 2, set); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 0); - CPU_SET_S(maxcpuid + 1, maxcpus * 2, set); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 1); + CPU_ZERO_S(cpusetsize, set); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 0); + CPU_SET_S(maxcpuid + 1, cpusetsize, set); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 1); ATF_REQUIRE(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == -1); ATF_REQUIRE_EQ(errno, EINVAL); - ATF_REQUIRE(CPU_COUNT_S(maxcpus * 2, set) == 1); + ATF_REQUIRE(CPU_COUNT_S(cpusetsize, set) == 1); ATF_REQUIRE(cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, cpusetsize, set) == 0); - ATF_REQUIRE(CPU_ISSET_S(maxcpuid + 1, maxcpus * 2, set) == false); - ATF_REQUIRE(CPU_ISSET_S(maxcpuid, maxcpus * 2, set) == true); + ATF_REQUIRE(CPU_ISSET_S(maxcpuid + 1, cpusetsize, set) == false); + ATF_REQUIRE(CPU_ISSET_S(maxcpuid, cpusetsize, set) == true); ATF_REQUIRE_EQ(maxcpuid, (uint32_t)sched_getcpu()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302061907.316J7hwD076856>