From f4698a4a84236f1d0d47a157c919fb98329c202b Mon Sep 17 00:00:00 2001
From: ZyCromerZ <neetroid97@gmail.com>
Date: Wed, 15 Jun 2022 20:58:28 +0700
Subject: [PATCH] add new tweak for cpu - set to 2 for using tweak from
 'latency' ktweak

Signed-off-by: ZyCromerZ <neetroid97@gmail.com>
---
 README-id.md                         |  2 +-
 README.md                            |  2 +-
 system/etc/ZyC-Core/main.sh          |  9 ++++-
 system/etc/ZyC-Core/misc/funclist.sh | 55 ++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/README-id.md b/README-id.md
index 6f4c783..a85963b 100644
--- a/README-id.md
+++ b/README-id.md
@@ -57,7 +57,7 @@ dan jangan sentuh / ubah file apapun di dalam folder <code>/data/adb/modules/(Id
 * force_doze.conf
     * paksa ke mode doze ketika layarnya mati
 * use_cpu_tweak.conf
-    * kalo anda mau pake beberapa tweak cpu, tinggal set ke 1
+    * kalo anda mau pake beberapa tweak cpu, tinggal set ke 1 atau 2
 * silent_overwrite.conf
     * kalo situ pake modol tweak laennya, teros jadi conflict, cobain set ke 1, default 0 
 * write_info.conf
diff --git a/README.md b/README.md
index 3692c54..c9819bb 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ and please dont touch / edit any files inside folder <code>/data/adb/modules/(Mo
 * force_doze.conf
     * forcing to doze idle state when display/screen off
 * use_cpu_tweak.conf
-    * if u want to apply some cpu tweak from this modules, just set it to 1
+    * if u want to apply some cpu tweak from this modules, just set it to 1 or 2
 * silent_overwrite.conf
     * if u use another tweak modules, then its conflict, try set this to 1, default 0
 * write_info.conf
diff --git a/system/etc/ZyC-Core/main.sh b/system/etc/ZyC-Core/main.sh
index 339c723..d8ef755 100644
--- a/system/etc/ZyC-Core/main.sh
+++ b/system/etc/ZyC-Core/main.sh
@@ -136,9 +136,15 @@
                     CpuInpuBoostUpdate "on"
                     UpdateGov write "$PMConfig/gov_on.conf"
                     if [[ "$CpuTweakMode" == "1" ]];then
+                         # https://github.com/tytydraco/KTweak/tree/latency
                         CpuPerformance
                         VmPerformance
                     fi
+                    if [[ "$CpuTweakMode" == "2" ]];then
+                         # https://github.com/tytydraco/KTweak/tree/throughput
+                        CpuPerformanceB
+                        VmPerformanceB
+                    fi
                     GoTurbo="0"
                     GoNormal="0"
                 elif [[ "$GoNormal" -ge "$MaxCheckGpuUsage" ]] && [[ "$GheymingMode" == "y" ]];then
@@ -146,7 +152,8 @@
                         SetOff
                         CpuInpuBoostUpdate "off"
                         UpdateGov write "$PMConfig/gov_off.conf"
-                        if [[ "$CpuTweakMode" == "1" ]];then
+                        if [[ "$CpuTweakMode" == "1" ]] || [[ "$CpuTweakMode" == "2" ]];then
+                             # https://github.com/tytydraco/KTweak/tree/balance
                             CpuBalance
                             VmBalance
                         fi
diff --git a/system/etc/ZyC-Core/misc/funclist.sh b/system/etc/ZyC-Core/misc/funclist.sh
index fe0b3a9..d5ab145 100644
--- a/system/etc/ZyC-Core/misc/funclist.sh
+++ b/system/etc/ZyC-Core/misc/funclist.sh
@@ -952,6 +952,61 @@ VmPerformance(){
                 swappiness:100 vfs_cache_pressure:80
 }
 
+CpuPerformanceB(){
+    local UINT_MAX="4294967295"
+    local SCHED_PERIOD="$((1 * 1000 * 1000))"
+    local SCHED_TASKS="10"
+    local IFS
+    local governor
+    local queue
+    WriteSysKernel  perf_cpu_time_max_percent:3 sched_autogroup_enabled:1 sched_child_runs_first:1 sched_tunable_scaling:0 "sched_latency_ns:$SCHED_PERIOD" \
+                    "sched_min_granularity_ns:$((SCHED_PERIOD / SCHED_TASKS))" "sched_wakeup_granularity_ns:$((SCHED_PERIOD / 2))" sched_migration_cost_ns:5000000 \
+                    sched_min_task_util_for_colocation:0 sched_nr_migrate:4 sched_schedstats:0 printk_devkmsg:off
+
+    WriteTo 1 /dev/stune/top-app/schedtune.prefer_idle
+    WriteTo 1 /dev/stune/top-app/schedtune.boost
+
+    find /sys/devices/system/cpu/ -name schedutil -type d | while IFS= read -r governor
+    do
+        WriteTo "0" "$governor/up_rate_limit_us"
+        WriteTo "0" "$governor/down_rate_limit_us"
+        WriteTo "0" "$governor/rate_limit_us"
+        WriteTo 85 "$governor/hispeed_load"
+        WriteTo "$UINT_MAX" "$governor/hispeed_freq"
+    done
+
+    find /sys/devices/system/cpu/ -name blu_schedutil -type d | while IFS= read -r governor
+    do
+        WriteTo "0" "$governor/up_rate_limit_us"
+        WriteTo "0" "$governor/down_rate_limit_us"
+        WriteTo "0" "$governor/rate_limit_us"
+        WriteTo 85 "$governor/hispeed_load"
+        WriteTo "$UINT_MAX" "$governor/hispeed_freq"
+    done
+
+    find /sys/devices/system/cpu/ -name interactive -type d | while IFS= read -r governor
+    do
+        WriteTo "0" "$governor/timer_rate"
+        WriteTo "0" "$governor/min_sample_time"
+        WriteTo 85 "$governor/go_hispeed_load"
+        WriteTo "$UINT_MAX" "$governor/hispeed_freq"
+    done
+
+    for queue in /sys/block/*/queue
+    do
+        WriteTo 0 "$queue/add_random"
+        WriteTo 0 "$queue/iostats"
+        WriteTo 32 "$queue/read_ahead_kb"
+        WriteTo 32 "$queue/nr_requests"
+    done
+
+}
+
+VmPerformanceB(){
+    WriteSysVm  dirty_background_ratio:15 dirty_ratio:30 dirty_expire_centisecs:3000 dirty_writeback_centisecs:3000 page-cluster:0 stat_interval:10 \
+                swappiness:100 vfs_cache_pressure:80
+}
+
 SetFreqCpu(){
     local Lt="-1"
     local Bg="-1"
-- 
GitLab