#!/system/bin/sh
#
# 89system_tweak V66
# by zacharias.maladroit
# modifications and ideas taken from: ckMod SSSwitch by voku1987 and "battery tweak" (collin_ph@xda)
# OOM/LMK settings by Juwe11
# network security settings inspired by various security, server guides on the web
#Slaid480 Modification  ==============================================================
# ==============================================================
# ==============================================================
# One-time tweaks to apply on every boot
# ==============================================================
# ==============================================================
# ==============================================================
# =========
STL=`ls -d /sys/block/stl*`;
BML=`ls -d /sys/block/bml*`;
MMC=`ls -d /sys/block/mmc*`;
ZRM=`ls -d /sys/block/zram*`;

# set the cfq scheduler as default i/o scheduler (Samsung ROMs)
#for i in $STL $BML $MMC;
#do
#	echo "noop" > $i/queue/scheduler; 
#done;

# Optimize non-rotating storage; 
for i in $STL $BML $MMC $ZRM;
do
	#IMPORTANT!
	if [ -e $i/queue/rotational ]; 
	then
		echo 0 > $i/queue/rotational; 
	fi;
	if [ -e $i/queue/nr_requests ];
	then
		echo 8192 > $i/queue/nr_requests; # for starters: keep it sane
	fi;
	#CFQ specific
	if [ -e $i/queue/iosched/back_seek_penalty ];
	then 
		echo 1 > $i/queue/iosched/back_seek_penalty;
	fi;
	#CFQ specific
	if [ -e $i/queue/iosched/low_latency ];
	then
		echo 1 > $i/queue/iosched/low_latency;
	fi;
	#CFQ Specific
	if [ -e $i/queue/iosched/slice_idle ];
	then 
		echo 0 > $i/queue/iosched/slice_idle; # previous: 1
	fi;
	# deadline/VR/SIO scheduler specific
	if [ -e $i/queue/iosched/fifo_batch ];
	then
		echo 1 > $i/queue/iosched/fifo_batch;
	fi;
	if [ -e $i/queue/iosched/writes_starved ];
	then
		echo 1 > $i/queue/iosched/writes_starved;
	fi;
	#CFQ specific
	if [ -e $i/queue/iosched/quantum ];
	then
		echo 8 > $i/queue/iosched/quantum;
	fi;
	#VR Specific
	if [ -e $i/queue/iosched/rev_penalty ];
	then
		echo 1 > $i/queue/iosched/rev_penalty;
	fi;
	if [ -e $i/queue/rq_affinity ];
	then
	echo "1"   >  $i/queue/rq_affinity;   
	fi;
done;

#disable iostats to reduce overhead  # idea by kodos96 - thanks !
for k in $STL $BML $MMC $ZRM;
do
	if [ -e $i/queue/iostats ];
	then
		echo "0" > $k/queue/iostats;
	fi;
done;

# Remount all partitions with noatime
for k in $(busybox mount | grep relatime | cut -d " " -f3);



do
sync;
busybox mount -o remount,noatime $k;
done;


# Optimize for read- & write-throughput; 
# Optimize for readahead; 

for i in $STL $BML $MMC $ZRM; 
do
	if [ -e $i/queue/read_ahead_kb ];
	then
		echo "256" >  $i/queue/read_ahead_kb; # yes - I know - this is evil ^^, might help with battery runtime still (in certain workloads)
	fi;
                                     
done;
##         /bin/echo "0"   >  $i/queue/nomerges
#          echo "128" >  $i/queue/max_sectors_kb


# =========
# TWEAKS: raising read_ahead_kb cache-value for sd card to 2048 [not needed with above tweak but just in case it doesn't get applied]
# =========
#echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb

# improved approach of the readahead-tweak:


if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ];
then
    /system/xbin/echo "1024" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
fi;
	
if [ -e /sys/devices/virtual/bdi/179:8/read_ahead_kb ];
  then
    /system/xbin/echo "1024" > /sys/devices/virtual/bdi/179:8/read_ahead_kb;
fi;

if [ -e /sys/devices/virtual/bdi/179:28/read_ahead_kb ];
  then
    /system/xbin/echo "1024" > /sys/devices/virtual/bdi/179:28/read_ahead_kb;
fi;

if [ -e /sys/devices/virtual/bdi/179:33/read_ahead_kb ];
  then
    /system/xbin/echo "1024" > /sys/devices/virtual/bdi/179:33/read_ahead_kb;
fi;

if [ -e /sys/devices/virtual/bdi/default/read_ahead_kb ];
  then
    /system/xbin/echo "256" > /sys/devices/virtual/bdi/default/read_ahead_kb;
fi;



# ==============================================================
# ==============================================================
# ==============================================================
# VFS, VM settings
# ==============================================================
# ==============================================================
# ==============================================================

# =========
# TWEAKS: MEMORY SETTINGS for general operation + zcache/zram usage
# =========

# optimizing the system for zcache & zram usage & general VM (compatible with all ROMs)

#echo 0 > /proc/sys/vm/swappiness # 70 for zram, Talon # 0 for CM7 / MIUI (no zram yet)
#echo 3 > /proc/sys/vm/page-cluster # when swapping then hesitate to swap out pages & pull them in again in a fast manner

#echo 20 > /proc/sys/vm/vfs_cache_pressure; # 100 while screen off # 200 # 50
#echo 50 > /proc/sys/vm/vfs_cache_pressure; # same value for both: screen on & off - needs some testing due to RAM filling and OOM killer triggering # 20 (on talon)

# make sure we don't use laptop-mode
#echo 0 > /proc/sys/vm/laptop_mode;


		sysctl -w vm.page-cluster=3;
		sysctl -w vm.laptop_mode=0;
		sysctl -w vm.dirty_expire_centisecs=3000;
		sysctl -w vm.dirty_expire_centisecs=500;
		sysctl -w vm.dirty_background_ratio=65;
		sysctl -w vm.dirty_ratio=80;
		sysctl -w vm.vfs_cache_pressure=1;
		sysctl -w vm.overcommit_memory=1;
		sysctl -w vm.oom_kill_allocating_task=0;
		sysctl -w vm.panic_on_oom=0;
		sysctl -w kernel.panic_on_oops=1;
		sysctl -w kernel.panic=0;

		#echo 3 > /proc/sys/vm/page-cluster; # 12
		#echo 0 > /proc/sys/vm/laptop_mode; # do not omit syncing
		#echo 3000 > /proc/sys/vm/dirty_expire_centisecs; # 2000 # 700 is long enough [stability testing]
		#echo 500 > /proc/sys/vm/dirty_writeback_centisecs; # 1000 # 500 is long enough [stability testing]
		#echo 65 > /proc/sys/vm/dirty_background_ratio; # 15 # 10 # 50 #10 #55
		#echo 80 > /proc/sys/vm/dirty_ratio; # 40 # 90
		#echo 1 > /proc/sys/vm/vfs_cache_pressure; # 100 while screen off # 200 # 50 # 20 [less reclaim] #
		#echo 1 > /proc/sys/vm/overcommit_memory;
		#echo 0 > /proc/sys/vm/oom_kill_allocating_task;
		#echo 0 > /proc/sys/vm/panic_on_oom;
		#echo 1 > /proc/sys/kernel/panic_on_oops;
		#echo 0 > /proc/sys/kernel/panic;


# =========
# renice processes at wake. Credits to lpy: http://forum.xda-developers.com/showthread.php?t=1137554
# =========

    ### Phone dialer app ###
#    renice -1 `pidof com.android.phone`;

    ### System apps ###
#    renice -1 `pidof com.android.mms`; # Text message app
#    renice -1 `pidof com.swype.android.inputmethod`; # Keyboard
#    renice -1 `pidof com.sec.android.app.controlpanel`; # Task manager
#    renice -1 `pidof com.android.systemui`; # Status bar
#    renice -1 `pidof com.android.settings`; # Settings menu
#    renice -1 `pidof com.android.vending`; # Market app
#    renice -1 `pidof com.sec.android.app.camera`; # Camera app
#    renice -1 `pidof android.process.acore`;
#    renice -1 `pidof kondemand/0`;
#    renice -1 `pidof ksmartass_up/0`;
  
# =========
# TWEAKS: adding zram swap in RAM
# =========

#insmod /system/modules/zram.ko num_devices=1
#echo $((96*1024*1024)) > /sys/block/zram0/disksize
#mknod /dev/zram0 b 253 0
#mkswap /dev/zram0
#swapon /dev/zram0





# ==============================================================
# ==============================================================
# ==============================================================
# network speed and throughput
# ==============================================================
# ==============================================================
# ==============================================================



# =========
# TWEAKS: for TCP read/write
# =========

sysctl -w net.ipv4.tcp_timestamps=0;
sysctl -w net.ipv4.tcp_tw_reuse=1;
sysctl -w net.ipv4.tcp_sack=1;
sysctl -w net.ipv4.tcp_dsack=1;
sysctl -w net.ipv4.tcp_tw_recycle=1;
sysctl -w net.ipv4.tcp_window_scaling=1;
sysctl -w net.ipv4.tcp_keepalive_probes=5;
sysctl -w net.ipv4.tcp_keepalive_intvl=30;
sysctl -w net.ipv4.tcp_fin_timeout=30;
#echo 0 > /proc/sys/net/ipv4/tcp_timestamps;
#echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse;
#echo 1 > /proc/sys/net/ipv4/tcp_sack;
#echo 1 > /proc/sys/net/ipv4/tcp_dsack;
#echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle;
#echo 1 > /proc/sys/net/ipv4/tcp_window_scaling;
#echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes;
#echo 30 > /proc/sys/net/ipv4/tcp_keepalive_intvl;
#echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout;
#echo 524288 > /proc/sys/net/core/wmem_max;
#echo 524288 > /proc/sys/net/core/rmem_max;


# increase Linux auto tuning TCP buffer limits
# min, default, and max number of bytes to use
# set max to at least 4MB, or higher if you use very high BDP paths
#echo "524280" > /proc/sys/net/core/rmem_default # default: 
#echo "524280" > /proc/sys/net/core/wmem_default # default: 
# Increase the maximum total TCP buffer-space allocatable
#sysctl -w net.ipv4.tcp_mem="57344 57344 524288";

sysctl -w net.ipv4.tcp_moderate_rcvbuf=1;
#echo 1 > /proc/sys/net/ipv4/tcp_moderate_rcvbuf # enabled by default
# removes an odd behavior in the 2.6 kernels, whereby the kernel stores the slow start threshold for a client between TCP sessions. This can cause undesired results, as a single period of congestion can affect many subsequent connections.

#echo 256960 > /proc/sys/net/core/rmem_default;
#echo 256960 > /proc/sys/net/core/wmem_default;
#echo 4096 16384 404480 > /proc/sys/net/ipv4/tcp_wmem;
#echo 4096 87380 404480 > /proc/sys/net/ipv4/tcp_rmem;
#setprop net.tcp.buffersize.default 4096,87380,256960,4096,16384,256960;
#setprop net.tcp.buffersize.wifi 4095,87380,256960,4096,16384,256960;
#setprop net.tcp.buffersize.umts 4094,87380,256960,4096,16384,256960;
#setprop net.tcp.buffersize.gprs 4094,87380,256960,4096,16384,256960;
#setprop net.tcp.buffersize.edge 4094,87380,256960,4096,16384,256960;


# Increase the tcp-time-wait buckets pool size
#sysctl -w net.ipv4.tcp_max_tw_buckets="1440000"
# default: 180000

# Increase the maximum amount of option memory buffers
#sysctl -w net.core.optmem_max="57344"
# default: 20480

# disable ECN
# enable it - since it's needed for SFB to work properly/optimally
# echo "0" > /proc/sys/net/ipv4/tcp_ecn # default at 2
# explicitly disable it since there's still buggy routers and other stations involved that break networking



# ==============================================================
# ==============================================================
# ==============================================================
# network security related settings
# ==============================================================
# ==============================================================
# ==============================================================




# disables IP source routing (for ipv4)

#for i in /proc/sys/net/ipv4/conf/*; do
#         /bin/echo "0" >  $i/accept_source_route
#done # does not get applied - FIXME

## echo "1" > /proc/sys/net/ipv4/conf/all/accept_source_route ## fix wifi, networking issues # leave at default


#for i in /proc/sys/net/ipv6/conf/*; do
#         /bin/echo "0" >  $i/accept_source_route
#done # does not get applied - FIXME

## echo "1" > /proc/sys/net/ipv6/conf/all/accept_source_route ## fix wifi, networking issues # leave at default

# These commands configure the server to ignore redirects from machines that are listed as
# gateways. Redirect can be used to perform attacks, so we only want to allow them from
# trusted sources:

#for i in /proc/sys/net/ipv4/conf/*; do
#         /bin/echo "1" >  $i/secure_redirects
#done

## echo "0" > /proc/sys/net/ipv4/conf/all/secure_redirects ## fix wifi, networking issues # leave at default

#for i in /proc/sys/net/ipv6/conf/*; do
#         /bin/echo "1" >  $i/secure_redirects
#done

# disables IP redirects (for ipv4)
#for i in /proc/sys/net/ipv4/conf/*; do
#         /bin/echo "0" >  $i/accept_redirects
#done # does not get applied - FIXME

# echo "1" > /proc/sys/net/ipv4/conf/all/accept_redirects ## fix wifi, networking issues # leave at default

#for i in /proc/sys/net/ipv6/conf/*; do
#         /bin/echo "0" >  $i/accept_redirects
#done # does not get applied - FIXME

# echo "1" > /proc/sys/net/ipv6/conf/all/accept_redirects ## fix wifi, networking issues # leave at default

# If this server does not act as a router, it does not have to send redirects, so they can be
# disabled:

#for i in /proc/sys/net/ipv4/conf/*; do
#         /bin/echo "0" >  $i/send_redirects
#done # does not get applied - FIXME

# echo "1" > /proc/sys/net/ipv4/conf/all/send_redirects ## fix wifi, networking issues # # leave at default

# Configure the server to ignore broadcast pings and smurf attacks:
# (smurf-attacks)
sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1;

#echo "1" >  /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts; # default
if [ -e /proc/sys/net/ipv6/icmp_echo_ignore_broadcasts ]
then
	echo "1" >  /proc/sys/net/ipv6/icmp_echo_ignore_broadcasts; # default
fi;

# Ignore all kinds of icmp packets or pings:
sysctl -w net.ipv4.icmp_echo_ignore_all=1;
#echo "1" >  /proc/sys/net/ipv4/icmp_echo_ignore_all; # default: 0

if [ -e /proc/sys/net/ipv6/icmp_echo_ignore_all ]
then
	echo "1" >  /proc/sys/net/ipv6/icmp_echo_ignore_all; # default: 0
fi;
# Some routers send invalid responses to broadcast frames, and each one generates a
# warning that is logged by the kernel. These responses can be ignored:
sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1;
#echo "1" >  /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses;

if [ -e /proc/sys/net/ipv6/icmp_ignore_bogus_error_responses ]
then
	echo "1" >  /proc/sys/net/ipv6/icmp_ignore_bogus_error_responses;
fi;
# When the server is heavily loaded or has many clients with bad connections with high
# latency, it can result in an increase in half-open connections. This is common for Web
# servers, especially when there are a lot of dial-up users. These half-open connections are
# stored in the backlog connections queue. You should set this value to at least 4096. (The
# default is 1024.)
# Setting this value is useful even if your server does not receive this kind of connection,
# because it can still be protected from a DoS (syn-flood) attack.
sysctl -w net.ipv4.tcp_max_syn_backlog=4096;
#echo 4096 > /proc/sys/net/ipv4/tcp_max_syn_backlog; # default: 128

#echo 2 > /proc/sys/net/ipv4/tcp_synack_retries; # default: 5

# Increase the number of outstanding syn requests allowed.
# Note: some people (including myself) have used tcp_syncookies to handle the problem of too many legitimate outstanding SYNs. 
sysctl -w net.core.netdev_max_backlog=2500;

#echo "2500" > /proc/sys/net/core/netdev_max_backlog; # default: 1000
#echo "1" > /proc/sys/net/ipv4/tcp_window_scaling; # default

# While TCP SYN cookies are helpful in protecting the server from syn-flood attacks, both
# denial-of-service (DoS) or distributed denial-of-service (DDoS), they could have an
# adverse effect on performance. We suggest enabling TCP SYN cookies only when there is
# a clear need for them.

# enabling syncookies
sysctl -w net.ipv4.tcp_syncookies=1;

#if [ -e /proc/sys/net/ipv4/tcp_syncookies ]
#then
#	echo "1" >  /proc/sys/net/ipv4/tcp_syncookies; # default
#fi;

#echo "0" >  /proc/sys/net/ipv6/tcp_syncookies;

# We have also learned that window scaling can be an option to enlarge the transfer
# window. However, benchmarks have shown that window scaling is not suited for systems
# experiencing very high network load. Additionally, some network devices do not follow the
# RFC guidelines and could cause window scaling to malfunction. We suggest disabling
# window scaling and manually setting the window sizes.

# sysctl -w net.ipv4.tcp_window_scaling=1
#echo "1" > /proc/sys/net/ipv4/tcp_window_scaling; # default

# log and drop "martian" packets

#for i in /proc/sys/net/ipv4/conf/*; do
#         /bin/echo "1" >  $i/log_martians
#done # does not get applied - FIXME

# echo "1" > /proc/sys/net/ipv4/conf/all/log_martians

# enable reverse path-filtering  [prevents IP-Spoofing]
#for i in /proc/sys/net/ipv4/conf/*; do
#         /bin/echo "1" >  $i/rp_filter
#done # does not get applied - FIXME

#echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter # not enabled by default # uncomment for enhanced security & NOT using VPN (breaks VPN functionality)

# disable  IP dynaddr
sysctl -w net.ipv4.ip_dynaddr=0;
#echo "0" > /proc/sys/net/ipv4/ip_dynaddr; # default




# ==============================================================
# ==============================================================
# ==============================================================
# general phone/RIL-related settings
# ==============================================================







# For HSDPA low throughput
# setprop ro.ril.disable.power.collapse = 1

# =========
# TWEAKS: overall
# =========
setprop ro.telephony.call_ring.delay 1000; # let's minimize the time Android waits until it rings on a call
#setprop ro.ril.disable.power.collapse 0;
setprop pm.sleep_mode 1;
setprop debug.sf.hw 1;  # HARDWARE RENDERING (GPU) 
setprop video.accelerate.hw 1;
setprop debug.performance.tuning 1;
#setprop dalvik.vm.startheapsize 8m;
setprop dalvik.vm.heapsize 48m; # leave that setting to cyanogenmod settings or uncomment it if needed
setprop wifi.supplicant_scan_interval 60; # higher is not recommended, scans while not connected anyway so shouldn't affect while connected
setprop windowsmgr.max_events_per_sec 60; # smoother GUI
#echo 64000 > /proc/sys/kernel/msgmni;

sysctl -w kernel.sem=500,512000,100,2048;
#if [ -e /proc/sys/kernel/sem ];
#then
#	echo 500 512000 100 2048 > /proc/sys/kernel/sem; # allow more semaphores
#fi;
sysctl -w kernel.shmmax=268435456;
#if [ -e /proc/sys/kernel/shmmax ];
#then
#	echo 268435456 > /proc/sys/kernel/shmmax; # Increased max shared memory segment
#fi;
sysctl -w kernel.msgmni=1024;
#if [ -e /proc/sys/kernel/msgmni ];
#then
#	echo 1024 > /proc/sys/kernel/msgmni;
#fi;


#echo 5000 > /proc/sys/kernel/threads-max;
sysctl -w kernel.hung_task_timeout_secs=30;
#echo 30 > /proc/sys/kernel/hung_task_timeout_secs;


#media.stagefright.enable-player=true
#media.stagefright.enable-meta=true
#media.stagefright.enable-scan=true
#media.stagefright.enable-http=true





# ==============================================================
# ==============================================================
# ==============================================================
# TWEAKS: improve handling & reactivity of the CFS cpu scheduler
# ==============================================================
# ==============================================================
# ==============================================================
# =========
# CFS options moved elsewhere!
#if [ -e /proc/sys/kernel/rr_interval ];
#then
	# BFS;
#	echo 6 > /proc/sys/kernel/rr_interval;
#	echo 75 > /proc/sys/kernel/iso_cpu;
#else
	# CFS
	# following 2 settings are to be handled with care - could lead to bootlooping phone or other issues if too low !
	#echo 100000 > /proc/sys/kernel/sched_latency_ns; # 1000000 # 18000000 # 1000000 # 100000 ## new
	#echo 500000 > /proc/sys/kernel/sched_wakeup_granularity_ns	; # 500000 # 3000000 # 25000 # 0 (?)
	#echo 750000 > /proc/sys/kernel/sched_min_granularity_ns; # 1000000 # 1500000 # 100000 # 1000000 ## 750000 (upstream)
	#echo 200000 > /proc/sys/kernel/sched_min_granularity_ns; # 1000000 # 1500000 # 100000 # 1000000 ## 750000 (upstream)
	#echo 400000 > /proc/sys/kernel/sched_latency_ns; # 1000000 # 18000000 # 1000000 # 100000 ## new
	#echo 100000 > /proc/sys/kernel/sched_wakeup_granularity_ns	; # 500000 # 3000000 # 25000 # 0 (?)
	#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; # default: 950000; very small values in sched_rt_runtime_us can result in an unstable system when the runtime is so small 
		      # the system has difficulty making forward progress (the migration thread and kstopmachine both are real-time processes)
#fi;


# =========
# TWEAKS: new scheduler performance settings (test)
# =========

#echo "now disabling GENTLE_FAIR_SLEEPERS"
echo "NO_GENTLE_FAIR_SLEEPERS" > /sys/kernel/debug/sched_features;
#cat /sys/kernel/debug/sched_features
#echo "done"
#echo ""
#echo "now disabling FAIR_SLEEPERS"
echo "NO_NEW_FAIR_SLEEPERS" > /sys/kernel/debug/sched_features;
#cat /sys/kernel/debug/sched_features
#echo "done"
#echo "now disabling NORMALIZED_SLEEPERS"
echo "NO_NORMALIZED_SLEEPER" > /sys/kernel/debug/sched_features;
#cat /sys/kernel/debug/sched_features
#echo "done"
#if [ -e /proc/sys/kernel/sched_features ]
#then
#	echo "24319" > /proc/sys/kernel/sched_features;
#fi;

# =========
# TWEAKS: raise throughput & responsiveness [reboots & instability ?!]
# =========

#echo "now disabling FAIR_SLEEPERS"
#echo "NO_NEW_FAIR_SLEEPERS" > /sys/kernel/debug/sched_features
#cat /sys/kernel/debug/sched_features
#echo "done"
#echo ""
#echo "now disabling START_DEBIT"
#echo "NO_START_DEBIT" > /sys/kernel/debug/sched_features
#cat /sys/kernel/debug/sched_features
#echo "done"
#echo ""
#echo "now disabling LB_BIAS"
#echo "NO_LB_BIAS" > /sys/kernel/debug/sched_features
#cat /sys/kernel/debug/sched_features
#echo "done"
#echo ""

#echo "now disabling NEXT_BUDDY"
#echo "NO_NEXT_BUDDY" > /sys/kernel/debug/sched_features
#cat /sys/kernel/debug/sched_features
#echo "done"
#echo ""

#echo "now enabling sched_child_runs_first"
#echo "1" > /proc/sys/kernel/sched_child_runs_first
#cat /proc/sys/kernel/sched_child_runs_first
#echo "done"
#echo ""


# =========
# TWEAKS: low-latency features [issues with auto-rotation & stuff]
# =========

#echo "now enabling the low-latency functionality of CFS provided by"
#echo "Mathieu Desnoyers & Peter Zijlstra, sponsored by Nokia"

#for opt in DYN_MIN_VRUNTIME \
#        NO_FAIR_SLEEPERS FAIR_SLEEPERS_INTERACTIVE FAIR_SLEEPERS_TIMER \
#        INTERACTIVE TIMER \
#        INTERACTIVE_FORK_EXPEDITED TIMER_FORK_EXPEDITED;
#do echo $opt > /sys/kernel/debug/sched_features;
#done

#echo "low-latency for CFS activated ..."
#echo "done"



# ==============================================================
# ==============================================================
# ==============================================================
# remove lag when answering phone calls
# ==============================================================
# ==============================================================
# ==============================================================
# =========
#MAX_PHONE() 
#{
#pidphone=`pidof com.android.phone`;
#if [ $pidphone ]; # Wait for com.android.phone to start;
#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;
##	log -p i -t SSSwitch_v0.8 "*** MAX phone *** set oom_adj(-17) and nice(-20) for com.android.phone";
#	exit;
#else
#	sleep 5;
#	MAX_PHONE;
#fi;
#}



# =========
# Background process to optimize dialer process
# =========
#(while [ 1 ];
#do
#	sleep 10;
#	MAX_PHONE;
#done &);




# ==============================================================
# ==============================================================
# ==============================================================
# renicing kswapd (useful on non-swap phones)
# ==============================================================
# ==============================================================
# ==============================================================
# =========
#KSWAPD_RENICE() 
#{
#pidkswapd=`pidof kswapd0`;
#if [ $pidkswapd ]; # Wait for kswapd to be available;
#then
#	renice 19 $pidkswapd; # set kswapd lowest nice level possible;
#	exit;
#else
#	sleep 5;
#	KSWAPD_RENICE;
#fi;
#}



# =========
# Background process to keep priority of kwapd low
# =========
#(while [ 1 ];
#do
#	sleep 10;
#	KSWAPD_RENICE;
#done &);






# =========
# Changelog
# =========


# sdcard reading fix by brainmaster
# moved CFS cpu scheduler tweaks from 90screenstate_scaling to here; tweaks to read & write
# trying out CFS scheduler with lower refresh rate for more throughput & performance [fine]
# enable low-latency features and allow higher throughput
# disable readhead for other partitions (overhead) but keep write improvements enabled
# less tight scheduler timings
# fix disappearing data connection on GSM phones
# corrected paths for write tweak (thanks nexxx85 !)
# V21: stricter scheduler timings to make the phone operation smoother [needs stability & function testing]
# V22: fixed network security settings (some did not get applied)
# V23: disabled the ICMP parts
# V24: add notes for VPN users:
#      set 'echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter'
#      to
#      'echo "0" > /proc/sys/net/ipv4/conf/all/rp_filter'
# V27: re-enable scheduler settings @ Quorra pre-11_test3; false reports about phone reboots
# V28: set "deadline" as default i/o scheduler
# V29: enable read_ahead_kb optimization globally (testing)
# V30: keep stock scheduler settings
# V31: re-enable ICMP security measures
# V32: improved approach of the SD-card (readhaead) speed-fix; implementation by Darkyy (included in DarkyROM 10.1)
# V33: switch to cfq for Samsung GB ROMs (due to latency and lack of writeback-improvements [can't be applied - leads to reboot / non-boot])
# V34: fix some minor typos
# V35: moved some tweaks from the screenstate_scaling script here (for Samsung ROMs)
# V36: moved vfs_cache_pressure here
# V37: added memory tweaks by Juwe11
# V38: switch to deadline for CM7/MIUI base; swappiness at 0 (for now - no zram yet)
# V39: do not log martians (no dmesg / printk so no use for it)
# V40: add some scheduler tweaks from upstream
# V41: tweak the deadline ioscheduler some more (fifo_batch)
# V42: moved changelog to bottom to make things more clear
# V43: add some background processes to make the phone more reliable and responsive (phone dialer & kswapd0) [testing]
# V44: added some descriptions to make it hopefully more clear and easy to use
# V45: disable kswapd and phone background processes
# V46: set the wifi scanning interval back to 60 (180 was too much, if it doesn not scan often enough got to -> settings -> wireless & network -> wifi settings -> and it will scan immediately or use a wifi widget)
# V47: just leave the trouble-causing network-settings commented out and thus at default, might work better that way
# V48: made the script BFS & CFS cpu scheduler aware
# V49: some more scheduler performance settings (test)
# V50: disabling iostats to reduce overhead (thanks to kodos96 !)
# V51: some readahead tweaks - thanks to corgar !
# V52: inherited stuff from the screenstate_scaling script
# V53: more tweaks in several areas
# V54: some more tweaks & explanations
# V55: commented out a superfluous definition/occurence of vfs_cache_pressure - thanks to pikachu01 !
# V56: fixed a typo in NO_NORMALIZED_SLEEPERS;  no_new_fair_sleepers and no_normalized_sleepers are rather pointless since not available in the kernel but still setting them - just in case ;)
# V57: enable some more network tweaks (for all network types), smoother GUI, testing with sleep mode
# V58: fixed 2 typos in the agps tweaks - thanks to DerTeufel for spotting those !
# V59: (only cosmetic change in script version) commented out ro.ril.disable.power.collapse & pm.sleep_mode - troubleshooting attempt against SODs
# V60: disable scheduler optimizations [stability testing]
# V61: max_events_per_sec back to 60, wifi scanning to 30, leave semaphores at default number
# V62: max_events_per_sec set to 76 (testing for smoother GUI), bump vfs_cache_pressure up to 50
# V63: corrected a few proc -> /proc + ro.ril.enable.gea typos - thanks to DerTeufel !
# V64: re-enable scheduler tweaks (should be stable), reduce nr_requests & quantum
# V65: added some stuff from crunchengine tweak script & fixed some typos - thanks to Pikachu01
# V66: re-enable disabled power-collapse & sleep_mode


