Skip to content

Commit 082ed24

Browse files
committed
cpu: add e2e test for cstates
1 parent e1ab6fe commit 082ed24

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
config:
2+
agent:
3+
nodeResourceTopology: true
4+
allocatorTopologyBalancing: false
5+
availableResources:
6+
cpuset: 2-7,10-13 # policy must not touch C-states of unavailable CPUs
7+
reservedResources:
8+
cpu: 750m
9+
10+
pinCPU: true
11+
12+
idleCPUClass: default-class
13+
14+
balloonTypes:
15+
- name: lowlatency-bln
16+
cpuClass: lowlatency-class
17+
18+
control:
19+
cpu:
20+
classes:
21+
lowlatency-class:
22+
disabledCstates: [C4, C6, C8, C10]
23+
default-class:
24+
disabledCstates: []
25+
log:
26+
debug:
27+
- policy
28+
- cpu
29+
extraEnv:
30+
OVERRIDE_SYS_CSTATES: '''[{"cpus": "0-15", "names": ["C1E", "C2", "C4", "C8"], "files": {"disable": "0"}}]'''
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)