Skip to content

Instantly share code, notes, and snippets.

@yump
Created March 23, 2022 09:49
Show Gist options
  • Save yump/62b27daca9f6afff1be477c4734db96a to your computer and use it in GitHub Desktop.
Save yump/62b27daca9f6afff1be477c4734db96a to your computer and use it in GitHub Desktop.
Experiment to measure video playback power efficiency vs CPU frequency, with performance and schedutil governors
# freq performance_watt schedutil_watt
2000 19.31 18.38
2100 17.49 19.23
2200 18.47 18.70
2300 19.69 18.27
2400 19.89 18.53
2500 20.56 19.00
2600 19.01 18.35
2700 20.87 19.11
2800 21.05 18.85
2900 19.50 18.36
3000 20.85 19.74
3100 21.28 19.57
3200 19.69 19.16
3300 21.79 18.57
3400 22.29 19.16
3500 22.90 19.20
3600 23.53 19.24
3700 24.13 19.42
3800 23.11 18.77
3900 23.81 18.19
4000 25.27 18.52
4100 27.28 19.78
4200 28.17 19.32
#!/bin/bash
testvid="/tmp/vid/testvid.webm"
mhz_lo=2000
mhz_hi=4200
ncpu=$(grep -c processor /proc/cpuinfo)
measure_power () {
stress -q -c $ncpu -t 10 # preheat the die/IHS for 10 seconds
sudo turbostat \
--quiet --Summary --show PkgWatt --out "/tmp/turbostat.out" \
-- \
mpv \
--no-terminal --ao=null --fs \
--start=00:00:10 --length=60 "$testvid"
tail -n1 "/tmp/turbostat.out"
sudo rm "/tmp/turbostat.out"
}
collect () {
echo "please make sure screensaver is suspended"
sudo -v
# preheat the CPU heatsink for 2 minutes
sudo cpupower frequency-set -g performance -u 2000MHz
stress -c $ncpu -t 120
# clear old results
truncate --size 0 results.dat
# Test frequencies in random order
for mhz in $(seq "$mhz_lo" 100 "$mhz_hi" | shuf); do
sudo cpupower frequency-set -g schedutil -u "${mhz}MHz"
pow_schedutil="$(measure_power)"
sudo cpupower frequency-set -g performance -u "${mhz}MHz"
pow_performance="$(measure_power)"
printf "%s %s %s\n" "$mhz" "$pow_performance" "$pow_schedutil" \
>>"results.dat"
done
# put results in frequency order
sort -o "results.dat" "results.dat"
}
plot () {
gnuplot <<EOF
set terminal pngcairo size 800,600
set output "plot.png"
set xlabel "MHz"
set ylabel "Watts"
set autoscale x noextend
set xtics 200 rotate by -45 offset -1
plot "results.dat" using 1:2 with linespoints title "performance", \
"" using 1:3 with linespoints title "schedutil"
EOF
}
collect
plot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment