[Sony Xperia P, U, Sola, Go] Garcia98:
HOW TOs

HOW TO PLAY WITH THIS KERNEL

Terminal emulator or ADB shell is needed.

If any command outputs 'Permission denied', you need su permission.

`???` stands for the number to input.

Sometimes you will need to mount and unmount debugfs partition:

For mounting it:

mount -t debugfs debugfs /d

For unmounting it:

umount /d

Boot time:

To check boot time:

cat /sys/boottime/kernel

CPU governors:

Performance, Interactive (default), Powersave, Userspace, Conservative, InteractiveQ, PegasusQ, HotPlug, OnDemandQ, OnDemand, AbyssPlug, LulzactiveQ, SmartAssv2

- OnDemand has been patched with cpu idle detection.

- Most of custom governors are based on ondemand/interactive.

- OndemandQ/InteractiveQ will hotplug cpu when screen turns off only.

- If you care about the battery life time, choose HotPlug. It hotplugs cpu frequently.

- Interactive updated to linux-android-3.4 (recommended).

- LulzactiveQ, will hotplug CPU1.

I/O schedulers:

SIO, SIO-Plus, VR, BFQ, CFQ, NO-OP, ZEN, ROW, Deadline

- Default IO scheduler: SIO-Plus

- SIO/ROW/SIO-Plus recommended!

FRandom module:

insmod /system/lib/modules/frandom.ko
chmod 0666 /dev/frandom
chmod 0666 /dev/erandom
mv /dev/random /dev/random.orig
mv /dev/urandom /dev/urandom.orig
ln -s /dev/frandom /dev/random
ln -s /dev/frandom /dev/urandom

Deepest sleep state:

Stock: 3 Default: 3

Deepest supported is 5.

Mount debugfs

To change deepest sleep state:

echo 5 > /d/cpuidle/deepest_state

- HotPlug governors works badly with 5.

- OnDemand works well with 5.

- Please note that it won’t increase the using time but standby time.

- You can add an init.d script to tweak it if you want.

To check the cpuidle state:

cat /d/cpuidle/stats

Management of not killable processes:

This feature allows to define processes and system processes white-lists filled with the preferred process names and to not be killed by lowmemorykiller, unless it is absolutely necessary.

This feature exposes four new lowmemorykiller parameters:

- donotkill_proc, is the flag to enable / disable this feature for the processes chosen by the user

- donotkill_sysproc, is the flag to enable / disable this feature for the system processes chosen by the user

- donotkill_proc_names, is the list of process names (comma separated) chosen by the user to be preserved from killing

- donotkill_sysproc_names, is the list of user system process names (comma separated) chosen by the user to be preserved from killing

When the lowmemorykiller needs to free ram, it will first kill the processes not included inside the two process name lists chosen by the user.

If there are no more standard killable processes, then it will be necessary to kill one of the processes included inside one of the two white-lists, to prevent system hangs, slowdowns, etc.

How to customize the white lists of processes to preserve from killing:

- Run these commands if you want to enable the feature

# To enable this feature for the processes chosen by the user
echo 1 > /sys/module/lowmemorykiller/parameters/donotkill_proc
# To enable this feature for the system processes chosen by the user
echo 1 > /sys/module/lowmemorykiller/parameters/donotkill_sysproc

- Run these commands if you want to disable the feature

# To disable this feature for the processes chosen by the user
echo 0 > /sys/module/lowmemorykiller/parameters/donotkill_proc
# To disable this feature for the system processes chosen by the user
echo 0 > /sys/module/lowmemorykiller/parameters/donotkill_sysproc

- Run this command if you want to add, for example, Trebuchet Launcher (CM default launcher) and the default keyboard to the processes white list

echo "com.cyanogenmod.trebuchet,android.inputmethod.latin" > /sys/module/lowmemorykiller/parameters/donotkill_proc_names

- Run this command if you want to add, for example, the system process, the phone process and DSP Manager to the system processes white list

echo "android.process.acore,com.android.phone,com.bel.android.dspmanager" > /sys/module/lowmemorykiller/parameters/donotkill_sysproc_names

zRAM:

zRAM is optimized for Android. It is not lazy anymore. Recommended zRAM instead of SWAP.

Using zRAM will take a little CPU, because it needs to compress/decompress memory.

Recommended compressing about 18% of RAM, about 100MB.

Setup disk size first: (example: 200MB)

echo $((200 * 1024 * 1024)) > /sys/block/zram0/disksize

- Larger size more RAM will be compressed.

- Too large size might make phone lag

To enable:

mkswap /dev/block/zram0
swapon /dev/block/zram0

To check how many does it use:

cat /sys/block/zram0/num_reads
cat /sys/block/zram0/num_writes
cat /proc/meminfo | grep swap

- We can get other info in its sysfs

Swap:

Using a file as swap RAM: (Create a continuity file first)

su
cd /cache
dd if=/dev/zero of=swapfile bs=1024 count=81920
mkswap swapfile
swapon swapfile

Then we will have 80MB of swap RAM.

Cycle Charging Control:

Similar to BLX by Ezekeel. It can be used to limit the battery charging level.

Example: Limit the battery level at 70% ~ 75%

Enable:

echo on > /sys/kernel/abb-fg/fg_cyc

Disable:

echo off > /sys/kernel/abb-fg/fg_cyc

Discharging threshold (battery level %):

echo dischar=75 > /sys/kernel/abb-fg/fg_cyc

Recharging threshold:

echo dischar=70 > /sys/kernel/abb-fg/fg_cyc

Real charged notification:

Well, please let me call it notification.

To be honest, it needs to check manually:

cat /sys/kernel/abb-chargalg/eoc_status

- You can use Root Browser to view these files in /sys/kernel/abb-chargalg

- When it says "First eoc reached", then the UI should show you charged 100%, but it is not the real full charged.

- When it says the real EOC reached, unplug the charger.

POnKey Emulator:

This is the software emulator of power key.

To turn off screen: ( 20 < value(ms) < 520 )

echo 100 > /sys/kernel/abb-ponkey/emulator

To active the power menu: ( 520 < value(ms) < ∞)

echo 800 > /sys/kernel/abb-ponkey/emulator

ABBamp Audio:

Please note that listening to too high volume music over 1 hour or more can damage your ears.

Too high volume can make your external speakers/headset overload or damage them.

First, why is it called `AMP`?

Because most of our tweaks are about gain(volume)

Our codec is simple, It doesn't have any hardware EQ (although i want...)

ABBamp sysfs entries are in:

/sys/kernel/abb-codec

- Use Root Browser to view this folder,there are lots files

Tweaks will take effects immediately!

Most tweaks will accept inputs like "on", "off" (no quotes)...

So, say "on" to enable this tweak, then this tweak will apply the value stored/inputed

View (cat) these files, most of them will give you useful information about this tweak.

They will show you the volume in dB of gain

`cd` to /sys/kernel/abb-codec first then do echos, will be more convenient.

AnaGain3 (Headset analog gain path):

Enable tweaks:

echo on > /sys/kernel/abb-codec/anagain3

Disable tweaks:

echo off > /sys/kernel/abb-codec/anagain3

Gain control: (min:0 ,max: 15) Lower value,higher volume (default: 0[+4dB])

echo left=?? > /sys/kernel/abb-codec/anagain3
echo right=?? > /sys/kernel/abb-codec/anagain3

Write both left and right channels:

echo gain=?? > /sys/kernel/abb-codec/anagain3

HsLDigGain (Headset left digital path gain):

Enable tweaks:

echo on > /sys/kernel/abb-codec/hsldiggain

Disable tweaks:

echo off > /sys/kernel/abb-codec/hsldiggain

Gain control: (min:0 ,max: 15) Lower value,higher volume (default: 4[+4dB])

echo gain=?? > /sys/kernel/abb-codec/hsldiggain

HsRDigGain (Headset right digital path gain):

Enable tweaks:

echo on > /sys/kernel/abb-codec/hsrdiggain

Disable tweaks:

echo off > /sys/kernel/abb-codec/hsrdiggain

Gain control: (min:0 ,max: 15) Lower value,higher volume (default: 4[+4dB])

echo gain=?? > /sys/kernel/abb-codec/hsrdiggain

Headset Volume Table:

value | volume

0.......+8dB (maximum)

1.......+7dB

2.......+6dB

3.......+5dB

4.......+4dB (tweaks default)

5.......+3dB

6.......+2dB

7.......+1dB

8.......+0dB (device default)

>=9....mute

- If set up digital path +4dB, analog gain +4dB, the result will get over +8dB

HsLowPow (Headset driver low power mode):

This lowpow mode is enabled by device normally.

If you want high performance audio instead of LPA(low power audio) you can disable it.

Enable tweaks:

echo on > /sys/kernel/abb-codec/hslowpow

Disable tweaks:

echo off > /sys/kernel/abb-codec/hslowpow

To tweak the mode (0: disable LP mode, 1: enable LP mode)

echo mode=? > /sys/kernel/abb-codec/hslowpow

HsDacLowPow (Headset DAC low power mode):

DAC is Digital-to-Analong Converter.

This lowpow mode is enabled by device normally.

Enable tweaks:

echo on > /sys/kernel/abb-codec/hsdaclowpow

Disable tweaks:

echo off > /sys/kernel/abb-codec/hsdaclowpow

To tweak the mode (0: disable LP mode, 1: enable LP mode)

echo mode=? > /sys/kernel/abb-codec/hsdaclowpow

HsHpEn (Headset high pass filter):

This high pass filter is disabled by device normally.

Enable this can reduce some sub-noise of audio.

Enable tweaks:

echo on > /sys/kernel/abb-codec/hshpen

Disable tweaks:

echo off > /sys/kernel/abb-codec/hshpen

To tweak the mode (0: disable highpass filter, 1: enable highpass filter)

echo mode=? > /sys/kernel/abb-codec/hshepen

Besides, the file anaconf1 will shows you the status of LPA

ClassDHPG (ClassD high-pass gain):

ClassD is a kind of amplifier.

According to the documents, our ClassD only relate to Handsfree(speaker).

This can increase the high frequencies sound of speaker

Enable tweaks:

echo on > /sys/kernel/abb-codec/classdhpg

Disable tweaks:

echo off > /sys/kernel/abb-codec/classdhgp

Gain control: (min:0 ,max: 10) higher value,higher gain (default: 10[Max gain])

echo gain=?? > /sys/kernel/abb-codec/classdhpg

ClassDDithWGain:

Gain control for the white component of dithering filter

Enable tweaks:

echo on > /sys/kernel/abb-codec/classdwg

Disable tweaks:

echo off > /sys/kernel/abb-codec/classdwp

Gain control: (min:0 ,max: 10) higher value,higher gain (default: 10[Max gain])

echo gain=?? > /sys/kernel/abb-codec/classdwg

ADDigGain2:

This is the audio path of mic2(phone mic, not headset mic)

This tweak will enable automatically when mic2 is enabled by device

Enable tweaks:

echo on > /sys/kernel/abb-codec/addiggain2

Disable tweaks:

echo off > /sys/kernel/abb-codec/addiggain2

Gain control: (min:0 ,max: 63) lower value, higher gain (default: [+6dB], max: 00[+31dB])

echo gain=?? > /sys/kernel/abb-codec/addiggain2

EarDigGain:

This is the digital gain of earpiece

Enable tweaks:

echo on > /sys/kernel/abb-codec/eardiggain

Disable tweaks:

echo off > /sys/kernel/abb-codec/eardiggain

Gain control: (min:0 ,max: 15) lower value,higher gain (default: 4[+4dB])

echo gain=?? > /sys/kernel/abb-codec/classdwg

- It uses the same path of HsLDigGain,please check the volume table of HsLDigGain

- +8 dB might crash the sound of earpiece

ShortCirConf:

This is a misc tweak
View shortcir this file first

[7] EnShortPWD
0: Automatic switch off on short circuit detection is disabled
1: Automatic switch off on short circuit detection is enabled
[6] EarShortDis
0: Short circuit detection on Ear driver enabled
1: Short circuit detection on Ear driver disabled
[5] HsShortDis
0: Short circuit detection on HsL and HsR drivers enabled
1: Short circuit detection on HsL and HsR drivers disabled
[4] HsPullDEn
0: HsL and HsR outputs are in high impedance
1: HsL and HsR outputs are pulled down to ground
[2] HsOscEn (ABBamp enables it by default)
0: The HS drivers use the system clock
1: The HS drivers use a local oscillator (system clock absent: analog path only)
[1] HsFadDis
0: All intermediate steps are applied between two programmed gains (fading)
1: Gain on HS is applied immediately
[0] HsZcdDis
0: HS gain changes on signal zero cross (unless time-out occurs)
1: HS gain is changed without zero cross control

[CODE]echo ?? ?? > /sys/kernel/abb-codec/shortcir

- The first ?? the slot of each option,the second ?? stands for the value to write to this slot

- View shortcir this file,you will get it[/CODE]

AnaConf4:

This interface controls the enables of analog path

We can use it to disable Speaker in kernel level.

So that you don't have to use the "mute all sound" in system settings,

Because, "mute all sound" will also mute Earpiece, which is inconvenient for us in calls.

Command format: Check anaconf4 first, This interface is a bit different from others:

echo [Index] [Disable?] > anaconf4

To Disable Speaker:

echo 5 1 > anaconf4

To Enable Speaker:

echo 5 0 > anaconf4

Headset Charge Pump:

echo 0 > chargepump to use fixed 1.8V supply.
echo 1 > chargepump to use dynamic voltage supply, lower power cost.

Lower-power Audio Mode:

echo on > lpa_mode to enable LPA mode
echo vape=0x?? > lpa_mode to adjust Vape voltage used in LPA mode

Experts!:

This method can work on any ab850x codec platform!

Mount debugfs

cd /d/asoc/U8500-card/ab8500-codec.0

Play music, reduce the volume.

Now we are going to edit the codec registers.

echo REG VAL > codec_reg

E.G:

AnaGain3:

echo 0x16 0x00 > codec_reg

HsDigGain: (left/right channel)

echo 0x4F 0x00 > codec_reg
echo 0x50 0x00 > codec_reg

Disable all lowpow mode:

echo 0x04 0x00 > codec_reg

- These hacks will restore when codec power off.

Camera LED Flash:

Turn on torch with more brightness, turning this on for a long time will heat up your device, be careful!

Enable/Disable:

echo 1/0 > /sys/devices/platform/nmk-i2c.2/i2c-2/2-0053/torch_enable
echo 149600 > /sys/devices/platform/nmk-i2c.2/i2c-2/2-0053/torch_current

FSync control:

Get current status:

cat /sys/kernel/fsync/mode

FSYNC modes:

0: fsync on

1: fsync off

2: fsync dyn

Disable FSYNC:

echo 1 > /sys/kernel/fsync/mode

Disabling fsync can improve I/O performance, but it can make the data which hasn't been written lose when a sudden power cut occurs.

Enable Dynamic FSYNC:

echo 2 > /sys/kernel/fsync/mode

- Dynamic fsync will sync all buffers when screen turns off.

- If there is a heavy I/O load, the screen might get stuck for seconds.

Mali GPU:

Mali debug level:

Disabling can speed up a bit

echo 0 > /sys/module/mali/parameters/mali_debug_level

- Higher level, more messages will be printed in dmesg, system will slow down

Mali L2 max reads control: (Stock:28kb,Default:48kb(max))

echo xx > /sys/module/mali/parameters/mali_l2_max_read

- Some values will slow down graphics

- If not sure, keep default

Mali PM sampling rate: (Default: 1000ms)

echo xx > /sys/module/mali/parameters/mali_pm_sampling_rate

Mali PP scheduler tweaks: (Default: disable)

echo 1 > /sys/module/mali/parameters/mali_pp_scheduler_balance_jobs

- Enabling this, some places will over ahead, choose by yourself

Mali Utilization sampling rate: (Stock:500ms, Default:1000ms)

How often report a mali utilization.

echo xxx > /sys/module/mali/parameters/mali_utilization_sampling_rate

- Keep this default if unsure.

Mali utilization control:

(Default: low_to_high 192 high_to_low 64)

Our driver will report a mali utilization frequently.

This utilization(range: 0~255) means the load of mali.

If utilization is bigger than low_to_high, driver will request higher hardware performance(highest APE/DDR OPP).

If utilization is smaller than high_to_low, the driver will store the requested OPP(uses low OPP).

OPP can be understood as freq simply.

To check mali utilization values:

echo 5 > /sys/module/mali/parameters/mali_debug_level
cat /proc/kmsg | grep -i utilization

When it says SIGNAL_HIGH, it will request highest OPP.

When it says SIGNAL_LOW, it will request lowest OPP.

Press Ctrl+C to stop printing.

You can reduce low_to_high to trigger higher OPP requirement.

For smoothness and less powersaving:

Set low_to_high between 100-192.

echo 120 > mali_utilization_low_to_high

Mali max preemptive allocated max memory size:

Default is 16mb(16*1024*1024), bigger max size more throughput.

But when this value is too big, no more throughput.

For example: 48mb = 48*1024*1024

echo 50331648 > /sys/module/mali/parameters/pre_allocated_memory_size_max

Mali OS Kernel memory allocation order:

The lower value, the higher preference of allocating OS memory.

The default value is 6, I decreased it to 9 to fix OS memory allocation failure.

If you feel laggy, try 6 (default by driver)

echo 6 > /sys/module/mali/parameters/mali_oskmem_allocorder

TCP congestions:

Supported:

cubic(default), westwood, highspeed, vegas, veno, yeah

To check all the available options:

busybox sysctl net.ipv4.tcp_available_congestion_control

To change to other option:

busybox sysctl -w net.ipv4.tcp_congestion_control=YOU_WANT_TO

Latency - Download - Upload

cubic:

1st run: 15ms - 10,75Mbps - 7,82Mbps

2nd run: 14ms - 10,84Mbps - 8,06Mbps

westwood:

1st run: 11ms - 17,65Mbps - 8,30Mbps

2nd run: 13ms - 13,28Mbps - 8,29Mbps

highspeed:

1st run: 13ms - 10,76Mbps - 7,94Mbps

2nd run: 16ms - 14,42Mbps - 8,52Mbps

vegas:

1st run: 14ms - 8,49Mbps - 6,62Mbps

2nd run: 14ms - 12,00Mbps - 7,07Mbps

veno:

1st run: 13ms - 9,58Mbps - 8,13Mbps

2nd run: 13ms - 8,50Mbps - 7,64Mbps

yeah:

1st run: 14ms - 13,37Mbps - 8,28Mbps

2nd run: 17ms - 13,89Mbps - 8,14Mbps

- In fact, every congestion is designed for different environments.

- Google to learn more!

EGL Driver:

To use Mali hardware egl driver only:

Edit /system/lib/egl.cfg

0 0 android

0 1 mali

To

0 0 mali

Then remove libGLES_android.so

- Recommend to backup these files

- In case it cannot boot,use TWRP file manager to recover changes

Logcat:

Create a new file(empty file) named logger in /data

When this file exists, kernel will load logger.ko for you automatically

Miscellaneous:

To refresh battery stats:

echo 1 > /sys/kernel/abb-fg/fg_refresh

Almost all tweaks will be restored to default after reboots.

So you can make your tweaks as init.d scripts or make scripts with SManager app to apply them at boot.