Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpufreqctl: avoid boosting when measuring pstate frequency #202

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a href="https://github.com/deinstapel/cpupower/releases">
<img alt="Lastest release" src="https://img.shields.io/github/v/release/deinstapel/cpupower?label=latest%20release&sort=semver">
</a>
<img alt="Gnome 42" src="https://img.shields.io/badge/gnome-42-blue?logo=gnome&logoColor=white">
<img alt="Gnome 43" src="https://img.shields.io/badge/gnome-43-blue?logo=gnome&logoColor=white">
<a href="https://github.com/deinstapel/cpupower/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/deinstapel/cpupower.svg">
</a>
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"localedir": "/usr/local/share/locale",
"shell-version": [
"3.28", "3.30", "3.36", "3.38", "40", "41", "42"
"3.28", "3.30", "3.36", "3.38", "40", "41", "42", "43"
],
"uuid": "cpupower@mko-sl.de",
"name": "CPU Power Manager",
Expand Down
7 changes: 6 additions & 1 deletion src/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ var CPUFreqIndicator = class CPUFreqIndicator extends baseindicator.CPUFreqBaseI
}

enable() {
this.power = Main.panel.statusArea["aggregateMenu"]._power;
if (parseFloat(Config.PACKAGE_VERSION.substring(0, 4)) >= 43) {
this.power = imports.ui.main.panel.statusArea.quickSettings._system._systemItem._powerToggle;
} else {
this.power = Main.panel.statusArea["aggregateMenu"]._power;
}

this.powerState = this.power._proxy.State;
this.powerConnectSignalId = this.power._proxy.connect(
"g-properties-changed",
Expand Down
88 changes: 30 additions & 58 deletions tool/cpufreqctl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

set -o errexit -o nounset
renice -n 19 0 >/dev/null

VERSION="10.1.2"
PRODUCTION=yes
Expand Down Expand Up @@ -93,6 +94,29 @@ not_supported ()
EXIT_CODE=9
}

# echo min/max/avg/rnd of a space-separated list of numbers
compute_min_max_avg_rnd ()
{
measures=($1)
nb_measures=${#measures[@]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈 this is bashism and may or may not work on distros like Alpine or Ubuntu (they use ash and dash). You can use shellcheck -a to lint against these things.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't tell me my sh is, in fact, bash....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is on Arch but that's not for granted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a symlink

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole sh vs. bash vs. dash compatibility thing is a deep rabbit hole. Yet another good reason to use GJS instead 🙈

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nooooo you're right! I'm correcting that right away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that easy. POSIX sh can't handle arrays...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to require bash... ? But yeah, I spent way to much time on it, GJS is the right way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, we can't require bash as this would rule out the whole Ubuntu land.

max=0
min=${measures[0]}
tot=0
for i in "${measures[@]}"; do
tot=$(($tot + $i))
if [ "$i" -gt "$max" ]; then
max=$i
fi
if [ "$i" -lt "$min" ]; then
min=$i
fi
done
avg=$(($tot/$nb_measures))
rnd_id=$(($RANDOM % $nb_measures))
rnd=${measures[$rnd_id]}
echo --min "${min}" --max "${max}" --avg "${avg}" --rnd "${rnd}"
}

fake_init ()
{
FAKE_DIR=/tmp/cpufreqctl-fake-backend
Expand Down Expand Up @@ -175,24 +199,8 @@ fake_info_frequencies ()
fake_info_current ()
{
fake_init

shuf -i 800000-3600000 -n 12 | sort -n | awk '
BEGIN {
srand()
}
NR == 1 {
printf "%d ", $1
}
{
sum += $1
r[NR] = $1
}
END {
printf "%d %.0f %d\n", $1, sum / NR, r[int(rand() * NR) + 1]
}' | while read -r min max avg rnd
do
report_info_current --min "${min}" --max "${max}" --avg "${avg}" --rnd "${rnd}"
done
measures=$(shuf -i 800000-3600000 -n 12)
report_info_current $(compute_min_max_avg_rnd "$measures")
}

intel_pstate_supported ()
Expand Down Expand Up @@ -276,26 +284,8 @@ intel_pstate_info_frequencies ()

intel_pstate_info_current ()
{
for scaling_cur_freq in /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq
do
cat "${scaling_cur_freq}" &
done | sort -n | awk '
BEGIN {
srand()
}
NR == 1 {
printf "%d ", $1
}
{
sum += $1
r[NR] = $1
}
END {
printf "%d %.0f %d\n", $1, sum / NR, r[int(rand() * NR) + 1]
}' | while read -r min max avg rnd
do
report_info_current --min "${min}" --max "${max}" --avg "${avg}" --rnd "${rnd}"
done
measures=$(cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)
report_info_current $(compute_min_max_avg_rnd "$measures")
}

cpufreq_supported ()
Expand Down Expand Up @@ -472,26 +462,8 @@ cpufreq_info_frequencies ()

cpufreq_info_current ()
{
for scaling_cur_freq in /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq
do
cat "${scaling_cur_freq}" &
done | sort -n | awk '
BEGIN {
srand()
}
NR == 1 {
printf "%d ", $1
}
{
sum += $1
r[NR] = $1
}
END {
printf "%d %.0f %d\n", $1, sum / NR, r[int(rand() * NR) + 1]
}' | while read -r min max avg rnd
do
report_info_current --min "${min}" --max "${max}" --avg "${avg}" --rnd "${rnd}"
done
measures=$(cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)
report_info_current $(compute_min_max_avg_rnd "$measures")
}

backend_select()
Expand Down