[How-to] Changing default CPU governor.
-
I will show how to change CPU governor in UT phone. Only tested with my N5, so your experience may vary. Phone is using interactive governor by default. I changed it to conservative. Conservative governor handles frequency a bit different way comparing to interactive governor.
It helped to keep my phone more cool and it seems to be more battery friendly at least in my use case.Connect to your UT phone with cable or ssh.
Check current governor
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor interactive
You can check how your current governor handles CPU frequency (leave it running on computer terminal and start using your phone, you should see frequency is changing)
$ watch cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
Change governor like this.
$ sudo su $ echo conservative > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor $ exit
Check new setting.
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor conservative
If you now run that "watch cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq" command again, you should see different cpu speed behavior.
Conservative- governor has few paraneters which you can adjust.
Kernel docs tells following story..2.5 Conservative
The CPUfreq governor "conservative", much like the "ondemand" governor, sets the CPU depending on the current usage. It differs in behaviour in that it gracefully increases and decreases the CPU speed rather than jumping to max speed the moment there is any load on the CPU. This behaviour more suitable in a battery powered environment.
The governor is tweaked in the same manner as the "ondemand" governor through sysfs with the addition of:
freq_step: this describes what percentage steps the cpu freq should be increased and decreased smoothly by. By default the cpu frequency will increase in 5% chunks of your maximum cpu frequency. You can change this value to anywhere between 0 and 100 where '0' will effectively lock your CPU at a speed regardless of its load whilst '100' will, in theory, make it behave identically to the "ondemand" governor.
down_threshold: same as the 'up_threshold' found for the "ondemand" governor but for the opposite direction. For example when set to its default value of '20' it means that if the CPU usage needs to be below 20% between samples to have the frequency decreased.
sampling_down_factor: similar functionality as in "ondemand" governor. But in "conservative", it controls the rate at which the kernel makes a decision on when to decrease the frequency while running in any speed. Load for frequency increase is still evaluated every sampling rate.I only tweaked these two.. 20 and 80 are the default values.
$ cat /sys/devices/system/cpu/cpufreq/conservative/down_threshold 20 $ cat /sys/devices/system/cpu/cpufreq/conservative/down_threshold 80
How to change. I change values to 40 and 90. You can use your own values which suits better for you.
$ sudo su $ echo 40 > /sys/devices/system/cpu/cpufreq/conservative/down_threshold $ echo 90 > /sys/devices/system/cpu/cpufreq/conservative/up_threshold $ exit
If you check once again how governor handles cpu speed, it should be different now.
These settings aren't permanent, so after reboot all of these are defaults again. I made simple script which I run after every reboot so I don't have to write all commands again and again. I reboot my phone about once in a two weeks so I don't have to do it very often.
$ mkdir .scripts $ cd .scripts $ nano governor.sh
#!/bin/sh sudo su <<EOF echo conservative > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor echo 40 > /sys/devices/system/cpu/cpufreq/conservative/down_threshold echo 90 > /sys/devices/system/cpu/cpufreq/conservative/up_threshold EOF exit 0
Save and exit.
Set execution permission.
$ chmod 755 governor.sh
You can run it from phone by opening terminal and write ./.scripts/governor.sh
It would be cool if we could change these settings straight from setting menu. Of course different phones may need different settings..
-
@hendrixxx said in [How-to] Changing default CPU governor.:
/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ...
My BQ E4.5 says:
phablet@ubuntu-phablet-bq:~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
hotplug -
@guru said in [How-to] Changing default CPU governor.:
@hendrixxx said in [How-to] Changing default CPU governor.:
/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ...
My BQ E4.5 says:
phablet@ubuntu-phablet-bq:~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
hotplugOh, so there is differences between devices. Never heard of hotplug governor before, but this explain what it is..
Hotplug Governor:
The Hotplug governor performs very similarly to the OnDemand governor, with the added benefit of being more precise about how it steps down through the kernel's frequency table as the governor measures the user's CPU load. However, the Hotplug governor's defining feature is its ability to turn unused CPU cores off during periods of low CPU utilization. This is known as "hotplugging."Seems like cool feature if it really works like that.
"scaling_available_governors" shows which are available in kernel.
-
@hendrixxx said in [How-to] Changing default CPU governor.:
It would be cool if we could change these settings straight from setting menu.
Yeah, it would be very cool. I think reporting an issue on github will help developer as may they forgot by only reading here... if you want I can report the issue for you, if you prefer...
-
I was very happy to find this post. I have been looking for ways to reduce battery usage on my Meizu Pro 5. So I was eager to try the things mentioned here.
Sadly:$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors interactive
So only
interactive
is available on my kernel.But nonetheless, thank you very much for the post. It serves to remind us that there is a real Linux kernel underneath the lovely UTouch interface.
-
@mymike feel free to report github issue if you want. Thanks!
-
@arubislander said in [How-to] Changing default CPU governor.:
I was very happy to find this post. I have been looking for ways to reduce battery usage on my Meizu Pro 5. So I was eager to try the things mentioned here.
Sadly:$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors interactive
So only
interactive
is available on my kernel.But nonetheless, thank you very much for the post. It serves to remind us that there is a real Linux kernel underneath the lovely UTouch interface.
Thanks! I am not developer but I like to tweak Linux everywhere possible. Just trying different things all to time..
I think it should be possible to add conservative governor in M5pro kernel just by enabling it and compile. I will check today what gov options my N4 has. -
When I try
echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
it says "bash: echo: write error: Invalid argument".I'm on turbo, vivid. Could anyone help me with this?
-
@mihael what does "$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors" says?
Do you have conservative option listed?
-
@arubislander Same on the mx4 interactive only if thats of any help to anyone.
-
Just for info.
On BQ E4.5 available governors are:
-userspace
-powersave
-hotplug (default)
-performanceI allso found a thread explaining governors on xda-developers:
https://forum.xda-developers.com/showthread.php?t=1736168 -
@HendriXXX I have interactive:
phablet@ubuntu-phablet:~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors interactive interactive interactive interactive
I tried with powersave and I get the same result:
root@ubuntu-phablet:/home/phablet# echo powersave > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor bash: echo: write error: Invalid argument
-
@mihael Ok. For some reason other governors aren't compiled in to the kernel then.
I just checked my N4 and it has all governor options in kernel.