AdnanHodzic / AdnanHodzic/auto-cpufreq

Performance of the scripts/cpufreqctl.sh script

未关闭
#588 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
7.8k
派生
357
平均合并
3 天 8 小时
30 天内合并 PR
14

描述

I don't have an issue running auto-cpufreq, I just wanted to share some information with benchmarks and script modification example.

When fiddling with auto-cpufreq, powertop and auditd to locate processes that wake the cpu up, ironically auto-cpufreq stands out on an otherwise completely idle system. Due to heavy usage of "expr" and "cat" the script functions run for a long time, and due to the nature of auto-cpufreq these functions are run periodically.

I made a proof of concept rewrite of scripts/cpufreqctl.sh/get_governor(), and these are the hyperfine benchmark results:

```
~ 6s ❯ hyperfine './get_governor_old.sh' './get_governor_new.sh'
Benchmark 1: ./get_governor_old.sh
Time (mean ± σ): 12.8 ms ± 0.5 ms [User: 10.2 ms, System: 2.1 ms]
Range (min … max): 11.2 ms … 14.3 ms 226 runs

Benchmark 2: ./get_governor_new.sh
Time (mean ± σ): 0.7 ms ± 0.2 ms [User: 0.6 ms, System: 0.1 ms]
Range (min … max): 0.5 ms … 1.8 ms 2653 runs

Summary
./get_governor_new.sh ran
18.06 ± 4.08 times faster than ./get_governor_old.sh
~ ❯
```

Basically what this says it that on my system (Ubuntu 23.10, ThinkPad X1) just calling the original get_governor() takes 12ms and the new one takes 1ms.

**The cpus are now working a lot less! Sleeping a lot more!**

This is also confirmed just by running them (and we can see they have the same output):

```
~ ❯ time ./get_governor_old.sh
performance performance performance performance performance performance performance performance performance performance performance performance
./get_governor_old.sh 0,01s user 0,00s system 95% cpu 0,015 total

~ ❯ time ./get_governor_new.sh
performance performance performance performance performance performance performance performance performance performance performance performance
./get_governor_new.sh 0,00s user 0,00s system 85% cpu 0,001 total
~ ❯
```

15ms vs 1ms.

Old vs New implementation:

```
~ ❯ cat get_governor_old.sh
#!/bin/bash

function get_governor () {
if [ -z $CORE ]
then
i=0
ag=''
while [ $i -ne $cpucount ]
do
if [ $i = 0 ]
then
ag=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
else
ag=$ag' '`cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor`
fi
i=`expr $i + 1`
done
echo $ag
else
cat /sys/devices/system/cpu/cpu$CORE/cpufreq/scaling_governor
fi
}

get_governor

~ ❯ cat get_governor_new.sh
#!/bin/bash
function get_governor() {
if [ -z "$CORE" ]; then
ag=''
for ((i=0; i

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。