[KERNEL]Huawei Ascend P6S / P7 K-Tuned Kernel

Search This thread

Kostyan_nsk

Senior Member
Nov 12, 2014
344
323
Ulan-Ude
Ascend P6S / P7 K-Tuned Kernel
Hello! Finally I decided to make a new thread for kernel with description of all features.
So, here they are:

  • CPU Governors:
    • PegasusQ
    • AbyssplugV2
    • Optdemand
    • Interactive
    • Impulse
    • Pwrctrl_hotplug default

  • I/O Schedulers:
    • CFQ
    • Deadline
    • ROW
    • Noop
    • FIOPS default

  • TCP Congestion:
    • HTCP
    • Reno
    • BIC
    • CUBIC
    • Westwood+ default

  • Upstreamed to 3.0.101 version
  • SELinux permissive for 5.1.1
  • LZ4 kernel & ramdisk compression
  • Backport random from kernel 4.0 branch
  • ExFAT version updated from 1.2.5 to 1.2.9
  • F2FS support
  • Fixed 5.1.1 GPU performance regression bug
  • USB Fast Charge
  • Intelli-Plug
  • Asynchronous Fsync
  • CPU overclock: enabled 1996MHz CPU frequency and 1795MHz for P6S
  • CPU undervolting
  • GPU overclock: enabled 700MHz GPU frequency for P6S
  • GPU undervolting
  • Adjusted stock CPU & GPU governor thresholds for better performance
  • DoubleTap2Wake
  • Sweep2Sleep
  • init.d support
  • set_immutable binary removed from ramdisk for 4.4.2
  • Speed up system startup

Now more detail about some features:
Governors
PegasusQ
Governor from Samsung with hotplug support. Perhaps, the most tunable and flexible one.
Parameters description:

  • sampling_rate: the interval with which governor will be carried out. Less value - better responsiveness, but at the same time, more load for CPU by governor itself.
  • sampling_down_factor: amount of iterations governor will stay at highest frequency before go down.
  • up_threshold: load threshold in % above which CPU frequency will be increased.
  • up_threshold_at_min_freq, freq_for_responsiveness: at frequency lower than freq_for_responsiveness will be used up_threshold_at_min_freq threshold - provided for better responsiveness.
  • down_threshold: load threshold in % below which CPU frequency will be decreased.
  • freq_step: step of frequency encrease in % from maximum frequency.
  • hotplug_freq_*: high and low frequency thresholds for making decision about hotplug of each core.
    For clarity, it looks like this:
    Code:
    static int hotplug_freq[4][2] = {
        {0,      1596000},
        {208000, 1795000},
        {416000, 1996000},
        {624000, 0}
    };
    In this array left column is frequency at which core will be disabled; right column - frequency at which will be enabled next core.
  • hotplug_rq_*: analogous parameters set (array), defining queue task length for making decision about hotplug of each core.
    Code:
    static int hotplug_rq[4][2] = {{0, 50}, {50, 100}, {100, 150}, {150, 0}};
    For example, second core will be disabled after reaching 208MHz frequency and amount of tasks must be less than 50;
    third core will be enabled after reaching 1795MHz frequency by second core and amount of tasks more than 100.
  • cpu_up_rate: amount of governor iterations cpu should stay at defined frequency for enabling next core.
  • cpu_down_rate: amount of governor iterations cpu should stay at defined frequency for disabling last active core.
  • down_differential: defines load in % which must be less than up_threshold to go to lower frequency.
  • hotplug_lock: lock amount of active cores.
  • min_cpu_lock: limits min value of enabled cores.
  • max_cpu_lock: limits max value of enabled cores.
  • up_nr_cpus: defines how many cores to enable at a time.
AbyssplugV2
Based on Conservative, has hotplug support. Pluses: pretty simple, hence doesn't load CPU by himself. Frequency increases sequentally, after reaching max frequency - enables next core. And vice versa. Minuses: often enables / disables cores (what in itself is energy intensive).
Distinctive parameters:

  • up_threshold_hotplug: load threshold in % above which will be enabled next core.
  • down_threshold_hotplug: load threshold in % below which will be disabled last active core.
  • boost: load threshold above which frequency will be increased through step (for exaample., from 208000 immediately on 624000)
Optdemand
Governor by Hisilicon, based on Ondemand. Backported from Honor 4X/4C. Distinctive feature is each frequency has its own thresholds to go to higher or lower frequency.
Distinctive parameters:

  • go_hispeed_load, hispeed_freq: after exceeding go_hispeed_load threshold, CPU goes immediately to hispeed_freq frequency.
  • up_thresholds, down_thresholds: above and below load thresholds for each frequency. For clarity:
    Code:
    static unsigned int operating_points[7][3] = {
        /* kHz   up_threshold   down_threshold */
        {208000,    60,    0},
        {416000,    60,    30},
        {624000,    70,    40},
        {798000,    80,    50},
        {1196000,    85,    50},
        {1596000,    90,    60},
        {1795000,    95,    70},
        {1996000,    100,    80},
    };
    For example, for frequency 624MHz, if load will go below 30%, will be calculated new lower frequency according to new load value; if load will go above 70% - frequency will be increased.
  • boost: frequency will be increased to hispeed_freq
  • bostpulse_duration: duration of boost in microseconds.
Interactive
Google's gold standard governor. Updated to 3.4 kernel branch
Impulse
Based on Interactive governor. Good responsiveness.
USB Fast Charge
Increases charge current when connected to USB. It has sense only when connected to USB 3.0
Can be enabled by writing "1" into /sys/kernel/fast_charge/force_fast_charge file or by third party applications.
Disabled by default
Intelli-Plug
Hotplug driver for governors not supporting hotplug.
Activated and deactivated automatically depending on chosen governor.
Parameters are in /sys/module/intelli_plug/parameters

  • nr_possible_cores: max cores affected by driver.
  • nr_run_profile_sel: has several profiles :
    • 0: balance default
    • 1: performance
    • 2: conservative
    • 3: eco
    • 4: eco extreme
  • screen_off_max: max frequency at screen off.
  • touch_boost_active: enables additional core at screen touch disabled by default
CPU undervolting
Undervolting values can be set for each frequency individually. Regulator has step 8mV starting from 700mV. I've got such stable values:
Screenshot_2016-04-02-23-02-41.png
But you should start from higher values. I've made a test: CPU locked at frequency 1795MHz, RAR creates archive with 4 threads in 10 minutes. Average CPU temperature during this time was 56.124 degrees, with undervolting average temperature became 51.119 degrees. I.e. average temperature became lower for 5 degrees which means less power consumption.
Comparative graph:
undervolt.png
GPU undervolting
Since I couldn't find any common used sysfs interface and applications supporting it, you can make it using script (see init.d spoiler).
My stable values are:
Code:
160: 860  -> 700
266: 860  -> 732
355: 876  -> 764
533: 956  -> 860
700: 1052 -> 924
But most probable, you will have troubles with such values, try to find suitable for your own.

3DMark Ice Storm Extreme showed average temperature decrease from 61.587 to 55.502 degrees.
Comparative grapth:
undervolt_gpu.png
DoubleTap2Wake
Screen on by double tap on it. Has two parameters in /sys/android_touch

  • doubletap2wake: enables dt2w. Possible values are:
    • 0: disabled default
    • 1: active at all screen
    • 2: active at top half
    • 3: active at bottom half
    • 4: active at navbar
  • dt2w_duration: Since I couldn't implement waking up device from deep sleep by irq from touch panel, so kernel doesn't go to deep sleep when dt2w is active, I added parameter defining how long dt2w stays active after screen off. After this duration dt2w becomes inactive and kernel can go into deep sleep.
Sweep2Sleep
Swipe on navbar for screen off. Can be enabled by writing "1" into /sys/android_touch/sweep2sleep file. Disabled by default.

s2s_length: swipe length in dots. By default, equal to 25% of screen width.
init.d
For executing scripts at startup, put them in /system/etc/init.d folder and set permissions to 0755
Several scripts examples (doubletap2wake, sweep2sleep, fast_charge, gpu_undervolting): View attachment scripts.rar
Scores
Screenshot_2016-04-08-19-12-11.png

For correct governors switching I recommend to use Kernel Adiutor
It also lets to manage IO schedulers, TCP congestion, fast charge, CPU undervolting.

Requirements:

  • Unlocked bootloader
  • TWRP
Installation:
Just install zip-archive from TWRP

Download:
View attachment K-Tuned_kernel-4.4.2.zip
View attachment K-Tuned_kernel-5.1.1.zip

Source: Github

Updates:
31.10.2016
CVE-2016-5195 "Dirty COW" fixed.
Now CPU voltage values take effect right after frequency changes.

30.07.2016
Adjusted voltages for overclocked frequencies due to cases of appearing stability issues on some devices.

15.05.2016
Removed GPU undervolting applying at booting due to some users had stability issues. Now for GPU undervolting use init.d script individually.
Adjusted governor thresholds.
Reduced min online CPUs from 3 to 2 when screen is on for stock pwrctrl_hotplug governor.


Regards,
Kostyan_nsk
 
Last edited:

kye04

Senior Member
May 6, 2012
227
30
What is your preferred setting?
Mine:
GOVERNOR: Impulse
CPU : maximum frequency 1596mhx
I/O : fiops with 128kb readahead
INTELLIPLUG :disabled

I discovered that with Intelliplug enabled, my phone has some glitches.....
With the settings above i get 50-60% battery when i go home, 8-10 pm

What are your settings ?
 

Kostyan_nsk

Senior Member
Nov 12, 2014
344
323
Ulan-Ude
@roxkiller, just set "Apply on boot" in Kernel Adiutor after limiting max. cpu frequency and enable Kernel Adiutor in Startup Manager, so KA will aplly your settings after reboot.
And btw, if you didn't notice, cpu voltage at 1996MHz is the same as at 1795MHz, therefore I doubt that power consumption will noticably increase relatively to 1795Mhz frequency...
 
  • Like
Reactions: Alivkin

kye04

Senior Member
May 6, 2012
227
30
I have set the cpu undervolting according to your recommandation. Today , i received a message on whattsap , when i picked up the phone to read it, the phone was already rebooting. It enter the system but saying no root available !!!
Rebooted the phone again, all ok.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 13
    Ascend P6S / P7 K-Tuned Kernel
    Hello! Finally I decided to make a new thread for kernel with description of all features.
    So, here they are:

    • CPU Governors:
      • PegasusQ
      • AbyssplugV2
      • Optdemand
      • Interactive
      • Impulse
      • Pwrctrl_hotplug default

    • I/O Schedulers:
      • CFQ
      • Deadline
      • ROW
      • Noop
      • FIOPS default

    • TCP Congestion:
      • HTCP
      • Reno
      • BIC
      • CUBIC
      • Westwood+ default

    • Upstreamed to 3.0.101 version
    • SELinux permissive for 5.1.1
    • LZ4 kernel & ramdisk compression
    • Backport random from kernel 4.0 branch
    • ExFAT version updated from 1.2.5 to 1.2.9
    • F2FS support
    • Fixed 5.1.1 GPU performance regression bug
    • USB Fast Charge
    • Intelli-Plug
    • Asynchronous Fsync
    • CPU overclock: enabled 1996MHz CPU frequency and 1795MHz for P6S
    • CPU undervolting
    • GPU overclock: enabled 700MHz GPU frequency for P6S
    • GPU undervolting
    • Adjusted stock CPU & GPU governor thresholds for better performance
    • DoubleTap2Wake
    • Sweep2Sleep
    • init.d support
    • set_immutable binary removed from ramdisk for 4.4.2
    • Speed up system startup

    Now more detail about some features:
    Governors
    PegasusQ
    Governor from Samsung with hotplug support. Perhaps, the most tunable and flexible one.
    Parameters description:

    • sampling_rate: the interval with which governor will be carried out. Less value - better responsiveness, but at the same time, more load for CPU by governor itself.
    • sampling_down_factor: amount of iterations governor will stay at highest frequency before go down.
    • up_threshold: load threshold in % above which CPU frequency will be increased.
    • up_threshold_at_min_freq, freq_for_responsiveness: at frequency lower than freq_for_responsiveness will be used up_threshold_at_min_freq threshold - provided for better responsiveness.
    • down_threshold: load threshold in % below which CPU frequency will be decreased.
    • freq_step: step of frequency encrease in % from maximum frequency.
    • hotplug_freq_*: high and low frequency thresholds for making decision about hotplug of each core.
      For clarity, it looks like this:
      Code:
      static int hotplug_freq[4][2] = {
          {0,      1596000},
          {208000, 1795000},
          {416000, 1996000},
          {624000, 0}
      };
      In this array left column is frequency at which core will be disabled; right column - frequency at which will be enabled next core.
    • hotplug_rq_*: analogous parameters set (array), defining queue task length for making decision about hotplug of each core.
      Code:
      static int hotplug_rq[4][2] = {{0, 50}, {50, 100}, {100, 150}, {150, 0}};
      For example, second core will be disabled after reaching 208MHz frequency and amount of tasks must be less than 50;
      third core will be enabled after reaching 1795MHz frequency by second core and amount of tasks more than 100.
    • cpu_up_rate: amount of governor iterations cpu should stay at defined frequency for enabling next core.
    • cpu_down_rate: amount of governor iterations cpu should stay at defined frequency for disabling last active core.
    • down_differential: defines load in % which must be less than up_threshold to go to lower frequency.
    • hotplug_lock: lock amount of active cores.
    • min_cpu_lock: limits min value of enabled cores.
    • max_cpu_lock: limits max value of enabled cores.
    • up_nr_cpus: defines how many cores to enable at a time.
    AbyssplugV2
    Based on Conservative, has hotplug support. Pluses: pretty simple, hence doesn't load CPU by himself. Frequency increases sequentally, after reaching max frequency - enables next core. And vice versa. Minuses: often enables / disables cores (what in itself is energy intensive).
    Distinctive parameters:

    • up_threshold_hotplug: load threshold in % above which will be enabled next core.
    • down_threshold_hotplug: load threshold in % below which will be disabled last active core.
    • boost: load threshold above which frequency will be increased through step (for exaample., from 208000 immediately on 624000)
    Optdemand
    Governor by Hisilicon, based on Ondemand. Backported from Honor 4X/4C. Distinctive feature is each frequency has its own thresholds to go to higher or lower frequency.
    Distinctive parameters:

    • go_hispeed_load, hispeed_freq: after exceeding go_hispeed_load threshold, CPU goes immediately to hispeed_freq frequency.
    • up_thresholds, down_thresholds: above and below load thresholds for each frequency. For clarity:
      Code:
      static unsigned int operating_points[7][3] = {
          /* kHz   up_threshold   down_threshold */
          {208000,    60,    0},
          {416000,    60,    30},
          {624000,    70,    40},
          {798000,    80,    50},
          {1196000,    85,    50},
          {1596000,    90,    60},
          {1795000,    95,    70},
          {1996000,    100,    80},
      };
      For example, for frequency 624MHz, if load will go below 30%, will be calculated new lower frequency according to new load value; if load will go above 70% - frequency will be increased.
    • boost: frequency will be increased to hispeed_freq
    • bostpulse_duration: duration of boost in microseconds.
    Interactive
    Google's gold standard governor. Updated to 3.4 kernel branch
    Impulse
    Based on Interactive governor. Good responsiveness.
    USB Fast Charge
    Increases charge current when connected to USB. It has sense only when connected to USB 3.0
    Can be enabled by writing "1" into /sys/kernel/fast_charge/force_fast_charge file or by third party applications.
    Disabled by default
    Intelli-Plug
    Hotplug driver for governors not supporting hotplug.
    Activated and deactivated automatically depending on chosen governor.
    Parameters are in /sys/module/intelli_plug/parameters

    • nr_possible_cores: max cores affected by driver.
    • nr_run_profile_sel: has several profiles :
      • 0: balance default
      • 1: performance
      • 2: conservative
      • 3: eco
      • 4: eco extreme
    • screen_off_max: max frequency at screen off.
    • touch_boost_active: enables additional core at screen touch disabled by default
    CPU undervolting
    Undervolting values can be set for each frequency individually. Regulator has step 8mV starting from 700mV. I've got such stable values:
    Screenshot_2016-04-02-23-02-41.png
    But you should start from higher values. I've made a test: CPU locked at frequency 1795MHz, RAR creates archive with 4 threads in 10 minutes. Average CPU temperature during this time was 56.124 degrees, with undervolting average temperature became 51.119 degrees. I.e. average temperature became lower for 5 degrees which means less power consumption.
    Comparative graph:
    undervolt.png
    GPU undervolting
    Since I couldn't find any common used sysfs interface and applications supporting it, you can make it using script (see init.d spoiler).
    My stable values are:
    Code:
    160: 860  -> 700
    266: 860  -> 732
    355: 876  -> 764
    533: 956  -> 860
    700: 1052 -> 924
    But most probable, you will have troubles with such values, try to find suitable for your own.

    3DMark Ice Storm Extreme showed average temperature decrease from 61.587 to 55.502 degrees.
    Comparative grapth:
    undervolt_gpu.png
    DoubleTap2Wake
    Screen on by double tap on it. Has two parameters in /sys/android_touch

    • doubletap2wake: enables dt2w. Possible values are:
      • 0: disabled default
      • 1: active at all screen
      • 2: active at top half
      • 3: active at bottom half
      • 4: active at navbar
    • dt2w_duration: Since I couldn't implement waking up device from deep sleep by irq from touch panel, so kernel doesn't go to deep sleep when dt2w is active, I added parameter defining how long dt2w stays active after screen off. After this duration dt2w becomes inactive and kernel can go into deep sleep.
    Sweep2Sleep
    Swipe on navbar for screen off. Can be enabled by writing "1" into /sys/android_touch/sweep2sleep file. Disabled by default.

    s2s_length: swipe length in dots. By default, equal to 25% of screen width.
    init.d
    For executing scripts at startup, put them in /system/etc/init.d folder and set permissions to 0755
    Several scripts examples (doubletap2wake, sweep2sleep, fast_charge, gpu_undervolting): View attachment scripts.rar
    Scores
    Screenshot_2016-04-08-19-12-11.png

    For correct governors switching I recommend to use Kernel Adiutor
    It also lets to manage IO schedulers, TCP congestion, fast charge, CPU undervolting.

    Requirements:

    • Unlocked bootloader
    • TWRP
    Installation:
    Just install zip-archive from TWRP

    Download:
    View attachment K-Tuned_kernel-4.4.2.zip
    View attachment K-Tuned_kernel-5.1.1.zip

    Source: Github

    Updates:
    31.10.2016
    CVE-2016-5195 "Dirty COW" fixed.
    Now CPU voltage values take effect right after frequency changes.

    30.07.2016
    Adjusted voltages for overclocked frequencies due to cases of appearing stability issues on some devices.

    15.05.2016
    Removed GPU undervolting applying at booting due to some users had stability issues. Now for GPU undervolting use init.d script individually.
    Adjusted governor thresholds.
    Reduced min online CPUs from 3 to 2 when screen is on for stock pwrctrl_hotplug governor.


    Regards,
    Kostyan_nsk
    3
    Thanks to @besker48 I have found that CPU voltages adjusted for every device individually in early bootup stage. Earlier I thought that voltages predefined in firmware and are the same for everybody. Voltage for 1996MHz frequency wasn't managing by mcuimage because this frequency is unavailable initially. Hence, there appeared situations when voltage at 1996MHz was lower than at 1795MHz what was leading to stability issues.
    For those who had such issues, in the first post is updated version with adjusted voltage. I hope it will solve stability issue.
    Thank @besker48 for providing logs and testing!:good:
    2
    Hello. @Kostyan_nsk is there any chance to add another governers like Lulzactive, Smartass, Zzmove for the better battery and performance balance.
    I'm not going to add more governors.

    And is is it possible to charge phone fastly in AC mode, because it is possible only in USB mode.
    Well, I think it's possible by increasing charging voltage. But it could be dangerous and will require a lot of time for tuning and testing to make it safe. However, now I'm busy with some other thing...

    I have sound delay in youtube, after restart it is fixed, but after some time it is repaiting, anyone with this problem or with solution for this?
    It's not because of kernel.
    1
    @roxkiller, just set "Apply on boot" in Kernel Adiutor after limiting max. cpu frequency and enable Kernel Adiutor in Startup Manager, so KA will aplly your settings after reboot.
    And btw, if you didn't notice, cpu voltage at 1996MHz is the same as at 1795MHz, therefore I doubt that power consumption will noticably increase relatively to 1795Mhz frequency...
    1
    In TWRP - advanced wipe - change file system but this will wipe all data!! so be sure to have a backup in place and also stock rom does not seem to support f2fs. I've tried this a while ago and my P7 on B861 wouldn't boot after formatting /data to f2fs
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone