From nobody Sun Feb 19 16:42:42 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 4PKWZ83dNdz3rQ4r; Sun, 19 Feb 2023 16:42:56 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4PKWZ80PVDz3PH1; Sun, 19 Feb 2023 16:42:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.17.1/8.17.1) with ESMTPS id 31JGggO5062801 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 19 Feb 2023 18:42:45 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 31JGggO5062801 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 31JGgg1X062800; Sun, 19 Feb 2023 18:42:42 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 19 Feb 2023 18:42:42 +0200 From: Konstantin Belousov To: Dmitry Chagin Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-branches@freebsd.org Subject: Re: git: f3f350c5c8e4 - stable/13 - cpuset: Add compat shim to the sched_affinity functions Message-ID: References: <202302190726.31J7QIvG039582@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202302190726.31J7QIvG039582@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Rspamd-Queue-Id: 4PKWZ80PVDz3PH1 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On Sun, Feb 19, 2023 at 07:26:18AM +0000, Dmitry Chagin wrote: > 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 Does it work to have 14.x osrel value for P_OSREL_TIDPID as compat selector on 13.x? > > #define P_OSREL_MAJOR(x) ((x) / 100000) > #endif