Tasker : Scale Up/Down CPU Speed at Different Times
http://techsplurge.com/4926/android-awesome-15-tasker-profiles-tutorials/
Yeah I know, there’s SetCPU app for under/over clocking CPU but it cannot be used to scale up or down when specific apps are launched or during a certain time period. So here’s how this can be achieved with Tasker. This is a very advanced profile and relatively long as well.
- You’ll need 2 apps for this profile: Locale Execute plug-in (free) and a terminal editor such as theAndroid Terminal Emulator. Download them from the link given and install ‘em.
- Download this script and save it to your sdcard.
- Open up the terminal editor and type these lines:
su mkdir /data/local/bin mv /sdcard/setcpu.sh /data/local/bin/setcpu chmod 755 /data/local/bin/setcpu
script :
#!/system/bin/sh # setcpu, a set cpu script written for custom Android Roms by clvv <[email protected]> # Usage: setcpu [MINFREQ MAXFREQ GOVERNOR] # setcpu -h, --help #print this message # setcpu -s, --status #print CPU status # If no parameter is specified, an interactive setup guide will start. # NOTE: This script MUST be run as root in order to make configuration change! # Tips: run 'watch -n1 setcpu -s' to watch CPU status, refresh every second. # Happy overclocking! :) # Script written by clvv <[email protected]> if [ $# -eq 0 ]; then freqs=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies) echo "NOTE: This script MUST be run as root in order to make configuration change!" echo -n "Current CPU min_freq: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq echo -n "Current CPU max_freq: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo -n "Current CPU governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo -n "Current CPU frequency: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq echo "Available CPU frequencies: $freqs" echo -n "Please enter a desired CPU min_freq: " read min if [ $min ]; then if [ $(echo $freqs | grep -q -E " $min |^$min | $min$"; echo $?) -eq 0 ]; then echo $min > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq && echo "Done" else echo "Please enter a valid value of CPU min_freq!" 1>&2 fi fi unset min echo -n "Please enter a desired CPU max_freq: " read max if [ $max ]; then if [ $(echo $freqs | grep -q -E " $max |^$max | $max$"; echo $?) -eq 0 ]; then echo $max > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq && echo "Done" else echo "Please enter a valid value of CPU max_freq!" 1>&2 fi fi unset max unset freqs gvnrs=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors) echo "Available CPU governors: $gvnrs" echo -n "Please enter a desired type of CPU governor: " read gvnr if [ $gvnr ]; then if [ $(echo $gvnrs | grep -q -E " $gvnr |^$gvnr | $gvnr$"; echo $?) -eq 0 ]; then echo $gvnr > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor && echo "Done" else echo "Please enter a valid type of CPU governor!" 1>&2 fi fi unset gvnr unset gvnrs elif [[ "$1" = '-h' -o "$1" = '--help' ]]; then echo "Usage: setcpu [MINFREQ MAXFREQ GOVERNOR]" echo " setcpu -h, --help #print this message" echo " setcpu -s, --status #print CPU status" echo "If no parameter is specified, an interactive setup guide will start." echo "NOTE: This script MUST be run as root in order to make configuration change!" echo "Tips: run 'watch -n1 setcpu -s' to watch CPU status, refresh every second." echo -n "Your available CPU frequencies are:" cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies echo "Happy overclocking! :)" echo "Script written by clvv <[email protected]>" elif [[ "$1" = '-s' -o "$1" = '--status' ]]; then echo -n "Available CPU frequencies:"; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies echo -n "Current CPU min_freq: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq echo -n "Current CPU max_freq: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq echo -n "Current CPU governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo -n "Current CPU frequency: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq else freqs=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies) if [ $1 ]; then if [ $(echo $freqs | grep -q -E " $1 |^$1 | $1$"; echo $?) -eq 0 ]; then echo $1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq else echo "Please use a valid value of CPU min_freq!" 1>&2 fi fi if [ $2 ]; then if [ $(echo $freqs | grep -q -E " $2 |^$2 | $2$"; echo $?) -eq 0 ]; then echo $2 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq else echo "Please use a valid value of CPU max_freq!" 1>&2 fi fi unset freqs if [ $3 ]; then if [ $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors | grep -q -E " $3 |^$3 | $3$"; echo $?) -eq 0 ]; then echo $3 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor else echo "Please use a valid type of CPU governor!" 1>&2 fi fi fi
Now, Create multiple profiles, categorized like:
- Display off: “CPU LOW” (Context: Event –> Display –> Display Off)
- Playing a game: “CPU HIGH” (Context: Application)
- Battery > 50%: “CPU MED” (Context: State –> Battery Level)
Then, in each of them, execute the Locale Execute plugin the script in the following format:
/data/local/bin/setcpu <min> <max> <scaling type>
e.g.: “setcpu 200000 800000 ondemand” will set my cpu speed to 200Mhz at minimum and 800Mhz at most with the scaling type as “ondemand”. In most of the kernels, “ondemand” and “performance” are available as the scaling governor.
ondemand – When the CPU load reaches a certain point, ondemand will rapidly scale the CPU up to meet demand, then gradually scale the CPU down when it isn’t needed.
performance – It will keep the CPU running at the “max” set value at all times for best performance.
SetCPU Step by Step Instructions
I fould this online and thought it may come in handy for some people ...
SetCPU for Root Users
SetCPU for Root Users allows you to manage the CPU frequency settings of your Android device. It works with most commercial Android devices that have root access enabled for applications. Combined with custom profiles, SetCPU can help you manage your CPU settings to optimize performance and battery life. On many phones, oftentimes with the help of custom kernels, SetCPU can also manage overclocking on your device. SetCPU is currently available on the Android Market and the SlideME Market.
SetCPU works on most devices running Android 1.5 to Android 2.2, with Android 1.6 and above recommended. If you have an HTC device, you may need to disable perflock (see 10) depending on your kernel.
1. Benefits
The CPU drains more power if it is running at a higher frequency. If the processor is running faster, the phone will be faster and more responsive, but the battery may drain more quickly. If the processor is running more slowly, the phone will be less responsive and take longer to complete tasks, but battery life will be increased. With SetCPU, you can set up profiles to manage the CPU speed based on certain conditions.
2. Main Tab and Basic Usage
To get started with SetCPU, start the app, read the introduction, and pick "autodetect frequencies." If you ever need to access this screen again, press the Menu button in SetCPU's Main tab, then choose Device Selection.
If your kernel doesn't support autodetect, you won't see it choose the device that best matches your phone from the list. After you've passed the introduction screen, you may get a request from Superuser Permissions. Depending on your version of Superuser Permissions, either check the box for "remember" and press "allow" or press the "always allow" button.
The sliders here allow you to manually control the CPU scaling bounds. The CPU frequency will always be between these two values. By default, the CPU should scale between the max and min frequencies based on need. The sliders also control the "main" profile as explained later.
The "scaling" drop-down list is an advanced feature that allows you to control the behavior of the CPU scaling mechanism. See explanations for the different governors in the CPU Scaling Governors section.
SetCPU also includes a widget for your home screen. Add SetCPU's widget like you would any other widget: long press on your home screen, select Widgets, and select the SetCPU widget. A screen will pop up so you can configure the widget's appearance. If you would like it to show current CPU speed, set the Active Refresh Interval to something other than "Passive," though a passive refresh interval is recommended to save battery.
HTC device users: If the green "current" display doesn't change as you change the sliders, you may be using an incompatible HTC kernel with a driver called "perflock" that prevents SetCPU from changing frequencies. To enable SetCPU, press the "Menu" button in SetCPU's main tab and select "disable perflock." Read through the notice and then press the button in the dialog. If successful, you should be able to change the frequency with SetCPU. If this process fails, please e-mail the developer with your kernel version and device so support can be added. For more details, see the perflock section below.
3. Profiles
Profiles allow you to configure SetCPU to set your CPU speed under certain conditions. This is useful to manage battery savings. To get started with profiles, check the "Enable" button in the Profiles tab and press "Add Profile" to add your first profile.
Your profile settings will be triggered if the condition you set in the profile is met. For example, if you choose "Screen Off," the profile settings will be set when the screen is off. If no profiles are met, SetCPU reverts to the default profile specified in the Main tab. Several conditions are available:
- Charging/Full - Set when the phone is charging from any source and when the battery is full while charging.
- Charging AC/Full - Set only when the phone is charging from a wall plug (AC adapter) and when the battery is full while charging from a wall plug.
- Charging USB/Full - Set only when the phone is charging from a computer (USB port) and when the battery is full while charging from the USB port.
- Screen Off - Set when the phone's screen is turned off.
- Battery < - Set when the battery falls below a certain point. You will also be able to specifiy battery level for this profile.
- Temp > - Set when the battery or system temperature rises above a certain point. SetCPU will notify you with a ringtone notification if you check the "Audible Warning" checkbox here. You will also be able to specify a temperature for this profile.
- CPU Temp > - Limited to phones whose hardware and kernels support it. Set when the CPU temperature rises above a certain point. SetCPU will notify you with a ringtone notification if you check the "Audible Warning" checkbox here. You will also be able to specify a temperature for this profile.
The priority of each profile specifies the order in which it will be evaluated. If the conditions of two profiles are both true, the one with the higher priority will be set. For example, if you have both a Screen Off and a Charging profile and the screen is off and charging at the same time, the one with the higher priority will be set.
You can add as many profiles as you want, and selectively enable and disable profiles by using the checkbox next to them. To edit profiles, click on them, make the necessary changes, and press "save." To remove profiles, click on it to edit, and press "delete."
Some things to keep in mind: For multiple battery level profiles, assign the profiles with lower percentages higher priorities. For multiple temperature profiles, assign the profiles with higher temperatures higher priories. Generally, battery level profiles should have lower priorities than other profiles, and temperature profiles should have higher priorites than other profiles.
Check the "Notifications" box to enable a persistent notification in the top bar showing exactly which profile is currently active.
4. Advanced Tab
The Advanced menu allows you to tweak the finer aspects of certain CPU governors. It is only activated when you choose the ondemand or conservative governors.
- Sampling Rate - An interval (in microseconds) at which the governor will poll for updates. When this happens, the governor will decide whether to scale the CPU up or down.
- Up Threshold - Defines a percentage from 1% to 100%. When the CPU load reaches this point, the governor will scale the CPU up.
- Down Threshold (conservative only) - Defines a percentage from 1% to 100%. When the CPU load reaches this point, the governor will scale the CPU down.
- Ignore Nice Load - If this value is "1," the system will ignore "Nice" processes when deciding to scale up or down.
- Powersave Bias (ondemand only) - Setting this value higher will "bias" the governor toward lower frequencies. This is a percentage, where 1000 is 100%, 100 is 10%, and 0 is 0%. The ondemand governor will scale the CPU to a frequency lower than its "target" speed according to this value.
- Freq Step (conservative only) - Defines how much (as a percentage of the maximum CPU speed) the conservative governor will increase the CPU speed by each time the CPU load reaches the Up Threshold.
Choose the "Set on Boot" checkbox to apply advanced settings when the phone boots. This option is completely independent of the similar option in the Main tab.
5. System Info
The System Info tab allows you to view information about your kernel, CPU, battery, phone, and memory status. It also includes a few tools for benchmarking the speed of the phone.
The lower the benchmark score, the faster the phone is running. Keep in mind that this score can only be used to accurately compare different frequencies across the same ROM and kernel. The score may fluctuate between runs due to interference by background processes. For best results, use the "performance" governor.
There is also a "stress test" function. Stress testing allows you to test the stability of undervolted kernels or higher overclocks. The stress test will peg your CPU usage to 100% The phone may be somewhat unresponsive during this time. The stress test will continue forever, so you have to manually end it after some time. To do this, simply press the back button.
To copy the text of the System Info menu to the clipboard, press the Menu button on your device and press "Copy to Clipboard."
6. About
The About menu prints information about SetCPU, including the current version. You can change the theme of the Main tab from using the drop down box. Restart SetCPU to apply it.
7. CPU Scaling Governors
CPU governors control exactly how the CPU scales between your "max" and "min" set frequencies. Most kernels have "ondemand" and "performance." The availability
- ondemand - Available in most kernels, and the default governor in most kernels. When the CPU load reaches a certain point (see "up threshold" in Advanced Settings), ondemand will rapidly scale the CPU up to meet demand, then gradually scale the CPU down when it isn't needed.
- conservative - Available in some kernels. It is similar to the ondemand governor, but will scale the CPU up more gradually to better fit demand. Conservative provides a less responsive experience than ondemand, but can save battery.
- performance - Available in most kernels. It will keep the CPU running at the "max" set value at all times. This is a bit more efficient than simply setting "max" and "min" to the same value and using ondemand because the system will not waste resources scanning for the CPU load. This governor is recommended for stable benchmarking.
- powersave - Available in some kernels. It will keep the CPU running at the "min" set value at all times.
- userspace- A method for controlling the CPU speed that isn't currently used by SetCPU. For best results, do not use the userspace governor.
8. Custom Frequency Config
In rare situations and in older kernels, SetCPU may not be able to autodetect the full range of speeds supported by the kernel. If this is the case, you can configure SetCPU to use custom frequencies. To get started, you'll need the list of frequencies your kernel can support in kHz (not MHz!). Only certain frequencies work, so be sure you know which speeds your kernel supports before using the custom option.
Create a plain text file called "setcpu.txt" and place it on the root directory of your SD card or on your SD card's ext partition (/sdcard/ or /system/sd/). The text files should sort the frequencies on one line by comma, from lowest to highest. For example, the following is a valid config file for some Motorola Droid kernels:
125000,250000,500000,550000,600000
To store the custom frequency list on your phone, save it as "setcpu" with no extension and put it in /data/local/. SetCPU reads from the SD card first and uses that text file if present, then tries to read from /data/local/.
To configure SetCPU to read your custom frequencies, go back to the device selection screen (in the Main tab, press Menu > Device Selection), choose "show other frequencies" if necessary, and choose the custom config option at the very bottom.
9. Task Managers
SetCPU does not run a background service unless profiles or the widget are enabled. Due to how multitasking works on Android, the Android system will automatically free up SetCPU if memory is needed and SetCPU isn't being used.
If either profiles or the widget are enabled, SetCPU does run background processes that keep them running. It's important that you add SetCPU to your task manager's "ignore" list, or otherwise avoid disabling the SetCPU process, if you have either profiles or the widget enabled. You should not have to use task managers to disable SetCPU at any time.
To disable all SetCPU background processes, remove the widget from the home screen and uncheck the "enable" box in the profiles menu. Anything else should be taken care of the Android system when memory is needed, just like any other app. Note that SetCPU briefly runs (and then immediately disables) a service upon startup to perform its "start on boot" duties. This is normal and should not add to memory usage.
10. Disabling Perflock
On most stock HTC kernels and some custom kernels, HTC has enabled a driver called "perflock" that constantly resets SetCPU's Max and Min settings. This does not apply to mostly "Google experience" HTC devices such as the T-Mobile G1, the myTouch 3G, any Google development device, or the Nexus One. It does, however, apply to "HTC Sense" devices such as the HTC Hero, Droid Eris, HTC Desire, HTC Incredible, EVO 4G, and myTouch Slide. Non-HTC devices never have perflock enabled.
SetCPU can disable perflock on newer HTC kernels, giving you control of the Max and Min settings of the CPU. To do this, press the Menu button on your device in the Main tab and choose "Disable Perflock." Read through the notice and then press the button in the dialog. If successful, you should be able to change the frequency with SetCPU. If this process fails, please e-mail the developer with your kernel version and device so support can be added.
Keep in mind that disabling perflock does not enable overclocking, though some overclocked kernels may require perflock to be disabled. Overclocking, in most cases, requires a custom kernel.