From 972ef98d660c3c2efba3d8aa7408126a1b555ff9 Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Mon, 8 Apr 2024 15:34:15 +0200 Subject: [PATCH] cpu-vm: check that automatic CPU balancing works https://github.com/canonical/lxd/pull/13257 Signed-off-by: Alexander Mikhalitsyn --- tests/cpu-vm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/cpu-vm b/tests/cpu-vm index d4bbce119..d1a63f67d 100755 --- a/tests/cpu-vm +++ b/tests/cpu-vm @@ -9,6 +9,12 @@ fi # Install LXD install_lxd +# required for "CPU auto pinning" feature check +# as we don't have a separate API extension for it +# and we rely on the debug output in the LXD daemon logs. +snap set lxd daemon.debug=true +systemctl restart snap.lxd.daemon.service + # Configure LXD lxc network create lxdbr0 lxc profile device add default eth0 nic network=lxdbr0 @@ -66,6 +72,25 @@ done lxc config set v1 limits.cpu="${cpuCount}" [ "$(lxc exec v1 -- ls /sys/devices/system/cpu | grep -Ec 'cpu[[:digit:]]+')" -eq "${cpuCount}" ] +# check that CPU affinity is automatically set if feature present +QEMU_PID=$(lxc info v1 | awk '/^PID:/ {print $2}') +if journalctl --quiet --no-hostname --no-pager --boot=0 --unit=snap.lxd.daemon.service | grep "Scheduler: virtual-machine"; then + # Check that there are processes with pinning set + # It will be shown like this: + # pid 2894's current affinity list: 6 + # pid 2895's current affinity list: 8 + # pid 2897's current affinity list: 0-15 + # pid 2898's current affinity list: 0-15 + # pid 2899's current affinity list: 0-15 + # 2894 and 2895 have affinity set, while others don't + PINNED_VCPU_NUM=$(taskset --cpu-list -a -p "${QEMU_PID}" | grep -E ':\s+[0-9]+$' | wc -l) + [ "${PINNED_VCPU_NUM}" = "$(lxc config get v1 limits.cpu)" ] +else + # check that there is no pinning set + ! taskset --cpu-list -a -p "${QEMU_PID}" | grep -E ':\s+[0-9]+$' + taskset --cpu-list -a -p "${QEMU_PID}" | grep "0-$((cpuCount-1))" +fi + # Unset CPU limit lxc config unset v1 limits.cpu