From nobody Sun Jan 29 12:38:20 2023 X-Original-To: dev-commits-src-main@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 4P4W7d0CVGz3cQ8N; Sun, 29 Jan 2023 12:38:21 +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 4P4W7c6b14z3rgF; Sun, 29 Jan 2023 12:38:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674995900; 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=iZktIp2OO1hglqq8dIEr/1TFwFKPDAbfPQz+0DQWtI8=; b=chmmVO3Ma3Ch1bPwNHlFFh1lO0SMMNz+pJAlgYSuJnxNktL/p3yxFoTFCIQ7cFXQqEUT6v 7YHo4LeWOaj8Kh0NEbO0T7YUPgY3q1Iot62y8yLClQlajeQtqsyi3v1VjYBc/3JfWkF67b xpStqisx/+0ye2qKp0gNTOHmFecGk484N02bw48cE1FXqa5MHGALoQV1vir/UFvbHpFvyH 7IIhyYVfswP/P4QPV6bI8Fg3YllEHCKrwdsXloFSAfYV2DWt9KOZhOKnCYz0xHO8ZFLjUj CP6Ev8pxUnr+KYscqu45hxOyfYeOfHozp617Y2CJkoaQt+tc4BumI8GcNpsLjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674995900; 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=iZktIp2OO1hglqq8dIEr/1TFwFKPDAbfPQz+0DQWtI8=; b=AaBtm2z4Y8HZ8XvAJ+NxgPc/BMwpCJoINtcAeO4X+80GeILuy4QTzCLzLJE9wBmoKkPtJN ug/5lgYV9vexF+BlN6wZFU1YNchCRiZ93jIaO7tf4ATbYTISYSWOHVPT0GIk5OHJRqXJkt g1TK+39fGGgnVT4yh/gXtT9PuZuG2Pv4zmkp0BuZIYeWvVV89bUuM5E1vZ1VKo+0a6vwIl 31AqyH4MtKXdNH+p+Tsk0kV8R/zylAiPC7X6AWjg6ZQiQswNPVwc0rqA6SIzf8JGQwtoXU vteTXKnOuGsfJmk57fzs7dr2pt/445dK1+IKEvrP1X+E5OQ/PLUdpakMpE3Y6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674995900; a=rsa-sha256; cv=none; b=suOc1Hs4a4spmilvN1CNPhkYrBnJg8Hiu6Vxu7JZg7OntRjWoPSA+WjV9xv5pB01n0B0oz F+cxjQWPf2N/z7wYDY1CxdrcJmzE/4sw0ub28gqmhGUxElSj2lM7uMRSl/tXdKwTRLRY1o rktvWk4y3prLvjlQH6jVZrbe5godkgMXw3gLROK8kSr8Z7OrAC3uhiXHXOrALTp6U1enC/ wwWBPmCwfeLn8V5++6vXegusRmIoYHHCX67lLuQDwtQVIWiTuviqOyySWaKpCNDlPqO0F/ 4Ul0TZfuJwdPeesMcf/dm2fpPczM9EbBAUeLk/gLlYDiw/b06Kb5ZR9BTtcCcg== 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 4P4W7c5j9wzTNb; Sun, 29 Jan 2023 12:38:20 +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 30TCcKd0050952; Sun, 29 Jan 2023 12:38:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30TCcKFb050951; Sun, 29 Jan 2023 12:38:20 GMT (envelope-from git) Date: Sun, 29 Jan 2023 12:38:20 GMT Message-Id: <202301291238.30TCcKFb050951@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 01f74ccd5a0d - main - libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 01f74ccd5a0d1a444703e931339709c7de5296b5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=01f74ccd5a0d1a444703e931339709c7de5296b5 commit 01f74ccd5a0d1a444703e931339709c7de5296b5 Author: Dmitry Chagin AuthorDate: 2023-01-29 12:35:18 +0000 Commit: Dmitry Chagin CommitDate: 2023-01-29 12:35:18 +0000 libthr: Fix pthread_attr_[g|s]etaffinity_np to match it's manual and the kernel. Since f35093f8 semantics of a thread affinity functions is changed to be a compatible with Linux: In case of getaffinity(), the minimum cpuset_t size that the kernel permits is the maximum CPU id, present in the system, / NBBY bytes, the maximum size is not limited. In case of setaffinity(), the kernel does not limit the size of the user-provided cpuset_t, internally using only the meaningful part of the set, where the upper bound is the maximum CPU id, present in the system, no larger than the size of the kernel cpuset_t. To match pthread_attr_[g|s]etaffinity_np checks of the user-provided cpusets to the kernel behavior export the minimum cpuset_t size allowed by running kernel via new sysctl kern.sched.cpusetsizemin and use it in checks. Reviewed by: Differential Revision: https://reviews.freebsd.org/D38112 MFC after: 1 week --- lib/libthr/thread/thr_attr.c | 6 ++++-- sys/kern/kern_cpuset.c | 6 ++++++ sys/kern/subr_smp.c | 2 ++ sys/sys/cpuset.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/libthr/thread/thr_attr.c b/lib/libthr/thread/thr_attr.c index 6ff23aa5a3da..5a06f793f4f8 100644 --- a/lib/libthr/thread/thr_attr.c +++ b/lib/libthr/thread/thr_attr.c @@ -599,8 +599,10 @@ _get_kern_cpuset_size(void) size_t len; len = sizeof(kern_cpuset_size); - if (sysctlbyname("kern.sched.cpusetsize", &kern_cpuset_size, - &len, NULL, 0)) + if (sysctlbyname("kern.sched.cpusetsizemin", &kern_cpuset_size, + &len, NULL, 0) != 0 && + sysctlbyname("kern.sched.cpusetsize", &kern_cpuset_size, + &len, NULL, 0) != 0) PANIC("failed to get sysctl kern.sched.cpusetsize"); } diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c index d89be2805759..6dfe22b66689 100644 --- a/sys/kern/kern_cpuset.c +++ b/sys/kern/kern_cpuset.c @@ -136,11 +136,17 @@ static struct domainlist cpuset_domains; static struct unrhdr *cpuset_unr; static struct cpuset *cpuset_zero, *cpuset_default, *cpuset_kernel; static struct domainset *domainset0, *domainset2; +u_int cpusetsizemin = 1; /* Return the size of cpuset_t at the kernel level */ SYSCTL_INT(_kern_sched, OID_AUTO, cpusetsize, CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, sizeof(cpuset_t), "sizeof(cpuset_t)"); +/* Return the minimum size of cpuset_t allowed by the kernel */ +SYSCTL_UINT(_kern_sched, OID_AUTO, cpusetsizemin, + CTLFLAG_RD | CTLFLAG_CAPRD, &cpusetsizemin, 0, + "The minimum size of cpuset_t allowed by the kernel"); + cpuset_t *cpuset_root; cpuset_t cpuset_domain[MAXMEMDOM]; diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c index b9b8968c5a37..6ab71fd63695 100644 --- a/sys/kern/subr_smp.c +++ b/sys/kern/subr_smp.c @@ -148,6 +148,8 @@ mp_setmaxid(void *dummy) KASSERT(mp_maxid >= mp_ncpus - 1, ("%s: counters out of sync: max %d, count %d", __func__, mp_maxid, mp_ncpus)); + + cpusetsizemin = howmany(mp_maxid + 1, NBBY); } SYSINIT(cpu_mp_setmaxid, SI_SUB_TUNABLES, SI_ORDER_FIRST, mp_setmaxid, NULL); diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h index 601da08a46a8..f8fc36b99aa7 100644 --- a/sys/sys/cpuset.h +++ b/sys/sys/cpuset.h @@ -120,6 +120,7 @@ #include LIST_HEAD(setlist, cpuset); +extern u_int cpusetsizemin; /* * cpusets encapsulate cpu binding information for one or more threads.