I was perusing the internets and found a init.d script to change governors based on screen state and I thought "Maybe I can take this one step further."
I originally made it just for a new Bionic Blurry JB update, but then figured I should share it with all of you!
*This script will only set CPU frequencies if Tweakerz OC Modules are installed*
*This script is currently set up with Stock Bionic frequencies.*
What does the script do?
It automatically changes the governor, scheduler, and CPU frequencies based on screen state, current battery level, and battery state. It originally had a CPU slot # check, but the razr doesnt have that problem so I removed it.
How does it work?
Note: There is a 10 second timer when the screen turns off. If turned back on within 10 seconds, it will not apply the sleep frequencies.
Infinite While Loop
- Battery Discharging
- Battery percentage greater than 15%
- Screen On
- Set CPU Frequencies to (300,600,800,1000,1200)
- Set Governor to HotplugX
- Set Scheduler to Noop
- Screen Off
- Set CPU Frequencies to (300,350,450,525,600)
- Set Governor to PegasusQ
- Set Scheduler to SIO
- Screen On
- Battery percentage less than or equal to 15%
- Screen On
- Set CPU Frequencies to (300,450,600,800,1000)
- Set Governor to PegasusQ
- Set Scheduler to SIO
- Screen Off
- Set CPU Frequencies to (300,350,450,525,600)
- Set Governor to PegasusQ
- Set Scheduler to SIO
- Screen On
- Battery percentage greater than 15%
- Battery Charging
- Screen On
- Set CPU Frequencies to (300,600,800,1000,1200)
- Set Governor to HotplugX
- Set Scheduler to Noop
- Screen Off
- Set CPU Frequencies to (300,350,450,525,600)
- Set Governor to PegasusQ
- Set Scheduler to SIO
- Screen On
End Infinite While Loop
*Its purposely set up to underclock the phone when less than 15% to save battery life till you can get to a charger. Obviously this can be changed with some simple editing.*
UPDATE: There are now two options that can be enabled that will turn off data when wifi is connected or turn data off when the screen if off. Unfortunately because I dont want to run a real infinite while loop, which would be bad for battery life, the option to turn data off when wifi is connected will only turn data on/off when the screen turns on or off. So if you enable that option and turn wifi off or on manually, you will have to turn the screen on or off or turn data on/off manually with a toggle or in settings.
Infinite While Loop... Isnt that bad for the CPU?
Traditionally yes, but this doesnt work like a traditional while loop. Thats because of the way /sys/power/wait_for_fb_wake and /sys/power/wait_for_fb_sleep work. Instead of just checking for the screen state, these files actually pause the script until that screen state is true. Basically, the script sets the awake profile then pauses until the screen turns off. Then it tries to apply the sleep profile. If the sleep profile is applied successfully, it pauses the script until the screen turns back on. Then the process repeats.
Why isnt it setting the CPU frequencies?
Download the tweakerz OC modules from the razr thread below if they are not already included with your ROM. Keep in mind that there are two different sets of flashable modules, one for the OTA and one for Kexec ROMs like AOKP and CM10.1.
*I do not maintain the OC modules. If they do not work on your rom, then you will just have to settle with alternative way it sets the screen off frequencies which can be read below*
What if I dont have the OC modules?
Change the governor and schedulers to match your ROM. Its as easy as adding a # to the beginning of the current governor or scheduler line, and then deleting the # at the beginning of the line with the governor or scheduler you want. Default schedulers are usually interactive, hotplug, ondemand, userspace, and performance. Default schedulers are usually noop, deadline, and cfq.
Without the OC modules the script will not set the custom CPU frequencies, but dont fret. Instead it sets the max frequency and minimum frequency for the lock screen. So basically instead of having 300, 350, 450, 525, and 600Mhz when the screen is off, it will have just 300, and 600Mhz wen the screen is off. Its not as efficient, but it will still help save battery life.
Customization:
I tried to set the script up so its fairly easy to understand and customize to your needs. Remember to change the governor, scheduler, and CPU frequencies to match your needs.
Installation:
Download and extract the script from below and place it in /system/etc/init.d on your phone and set permissions to 0644 and owner:group to 0:2000. Reboot, and enjoy!
Download:
Script Code: