|
| 1 | +# Test balloons with certain CPU C-states disabled |
| 2 | + |
| 3 | +helm-terminate |
| 4 | +helm_config=$TEST_DIR/balloons-cstates.cfg helm-launch balloons |
| 5 | + |
| 6 | +# cpuids-of-container returns CPU ids a container is allowed to use, e.g. "1 2 4" |
| 7 | +cpuids-of() { |
| 8 | + local ctr=$1 # e.g. pod0c0 |
| 9 | + pyexec "for cpu in cpus['$ctr']: print(cpu.replace('cpu0',''))" |
| 10 | +} |
| 11 | + |
| 12 | +# verify-cstates checks the last writes to "disable" files in the |
| 13 | +# override fs. |
| 14 | +verify-cstates() { |
| 15 | + local cpu_ids=$1 # e.g. "1 2 4" |
| 16 | + local enabled_cstates=$2 # e.g. "C1E C2" |
| 17 | + local disabled_cstates=$3 # e.g. "C6 C8" |
| 18 | + local last_n_writes=$4 # expect the write within last N writes, e.g. 6 |
| 19 | + |
| 20 | + vm-command "kubectl -n kube-system logs ds/nri-resource-policy-balloons | nl | grep 'cstates override fs: wrote' | tail -n $last_n_writes" |
| 21 | + for cpu_id in $cpu_ids; do |
| 22 | + for cstate in $enabled_cstates; do |
| 23 | + echo "verify last write to cpu$cpu_id cstate=$cstate disable is 0" |
| 24 | + grep "cpu${cpu_id} cstate=$cstate disable=" <<< $COMMAND_OUTPUT | tail -n 1 | grep -q 'disable="0"' || { |
| 25 | + command-error "expected write 0 not found" |
| 26 | + } |
| 27 | + done |
| 28 | + for cstate in $disabled_cstates; do |
| 29 | + echo "verify last write to cpu$cpu_id cstate=$cstate disable is 1" |
| 30 | + grep "cpu${cpu_id} cstate=$cstate disable=" <<< $COMMAND_OUTPUT | tail -n 1 | grep -q 'disable="1"' || { |
| 31 | + command-error "expected write 1 not found" |
| 32 | + } |
| 33 | + done |
| 34 | + done |
| 35 | +} |
| 36 | + |
| 37 | +cleanup() { |
| 38 | + vm-command "kubectl delete pods --all --now" |
| 39 | +} |
| 40 | + |
| 41 | +CPUREQ="750m" MEMREQ="100M" CPULIM="750m" MEMLIM="" |
| 42 | +POD_ANNOTATION="balloon.balloons.resource-policy.nri.io: lowlatency-bln" CONTCOUNT=1 create balloons-busybox |
| 43 | +report allowed |
| 44 | +verify 'len(cpus["pod0c0"]) == 1' |
| 45 | +verify-cstates "$(cpuids-of pod0c0)" "C1E C2" "C4 C8" 4 |
| 46 | + |
| 47 | + |
| 48 | +CPUREQ="3" MEMREQ="100M" CPULIM="" MEMLIM="" |
| 49 | +POD_ANNOTATION="balloon.balloons.resource-policy.nri.io: lowlatency-bln" CONTCOUNT=1 create balloons-busybox |
| 50 | +report allowed |
| 51 | +verify 'cpus["pod0c0"] == cpus["pod1c0"]' \ |
| 52 | + 'len(cpus["pod0c0"]) == 4' |
| 53 | +verify-cstates "$(cpuids-of pod1c0)" "C1E C2" "C4 C8" 16 |
| 54 | + |
| 55 | +max_lowlatency_cpus=$(cpuids-of pod1c0) |
| 56 | + |
| 57 | +vm-command 'kubectl delete pod pod1' |
| 58 | +report allowed |
| 59 | +verify 'len(cpus["pod0c0"]) == 1' |
| 60 | + |
| 61 | +pod0cpus=" $(echo $(cpuids-of pod0c0) ) " |
| 62 | + |
| 63 | +echo "verify that C-states of freed CPUs are enabled again after balloon was deflated" |
| 64 | +freed_cpus="" |
| 65 | +for cpu_id in $max_lowlatency_cpus; do |
| 66 | + grep -q " $cpu_id " <<< $pod0cpus || freed_cpus+=" $cpu_id" |
| 67 | +done |
| 68 | +echo "verify that all C-states of freed CPUs $freed_cpus (= {$max_lowlatency_cpus} - {$pod0cpus}) are enabled again after balloon was deflated" |
| 69 | +verify-cstates "$freed_cpus" "C1E C2 C4 C8" "" 32 |
| 70 | + |
| 71 | +echo "verify that C-states of remaining CPUs $(cpuids-of pod0c0) are still configured for low-latency" |
| 72 | +verify-cstates "$(cpuids-of pod0c0)" "C1E C2" "C4 C8" 18 |
| 73 | + |
| 74 | +vm-command 'kubectl delete pod pod0' |
| 75 | +report allowed |
| 76 | + |
| 77 | +# verify that after all containers are gone, all C-states of all their CPUs are restored |
| 78 | +verify-cstates "$max_lowlatency_cpus" "C1E C2 C4 C8" "" 32 |
| 79 | + |
| 80 | +breakpoint |
| 81 | +exit 1 # FORCED FAIL |
0 commit comments