From nobody Mon Feb 6 19:07:43 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P9bPC63h8z3n43n; Mon, 6 Feb 2023 19:07:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P9bPC5DGSz3Pwp; Mon, 6 Feb 2023 19:07:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675710463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LoCLz8r7dijSrBVa0epDT78LS/gHAG+sQIS7EToFhzs=; b=l8F1E2FJZ+c1LOhrDxxnNUfZpg9e8PBoyG0NqOw6iqUR3e9wCk3M1qidyspRNkwzGbCBfI rpLXAbNshJlwTZsO0XkcZXXJsx1X/WyGBVp7YkG6vk+IJIeZoz4S4qZyUqMCgBrefJxdD+ l+pM+kyZ/Y4GH/DtiJTrgEKjJvIYOBXU8WvK1k93iNbWDl3ToL/tDIN1tIoxeq41AQQrHc JlgUgd1ZcrT7wOQ6YGFP9Qpg8a2U5oLAazuCqTLywUaJ2zoeyaAl46jzwfK+VOeAF3VQzQ bWAwGMxnK2Ro+F39OwVA+tUa3sX177QqVcrSKGU76x1XVvG3kr32uAIYTHkn7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675710463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LoCLz8r7dijSrBVa0epDT78LS/gHAG+sQIS7EToFhzs=; b=Rk5L+Ai9q1fzJkY8ZFwgSH6giidWq9naCeXmO7BrLlzExiyfiVJEGR+h5bVw9/jDwAq3XR 5XFnB3DNtOiPZA0TPZ1iwE5yFO7Qw2/mqCsbA++TBIU1qAU20reXmycZ79u7sy/Dqkb6m+ P+VIdPVe50BbHvtFI53W9JfveaWMaBszB5TvGsRLiX1u2uKswJz5WHWh15r42YcQNtxi4a D8Ykj1z4IXbO9l7RfCTY+cuc0SUBeB+aOeuQXl46xlgJJ1lb5VKVVlBdlMCWTbiItrZxix g5aRQCZSnVvg3xZHHo1nC4hwh87uSXQmGa7nv67+1NQrelqrjrL88ClGuu+0/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675710463; a=rsa-sha256; cv=none; b=RvSXClKtL+H1pTHDTKVC4vL0Qp0wQ+it+hqe3nZKbcTYBa8R865TfJ3ioXGGjcT0D4LN+E FyNP/e5khx2tGVZvypxepji0FO+Ib25MYGNEkmfkpCLlgmDE+DoB4ob9RbCWaRL1z3eED6 wojcKrkK3l8zEjnld1x5NBb/01HDhQoaIoRKBPNS4Bt07L47zYsjHVl/VLv7s0E/bLeDp0 TFgjpCobpHUr+IytGIFdHixB8DtwUL1YyI+A2xgoGDKT1nb/mAhATjKWL4qll+xuQJUpxs 9WCCq9pDKY1s27zWpr1nXdEzwxKzzETw9AUkfi1YJ3QheKP9VHXoehVK8wyqTA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P9bPC4JN5zm2t; Mon, 6 Feb 2023 19:07:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 316J7hND076857; Mon, 6 Feb 2023 19:07:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 316J7hwD076856; Mon, 6 Feb 2023 19:07:43 GMT (envelope-from git) Date: Mon, 6 Feb 2023 19:07:43 GMT Message-Id: <202302061907.316J7hwD076856@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 669dc70e40ff - stable/13 - sched.h: Fix _S macros for better compatibility with glibc. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 669dc70e40ff68e6d58df84ce21c175fe6c6321f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=669dc70e40ff68e6d58df84ce21c175fe6c6321f commit 669dc70e40ff68e6d58df84ce21c175fe6c6321f Author: Dmitry Chagin AuthorDate: 2023-01-29 12:34:10 +0000 Commit: Dmitry Chagin 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()); }