|
| 1 | +# Prepare virtual machine before installing balloons. |
| 2 | +min_kernel_version=6.14 |
| 3 | +vm-command "uname -r" |
| 4 | +if [ "$( ( echo $min_kernel_version; echo $COMMAND_OUTPUT ) | sort --version-sort | tail -n 1 )" == "$min_kernel_version" ]; then |
| 5 | + error "quest OS runs too old kernel, hot-plugged CPU node topology may not work. Required: $min_kernel_version" |
| 6 | +fi |
| 7 | + |
| 8 | +# Hot-plug CPUs. |
| 9 | +vm-command 'grep 511,1535,4095 /sys/devices/system/cpu/enabled' || { |
| 10 | + vm-cpu-hotplug 0 511 0 |
| 11 | + vm-cpu-hotplug 2 511 0 |
| 12 | + vm-cpu-hotplug 7 511 0 |
| 13 | + |
| 14 | + # Wait for the kernel to expose all hot-plugged CPUs in sysfs. |
| 15 | + vm-run-until '[ -d /sys/devices/system/cpu/cpu511 ] && [ -d /sys/devices/system/cpu/cpu1535 ] && [ -d /sys/devices/system/cpu/cpu4095 ]' |
| 16 | + |
| 17 | + # Online all CPUs. |
| 18 | + vm-command 'for cpuX in /sys/devices/system/cpu/cpu[1-9]*; do |
| 19 | + echo onlining $cpuX |
| 20 | + ( echo 1 > $cpuX/online && echo Successful: write 1 to $cpuX/online ) || echo Failed: write 1 to $cpuX/online |
| 21 | + done |
| 22 | + grep . /sys/devices/system/cpu/cpu[1-9]*/online' |
| 23 | + |
| 24 | + # Restart kubelet to let it detect new enabled CPUs. |
| 25 | + vm-command "systemctl restart kubelet" |
| 26 | +} |
| 27 | + |
| 28 | +# Wait until kubelet has reported all enabled CPUs in node capacity. |
| 29 | +vm-run-until 'kubectl get node -o jsonpath="{.items[0].status.capacity.cpu}" | grep 6' || |
| 30 | + command-error "Unexpected node CPU capacity" |
| 31 | + |
| 32 | +# Make sure that k8s root cpuset.cpus contains hot-plugged CPUs. |
| 33 | +# containerd: kubepods/cpuset.cpus |
| 34 | +# cri-o: kubepods.slice/cpuset.cpus |
| 35 | +vm-command "grep . /sys/fs/cgroup/kubepods*/cpuset.cpus" |
| 36 | +if ! ( grep -q 511 <<< $COMMAND_OUTPUT && |
| 37 | + grep -q 1535 <<< $COMMAND_OUTPUT && |
| 38 | + grep -q 4095 <<< $COMMAND_OUTPUT ); then |
| 39 | + command-error "kubepods cpuset.cpus does not include expected CPUs" |
| 40 | +fi |
| 41 | + |
| 42 | +# Install topology-aware |
| 43 | +helm-terminate |
| 44 | +helm_config=$(COLOCATE_PODS=true instantiate helm-config.yaml) helm-launch topology-aware |
| 45 | + |
| 46 | +# socket #0 CPUs: 0,1,2,511 |
| 47 | +# socket #2 CPUs: 1535, cpuallocator takes this for reserved as it is a complete idle package |
| 48 | +# socket #7 CPUs: 4095 |
| 49 | + |
| 50 | +# 5-CPU allocation must include at least one CPU id>1024. |
| 51 | +CPU=5000m create guaranteed || { |
| 52 | + error "failed to create pod, possible cause: topology-aware not consuming all CPUs" |
| 53 | +} |
| 54 | + |
| 55 | +report allowed |
| 56 | +if pp 'cpus["pod0c0"]' | grep 4095; then |
| 57 | + verify 'len(cpus["pod0c0"]) == 5' |
| 58 | +else |
| 59 | + vm-command 'grep . /sys/fs/cgroup/$(grep . /proc/$(pgrep -f "echo pod0c0")/cgroup | awk -F::/ "{print \$2}")/cpuset.cpus.effective' |
| 60 | + if grep 4095 <<< "$COMMAND_OUTPUT"; then |
| 61 | + echo "RUNC BUG: pod0c0 cannot run on CPU 4095 yet the CPU is in cgroup cpuset.cpus.effective. See: https://github.com/opencontainers/runc/issues/5023" |
| 62 | + echo "Test verdict: SKIP (buggy runc)" |
| 63 | + exit 0 |
| 64 | + else |
| 65 | + error "expected: pod0c0 is allowed to run on CPU 4095" |
| 66 | + fi |
| 67 | +fi |
| 68 | + |
| 69 | +# Release all 5 CPUs. |
| 70 | +vm-command 'kubectl delete pod pod0 --now' |
| 71 | +vm-run-until '! kubectl get pod pod0' |
| 72 | + |
| 73 | +# Only socket #0 has enough CPUs for pod1. |
| 74 | +CONTCOUNT=1 CPUREQ=3100m CPULIM=4000m create burstable |
| 75 | +report allowed |
| 76 | +verify 'len(packages["pod1c0"]) == 1 and len(cpus["pod1c0"]) == 4' |
| 77 | + |
| 78 | +CONTCOUNT=1 CPUREQ=900m CPULIM=1 create burstable |
| 79 | +report allowed |
| 80 | +verify 'cpus["pod2c0"] == {"cpu4095"}' |
| 81 | + |
| 82 | +CONTCOUNT=1 create besteffort |
| 83 | +report allowed |
| 84 | + |
| 85 | +vm-command 'kubectl delete pods pod1 pod2 pod3 --now' |
| 86 | + |
| 87 | +# Verify no CPU leaks, allocate all again. |
| 88 | +CPU=5000m create guaranteed |
| 89 | +report allowed |
| 90 | +verify 'len(cpus["pod4c0"]) == 5' |
| 91 | + |
| 92 | +vm-command 'kubectl delete pods --all --now' |
0 commit comments