4

I have been fiddling with power management and I can't find a way to make the changes I want persistent. For example, I have set the maximum cpu frequency with this command:

sudo cpupower frequency-set --max 2GHz

but the value goes back to its original value on every reboot. Is there a standard way to make this change persistent? I have read about kernel modules but I don't know how they work... can anyone help me?

Note. My machine is running Ubuntu 20.04.

2 Answers 2

1

The Arch Wiki page on CPU frequency scaling suggests a couple of different ways to make changes performed in cpupower persistent.

  • One of those, as you mentioned, is adding a kernel module. But there are other simpler options that should be easier. The simpler is just to enable cpufreq's systemd service, as suggested in the Arch Wiki. Just run

sudo systemctl enable cpupower

and the service will be started every time you boot up the machine. I am not running in a machine with systemd right now, so I cannot perform any tests.

  • The second option is to add a udev rule. I've tested this one right now and it works perfectly. Just edit the file named /etc/udev/rules.d/50-scaling-governor.rules or similar (create it if it does not exist) and add the following content to it:

SUBSYSTEM=="module", ACTION=="add", KERNEL=="acpi_cpufreq", RUN+="/bin/sh -c 'echo 2000000 | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'"

This will change the maximum frequency of CPU0 to the value written. In your case, 2000000, or 2.0 GHz. To do the same for every CPU in your machine, just change the previous command to

SUBSYSTEM=="module", ACTION=="add", KERNEL=="acpi_cpufreq", RUN+="/bin/sh -c 'echo 2000000 | tee /sys/devices/system/cpu/cpu*[0-9]/cpufreq/scaling_max_freq'"

and this will change the maximum frequency for every CPU in your system.

1
# cat<<EOF > /etc/systemd/system/cpupower.service 
[Unit]
Description=CPU powersave
[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower -c all frequency-set --governor powersave  -d 400MHz -u 1000MHz
[Install]
WantedBy=multi-user.target


# systemctl daemon-reload
# systemcl enable cpupower

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .