[LG Optimus Black] aprold:
Hello everyone!

Here is a little script I wrote for setting frequencies, voltages, governor and I/O scheduler in your phone running Nova ROM. Largely inspired by knzo's own script I decided to write my own for two reasons: understand the black magic behind it and teach myself the basics of shell scripting. To achieve this I got rid of the overhead and rewrote the remaining as shortly as possible. Since I've been the only one to test it so far I'd be really glad if anyone else gives it a try as well.

However, if you decide to go forward and give it a try, I'm going to assume that you're already advanced enough to know what you're doing. It doesn't hurt to backup your /data partition first and only then start experimenting. It's not unheard of to make a mesh of your data because services and applications crashed due to too much over-clocking or under-volting. If you're already familiar with knzo's and Huexxx's work then it's not going to kill you (or your phone). Anyway, be careful!

With that out of the way I'll say few words about the script itself. Here is how the main menu looks like:

MAIN MENU
1. Set frequency and voltage
[1100/54(54),800/44(44),600/34(35),300/20(24)]
2. Set governor [SmartassV2]
3. Set I/O scheduler [vr]
4. Set current values at boot
5. Reboot
0. Quit

The menu items speak mostly for themselves. Current values are fetched from corresponding system files and are shown in square brackets (with calibrated voltages in parentheses). The current values are there for you and visible inside sub-menus as well. After changing the values you have an option to set these values to be loaded at boot time and tell the phone to reboot as well to see if your choices are bootable.

Keep in mind that the choices you have made here may look stable while running the script and doing parallel stress testing perhaps but they may not be bootable! I've added a watchdog to guard you and if it so happens that your phone hangs while booting then the script will not apply your settings next time. Take out your battery and try again. If you're lucky then your /data partition is unaffected and you can go on unharmed. If you push it too hard then it is very likely you'll have to lean on your backups.

Back to introducing the script. What I did differently from knzo was the method how the settings are applied. No matter where and what you change, all the values are dynamically written to a separate script and then this script gets executed. The same script is used inside init.d and I had to add a condition there which checks if we are running from init.d or not. This has to do with the "stubborn" governor which gets overwritten by some process at boot. Therefore I added 15 second sleep there to set it just a little bit later.

Also different from knzo's script is the way how governor and scheduler choices are shown. Namely, these lists are created dynamically from available values.

The script also checks if you are root or not and tells you a friendly message if you need to su first.

About installing it. I haven't yet learned anything about how to install this script with as few hassles as possible and you'll have to get this script into your phone manually for now. Just copy this on your sdcard over the USB or bluetooth or any way you like, move it to /system/xbin for example, set execute permissions and run it. I'll definitely teach myself the ways of APK next. And will write a standalone application afterwards :)

And now for something technical. As this is my very first shell script ever then there are couple of things that might not be done most elegantly.

1) Boot detection relies solely on the existence of ANDROID_SOCKET_zygote environment variable which is empty now at boot and gets initialized sometimes later. Things will not work as intended any more if the Zygote decides to do something differently in the future. What would be better indicator here?

2) User detection uses stderr output from whoami which seems to be 'unknown uid 0' for root now and 'unknown uid 10008' for ordinary user. Is it OK to rely on that or is there a change that it'll say something else on other phones?

Well, that's it. The script itself is attached here and I tried to write some comments there as well to help you read it better.

I hope this is of some use to anybody besides me and thanks for reading so far. All your comments are very welcome!

Regards,

Aprold