[Sprint Samsung Galaxy S III] freeza:
Hi. I wrote this script after coming across the "screenstate_scaling" by florian.schaefer & "battery tweak" by collin_ph@xda scripts. This goes quite a bit further than those were intended to do. So, I figure I would share with the community. What this script allows you to do is set certain parameters based on a number of factors, i.e. screen off, screen on, current charge state, and battery percentages. It's also very easy to add things in depending on what you want to do. The script is actually quite powerful in what it can do given the right scenario.

This is what I use in my ROM, custom, and stock kernels.

In its current form, it is set to do the folowing:

Version: Custom Kernel with msm-dcvs and intellidemand governors: If the kernel you're using has neither of these available, you must modify and fine tune the script to your liking.

-When phone is charging and the screen turns on:

--Set minimum CPU speed to 486MHz (between 96 and 486MHz the voltage is the same, so why not have it run at the highest?)

--Set the CPU governor to OnDemand

--Set slightly aggressive and performanced based parameters to the OnDemand governor

--Set the CPU Speed to 1.99 GHz

--Turn off dual core managing (mpdecision) and keep the second core online

--Set undervolt values to default

--Set first and second touch CPU speed limits to default

-When the phone is on battery power and the screen turns on and is above 85% battery life:

--Set the CPU governor to Intellidemand

--Set slightly aggressive and battery friendly parameters to the Intellidemand governor

--Set the CPU Speed to 1.67 GHz

--Turn on dual core managing (mpdecision) and lets the system manage when the second core comes on and offline.

--Set undervolt values to -25mv

--Set first touch CPU speed limits to 702MHz

Much of the settings will remain the same until the battery reaches a charge lower than 50%. However, max CPU frequency will decrease gradually to 1.13GHz.

-When the phone is on battery power and the screen turns on with a battery level below 50%:

--Set the CPU governor to msm-dcvs

--Set the CPU Speed to 1.13 GHz

-When the phone is on battery power and the screen turns on with a battery level below 25%:

--Set the CPU governor to msm-dcvs

--Set the max CPU Speed to 702MHz. This is the frequency I found best for maintaining fairly smooth experience at the same time conserving battery life as much as possible.

--Turn off dual core managing (mpdecision) and keep the second core online with a max speed of 702MHz

--Set undervolt values to -25mv

--Set first and second touch CPU speed limits to 648MHz and 486MHz respectively.

It also sets different memory management, file system based, and system tweaks when the screen is turned on and off.

-When the phone is charging and the screen turns off:

--Set the minimum CPU speed to 486MHz

--Set the CPU governor to OnDemand

--Set slightly aggressive and performanced based parameters to the OnDemand governor

--Set the CPU max Speed to 1.99 GHz

--Turn off dual core managing (mpdecision) and keep the second core online

--Set undervolt values to default

-When the phone is on battery power and the screen turns off:

--Set the minimum and max CPU speed to 486MHz

--Set the CPU governor to msm-dcvs

--Turn on dual core managing (mpdecision) and lets the system manage when the second core comes on and offline.

--Set undervolt values to -25mv

This also gives priority to the phone app so that it will be more responsive.

I will be uploading the file, not a flashable, so that you can fine tune this to your liking. Those who decide to modify settings should post their results so we can try different tihngs. You may find some settings that work much better than mine and it would benefit everyone.

Once done, you can go ahead and get this into /system/etc/init.d/ by adb or whatever means you prefer. It also needs to be chmodded to allow the system to read and execute it. I usually set things in init.d to 777 just out of habit.

Requirements:

-Kernel or ROM with init.d support.

-Busybox (with pgrep)

If you meet the requirements, continue reading for installation.

Installation:

ADB:

Open a command prompt/terminal navigate to your ADB directory (Windows users: if you have the android sdk or adb in your Environment Variables then ignore this next part)

Drag the 70cputweakMODv2 file into your directory with ADB

If you don't have the init.d folder in /system/etc, then create it by typing "adb shell" enter "cd /system/etc" enter "mkdir init.d" enter "chmod 0777 init.d" enter "exit"

Type the following: "adb remount" press enter, then "adb push 70cputweakMODv2 /system/etc/init.d/70cputweakMODv2" press enter, then "adb shell chmod 0777 /system/etc/init.d/70cputweakMODv2" press enter, then reboot your phone.

File explorer: If you're not using ADB.

Copy file to phone

Open your root explorer or es file explorer or whatever you use.

Navigate to where you copied the file

Copy the 70cputweakMODv2 script

Navigate to /system/etc/init.d/

If the folder isn't present, create a new directory with your file explorer app and set permissions to 777.

Paste the file 70cputweakMODv2 inside of init.d and set permissions to 777

Reboot your phone

Stock kernel version coming soon.

Changelog:

v1: release

v2: corrected pegasusq references to intellidemand

Script code:

#!/system/bin/sh
#
# parts taken from "screenstate_scaling" by florian.schaefer & "battery tweak" by collin_ph@xda
# by freeza for Galaxy S fre3 ROM

AWAKE_MODE() # Screen-ON
{
# VM parameters
BTLF=`cat /sys/class/power_supply/battery/capacity`
BTST=`cat /sys/class/power_supply/battery/status`
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
#chmod 0444 /sys/devices/system/cpu/cpu1/online
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
chmod 0644 /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
echo 486000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 486000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
chmod 0444 /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
if [ "$BTST" == "Charging" ] || [ "$BTST" == "Full" ]; then
if [ "$(pgrep mpdecision)" ]
then
stop mpdecision
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
chmod 0444 /sys/devices/system/cpu/cpu1/online
fi
echo "OnDemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "OnDemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1998000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1998000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "70" > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold;
echo "50000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate;
echo "2" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor;
echo "15" > /sys/devices/system/cpu/cpufreq/ondemand/down_differential;
echo 1134000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1350 1325 1300 1275 1250 1200 1200 1185 1185 1175 1175 1150 1150 1125 1125 1075 1075 1050 1050 1025 1025 975 975 950 950 925 925 925 925 925 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 85 ]; then
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "intellidemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "intellidemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1674000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1674000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "90" > /sys/devices/system/cpu/cpufreq/intellidemand/up_threshold;
echo "50000" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_rate;
echo "4" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_down_factor;
echo "3" > /sys/devices/system/cpu/cpufreq/intellidemand/down_differential;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 74 ] && [ "$BTLF" -lt 85 ]; then
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "intellidemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "intellidemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1458000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1458000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "90" > /sys/devices/system/cpu/cpufreq/intellidemand/up_threshold;
echo "50000" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_rate;
echo "4" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_down_factor;
echo "3" > /sys/devices/system/cpu/cpufreq/intellidemand/down_differential;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 64 ] && [ "$BTLF" -lt 74 ]; then
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "intellidemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "intellidemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1350000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1350000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "90" > /sys/devices/system/cpu/cpufreq/intellidemand/up_threshold;
echo "50000" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_rate;
echo "4" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_down_factor;
echo "3" > /sys/devices/system/cpu/cpufreq/intellidemand/down_differential;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 50 ] && [ "$BTLF" -lt 64 ]; then
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "intellidemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "intellidemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1242000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1242000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "90" > /sys/devices/system/cpu/cpufreq/intellidemand/up_threshold;
echo "50000" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_rate;
echo "4" > /sys/devices/system/cpu/cpufreq/intellidemand/sampling_down_factor;
echo "3" > /sys/devices/system/cpu/cpufreq/intellidemand/down_differential;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 40 ] && [ "$BTLF" -lt 50 ]; then
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "msm-dcvs" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "msm-dcvs" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1134000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1134000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
#	echo "95" /sys/devices/system/cpu/cpufreq/ondemand/up_threshold;
#	echo "120000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate;
#	echo "1" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor;
#	echo "5" > /sys/devices/system/cpu/cpufreq/ondemand/down_differential;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 25 ] && [ "$BTLF" -lt 40 ]; then
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "msm-dcvs" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "msm-dcvs" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1026000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1026000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
#	echo "95" /sys/devices/system/cpu/cpufreq/ondemand/up_threshold;
#	echo "120000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate;
#	echo "1" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor;
#	echo "5" > /sys/devices/system/cpu/cpufreq/ondemand/down_differential;
echo 810000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
else
if [ "$BTLF" -ge 0 ] && [ "$BTLF" -lt 25 ]; then
if [ "$(pgrep mpdecision)" ]
then
stop mpdecision
fi
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
chmod 0444 /sys/devices/system/cpu/cpu1/online
echo "msm-dcvs" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "msm-dcvs" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 702000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 702000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
#	echo "95" /sys/devices/system/cpu/cpufreq/ondemand/up_threshold;
#	echo "120000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate;
#	echo "1" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor;
#	echo "5" > /sys/devices/system/cpu/cpufreq/ondemand/down_differential;
echo 648000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_first_freq_limit;
echo 486000 > /sys/devices/system/cpu/cpu0/cpufreq/touch_booster_second_freq_limit;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
fi
fi
fi
fi
fi
fi
fi
fi
echo -1 > /proc/sys/kernel/sched_rt_runtime_us;
echo 100000 > /proc/sys/kernel/sched_rt_period_us;
echo 95000 > /proc/sys/kernel/sched_rt_runtime_us;
echo 30 > /proc/sys/vm/swappiness;
echo 1000 > /proc/sys/vm/dirty_expire_centisecs;
echo 2000 > /proc/sys/vm/dirty_writeback_centisecs;
echo 10 > /proc/sys/vm/dirty_background_ratio;
echo 40 > /proc/sys/vm/dirty_ratio;
echo 0 > /proc/sys/vm/page-cluster;
echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
echo "2056" > /sys/block/mmcblk0/bdi/read_ahead_kb;
echo "2056" > /sys/block/mmcblk0/queue/read_ahead_kb;
echo 0 > /proc/sys/vm/laptop_mode;
echo 300 > /proc/sys/vm/vfs_cache_pressure;
echo 8192 > /proc/sys/vm/min_free_kbytes;
}

SLEEP_MODE()# Screen-OFF
{
# VM parameters
BTSTo=`cat /sys/class/power_supply/battery/status`
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
chmod 0444 /sys/devices/system/cpu/cpu1/online
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
chmod 0644 /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
echo 486000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 486000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
chmod 0444 /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
if [ "$BTSTo" == "Charging" ] || [ "$BTSTo" == "Full" ]; then
if [ "$(pgrep mpdecision)" ]
then
stop mpdecision
chmod 0664 /sys/devices/system/cpu/cpu1/online
echo "1" > /sys/devices/system/cpu/cpu1/online
chmod 0444 /sys/devices/system/cpu/cpu1/online
echo "OnDemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor;
echo "OnDemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor;
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1998000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 1998000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "70" > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold;
echo "50000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate;
echo "2" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor;
echo "15" > /sys/devices/system/cpu/cpufreq/ondemand/down_differential;
echo "1350 1325 1300 1275 1250 1200 1200 1185 1185 1175 1175 1150 1150 1125 1125 1075 1075 1050 1050 1025 1025 975 975 950 950 925 925 925 925 925 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
fi
else
if [ -z "$(pgrep mpdecision)" ]
then
chmod 0664 /sys/devices/system/cpu/cpu1/online
start mpdecision
fi
echo "msm-dcvs" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor;
echo "msm-dcvs" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor;
chmod 0644 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 486000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo 486000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq;
chmod 0444 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo "1325 1300 1275 1250 1225 1175 1175 1160 1160 1150 1150 1125 1125 1100 1100 1050 1050 1025 1025 1000 1000 950 950 925 925 900 900 900 900 900 " > /sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table;
fi
echo -1 > /proc/sys/kernel/sched_rt_runtime_us;
echo 1000000 > /proc/sys/kernel/sched_rt_period_us;
echo 950000 > /proc/sys/kernel/sched_rt_runtime_us;
echo 0 > /proc/sys/vm/swappiness;
echo 0 > /proc/sys/vm/dirty_expire_centisecs;
echo 0 > /proc/sys/vm/dirty_writeback_centisecs;
echo 60 > /proc/sys/vm/dirty_background_ratio;
echo 95 > /proc/sys/vm/dirty_ratio;
echo 3 > /proc/sys/vm/page-cluster;
echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
echo "2056" > /sys/block/mmcblk0/bdi/read_ahead_kb;
echo "2056" > /sys/block/mmcblk0/queue/read_ahead_kb;
echo 5 > /proc/sys/vm/laptop_mode;
echo 10 > /proc/sys/vm/vfs_cache_pressure;
echo 2048 > /proc/sys/vm/min_free_kbytes;
}

MAX_PHONE() # remove lag when answering phone calls
{
pidphone=`pidof com.android.phone`;
if [ $pidphone ];
then
echo -17 > /proc/$pidphone/oom_adj; # exclude com.android.phone from oom-killer
renice -20 $pidphone; # set highest nice level for com.android.phone
exit;
else
sleep 1;
MAX_PHONE;
fi;
}

# Background process to check screen state
(while [ 1 ];
do
cat /sys/power/wait_for_fb_wake;
AWAKE_MODE;

cat /sys/power/wait_for_fb_sleep;
SLEEP_MODE;
done &);

# One-time process to optimize com.android.phone
(while [ 1 ];
do
sleep 10;
MAX_PHONE;
done &);