From nobody Sun Feb 19 07:26:18 2023 X-Original-To: dev-commits-src-all@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 4PKHCt4XP6z3st81; Sun, 19 Feb 2023 07:26:18 +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 4PKHCt3Xkjz3pC3; Sun, 19 Feb 2023 07:26:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676791578; 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=DMv8A0s2K38tt6VDzdK5oWFP/SH4QQZcVmxURWcwNks=; b=sJvyNanE04Pypfy+j3RhHu3Slg75TFQfP3eIMt8vps7fFhN2hM2tnVfQqiwCQrTnwwsB36 esyFM/KDAI4oDT1PvUpiY7nzhtLfSbTEF+n8SeIk+/qFNnTBaIYG2JdsKmciU3/RtRmIcn Gn4GQLWCBhbjL7CtCBQD93B+FMEPeF0vlOXpWsp9kkCliSNnyws2ee/6xcZAKfIpIteV/i ymszy2THGWPlp3dgl3IwCgSYwJQQ94BMXaWXh4v2VRAZYyLyasqe7i5Mk3HZczG1zGsEe/ yj2Sk+n6oLx7/Uoe+pt/Ev6KEPgveVWvQGEiF3Ypz5iKiAW7JqzvnF1yJe2+OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676791578; 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=DMv8A0s2K38tt6VDzdK5oWFP/SH4QQZcVmxURWcwNks=; b=UlSV1uFdlLfpQvybs5o9NfG8PCUjRbuyfH7M7NLtsD0VH0tFvRz6OHYISpQ+jFUdGU7QtV Ky5s826A7rA7tPIkW8KgfbEpVjvPrO5gqxyVpswFpCbt62Iee/A/fmqY18cX4+XVsLhdxE o2aX5Pnx2EfSDIi/zJ6mT8HSqf67vSATOXclUtrNwr6vIIXctdJzG/+1ldp6/y8C7wIHHc BnBrMHGJ/TEIuZZ/ThheYSQ3S/KigmvXURnxJfiWn0yXdvU1O7wzKCwla42QgdECzuOzBI B6Wnye6cpvQhZ3k91OV3RKADyHkleJQ4iNwtdLT1Zm+9pJ763cVb8ocO7ALVAA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676791578; a=rsa-sha256; cv=none; b=B1mqM3jmMV+37OqEcXe1eERBpRlsDjWew3TKU2CG78oY3dyUo2doyNhajalrx7M/JgpXY8 sKI2wKP3cghwx86qgTfs5FU/MXGgv1XfazTSK5eonxi6lL5gFUZFDXGT+omaD+Ud8Rvvf/ PXYorEanhsGePz7h4mCwsfSEVT9aewaHP9jrRgtpOcnxOR7jmyiJJTffD93KDB5JiC6APc k1jYFu0EizXF8FGXP935mgTB/4ot/sglT1pxg7QhsUSFM2nlXGaOAGt8NIUMpCYdBIRncJ fKXiTvko6Uxq9yMjB/rmOlhhsROWHUB+qpFQVtA8kFMQEEH5pNk7FcxrgSQ/og== 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 4PKHCt2FKyzt6y; Sun, 19 Feb 2023 07:26:18 +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 31J7QINJ039583; Sun, 19 Feb 2023 07:26:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31J7QIvG039582; Sun, 19 Feb 2023 07:26:18 GMT (envelope-from git) Date: Sun, 19 Feb 2023 07:26:18 GMT Message-Id: <202302190726.31J7QIvG039582@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: f3f350c5c8e4 - stable/13 - cpuset: Add compat shim to the sched_affinity functions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: f3f350c5c8e4f6b0d3ff9806881b8f042a9ca925 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=f3f350c5c8e4f6b0d3ff9806881b8f042a9ca925 commit f3f350c5c8e4f6b0d3ff9806881b8f042a9ca925 Author: Dmitry Chagin AuthorDate: 2023-02-15 09:23:15 +0000 Commit: Dmitry Chagin CommitDate: 2023-02-19 07:26:06 +0000 cpuset: Add compat shim to the sched_affinity functions To allow to run a newer world on a pre-1400079 kernel a compat shims to the sched_affinity functions has beed added. Reported by: antoine Tested by: antoine Reviewed by: kib Differential revision: https://reviews.freebsd.org/D38555 MFC after: 3 days (cherry picked from commit cbc32e4c5e8427e0f1032d9d3aa5863dd1538c11) --- lib/libc/gen/sched_getaffinity.c | 15 ++++++++++++++- lib/libc/gen/sched_setaffinity.c | 14 +++++++++++++- lib/libc/include/libc_private.h | 6 ++++++ sys/sys/param.h | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c index 95145a1eb019..fce47fbfc0d2 100644 --- a/lib/libc/gen/sched_getaffinity.c +++ b/lib/libc/gen/sched_getaffinity.c @@ -26,16 +26,29 @@ * SUCH DAMAGE. */ +#define _WANT_P_OSREL +#include #include #include #include +#include "libc_private.h" + int sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset) { + cpuwhich_t which; int error; - error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, + if (__getosreldate() < P_OSREL_TIDPID) { + if (pid == 0 || pid > _PID_MAX) + which = CPU_WHICH_TID; + else + which = CPU_WHICH_PID; + } else + which = CPU_WHICH_TIDPID; + + error = cpuset_getaffinity(CPU_LEVEL_WHICH, which, pid == 0 ? -1 : pid, cpusetsz, cpuset); if (error == -1 && errno == ERANGE) errno = EINVAL; diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c index 36ed0f45d417..b878e1affc41 100644 --- a/lib/libc/gen/sched_setaffinity.c +++ b/lib/libc/gen/sched_setaffinity.c @@ -26,20 +26,32 @@ * SUCH DAMAGE. */ +#define _WANT_P_OSREL #include #include #include #include #include +#include "libc_private.h" + int sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset) { static int mp_maxid; + cpuwhich_t which; cpuset_t c; int error, lbs, cpu; size_t len, sz; + if (__getosreldate() < P_OSREL_TIDPID) { + if (pid == 0 || pid > _PID_MAX) + which = CPU_WHICH_TID; + else + which = CPU_WHICH_PID; + } else + which = CPU_WHICH_TIDPID; + sz = cpusetsz > sizeof(cpuset_t) ? sizeof(cpuset_t) : cpusetsz; memset(&c, 0, sizeof(c)); memcpy(&c, cpuset, sz); @@ -58,7 +70,7 @@ sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset) if (cpu > mp_maxid) CPU_CLR(cpu, &c); } - error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, + error = cpuset_setaffinity(CPU_LEVEL_WHICH, which, pid == 0 ? -1 : pid, sizeof(cpuset_t), &c); if (error == -1 && errno == EDEADLK) errno = EINVAL; diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index 61c1eb438142..78a75cc6284d 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -39,6 +39,12 @@ #include #include +/* + * The kernel doesn't expose PID_MAX to the user space. Save it here + * to allow to run a newer world on a pre-1400079 kernel. + */ +#define _PID_MAX 99999 + /* * This global flag is non-zero when a process has created one * or more threads. It is used to avoid calling locking functions diff --git a/sys/sys/param.h b/sys/sys/param.h index 909ff0ef1d8b..d2fbad6c127b 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -91,6 +91,7 @@ #define P_OSREL_CK_SUPERBLOCK 1300000 #define P_OSREL_CK_INODE 1300005 #define P_OSREL_POWERPC_NEW_AUX_ARGS 1300070 +#define P_OSREL_TIDPID 1400079 #define P_OSREL_MAJOR(x) ((x) / 100000) #endif