Skip to content

Commit

Permalink
21.01.31
Browse files Browse the repository at this point in the history
1. 本次更新合并了20+个commit
2. 增加:开放HMP平台支持
3. 增加:支持骁龙750g/775/870、天玑720/800u
4. 增加:与Qualcomm和MTK的perfhal共存,保持运行但是精简配置,避免一些离奇问题
5. 修复:由于禁用perfhal后重负载下服务管理进程被阻塞后composer也被阻塞导致的卡顿
6. 修复:由于重负载下perfhal被阻塞后composer也被阻塞导致的卡顿
7. 修复:部分安卓虚拟机更改background中任务只能够使用cpu0导致严重卡顿
8. 修复:小核过于拥挤导致音频卡顿
9. 改进:关闭需求不强的stune低延迟设置,调度器任务放置更整齐
10. 改进:system_server任务放置采用黑名单方式,减少未知线程限制在小核被阻塞导致卡顿
11. 改进:不再限制Java内存回收线程运行在小核阻塞渲染管线,减少卡顿
12. 改进:关闭强制负载均衡,避免亲和性设置失效
13. 改进:下调unity游戏主线程性能余量的激进程度,降低一些耗电
14. 改进:降低top-app中常规线程放置到大核的难度,减少卡顿
15. 改进:MTK平台SOC的配置文件的命名可读性

Signed-off-by: Matt Yang <yccy@outlook.com>
  • Loading branch information
yc9559 committed Jan 31, 2021
1 parent af4a099 commit 4070883
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 86 deletions.
18 changes: 16 additions & 2 deletions magisk/common/post-fs-data.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
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
# do not place empty json if it doesn't exist in system
# vendor/etc/powerhint.json: andorid perf hal
# vendor/etc/powerscntbl.cfg: mediatek perf hal (android 9)
# vendor/etc/powerscntbl.xml: mediatek perf hal (android 10+)
# vendor/etc/perf/perfboostsconfig.json: qualcomm perf hal
# vendor/etc/perf/targetresourceconfigs.json: qualcomm perf hal overrides
perfcfgs="
vendor/etc/powerhint.json
vendor/etc/powerscntbl.cfg
vendor/etc/powerscntbl.xml
vendor/etc/perf/perfboostsconfig.json
vendor/etc/perf/targetresourceconfigs.json
"
for f in $perfcfgs; do
[ ! -f "/$f" ] && rm "$MODDIR/system/$f"
done

# pin kworker on little
for f in $(find /sys/devices/virtual/workqueue "cpumask"); do
Expand Down
28 changes: 3 additions & 25 deletions magisk/common/system.prop
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,10 @@

# unify surfaceflinger props
debug.sf.latch_unsignaled=1
ro.surface_flinger.max_frame_buffer_acquired_buffers=4
# app phase
# 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=-4000000
# early SF phase
# debug.sf.early_phase_offset_ns=-4000000
# GL early SF phase
# debug.sf.early_gl_phase_offset_ns=-4000000
# early SF phase(90Hz+)
# 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
ro.surface_flinger.set_idle_timer_ms=1000

# HeapTaskDaemon is controlled by uperf, reserve more room for direct heap reclaim
# default = 512k/8m
dalvik.vm.heapminfree=2m
dalvik.vm.heapmaxfree=10m
dalvik.vm.heapminfree=4m
dalvik.vm.heapmaxfree=12m
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.24)
version=v2 (21.01.31)
versionCode=2
author=Matt Yang
description=Userspace performance controller for android. Repo: https://github.com/yc9559/uperf/
Expand Down
61 changes: 52 additions & 9 deletions magisk/script/libcgroup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
# Cgroup Library
# https://github.com/yc9559/
# Author: Matt Yang
# Version: 20210110
# Version: 202101230

BASEDIR="$(dirname "$0")"
. $BASEDIR/pathinfo.sh
. $BASEDIR/libcommon.sh

# launcher&home usually in foreground cpuset group
# reserve one LITTLE for hwservicemanager which will block composer
# thread priority settings not working on hwservicemanager
# okay, disabling perf-hal resulting hwservicemanager frequently wakeup
CPUMASK_ULV="03"
CPUMASK_LOW="0f"
CPUMASK_MID="63"
CPUMASK_HIGH="f0"
CPUID_ULV="0-1"
CPUID_LOW="0-3"
CPUID_MID="0-1,5-6"
CPUID_HIGH="4-7"

# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
Expand Down Expand Up @@ -160,22 +173,50 @@ change_thread_high_prio()
done
}

# $1:task_name $2:thread_name
unpin_thread()
{
change_thread_cgroup "$1" "$2" "" "cpuset"
}

# $1:task_name $2:thread_name
pin_thread_on_ulv()
{
change_thread_cgroup "$1" "$2" "background" "cpuset"
change_thread_affinity "$1" "$2" "$CPUMASK_ULV"
}

# $1:task_name $2:thread_name
pin_thread_on_pwr()
{
change_thread_cgroup "$1" "$2" "background" "cpuset"
}

# $1:task_name $2:thread_name
pin_thread_on_perf()
pin_thread_on_mid()
{
change_thread_affinity "$1" "$2" "f0"
unpin_thread "$1" "$2"
change_thread_affinity "$1" "$2" "$CPUMASK_MID"
}

# $1:task_name $2:thread_name
unpin_thread()
pin_thread_on_perf()
{
change_thread_cgroup "$1" "$2" "" "cpuset"
unpin_thread "$1" "$2"
change_thread_affinity "$1" "$2" "$CPUMASK_HIGH"
}

# $1:task_name
unpin_proc()
{
change_task_cgroup "$1" "" "cpuset"
}

# $1:task_name
pin_proc_on_ulv()
{
change_task_cgroup "$1" "background" "cpuset"
change_task_affinity "$1" "$CPUMASK_ULV"
}

# $1:task_name
Expand All @@ -185,13 +226,15 @@ pin_proc_on_pwr()
}

# $1:task_name
pin_proc_on_perf()
pin_proc_on_mid()
{
change_task_affinity "$1" "f0"
unpin_proc "$1"
change_task_affinity "$1" "$CPUMASK_MID"
}

# $1:task_name
unpin_proc()
pin_proc_on_perf()
{
change_task_cgroup "$1" "" "cpuset"
unpin_proc "$1"
change_task_affinity "$1" "$CPUMASK_HIGH"
}
6 changes: 3 additions & 3 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: 20210120
# Version: 20210124

BASEDIR="$(dirname "$0")"
. $BASEDIR/pathinfo.sh
Expand Down Expand Up @@ -147,7 +147,7 @@ perfhal_stop()
{
for i in 0 1 2 3 4; do
for j in 0 1 2 3 4; do
stop "perf-hal-$i-$j"
stop "perf-hal-$i-$j" 2> /dev/null
done
done
usleep 500
Expand All @@ -158,7 +158,7 @@ perfhal_start()
{
for i in 0 1 2 3 4; do
for j in 0 1 2 3 4; do
start "perf-hal-$i-$j"
start "perf-hal-$i-$j" 2> /dev/null
done
done
}
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.24)"
write_panel "Version: v2 (21.01.31)"
write_panel "Last performed: $(date '+%Y-%m-%d %H:%M:%S')"
write_panel ""
write_panel "[Uperf status]"
Expand Down
104 changes: 67 additions & 37 deletions magisk/script/powercfg_once.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ 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
lock_val "0" /dev/stune/background/schedtune.sched_boost_no_override
lock_val "0" /dev/stune/background/schedtune.boost
lock_val "0" /dev/stune/background/schedtune.prefer_idle
lock_val "0" /dev/stune/foreground/schedtune.sched_boost_no_override
lock_val "0" /dev/stune/foreground/schedtune.boost
lock_val "0" /dev/stune/foreground/schedtune.prefer_idle
lock_val "1" /dev/stune/top-app/schedtune.sched_boost_no_override
lock_val "0" /dev/stune/top-app/schedtune.boost
lock_val "0" /dev/stune/top-app/schedtune.prefer_idle

# 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
lock_val "0" /dev/cpuctl/background/cpu.uclamp.sched_boost_no_override
lock_val "0" /dev/cpuctl/background/cpu.uclamp.min
lock_val "0" /dev/cpuctl/background/cpu.uclamp.latency_sensitive
lock_val "0" /dev/cpuctl/foreground/cpu.uclamp.sched_boost_no_override
lock_val "0" /dev/cpuctl/foreground/cpu.uclamp.min
lock_val "0" /dev/cpuctl/foreground/cpu.uclamp.latency_sensitive
lock_val "1" /dev/cpuctl/top-app/cpu.uclamp.sched_boost_no_override
lock_val "0" /dev/cpuctl/top-app/cpu.uclamp.min
lock_val "0" /dev/cpuctl/top-app/cpu.uclamp.latency_sensitive

# VMOS may set cpuset/background/cpus to "0"
lock_val "$CPUID_MID" /dev/cpuset/foreground/boost/cpus
lock_val "$CPUID_MID" /dev/cpuset/foreground/cpus
lock_val "$CPUID_LOW" /dev/cpuset/background/cpus

# Reduce Perf Cluster Wakeup
# daemons
Expand All @@ -55,31 +55,56 @@ unify_cgroup()
# hardware services, eg. android.hardware.sensors@1.0-service
pin_proc_on_pwr "\.hardware\."
# save bandwidth for UI
pin_proc_on_pwr "system_server"
pin_proc_on_mid "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_proc_on_pwr "com\.android\.providers\.media"
pin_proc_on_pwr "android\.process.media"
# com.miui.securitycenter & com.miui.securityadd
pin_proc_on_pwr "miui\.security"

# Render Pipeline
# system_server blacklist
pin_proc_on_mid "system_server"
# input dispatcher
change_thread_high_prio "system_server" "input"
# transition animation
unpin_thread "system_server" "android\.anim"
unpin_thread "system_server" "android\.ui"
unpin_thread "system_server" "android\.display"
pin_thread_on_perf "system_server" "android\.anim"
pin_thread_on_perf "system_server" "android\.ui"
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"
# not important
pin_thread_on_ulv "system_server" "Async"
pin_thread_on_ulv "system_server" "backup"
pin_thread_on_ulv "system_server" "Greezer"
pin_thread_on_ulv "system_server" "TaskSnapshot"
pin_thread_on_ulv "system_server" "Oom"
pin_thread_on_ulv "system_server" "Sync"
pin_thread_on_ulv "system_server" "\.bg"
pin_thread_on_ulv "system_server" "Miui"
pin_thread_on_ulv "system_server" "Observer"
pin_thread_on_ulv "system_server" "Connect"
pin_thread_on_ulv "system_server" "Network"
pin_thread_on_ulv "system_server" "Power"
pin_thread_on_ulv "system_server" "Sensor"
pin_thread_on_ulv "system_server" "Wifi"
pin_thread_on_ulv "system_server" "Thread-"
pin_thread_on_ulv "system_server" "pool-"
# do not let GC thread block system_server
# pin_thread_on_mid "system_server" "HeapTaskDaemon"
# pin_thread_on_mid "system_server" "FinalizerDaemon"

# Render Pipeline
# 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"
# vendor.qti.hardware.perf@2.2-service blocks hardware.display.composer-service
# perf will automatically set self to prio=100
unpin_proc "\.hardware\.perf"
# kworkers may block binders
change_task_high_prio "\[rcu"
change_task_high_prio "\[kworker\/"
Expand All @@ -90,10 +115,11 @@ unify_cgroup()
# 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 "\.hardware\.display" "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
# Heavy Scene Boost
# camera service
unpin_proc "\.hardware\.camera\.provider"
# provide best performance for fingerprint service
Expand Down Expand Up @@ -126,7 +152,7 @@ unify_cpufreq()
# 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"
set_governor_param "schedutil/pl" "0:1 2:1 4:1 6:1 7:1"

# 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 Down Expand Up @@ -164,6 +190,7 @@ unify_sched()
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
lock_val "0" $SCHED/sched_force_lb_enable

# scheduler boost for top app main from msm kernel 4.19
lock_val "0" $SCHED/sched_boost_top_app
Expand All @@ -180,11 +207,12 @@ unify_sched()
# place a little heavier processes on big cluster, due to Cortex-A55 poor efficiency
# The same Binder, A55@1.0g took 7.3ms,A76@1.0g took 3.0ms, in this case, A76's efficiency is 2.4x of A55's.
# However in EAS model A76's efficiency is 1.7x of A55's, so the migrate thresholds need compensate.
set_sched_migrate "99" "40" "999" "888"
set_sched_migrate "99 99" "40 40" "999" "888"
set_sched_migrate "80" "20" "999" "888"
set_sched_migrate "80 80" "20 40" "999" "888"

# prefer to use prev cpu, decrease jitter from 0.5ms to 0.3ms with lpm settings
lock_val "10000000" $SCHED/sched_migration_cost_ns
# system_server binders maybe pinned on perf cluster due to this
# lock_val "10000000" $SCHED/sched_migration_cost_ns
}

unify_lpm()
Expand Down Expand Up @@ -317,11 +345,13 @@ disable_kernel_boost()
disable_userspace_boost()
{
# Qualcomm perfd
stop perfd
stop perfd 2> /dev/null
# Qualcomm perfhal
# running with empty config file
perfhal_stop
perfhal_start
# brain service maybe not smart
stop oneplus_brain_service
stop oneplus_brain_service 2> /dev/null
# disable service below will BOOM
# stop vendor.power.stats-hal-1-0
# stop vendor.power-hal-1-0
Expand Down
Loading

0 comments on commit 4070883

Please sign in to comment.