From 62284825a7b63f696477cb4ec6e243f2b783204a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 5 Sep 2025 16:59:37 -0500 Subject: [PATCH] Jesse Rosenstock wants taskset to work with an arbitrary number of leading zeroes for some reason, so take the rightmost 8k of mask data and test with leading zeroes. (It could instead specifically skip leading zeroes, but would still have to check sizeof(toybuf) anyway.) Again, the 6.16 kernel can only set NR_CPUS to 8k (1/4 of the bits in toybuf) for 2 architectures (x86-64 and powerpc64, and ARM64 maxes out at 4k (1/8 of toybuf). Last I checked nobody's made hardware anywhere near that: they thought they might 20 years ago but NUMA didn't scale. Beowulf clusters existed back in the 1990s and if you really want to have a cluster mmap() shared memory from network storage you can just do that and address contentional manually (with manual flock and madvise or your own bespoke mechanism), or create data stores like riak, or... --- tests/taskset.test | 2 +- toys/other/taskset.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/taskset.test b/tests/taskset.test index 06ba64f5..5732e23f 100755 --- a/tests/taskset.test +++ b/tests/taskset.test @@ -31,6 +31,6 @@ testing 'run on last' \ "$((CPUS-1))\n" '' '' testing "long mask doesn't segfault" \ - 'taskset $(printf %99999s | tr \ f) echo; echo $?' '\n0\n' '' '' + 'taskset $(printf %99999s | tr \ 0)f echo; echo $?' '\n0\n' '' '' testing "taskset error checking" \ 'taskset 0 echo nope 2>/dev/null; echo $?' '1\n' '' '' diff --git a/toys/other/taskset.c b/toys/other/taskset.c index 55b0dae1..94044ebd 100644 --- a/toys/other/taskset.c +++ b/toys/other/taskset.c @@ -70,7 +70,11 @@ static void do_taskset(pid_t pid) // Convert hex string to mask[] bits memset(toybuf, 0, sizeof(toybuf)); - k = minof(strlen(s = *toys.optargs), 2*sizeof(toybuf)); + j = (k = strlen(s = *toys.optargs))-2*sizeof(toybuf); + if (j>0) { + s += j; + k -= j; + } s += k; for (j = 0; j