Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jan 2022 00:16:30 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Stefan Esser <se@freebsd.org>
Cc:        Antoine Brodin <antoine@freebsd.org>, Konstantin Belousov <kib@freebsd.org>, src-committers <src-committers@freebsd.org>, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org, FreeBSD Ports Management Team <portmgr@freebsd.org>
Subject:   Re: git: e2650af157bc - main - Make CPU_SET macros compliant with other implementations
Message-ID:  <YdIkPotPUKVwgCuF@kib.kiev.ua>
In-Reply-To: <9dffb50a-9374-be91-8007-ce8933571398@freebsd.org>
References:  <202112301154.1BUBsR1q017491@gitrepo.freebsd.org> <CAALwa8m3u3xrO3N0j8um57qGTVnMEQwx1gP2YxJbzE5%2BLhbsWA@mail.gmail.com> <d1553b68-23dd-128e-6ac0-6c3c1f66c7cd@freebsd.org> <CAALwa8kn9h%2BKn53RvKX1Vx%2BqFK2Txt-sqj80nTSJUFC1U=8AGg@mail.gmail.com> <9dffb50a-9374-be91-8007-ce8933571398@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 02, 2022 at 10:45:14PM +0100, Stefan Esser wrote:
> Am 02.01.22 um 20:51 schrieb Antoine Brodin:
> > Hi,
> > 
> > It seems that the 2 main ports failing are math/py-numpy (503 ports
> > skipped) and sysutils/slurm-wlm (232 ports skipped)
> 
> Hi Antoine,
> 
> thank you for the information!
> 
> > Failure logs:
> > http://beefy18.nyi.freebsd.org/data/main-amd64-default/pe2d17ded99d5_s5169832c96/logs/errors/py38-numpy-1.20.3,1.log
> 
> Python 3.8.12 (default, Dec 31 2021, 10:50:47)
> >>> import os
> >>> os.sched_getaffinity(0)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> OSError: [Errno 34] Result too large
> 
> This is a Python interpreter problem: it seems that the wrapper
> for the sched_getaffinity() function that has been introduced by
> kib in <sched.h> is buggy.
> 
> As a work-around I have added a patch to comment out the
> os.sched_getaffinity(0) call (which used to cause an Attribute
> error that was caught by try/except, before).
> 
> See ports commit 507c189b2876.

Buggy in which way?

Our cpuset_getaffinity(2) syscall returns ERANGE for cpuset size not
equal to CPU_SETSIZE.  It seems that python source expects EINVAL in
this case.

I can change the wrapper to translate ERANGE to EINVAL.  sched_setaffinity()
probably would require a symmetrical patch, but lets postpone it.

diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c
index 2ae8c5b763a3..8748d7a60278 100644
--- a/lib/libc/gen/sched_getaffinity.c
+++ b/lib/libc/gen/sched_getaffinity.c
@@ -26,11 +26,29 @@
  * SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <sched.h>
+#include <string.h>
 
 int
 sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset)
 {
+	/*
+	 * Be more Linux-compatible:
+	 * - return EINVAL in passed size is less than size of cpuset_t
+	 *   in advance, instead of ERANGE from the syscall
+	 * - if passed size is larger than the size of cpuset_t, be
+	 *   permissive by claming it back to sizeof(cpuset_t) and
+	 *   zeroing the rest.
+	 */
+	if (cpusetsz < sizeof(cpuset_t))
+		return (EINVAL);
+	if (cpusetsz > sizeof(cpuset_t)) {
+		memset((char *)cpuset + sizeof(cpuset_t), 0,
+		    cpusetsz - sizeof(cpuset_t));
+		cpusetsz = sizeof(cpuset_t);
+	}
+
 	return (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
 	    pid == 0 ? -1 : pid, cpusetsz, cpuset));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YdIkPotPUKVwgCuF>