Follow the number of CPU set by taskset/cpuset
Administrators may wish to constrain the set of cores that BIND 9 runs on via the 'taskset', 'cpuset' or 'numactl' programs (or equivalent on other O/S), for example to achieve higher (or more stable) performance by more closely associating threads with individual NIC rx queues. If the admin has used taskset, it follows that BIND ought to automatically use the given number of CPUs rather than the system wide count. Co-Authored-By: Ray Bellis <ray@isc.org>
This commit is contained in:
16
bin/tests/system/cpu/clean.sh
Normal file
16
bin/tests/system/cpu/clean.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
set -e
|
||||
|
||||
rm -f ./named.run.*
|
||||
20
bin/tests/system/cpu/ns1/named.conf.in
Normal file
20
bin/tests/system/cpu/ns1/named.conf.in
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
options {
|
||||
query-source address 10.53.0.1;
|
||||
port @PORT@;
|
||||
pid-file "named.pid";
|
||||
listen-on { 10.53.0.1; };
|
||||
listen-on-v6 { none; };
|
||||
};
|
||||
21
bin/tests/system/cpu/prereq.sh
Normal file
21
bin/tests/system/cpu/prereq.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
. ../conf.sh
|
||||
|
||||
command -v cpuset >/dev/null || command -v numactl >/dev/null || command -v taskset >/dev/null || {
|
||||
echo_i "This test requires cpuset, numactl, or taskset." >&2
|
||||
exit 255
|
||||
}
|
||||
|
||||
exit 0
|
||||
21
bin/tests/system/cpu/setup.sh
Normal file
21
bin/tests/system/cpu/setup.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
# shellcheck source=conf.sh
|
||||
. ../conf.sh
|
||||
|
||||
set -e
|
||||
|
||||
$SHELL clean.sh
|
||||
|
||||
copy_setports ns1/named.conf.in ns1/named.conf
|
||||
65
bin/tests/system/cpu/tests.sh
Executable file
65
bin/tests/system/cpu/tests.sh
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
# shellcheck source=conf.sh
|
||||
. ../conf.sh
|
||||
|
||||
status=0
|
||||
n=0
|
||||
|
||||
CPUSET=$(command -v cpuset)
|
||||
NUMACTL=$(command -v numactl)
|
||||
TASKSET=$(command -v taskset)
|
||||
|
||||
cpulist() (
|
||||
if [ -n "$CPUSET" ]; then
|
||||
cpuset -g | head -1 | sed -e "s/.*: //" | tr -s ', ' '\n'
|
||||
elif [ -n "$NUMACTL" ]; then
|
||||
numactl --show | sed -ne 's/^physcpubind: //p' | tr -s ' ' '\n'
|
||||
elif [ -n "$TASKSET" ]; then
|
||||
# shellcheck disable=SC2046
|
||||
seq $(taskset -c -p $$ | sed -e 's/.*: //' | tr -s ' -' ' ')
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
)
|
||||
|
||||
cpulimit() (
|
||||
set -x
|
||||
min_cpu="${1}"
|
||||
shift
|
||||
max_cpu="${1}"
|
||||
shift
|
||||
|
||||
if [ -n "$CPUSET" ]; then
|
||||
cpuset -l "${min_cpu}-${max_cpu}" "$@" 2>&1
|
||||
elif [ -n "$NUMACTL" ]; then
|
||||
numactl --physcpubind="${min_cpu}-${max_cpu}" "$@" 2>&1
|
||||
elif [ -n "$TASKSET" ]; then
|
||||
taskset -c "${min_cpu}-${max_cpu}" "$@" 2>&1
|
||||
fi
|
||||
)
|
||||
|
||||
ret=0
|
||||
for cpu in $(cpulist); do
|
||||
n=$((n + 1))
|
||||
echo_i "testing that limiting CPU sets to 0-${cpu} works ($n)"
|
||||
cpulimit 0 "$cpu" "$NAMED" -g >named.run.$n 2>&1 || true
|
||||
ncpus=$(sed -ne 's/.*found \([0-9]*\) CPU.*\([0-9]*\) worker thread.*/\1/p' named.run.$n)
|
||||
[ "$ncpus" -eq "$((cpu + 1))" ] || ret=1
|
||||
done
|
||||
test "$ret" -eq 0 || echo_i "failed"
|
||||
status=$((status + ret))
|
||||
|
||||
echo_i "exit status: $status"
|
||||
[ $status -eq 0 ] || exit 1
|
||||
14
bin/tests/system/cpu/tests_sh_cpu.py
Normal file
14
bin/tests/system/cpu/tests_sh_cpu.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
|
||||
def test_cpu(run_tests_sh):
|
||||
run_tests_sh()
|
||||
Reference in New Issue
Block a user