Jump to content


Photo

[INIT.D][SCRIPT] SetCPU like Profiles with init.d!

init.d scripts

  • Please log in to reply
18 replies to this topic

#1 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 31 May 2013 - 11:13 PM

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
    • 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
  • 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

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.

Please Login or Register to see this Hidden Content

 

*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:

Please Login or Register to see this Hidden Content

 

Script Code:

Please Login or Register to see this Hidden Content


  • neckchop, tucstwo, The Persuader and 1 other like this

#2 LDubs

LDubs

    Pawn In Game of Life

  • Dedicated Supporter
  • PipPipPipPipPip
  • 9,548 posts
  • Twitter:lew_bklyn
  • LocationBrooklyn, NY
  • Current Device(s):Nexus 6P, Nexus 5, Nvidia Shield 32gb LTE, Moto X 2013 (thanks S3inks!)

Posted 01 June 2013 - 10:28 AM

Sweet.  Will this work on Bionic too?


The price of liberty, and even of common humanity, is eternal vigilance. -- Aldous Huxley
 
Always do what is right. It will gratify half of mankind and astound the other.  ---Mark Twain

 

Thoughts become things. If you see it in your mind, you will hold it in your hand. --Bob Proctor


#3 larrygeary

larrygeary

    Member

  • Members
  • PipPip
  • 160 posts
  • LocationNJ, USA

Posted 01 June 2013 - 11:19 AM

We need just a little more instruction. Where do we find these "tweakerz" modules? And what exactly do we do with this script?



#4 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 01 June 2013 - 03:42 PM

Sweet.  Will this work on Bionic too?

 

Yes, I posted it in the Bionic Development section. Just make sure to change the frequencies as they arent exactly perfect yet. The awake freqencies are fine, but the sleep frequencies and millivolts may cause some problems.

 

We need just a little more instruction. Where do we find these "tweakerz" modules? And what exactly do we do with this script?

 

I more or less posted it for rom devs who use the modules. Im not sure they will work for AOKP. I know they work on OTA based roms, and the official latest OTA, and there are specific modules for CM10 Kexec in the link below as well.

 

The modules can be found here:

Please Login or Register to see this Hidden Content

 

To use the script place it in /system/etc/init.d/ and change the permissions to 755 and the owner/group to 0:2000. Remember, this is more of a proof on concept, and the frequencies and millivoltage is not perfect so you would need to change them in the script.

 

echo 0 300  1025 > /proc/cpu_control/tweak_cpu

 

In the example above the 1st slot on the CPU is being modified to 300Mhz at 1025mV.

 

Remember, if you screw something up, it is not my fault. Although generally you shouldnt have any problems as you can always get back into safestrap. So Id do a backup up your current rom before trying to modify and use this script.

 

The tweakerz thread can be found with the link below. The modules are outdated, but they have the stock frequencies and voltages at the bottom of the OP, and the equation to calculate mV.



#5 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 05 June 2013 - 09:16 PM

Will be updating tomorrow with a rewritten script. It still does exactly what OP says it does, but is more efficient. It doesnt constantly reapply the governor, scheduler, and frequency values if already awake or asleep like this one did.

 

It also has a 10 second timer when the screen goes off, and if turned back on before it counts to 10 it will not apply sleep frequencies. < This helps avoid lag from the screen switching on and off quickly or multiple times in a row.



#6 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 13 June 2013 - 12:00 PM

Script has been updated to be more efficient. I didnt pretty up the code this time in the post. If you want to see it with the different colors and such like it was before, open the script with Notepad++ and select Language>S>Shell.



#7 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 15 June 2013 - 04:47 PM

UPDATE:

Fixed some programming errors that stopped it from applying the sleep frequencies. Had to change the method for checking screen state, but it completely works now.



#8 tucstwo

tucstwo

    www.drdevs.com

  • Administrator
  • 14,435 posts
  • Twitter:tucstwo
  • Google+:tucstwo@gmail.com
  • LocationNJ
  • Current Device(s):LG G3 VS985, Nexus 7 (flo)

Posted 17 June 2013 - 07:39 PM

 

UPDATE:

Fixed some programming errors that stopped it from applying the sleep frequencies. Had to change the method for checking screen state, but it completely works now.

 

Might I make a suggestion for you in the future? Just for your own OP's sake and for keeping things organized AND/Or separated from version to version? Use a free service like

Please Login or Register to see this Hidden Content

? So that your OP script instead of being posted like it is could

Please Login or Register to see this Hidden Content

?

 

Don't have to take my suggestion, that's all it is. Jus sayin' cause sometimes, posts that are THAT text intensive are easier to post like that rather than like you've done it? It also makes it nice and easy for you to keep track of different versions/edits? Just sayin' :)  Not a rule or anything. Just trying to make life easier for ya ;)


Visit DRDevs.com hosting site for all official Droidrzr.com ROMs, Apps, GApps and other mods/files!!
Please PM me if you need help!
I will be hosting AOSP-Based ROM GApps packages!
Download the most Up-to-Date GApps Packages for AOSP ROMs from me here!


#9 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 17 June 2013 - 10:51 PM

Might I make a suggestion for you in the future? Just for your own OP's sake and for keeping things organized AND/Or separated from version to version? Use a free service like

Please Login or Register to see this Hidden Content

? So that your OP script instead of being posted like it is could

Please Login or Register to see this Hidden Content

?

 

Don't have to take my suggestion, that's all it is. Jus sayin' cause sometimes, posts that are THAT text intensive are easier to post like that rather than like you've done it? It also makes it nice and easy for you to keep track of different versions/edits? Just sayin' :)  Not a rule or anything. Just trying to make life easier for ya ;)

 

I know what you mean. When I made the post originally I expected the code tags to work like on xda where it just becomes a small scrollable box. I also wasnt expecting to have to update it, since I kept thinking it was working originally. Now that its pretty much finished there shouldnt be anymore updates. I cant think of anything else to add to it really.



#10 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 01 July 2013 - 12:29 AM

Script updated.

 

No longer writes a log file in /data/ to read the screen state and 2 options have been added that allow data to be turned off when the screen turns off, or when wifi is connected (Read the update in the OP, it has some more info you will need for disabling data when wifi connected.)



#11 The Persuader

The Persuader

    Droid Elite

  • Members
  • PipPipPipPip
  • 2,009 posts
  • LocationMaine
  • Current Device(s):Razr Maxx

Posted 01 July 2013 - 02:21 PM

Script updated.

No longer writes a log file in /data/ to read the screen state and 2 options have been added that allow data to be turned off when the screen turns off, or when wifi is connected (Read the update in the OP, it has some more info you will need for disabling data when wifi connected.)

Good Evening-

I will be brief...
Downloaded SetCPU to make a difference on my phone...My setting are 1200/800 but it defaults to 1200/300 and on occasion it will Bench to 800 MHzchecking the CPU Frequencies for Performance.

Does this App really work just from downloading from the Play Store...

Looking for Performance with Lags and Battery Life or is the App Just another Ghost for Correct Readings...

I am not having any Issues with Lags-Performance-Speed or excessive Battery usage so, I am thinking its working...

But when I set at 800 HMz it shows on the setting but performs in the background as 1200/300

Your Thoughts

Its Bubba...."Stubborn In Your Bones"


#12 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 01 July 2013 - 03:37 PM

Good Evening-

I will be brief...
Downloaded SetCPU to make a difference on my phone...My setting are 1200/800 but it defaults to 1200/300 and on occasion it will Bench to 800 MHzchecking the CPU Frequencies for Performance.

Does this App really work just from downloading from the Play Store...

Looking for Performance with Lags and Battery Life or is the App Just another Ghost for Correct Readings...

I am not having any Issues with Lags-Performance-Speed or excessive Battery usage so, I am thinking its working...

But when I set at 800 HMz it shows on the setting but performs in the background as 1200/300

Your Thoughts

 

Im not sure I entirely understand what you are saying/asking. But I will try to respond in an effective manner. SetCPU allows you to set the minimum and maximum operating frequencies for the CPU. When you first start the app it reads your default CPU frequencies which should default to 300 minimum and 1200 maximum. It doesnt actually let you change the frequencies themselves. It shouldnt change frequencies by itself, so if you set 800Mhz as the minimum it should stay at 800Mhz for the minimum even if its closed or the screen if locked. Same goes for the max frequency. I can confirm that the app does indeed work properly.

 

Now I have to ask, are you using SetCPU with this script? If so, then SetCPU is completely useless other than checking to see if its working. Which you can do by changing the governor or scheduler, switching the screen off and then on and checking the governor/scheduler again in SetCPU. Every time the screen turns on or off, the script sets the frequencies again. So any changes made in SetCPU will not work. For the most part this script should actually perform better than SetCPU because it sets all 5 frequency steps instead of just setting a min and max and using 2 frequency steps as SetCPU does. SetCPU also allows you to set different frequencies based on profiles such as battery below a certain limit, screen off, screen on, phone unlocked, etc... Most of these are useless. The two biggest and most used profiles in SetCPU are the battery limit and screen states, which is what I built into this script.

 

Keep in mind that if the OC modules are not installed on the rom you are currently using, this script basically functions exactly the same way SetCPU does, but doesnt require a service to run in the background of the OS. So in a sense, its still better athough doesnt offer as many options.



#13 The Persuader

The Persuader

    Droid Elite

  • Members
  • PipPipPipPip
  • 2,009 posts
  • LocationMaine
  • Current Device(s):Razr Maxx

Posted 01 July 2013 - 04:13 PM

Im not sure I entirely understand what you are saying/asking. But I will try to respond in an effective manner. SetCPU allows you to set the minimum and maximum operating frequencies for the CPU. When you first start the app it reads your default CPU frequencies which should default to 300 minimum and 1200 maximum. It doesnt actually let you change the frequencies themselves. It shouldnt change frequencies by itself, so if you set 800Mhz as the minimum it should stay at 800Mhz for the minimum even if its closed or the screen if locked. Same goes for the max frequency. I can confirm that the app does indeed work properly.

 

Now I have to ask, are you using SetCPU with this script? If so, then SetCPU is completely useless other than checking to see if its working. Which you can do by changing the governor or scheduler, switching the screen off and then on and checking the governor/scheduler again in SetCPU. Every time the screen turns on or off, the script sets the frequencies again. So any changes made in SetCPU will not work. For the most part this script should actually perform better than SetCPU because it sets all 5 frequency steps instead of just setting a min and max and using 2 frequency steps as SetCPU does. SetCPU also allows you to set different frequencies based on profiles such as battery below a certain limit, screen off, screen on, phone unlocked, etc... Most of these are useless. The two biggest and most used profiles in SetCPU are the battery limit and screen states, which is what I built into this script.

 

Keep in mind that if the OC modules are not installed on the rom you are currently using, this script basically functions exactly the same way SetCPU does, but doesnt require a service to run in the background of the OS. So in a sense, its still better athough doesnt offer as many options.

Thanks for the follow up...Seriously I know enough to be dangerous...Oh, Thank you for an Awesome Explanations...

 

My question back to you is Yes, I am running SetCPU but, What the hell is a Script...Not even sure I would know my friend if its running in the background...That said, I do change the settings to 1200/800...

 

It shows on the screen but changes in the background are running 1200/300...What did I do wrong?


Its Bubba...."Stubborn In Your Bones"


#14 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 01 July 2013 - 04:41 PM

Thanks for the follow up...Seriously I know enough to be dangerous...Oh, Thank you for an Awesome Explanations...

 

My question back to you is Yes, I am running SetCPU but, What the hell is a Script...Not even sure I would know my friend if its running in the background...That said, I do change the settings to 1200/800...

 

It shows on the screen but changes in the background are running 1200/300...What did I do wrong?

 

Well, this thread is for the init.d script I posted in the OP which functions similar to SetCPU. If you havent downloaded the script and put it into /system/etc/init.d then you are not running the script. I do have to ask, how exactly do you know its continuing to run at 1200/300 in the background?



#15 The Persuader

The Persuader

    Droid Elite

  • Members
  • PipPipPipPip
  • 2,009 posts
  • LocationMaine
  • Current Device(s):Razr Maxx

Posted 01 July 2013 - 04:57 PM

Well, this thread is for the init.d script I posted in the OP which functions similar to SetCPU. If you havent downloaded the script and put it into /system/etc/init.d then you are not running the script. I do have to ask, how exactly do you know its continuing to run at 1200/300 in the background?

Evening Markus-

Here's a Screen Shot:
Front shows my settings I changed. ..
In the background you'll see the standard 1200/300 settings pinging behind my settings


Its Bubba
"Stubborn In Your Bones"

Attached Files


Its Bubba...."Stubborn In Your Bones"


#16 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 02 July 2013 - 05:10 AM

Evening Markus-

Here's a Screen Shot:
Front shows my settings I changed. ..
In the background you'll see the standard 1200/300 settings pinging behind my settings


Its Bubba
"Stubborn In Your Bones"

 

It must be something with your phone. I have seen it work on every phone my friends, brothers, and myself have had. Sorry to tell you that man, but thats the only explanation I can come up with. You could always try something like no-frills CPU controll or Rom toolbox and see if those apps will work like they are suppose to.

 

Please Login or Register to see this Hidden Content

 

Please Login or Register to see this Hidden Content

  90.36KB   9 downloads



#17 The Persuader

The Persuader

    Droid Elite

  • Members
  • PipPipPipPip
  • 2,009 posts
  • LocationMaine
  • Current Device(s):Razr Maxx

Posted 02 July 2013 - 05:25 AM

It must be something with your phone. I have seen it work on every phone my friends, brothers, and myself have had. Sorry to tell you that man, but thats the only explanation I can come up with. You could always try something like no-frills CPU controll or Rom toolbox and see if those apps will work like they are suppose to.

http://www.droidrzr.com/public/style_images/dark_matter/attachicon.gif

Please Login or Register to see this Hidden Content

Nope, sticking with this one...I'll wipe Cache & Data within this App...
Thanks Man, appreciated you're knowledge about this SetCPU App...off to reread some more about this App...

Its Bubba
"Stubborn In Your Bones"


Its Bubba...."Stubborn In Your Bones"


#18 The Persuader

The Persuader

    Droid Elite

  • Members
  • PipPipPipPip
  • 2,009 posts
  • LocationMaine
  • Current Device(s):Razr Maxx

Posted 02 July 2013 - 05:30 AM

It must be something with your phone. I have seen it work on every phone my friends, brothers, and myself have had. Sorry to tell you that man, but thats the only explanation I can come up with. You could always try something like no-frills CPU controll or Rom toolbox and see if those apps will work like they are suppose to.

http://www.droidrzr.com/public/style_images/dark_matter/attachicon.gif

Please Login or Register to see this Hidden Content

After you change the settings...Does it default back to 1200/300 pinging in the background....mine shows the same until I back out of the App...
Won't bug anymore my friend :)

Its Bubba
"Stubborn In Your Bones"


Its Bubba...."Stubborn In Your Bones"


#19 MarkusMcNugen

MarkusMcNugen

    Blurred Effectz

  • Developer
  • 277 posts
  • LocationDecatur, MI
  • Current Device(s):Bionic

Posted 02 July 2013 - 08:14 AM

No, it shouldnt default back to 1200/300 when you exit out. For some reason it just isnt operating correctly on your phone. Wish I could help you out more but Im at the limits of my knowledge when it comes to SetCPU. You could always email the devs for it and ask them about it.







Also tagged with one or more of these keywords: init.d, scripts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users