Skip to content

Commit

Permalink
cpu-vm: check that automatic CPU balancing works
Browse files Browse the repository at this point in the history
canonical/lxd#13257

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
  • Loading branch information
mihalicyn committed Apr 8, 2024
1 parent 2894669 commit 66116ae
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/cpu-vm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ fi
# Install LXD
install_lxd

# required for CPU auto pinning feature check
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
Expand Down Expand Up @@ -66,6 +70,21 @@ 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
if journalctl --quiet --no-hostname --no-pager --boot=0 --unit=snap.lxd.daemon.service | grep "Scheduler: virtual-machine"; then
QEMU_PID=$(lxc info v1 | grep PID | grep -o -E "([0-9]+)")

# 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
taskset --cpu-list -a -p "${QEMU_PID}" | grep -v "0-$((cpuCount-1))"
fi

# Unset CPU limit
lxc config unset v1 limits.cpu

Expand Down

0 comments on commit 66116ae

Please sign in to comment.