CPU test for taskset fails if machine has four threads or less
Summary
The CPU test for processor affinity fails on machines with four threads or less because the value used for the taskset
command selects threads 4-15 and excludes 0-3.
BIND version used
9.16.11
Steps to reproduce
Run on a VM with four vCPUs (or less).
./configure --prefix=/usr --sysconfdir=/etc --enable-static --localstatedir=/var
make -j $(nproc)
sudo bin/tests/system/ifconfig.sh up
cd bin/tests/system/
sh run.sh cpu
What is the current bug behavior?
Output of test:
T:cpu:1:A
A:cpu:System test cpu
I:cpu:PORTRANGE:5300 - 5399
I:cpu:starting servers
/home/user/bind/bin/named/named -D cpu-ns1 -X named.lock -m record,size,mctx -c named.conf -d 99 -g -U 4 -T maxcachesize=2097152 >named.run 2>&1 & echo $!
I:cpu:stop server (1)
I:cpu:start server with taskset (2)
I:cpu:Couldn't start server taskset fff0 /home/user/bind/bin/named/named -D cpu-ns1 -X named.lock -m record,size,mctx -c named.conf -d 99 -g -U 4 -T maxcachesize=2097152 >>named.run 2>&1 & echo $! (pid=13759)
I:cpu:failed
I:cpu:failed
I:cpu:check ps output (3)
cat: ns1/named.pid: No such file or directory
I:cpu:pid=
I:cpu:psr=
tests.sh: line 41: test: : integer expression expected
I:cpu:failed
I:cpu:exit status: 2
I:cpu:stopping servers
I:cpu:pytest not installed, skipping python tests
R:cpu:FAIL
What is the expected correct behavior?
Test succeeds.
Relevant configuration files
N/A
Relevant logs and/or screenshots
From bin/tests/system/cpu/ns1/named.run
taskset: failed to set pid 0's affinity: Invalid argument
Possible fixes
Line that causes the problem: bin/tests/system/cpu/tests.sh#L28
The mask argument fff0
for the taskset
command selects CPUs/threads 4-15 and excludes 0-3. On a machine that only has 4 CPUs/threads, the command fails because there are no valid CPUs/threads to select.
Several possible fixes could be done. Changing the mask value from fff0
to fffe
would select CPUs/threads 1-15 and only exclude CPU/thread 0. This would work for everything except for single core/thread machines. For that case, a prereq could be added to check that the output of nproc --all
is greater than one.
It appears that in later versions, a check was added to skip this test entirely if the taskset
command fails. bin/tests/system/cpu/prereq.sh#L32 This prereq could be replaced by the above suggested one if the mask value is changed to fffe
.