Patch webOS CPU Frequency or Voltage Scaling

From WebOS Internals
Revision as of 15:29, 20 July 2009 by Hopspitfire (talk | contribs) (New page: = Overview= There are currently 2 methods to enable further power saving - neither is perfect. Note that '''these 2 methods CANNOT be used together''' so make sure you try only one solutio...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

There are currently 2 methods to enable further power saving - neither is perfect. Note that these 2 methods CANNOT be used together so make sure you try only one solution at a time. Using both has been reported to brick your Pre, requiring a visit to the WebOS Doctor. Patches for these are now available in the gitorious repo. See Applying Patches

1 CPU Scaling

  • This allows the Pre to scale the CPU clock speed up and down in response to changes in CPU utilization. Some people have reported glitching when using scaling when the CPU is under heavy load (lots of multitasking, playing video, etc).

2 SmartReflex

  • This allows the Pre to vary the voltage inside the core in response to silicon characteristics, temperature, voltage, etc. This does not save that much power because it is supposed to be used along with CPU scaling to reduce voltage when the CPU is running slower, but the Pre's kernel is missing the modules to do this. This is why using both together will freeze the Palm Pre. (Remove the battery, restart with the USB plugged into your computer with NovaCom installed, During the phones boot procedure simply telnet to the phone through NovaCom's Proxy port 8023, remove the smartreflex files you installed in the events folder in /etc/ before WebOS panics)

CPU Scaling

Default Setting

Frequency scaling does not appear to be active by default on the Pre by default. The directory /sys/devices/system/cpu/cpu0/cpufreq contains information on the current state. The clock seems to be fixed at 500mHz for normal operation (according to cpuinfo_cur_freq), however several other frequencies exist:

root@castle:/sys/devices/system/cpu/cpu0/cpufreq# cat ./scaling_available_frequencies 
600000 550000 500000 250000 125000 

The file /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state shows that at some point (probably during startup) the frequency is raised to 550mHz for a short period of time.


Enabling Scaling

It is possible to enable frequency scaling using the 'ondemand' governor:

root@castle:/sys/devices/system/cpu/cpu0/cpufreq# echo ondemand > ./scaling_governor 

this will cause the frequency to be reduced automatically while idle, and increased as needed during operation, potentially increasing battery life. Because higher frequencies may cause overheating, and TI has noted a significant decrease in the life of the processor when running above 500mHz, you should also restrict the frequency scaling to 500mHz and below by doing the following:

root@castle:/sys/devices/system/cpu/cpu0/cpufreq# echo 500000 > ./scaling_max_freq

If your Pre seems sluggish after enabling scaling, you can try changing the values in /sys/devices/system/cpu/cpu0/cpufreq/ondemand as detailed below.


'ondemand' Configuration

Increasing the value of 'scaling_min_freq' will prevent the CPU from going into extremely low speed configurations, which will significantly improve the responsiveness of the device when it first detects increased CPU usage, at the cost of a little bit of battery life.

root@castle:/sys/devices/system/cpu/cpu0/cpufreq# echo 250000 > ./scaling_min_freq

Setting the value of 'up_threshold' lower will cause the frequency to be increased at lower levels of activity.

root@castle:/sys/devices/system/cpu/cpu0/cpufreq/ondemand# echo 30 > ./up_threshold

Note: The default setting for 'up_threshold' is 80.


Checking Performance and Stats

To check how long your Pre has been running and at what frequency, do this:

cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state

You will see something like this:

600000 906
550000 768
500000 380
250000 0
125000 180505

The first number is the CPU frequecy, the second is a time interval. In this example, my Pre has spent the most time @ 125mHz, but you can see it shoots up when needed. Note that if you are overclocking, it really doesn't spend much time at 600mHz, so overheating shouldn't be a problem, but you will definitely notice an improvement. These stats are reset after a reboot.


Overclocking

Overclocking is not recommended, as TI has reported a significant decrease in the life of the CPU at frequencies about 500mHz. However some users have reported better responsiveness, in addition to running cooler and using less battery while overclocking.

To overclock to the CPU's maximum speed, do:

echo "600000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

To put it back, do:

echo "500000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq


Making your changes stick after a reboot

Create a file called cpu-scaling in /etc/event.d and put this code in it, then reboot.

# Enables cpu scaling

start on stopped finish
stop on runlevel [!2]

console none

script
    echo "500000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
    echo "250000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
    echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    echo "30" > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
end script


Return to Stock Fixed Frequency

The simple way is just to remove the cpu-scaling script from /etc/event.d (if you created it) and reboot. None of these changes are persistent without the "sticky" script shown above.

If you switch back to the 'userspace' governor without rebooting, your frequency could get stuck at a lower setting and the whole system get really bogged down. Here is a quick shell script to help you revert to userspace with the original frequency:

Copy/paste this whole line as one command:

echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ; echo 500000 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 

Then confirm the frequency/governor are back the way you want.


Comments and Caveats

  • "I tried this out but video playback was flickery and horrible. The up_threshold tweak setting to 30 seems to improve it a lot , but it's still flickery a bit. Some people may not be happy."
  • "I found that setting the max freq to 600000 with the threshold helps this problem. See relevant warnings above first! I don't really watch video on my Pre, so it's not so big of a deal." -pEEf
  • "A lot of people on the Precentral forums (myself included) are experiencing the phone locking up after a while of using this, and need to pull the battery to reset. (On webOS 1.0.3 at least.)"
  • "I've been running my phone with scaling for nearly a week now without problems, but I'm not 'overlcocking' so to speak. Any specifics on what might cause the locks? (ok had my first locks tonight while attached to the touchstone, weird it never happened before now (and annoying))" -retry


SmartReflex

Enable SmartReflex

SmartReflex can be enabled in the VDD1 and VDD2 areas of the OMAP processor by setting two flags under /sys/power

root@castle:/sys/power# echo -n 1 > ./sr_vdd1_autocomp
root@castle:/sys/power# echo -n 1 > ./sr_vdd2_autocomp

This slide deck has much of the pertinent information about SmartReflex and other power-saving technologies on the OMAP processor. Unfortunately the kernel modules that provide many of the features mentioned in the slide deck are not present on the Pre. This is the main reason that SmartReflex may not save a terribly large amount of power.


Making your changes stick after a reboot

To enable SmartReflex, create a file called smartreflex in /etc/event.d and put this code in it, then reboot.

# -*- mode: shell-script; -*-
description "SmartReflex"
author "Alex Markson"
version 1.0

start on stopped finish
stop on runlevel [!2]

console none

script

# SmartReflex
# "SmartReflex™ driver allows for auto-compensation of VDD1 and
# VDD2 voltages (around the voltages specified by current OPP)
# by analyzing the silicon characteristics, temperature, voltage etc"
# 
# Enable SmartReflex
echo -n 1 > /sys/power/sr_vdd1_autocomp
echo -n 1 > /sys/power/sr_vdd2_autocomp

end script

If you want to enable overclocking in addition to SmartReflex, add the following JUST BEFORE the end script line:

# according to the OEM shell script in /etc/miniboot.sh
# this seems like it needs to be set twice to make sure ?
echo 600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
echo 600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed


Comments and Caveats

  • "After updating to 1.0.4 my pre would lock up and get really hot using the ONDEMAND cpu scaling method and with smartflex everything running great and battery seems even better than ondemand." -seekis
  • "AFter using this for about a week, I find that using SmartReflex causes the Pre to stutter every so often"


Credits

  • Alex Markson for the SmartReflex find and the script.
  • pEEf for numerous discoveries related to cpu scaling.
  • sidamos for the info about 'up_threshold'
  • garrettwp for the cpu scaling event.d script.
  • Jauder Ho for gitorious patches

Hacking

There is still a lot of work to be done in making this work optimally. The following are some resources and thoughts.