Skip to content

Commit

Permalink
DEV 21.01.24
Browse files Browse the repository at this point in the history
1. 本次更新合并了40+个commit
2. 新增:适配骁龙888和Linux 5.4引入的uclamp
3. 新增:仅允许后台与UX相关的线程运行在大核,减少大核唤醒
4. 新增:固定全面屏手势动画相关的线程到大核且不被抢占,减少掉帧
5. 新增:动态控制UI渲染管线相关线程到大核,减少掉帧
6. 新增:优化基于Unity游戏线程放置的合理性,减少迷之掉帧
7. 新增:CPU频点模糊匹配
8. 新增:识别zygote,修复偏慢的APP冷启动
9. 新增:重构动态Affinity,改善线程调度参数设置生命周期完整性
10. 改进:恢复WALT EAS负载预测,修复选频过于保守
11. 改进:加快HeavyLoad检测频率到20hz
12. 改进:卡顿和均衡模式小核最低频使用尽可能低的值
13. 修复:goodix和屏幕指纹动画线程被固定到小核,修复MIUI屏幕指纹解锁停顿太久
14. 修复:SfAnalysis在MIUI 12.5初始化失败
15. 修复:关闭高通perfd时拉高的DDR频率没有恢复导致空载高耗电
16. 修复:sigwait遗漏信号导致状态卡在Sflag
17. 修复:一个罕见的崩溃bug

Signed-off-by: Matt Yang <yccy@outlook.com>
  • Loading branch information
yc9559 committed Jan 24, 2021
1 parent 0564f01 commit af4a099
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 93 deletions.
5 changes: 5 additions & 0 deletions magisk/common/post-fs-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ MODDIR=${0%/*}

# do not place empty powerhint.json if it doesn't exist in system
[ ! -f /vendor/etc/powerhint.json ] && rm $MODDIR/system/vendor/etc/powerhint.json

# pin kworker on little
for f in $(find /sys/devices/virtual/workqueue "cpumask"); do
echo 0f > $f
done
33 changes: 19 additions & 14 deletions magisk/common/system.prop
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@

# unify surfaceflinger props
debug.sf.latch_unsignaled=1
ro.surface_flinger.max_frame_buffer_acquired_buffers=3
ro.surface_flinger.max_frame_buffer_acquired_buffers=4
# app phase
ro.surface_flinger.vsync_event_phase_offset_ns=1000000
# ro.surface_flinger.vsync_event_phase_offset_ns=1000000
# early app phase
# debug.sf.early_app_phase_offset_ns=1000000
# GL early app phase
# debug.sf.early_gl_app_phase_offset_ns=1000000
# SF phase
ro.surface_flinger.vsync_sf_event_phase_offset_ns=1000000
# the offset in nanoseconds to add to vsync time when timestamping present fences.
ro.surface_flinger.present_time_offset_from_vsync_ns=0
# ro.surface_flinger.vsync_sf_event_phase_offset_ns=-4000000
# early SF phase
debug.sf.early_phase_offset_ns=1000000
# GL early app phase
debug.sf.early_gl_phase_offset_ns=1000000
# early app phase
debug.sf.early_app_phase_offset_ns=1000000
# debug.sf.early_phase_offset_ns=-4000000
# GL early SF phase
debug.sf.early_gl_app_phase_offset_ns=1000000
# GL early app phase(90Hz+)
debug.sf.high_fps_early_gl_phase_offset_ns=1000000
# debug.sf.early_gl_phase_offset_ns=-4000000
# early SF phase(90Hz+)
debug.sf.high_fps_early_phase_offset_ns=1000000
# debug.sf.high_fps_early_phase_offset_ns=-4000000
# GL early SF phase(90Hz+)
# debug.sf.high_fps_early_gl_phase_offset_ns=-4000000
# Below defines the threshold when an offset is considered to be negative, i.e. targeting
# for the N+2 vsync instead of N+1. This means that:
# For offset < threshold, SF wake up (vsync_duration - offset) before HW vsync.
# For offset >= threshold, SF wake up (2 * vsync_duration - offset) before HW vsync.
# debug.sf.phase_offset_threshold_for_next_vsync_ns=6100000
# used by the Scheduler to trigger inactivity callbacks that will switch the display to a lower refresh rate
ro.surface_flinger.set_idle_timer_ms=2000

# HeapTaskDaemon is controlled by uperf, reserve more room for direct heap reclaim
# default = 512k/8m
dalvik.vm.heapminfree=2m
dalvik.vm.heapmaxfree=10m
2 changes: 1 addition & 1 deletion magisk/module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=uperf
name=Uperf
version=v2 (21.01.04)
version=v2 (21.01.24)
versionCode=2
author=Matt Yang
description=Userspace performance controller for android. Repo: https://github.com/yc9559/uperf/
Expand Down
32 changes: 30 additions & 2 deletions magisk/script/libcgroup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Cgroup Library
# https://github.com/yc9559/
# Author: Matt Yang
# Version: 20201230
# Version: 20210110

BASEDIR="$(dirname "$0")"
. $BASEDIR/pathinfo.sh
Expand Down Expand Up @@ -98,7 +98,21 @@ change_task_nice()
done
}

# $1:task_name $2:thread_name $3:priority(100-x, 2-99)
# $1:task_name $2:priority(99-x, 1<=x<=99)
change_task_rt()
{
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep -i "$1" | awk '{print $1}'); do
for temp_tid in $(ls "/proc/$temp_pid/task/"); do
comm="$(cat /proc/$temp_pid/task/$temp_tid/comm)"
log "change $1/$comm($temp_tid) -> RT policy"
chrt -f -p "$2" "$temp_tid" >> $LOG_FILE
done
done
}

# $1:task_name $2:thread_name $3:priority(99-x, 1<=x<=99)
change_thread_rt()
{
local ps_ret
Expand All @@ -115,6 +129,20 @@ change_thread_rt()
done
}

# $1:task_name
change_task_high_prio()
{
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep -i "$1" | awk '{print $1}'); do
for temp_tid in $(ls "/proc/$temp_pid/task/"); do
comm="$(cat /proc/$temp_pid/task/$temp_tid/comm)"
log "change $1/$comm($temp_tid) -> Nice -20"
renice -n -20 -p "$temp_tid" >> $LOG_FILE
done
done
}

# $1:task_name $2:thread_name
change_thread_high_prio()
{
Expand Down
36 changes: 11 additions & 25 deletions magisk/script/libpowercfg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Powercfg Library
# https://github.com/yc9559/
# Author: Matt Yang
# Version: 20210103
# Version: 20210120

BASEDIR="$(dirname "$0")"
. $BASEDIR/pathinfo.sh
Expand Down Expand Up @@ -145,36 +145,22 @@ perfhal_mode="balance"
# stop before updating cfg
perfhal_stop()
{
stop perf-hal-1-0
stop perf-hal-1-1
stop perf-hal-1-2
stop perf-hal-1-3
stop perf-hal-2-0
stop perf-hal-2-1
stop perf-hal-2-2
stop perf-hal-2-3
stop perf-hal-3-0
stop perf-hal-3-1
stop perf-hal-3-2
stop perf-hal-3-3
for i in 0 1 2 3 4; do
for j in 0 1 2 3 4; do
stop "perf-hal-$i-$j"
done
done
usleep 500
}

# start after updating cfg
perfhal_start()
{
start perf-hal-1-0
start perf-hal-1-1
start perf-hal-1-2
start perf-hal-1-3
start perf-hal-2-0
start perf-hal-2-1
start perf-hal-2-2
start perf-hal-2-3
start perf-hal-3-0
start perf-hal-3-1
start perf-hal-3-2
start perf-hal-3-3
for i in 0 1 2 3 4; do
for j in 0 1 2 3 4; do
start "perf-hal-$i-$j"
done
done
}

# $1:mode(such as balance)
Expand Down
2 changes: 1 addition & 1 deletion magisk/script/powercfg_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ save_panel()
write_panel ""
write_panel "Uperf https://github.com/yc9559/uperf/"
write_panel "Author: Matt Yang"
write_panel "Version: v2 (21.01.04)"
write_panel "Version: v2 (21.01.24)"
write_panel "Last performed: $(date '+%Y-%m-%d %H:%M:%S')"
write_panel ""
write_panel "[Uperf status]"
Expand Down
133 changes: 85 additions & 48 deletions magisk/script/powercfg_once.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,99 @@ BASEDIR="$(dirname "$0")"

unify_cgroup()
{
# clear stune
mutate "0" /dev/stune/background/schedtune.sched_boost_no_override
mutate "0" /dev/stune/background/schedtune.boost
mutate "0" /dev/stune/background/schedtune.prefer_idle
mutate "0" /dev/stune/foreground/schedtune.sched_boost_no_override
mutate "0" /dev/stune/foreground/schedtune.boost
mutate "0" /dev/stune/foreground/schedtune.prefer_idle
mutate "1" /dev/stune/top-app/schedtune.sched_boost_no_override
mutate "0" /dev/stune/top-app/schedtune.boost
mutate "0" /dev/stune/top-app/schedtune.prefer_idle
mutate "100" /dev/stune/rt/schedtune.boost
mutate "1" /dev/stune/rt/schedtune.prefer_idle

mutate "0-2,6" /dev/cpuset/foreground/cpus
# clear uclamp
mutate "0" /dev/cpuctl/background/cpu.uclamp.sched_boost_no_override
mutate "0" /dev/cpuctl/background/cpu.uclamp.min
mutate "0" /dev/cpuctl/background/cpu.uclamp.latency_sensitive
mutate "0" /dev/cpuctl/foreground/cpu.uclamp.sched_boost_no_override
mutate "0" /dev/cpuctl/foreground/cpu.uclamp.min
mutate "0" /dev/cpuctl/foreground/cpu.uclamp.latency_sensitive
mutate "1" /dev/cpuctl/top-app/cpu.uclamp.sched_boost_no_override
mutate "0" /dev/cpuctl/top-app/cpu.uclamp.min
mutate "0" /dev/cpuctl/top-app/cpu.uclamp.latency_sensitive

# launcher&home usually in foreground cpuset group
mutate "4-6" /dev/cpuset/foreground/boost/cpus
mutate "0-2,4-6" /dev/cpuset/foreground/cpus
mutate "0-3" /dev/cpuset/background/cpus

# fix laggy bilibili feed scrolling
change_task_cgroup "servicemanager" "top-app" "cpuset"
change_task_cgroup "servicemanager" "foreground" "stune"
change_task_cgroup "android\.phone" "top-app" "cpuset"
change_task_cgroup "android\.phone" "foreground" "stune"

# provide best performance for fingerprint service
change_task_cgroup "\.hardware\.biometrics\.fingerprint" "rt" "stune"
change_task_nice "\.hardware\.biometrics\.fingerprint" "-20"

# reduce big cluster wakeup
# Reduce Perf Cluster Wakeup
# daemons
pin_proc_on_pwr "\[rcu"
pin_proc_on_pwr "crtc_commit"
pin_proc_on_pwr "crtc_event"
pin_proc_on_pwr "ueventd"
pin_proc_on_pwr "netd"
# eg. android.hardware.sensors@1.0-service
pin_proc_on_pwr "mdnsd"
pin_proc_on_pwr "pdnsd"
pin_proc_on_pwr "qcrild"
pin_proc_on_pwr "magiskd"
pin_proc_on_pwr "daemon"
pin_proc_on_pwr "analytics"
# hardware services, eg. android.hardware.sensors@1.0-service
pin_proc_on_pwr "\.hardware\."
# ...but exclude fingerprint&camera&display service for speed
unpin_proc "\.hardware\.biometrics\.fingerprint"
unpin_proc "\.hardware\.camera\.provider"
unpin_proc "\.hardware\.display\."
# save bandwidth for UI
pin_proc_on_pwr "system_server"
# pwr cluster has enough capacity for surfaceflinger
pin_proc_on_pwr "surfaceflinger"
# MediaProvider is background service
pin_proc_on_pwr "com.android.providers.media.module"
pin_proc_on_pwr "android.process.media"

# pin system_server in background to save bandwidth for UI
change_task_cgroup "system_server" "background" "cpuset"
change_task_cgroup "system_server" "top-app" "stune"
# ...but exclude Binders and animations
unpin_thread "system_server" "Binder"
# Render Pipeline
# input dispatcher
change_thread_high_prio "system_server" "input"
# transition animation
unpin_thread "system_server" "android\.anim"
unpin_thread "system_server" "android\.ui"
pin_thread_on_perf "system_server" "Binder"
unpin_thread "system_server" "android\.display"
pin_thread_on_perf "system_server" "android\.anim"
pin_thread_on_perf "system_server" "android\.ui"
# ...set UX pipeline related thread high priority
change_thread_high_prio "system_server" "input"
change_thread_high_prio "system_server" "android\.anim"

# apply prefer idle to systemui
change_task_cgroup "com.android.systemui" "top-app" "stune"

pin_thread_on_perf "system_server" "android\.display"
change_thread_rt "system_server" "android\.anim" "1"
change_thread_rt "system_server" "android\.ui" "1"
change_thread_rt "system_server" "android\.display" "1"
# speed up searching service binder
change_task_cgroup "servicemanag" "top-app" "cpuset"
# prevent display service from being preempted by normal tasks
change_task_rt "\.hardware\.display" "2"
change_task_rt "\.composer" "2"
# kworkers may block binders
change_task_high_prio "\[rcu"
change_task_high_prio "\[kworker\/"
change_task_high_prio "\[ksoftirqd\/"
# fix laggy bilibili feed scrolling
change_task_cgroup "android\.phone" "foreground" "cpuset"
change_thread_cgroup "android\.phone" "Binder" "top-app" "cpuset"
# let UX related Binders run with top-app
change_thread_cgroup "surfaceflinger" "surfaceflinger" "top-app" "cpuset"
change_thread_cgroup "surfaceflinger" "Binder" "top-app" "cpuset"
change_thread_cgroup "\.composer" "Binder" "top-app" "cpuset"
change_thread_cgroup "system_server" "Binder" "top-app" "cpuset"

# Latency Sensitive Scene Boost
# camera service
unpin_proc "\.hardware\.camera\.provider"
# provide best performance for fingerprint service
unpin_proc "\.hardware\.biometrics\.fingerprint"
change_task_high_prio "\.hardware\.biometrics\.fingerprint"
# mfp-daemon: goodix in-screen fingerprint daemon
unpin_proc "mfp"
change_task_high_prio "mfp"
# boost app boot process, zygote--com.xxxx.xxx
unpin_proc "zygote"
pin_proc_on_perf "zygote"

# let binders of surfaceflinger run with top-app
pin_proc_on_pwr "surfaceflinger"
unpin_thread "surfaceflinger" "Binder"
change_task_high_prio "zygote"
}

unify_cpufreq()
Expand All @@ -88,13 +123,10 @@ unify_cpufreq()
set_governor_param "scaling_governor" "0:interactive 2:interactive 4:interactive 6:interactive 7:interactive"
fi

# more conservative governor
set_governor_param "schedutil/hispeed_load" "0:99 2:99 4:99 6:99 7:99"
set_governor_param "schedutil/hispeed_freq" "0:1500000 2:1500000 4:1500000 6:1500000 7:1500000"
set_governor_param "schedutil/pl" "0:0 2:0 4:0 6:0 7:0"
# ...but prefer longer idle time in light loads
set_governor_param "schedutil/hispeed_load" "0:80"
set_governor_param "schedutil/hispeed_freq" "0:1000000"
# unify walt schedutil governor
set_governor_param "schedutil/hispeed_freq" "0:0 2:0 4:0 6:0 7:0"
set_governor_param "schedutil/hispeed_load" "0:100 2:100 4:100 6:100 7:100"
set_governor_param "schedutil/pl" "0:1 2:1 4:1 6:1 7:1 0:0"

# unify hmp interactive governor, only 2+2 4+2 4+4
set_governor_param "interactive/use_sched_load" "0:1 2:1 4:1"
Expand All @@ -119,6 +151,9 @@ unify_gpufreq()
# unlock mtk gpu strict limit
lock_val "1" /sys/module/ged/parameters/gpu_dvfs
lock_val "1" /sys/module/ged/parameters/gx_game_mode
lock_val "0" /sys/module/ged/parameters/gx_3d_benchmark_on
lock_val "1" /proc/mali/dvfs_enable
lock_val "0" /proc/gpufreq/gpufreq_opp_freq
}

unify_sched()
Expand All @@ -128,6 +163,7 @@ unify_sched()
lock_val "0" $SCHED/sched_walt_rotate_big_tasks
lock_val "1000" $SCHED/sched_min_task_util_for_boost
lock_val "1000" $SCHED/sched_min_task_util_for_colocation
lock_val "0" $SCHED/sched_conservative_pl

# scheduler boost for top app main from msm kernel 4.19
lock_val "0" $SCHED/sched_boost_top_app
Expand Down Expand Up @@ -185,9 +221,9 @@ disable_hotplug()
disable_kernel_boost()
{
# Qualcomm
lock_val "0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0" $CPU_BOOST/input_boost_freq
lock_val "0" $CPU_BOOST/input_boost_ms
lock_val "0" $CPU_BOOST/sched_boost_on_input
lock_val "0" /sys/devices/system/cpu/cpu_boost/parameters/input_boost_ms
lock_val "0" /sys/devices/system/cpu/cpu_boost/input_boost_ms
lock_val "0" /sys/module/cpu_boost/parameters/input_boost_ms
lock_val "0" /sys/module/msm_performance/parameters/touchboost
lock_val "0" /sys/module/cpu_boost/parameters/boost_ms

Expand All @@ -205,11 +241,12 @@ disable_kernel_boost()
# [9] PPM_POLICY_SYS_BOOST: disabled
# [10] PPM_POLICY_HICA: ?
# Usage: echo <policy_idx> <1(enable)/0(disable)> > /proc/ppm/policy_status
lock_val "1" /proc/ppm/enabled
lock_val "0 0" /proc/ppm/policy_status
lock_val "1 0" /proc/ppm/policy_status
lock_val "2 0" /proc/ppm/policy_status
lock_val "3 0" /proc/ppm/policy_status
lock_val "4 1" /proc/ppm/policy_status
lock_val "4 0" /proc/ppm/policy_status
lock_val "5 0" /proc/ppm/policy_status
lock_val "6 1" /proc/ppm/policy_status # used by uperf
lock_val "7 0" /proc/ppm/policy_status
Expand Down
Loading

0 comments on commit af4a099

Please sign in to comment.