Skip to content

Commit

Permalink
DEV 21.05.02
Browse files Browse the repository at this point in the history
1. 本次更新合并了30+个commit
2. 新增:不同于v1的屏幕点亮HintWakeup,默认关联切换到重负载动作
3. 新增:dumpsys法获取顶层APP名称,处理MIUI12小窗场景识别更准确
4. 新增:防卡开机系统,如果在开机60秒内重启自动禁用本模块
5. 新增:标志位系统,包括SELinux、SfAnalysis、SsAnalysis、perfhal-stub开关
6. 新增:内置busybox(@osm0sis),降低对平台二进制工具集依赖
7. 新增:HeavyWorker辅助线程处理如线程分类器等耗时任务,消除内部阻塞
8. 新增:支持联发科Helio P65(mt6768)/G70(mt6769v)/G80(mt6769t)/G85(mt6769z)
9. 新增:支持高通骁龙662
10. 修复:容易死机的SfAnalysis和SsAnalysis异步通知方法
11. 修复:安兔兔9.0负载被固定小核集群
12. 修复:MIUI桌面卸载应用后卡死数秒
13. 修复:部分系统硬件服务和daemon错误锁定在小核
14. 修复:动态刷新率帧率切换缓存错误
15. 修复:三星Exynos 2100不支持schedtune调参
16. 改进:均衡模式在boost时减少点亮超大核时长
17. 改进:CPU affinity设置执行耗时从1ms降低到0.6ms
18. 改进:费电模式以stuneboost/uclamp作为核心,限制性能在散热允许范围内
19. 改进:无画面渲染时如待机,最低频率尽可能低,有画面渲染时,最低频率在1.0g上下减少频率波动

Signed-off-by: Matt Yang <yccy@outlook.com>
  • Loading branch information
yc9559 committed May 2, 2021
1 parent 1fe017d commit aed0c0f
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 81 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ UFS节能开关的`sysfs`节点路径为`/sys/devices/platform/soc/1d84000.ufshc
- [xHook](https://github.com/iqiyi/xHook)
- [@cjybyjk](https://github.com/cjybyjk)
- [@SatySatsZB](https://github.com/SatySatsZB)
- [@osm0sis](https://github.com/osm0sis)
- @YMJ

感谢以下用户的测试反馈和错误定位:
Expand Down
Binary file added magisk/busybox/busybox-arm-selinux
Binary file not shown.
Binary file added magisk/busybox/busybox-arm64-selinux
Binary file not shown.
60 changes: 39 additions & 21 deletions magisk/common/post-fs-data.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
MODDIR=${0%/*}

# do not place empty json if it doesn't exist in system
# vendor/etc/powerhint.json: android perf hal
# vendor/etc/powerscntbl.cfg: mediatek perf hal (android 9)
# vendor/etc/powerscntbl.xml: mediatek perf hal (android 10+)
# vendor/etc/perf/commonresourceconfigs.json: qualcomm perf hal resource
# vendor/etc/perf/targetresourceconfigs.json: qualcomm perf hal resource overrides
perfcfgs="
vendor/etc/powerhint.json
vendor/etc/powerscntbl.cfg
vendor/etc/powerscntbl.xml
vendor/etc/perf/commonresourceconfigs.xml
vendor/etc/perf/targetresourceconfigs.xml
"
for f in $perfcfgs; do
[ ! -f "/$f" ] && rm "$MODDIR/system/$f"
done
remove_unnecessary_overlay()
{
# do not place empty json if it doesn't exist in system
# vendor/etc/powerhint.json: android perf hal
# vendor/etc/powerscntbl.cfg: mediatek perf hal (android 9)
# vendor/etc/powerscntbl.xml: mediatek perf hal (android 10+)
# vendor/etc/perf/commonresourceconfigs.json: qualcomm perf hal resource
# vendor/etc/perf/targetresourceconfigs.json: qualcomm perf hal resource overrides
perfcfgs="
vendor/etc/powerhint.json
vendor/etc/powerscntbl.cfg
vendor/etc/powerscntbl.xml
vendor/etc/perf/commonresourceconfigs.xml
vendor/etc/perf/targetresourceconfigs.xml
"
for f in $perfcfgs; do
[ ! -f "/$f" ] && rm "$MODDIR/system/$f"
done

# drivers/net/wireless/cnss2/main.c in kworker/u16:1 Tainted
# because cnss: fatal: MHI power up returns timeout, which QMI timeout is 10000 ms
# for f in $(find /sys/devices/virtual/workqueue "cpumask"); do
# echo f > $f
# done
rm -f $MODDIR/flags/enable_perfhal_stub
for f in $perfcfgs; do
[ -f "$MODDIR/system/$f" ] && true > $MODDIR/flags/enable_perfhal_stub
done
}

remove_all_overlay()
{
rm -rf "$MODDIR/system/vendor/etc"
}

crash_recuser()
{
true > $MODDIR/flags/crash_on_postfs
sleep 30
rm -f $MODDIR/flags/crash_on_postfs
}

remove_unnecessary_overlay
[ -f "$MODDIR/flags/crash_on_postfs" ] && remove_all_overlay
(crash_recuser &)
Empty file added magisk/flags/enable_sfanalysis
Empty file.
Empty file added magisk/flags/enable_ssanalysis
Empty file.
Empty file added magisk/flags/selinux_permissive
Empty file.
20 changes: 17 additions & 3 deletions magisk/initsvc_uperf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@ wait_until_login()

# we doesn't have the permission to rw "/sdcard" before the user unlocks the screen
local test_file="/sdcard/Android/.PERMISSION_TEST"
touch "$test_file"
true > "$test_file"
while [ ! -f "$test_file" ]; do
touch "$test_file"
true > "$test_file"
sleep 1
done
rm "$test_file"
}

crash_recuser()
{
local logcat_pid

true > $BASEDIR/disable
logcat -f $BASEDIR/logcat.log &
logcat_pid=$!

sleep 60

rm -f $BASEDIR/disable
kill -9 $logcat_pid
}

(crash_recuser &)
wait_until_login
# do not sleep 60, may causing MIUI 12 launcher freezed by sfanalysis
sh $BASEDIR/run_uperf.sh
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.04.11)
version=v2 (21.05.02)
versionCode=2
author=Matt Yang
description=Userspace performance controller for android. Repo: https://github.com/yc9559/uperf/
Expand Down
3 changes: 3 additions & 0 deletions magisk/run_uperf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
BASEDIR="$(dirname $(readlink -f "$0"))"
SCRIPT_DIR="$BASEDIR/script"

# create busybox symlinks
$BASEDIR/bin/busybox/busybox --install -s $BASEDIR/bin/busybox/

# support vtools
cp -af $SCRIPT_DIR/vtools-powercfg.sh /data/powercfg.sh
cp -af $SCRIPT_DIR/vtools-powercfg.sh /data/powercfg-base.sh
Expand Down
4 changes: 2 additions & 2 deletions magisk/script/libcommon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ wait_until_login()

# we doesn't have the permission to rw "/sdcard" before the user unlocks the screen
local test_file="/sdcard/Android/.PERMISSION_TEST"
touch "$test_file"
true > "$test_file"
while [ ! -f "$test_file" ]; do
touch "$test_file"
true > "$test_file"
sleep 1
done
rm "$test_file"
Expand Down
5 changes: 3 additions & 2 deletions magisk/script/pathinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ MODULE_PATH="${MODULE_PATH%\/$SCRIPT_DIR}"
USER_PATH="/sdcard/yc/uperf"
PANEL_FILE="$USER_PATH/panel_uperf.txt"
LOG_FILE="$USER_PATH/log_uperf_initsvc.log"
FLAGS="$MODULE_PATH/flags"

# prefer to use magisk's busybox and busybox for android ndk
# use private busybox
PATH="/sbin:/system/sbin:/system/xbin:/system/bin:/vendor/xbin:/vendor/bin"
PATH="/sbin/.magisk/busybox:/sbin/.core/busybox:/magisk/.core/busybox:$PATH"
PATH="$MODULE_PATH/$BIN_DIR/busybox:$PATH"
78 changes: 38 additions & 40 deletions magisk/script/powercfg_once.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,46 @@ unify_cgroup()
# launcher is usually in foreground group, uperf will take care of them
lock_val "0-7" /dev/cpuset/foreground/boost/cpus
lock_val "0-7" /dev/cpuset/foreground/cpus
lock_val "0-6" /dev/cpuset/restricted/cpus
# VMOS may set cpuset/background/cpus to "0"
lock /dev/cpuset/background/cpus

# Reduce Perf Cluster Wakeup
# daemons
pin_proc_on_pwr "crtc_commit"
pin_proc_on_pwr "crtc_event"
pin_proc_on_pwr "pp_event"
pin_proc_on_pwr "pp_event"
pin_proc_on_pwr "msm_irqbalance"
pin_proc_on_pwr "netd"
pin_proc_on_pwr "mdnsd"
pin_proc_on_pwr "pdnsd"
pin_proc_on_pwr "analytics"
pin_proc_on_pwr "daemon"
change_task_affinity "android\.system\.suspend" "7f"
pin_proc_on_pwr "imsdaemon"
pin_proc_on_pwr "cnss-daemon"
pin_proc_on_pwr "qadaemon"
pin_proc_on_pwr "ATFWD-daemon"
pin_proc_on_pwr "ims_rtp_daemon"
change_task_affinity "android.system.suspend" "7f"
# ueventd related to hotplug of camera, wifi, usb...
# pin_proc_on_pwr "ueventd"
# hardware services, eg. android.hardware.sensors@1.0-service
pin_proc_on_pwr "\.hardware\."
change_task_affinity "\.hardware\." "ff"
pin_proc_on_pwr "android.hardware.bluetooth"
pin_proc_on_pwr "android.hardware.gnss"
pin_proc_on_pwr "android.hardware.health"
pin_proc_on_pwr "android.hardware.sensors"
pin_proc_on_pwr "android.hardware.thermal"
pin_proc_on_pwr "android.hardware.wifi"
pin_proc_on_pwr "vendor.qti.hardware.qseecom"
# pwr cluster has enough capacity for surfaceflinger
pin_proc_on_pwr "surfaceflinger"
# MediaProvider is background service
pin_proc_on_pwr "android\.process\.media"
unpin_proc "com\.android\.providers\.media"
change_thread_nice "com\.android\.providers\.media" "Thread-" "4"
change_thread_affinity "com\.android\.providers\.media" "Thread-" "f"
# com.android.providers.media.module controlled by uperf
pin_proc_on_pwr "android.process.media"
# com.miui.securitycenter & com.miui.securityadd
pin_proc_on_pwr "miui\.security"
# ueventd related to hotplug of camera, wifi, usb...
# pin_proc_on_pwr "ueventd"
# provide best performance for fingerprint service
change_task_nice "\.hardware\.biometrics\." "-4"
# mfp-daemon: goodix in-screen fingerprint daemon
change_task_nice "mfp" "-4"

# system_server blacklist
pin_proc_on_mid "system_server"
Expand All @@ -67,7 +79,6 @@ unify_cgroup()
change_thread_affinity "system_server" "ProcessManager" "ff"
# not important
pin_thread_on_pwr "system_server" "Miui"
pin_thread_on_pwr "system_server" "ActivityManager"
pin_thread_on_pwr "system_server" "Connect"
pin_thread_on_pwr "system_server" "Network"
pin_thread_on_pwr "system_server" "Wifi"
Expand Down Expand Up @@ -121,26 +132,15 @@ unify_cgroup()
change_thread_cgroup "\.hardware\.display" "^HwBinder" "top-app" "cpuset"
change_thread_cgroup "\.composer" "^Binder" "top-app" "cpuset"
# transition animation
change_thread_cgroup "system_server" "android\.anim" "top-app" "cpuset"
change_thread_cgroup "system_server" "android\.anim" "top-app" "stune"
change_thread_cgroup "system_server" "android\.anim" "top-app" "cpuctl"
change_thread_cgroup "system_server" "android\.display" "top-app" "cpuset"
change_thread_cgroup "system_server" "android\.display" "top-app" "stune"
change_thread_cgroup "system_server" "android\.display" "top-app" "cpuctl"
change_thread_cgroup "system_server" "android\.ui" "top-app" "cpuset"
change_thread_cgroup "system_server" "android.anim" "top-app" "cpuset"
change_thread_cgroup "system_server" "android.anim" "top-app" "stune"
change_thread_cgroup "system_server" "android.anim" "top-app" "cpuctl"
change_thread_cgroup "system_server" "android.display" "top-app" "cpuset"
change_thread_cgroup "system_server" "android.display" "top-app" "stune"
change_thread_cgroup "system_server" "android.display" "top-app" "cpuctl"
change_thread_cgroup "system_server" "android.ui" "top-app" "cpuset"

# Heavy Scene Boost
# camera & video recording
unpin_proc "\.hardware\.camera"
pin_proc_on_mid "^camera"
pin_proc_on_mid "\.hardware\.audio"
pin_proc_on_mid "^audio"
# provide best performance for fingerprint service
pin_proc_on_perf "\.hardware\.biometrics\."
change_task_high_prio "\.hardware\.biometrics\."
# mfp-daemon: goodix in-screen fingerprint daemon
pin_proc_on_perf "mfp"
change_task_high_prio "mfp"
# boost app boot process, zygote--com.xxxx.xxx
unpin_proc "zygote"
change_task_high_prio "zygote"
Expand All @@ -150,7 +150,7 @@ unify_cgroup()

# busybox fork from magiskd
pin_proc_on_mid "magiskd"
change_task_nice "magiskd" "39"
change_task_nice "magiskd" "19"
}

unify_cpufreq()
Expand All @@ -172,11 +172,9 @@ unify_cpufreq()
set_governor_param "scaling_governor" "0:schedutil 2:schedutil 4:schedutil 6:schedutil 7:schedutil"

# unify walt schedutil governor
set_governor_param "schedutil/hispeed_freq" "0:1200000 2:1200000 4:1200000 6:1200000 7:1200000"
set_governor_param "schedutil/hispeed_freq" "0:1000000"
set_governor_param "schedutil/hispeed_load" "0:70 2:70 4:70 6:70 7:70"
set_governor_param "schedutil/pl" "0:0 2:0 4:0 6:0 7:0"
set_governor_param "schedutil/pl" "7:1"
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"

# 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 @@ -212,8 +210,8 @@ 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 down migrate threshold need compensate.
set_sched_migrate "40" "20" "999" "888"
set_sched_migrate "40 80" "20 40" "999" "888"
set_sched_migrate "50" "15" "999" "888"
set_sched_migrate "50 90" "15 60" "999" "888"

# prefer to use prev cpu, decrease jitter from 0.5ms to 0.3ms with lpm settings
# system_server binders maybe pinned on perf cluster due to this
Expand Down Expand Up @@ -358,7 +356,7 @@ disable_userspace_boost()

# Qualcomm&MTK perfhal
# keep perfhal running with empty config file in magisk mode
[ "$(is_magisk)" == "false" ] && perfhal_stop
[ ! -f "$FLAGS/enable_perfhal_stub" ] && perfhal_stop

# xiaomi perfservice
stop vendor.perfservice
Expand Down
12 changes: 4 additions & 8 deletions magisk/script/start_injector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ inj_do_inject()

inj_start()
{
# raise inotify limit
lock_val "131072" /proc/sys/fs/inotify/max_queued_events
lock_val "131072" /proc/sys/fs/inotify/max_user_watches
lock_val "1024" /proc/sys/fs/inotify/max_user_instances

log "$(date '+%Y-%m-%d %H:%M:%S')"
inj_do_inject "/system/bin/surfaceflinger" "libsfanalysis.so" "SfAnalysis"
inj_do_inject "system_server" "libssanalysis.so" "SsAnalysis"
[ -f "$FLAGS/selinux_permissive" ] && setenforce 0
[ -f "$FLAGS/enable_sfanalysis" ] && inj_do_inject "/system/bin/surfaceflinger" "libsfanalysis.so" "SfAnalysis"
[ -f "$FLAGS/enable_ssanalysis" ] && inj_do_inject "system_server" "libssanalysis.so" "SsAnalysis"
}

clear_log
[ -f "$MODULE_PATH/enable_injector" ] && inj_start
inj_start
28 changes: 24 additions & 4 deletions magisk/setup_uperf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ _get_cfgname()
"sdm660") ret="$(_get_sdm660_type)" ;;
"sdm636") ret="$(_get_sdm636_type)" ;;
"trinket") ret="sdm665" ;;
"bengal") ret="sdm665" ;; # sdm662
"msm8976") ret="sdm652" ;;
"msm8956") ret="sdm650" ;;
"msm8998") ret="$(_get_sdm835_type)" ;;
Expand All @@ -329,6 +330,7 @@ _get_cfgname()
"universal8895") ret="$(_get_e8895_type)" ;;
"universal8890") ret="$(_get_e8890_type)" ;;
"universal7420") ret="e7420" ;;
"mt6768") ret="mtg80" ;; # Helio P65(mt6768)/G70(mt6769v)/G80(mt6769t)/G85(mt6769z)
"mt6785") ret="mtg90t" ;;
"mt6853") ret="$(_get_mt6853_type)" ;;
"mt6873") ret="$(_get_mt6873_type)" ;;
Expand All @@ -345,7 +347,7 @@ uperf_print_banner()
echo ""
echo "* Uperf https://github.com/yc9559/uperf/"
echo "* Author: Matt Yang"
echo "* Version: v2 (21.04.11)"
echo "* Version: v2 (21.05.02)"
echo ""
}

Expand Down Expand Up @@ -396,6 +398,8 @@ uperf_install()
injector_install()
{
echo "- Installing injector"
echo "- SELinux will be set to PERMISSIVE at boot for better compatibility"
echo "- ...delete \$MODDIR/flags/selinux_permissive to leave SELinux untouched."

local src_path
local dst_path
Expand All @@ -418,9 +422,6 @@ injector_install()
# in case of set_perm_recursive is broken
chmod 0755 $BASEDIR/bin/*

# create injector enable flag
touch $BASEDIR/enable_injector

rm -rf $BASEDIR/injector
}

Expand All @@ -435,9 +436,28 @@ powerhal_stub_install()
_set_perm "$BASEDIR/system/vendor/etc/perf/targetresourceconfigs.xml" 0 0 0755 u:object_r:vendor_configs_file:s0
}

busybox_install()
{
echo "- Installing private busybox"

local dst_path
dst_path="$BASEDIR/bin/busybox/"

mkdir -p "$dst_path"
if [ "$(_is_aarch64)" == "true" ]; then
cp "$BASEDIR/busybox/busybox-arm64-selinux" "$dst_path/busybox"
else
cp "$BASEDIR/busybox/busybox-arm-selinux" "$dst_path/busybox"
fi
chmod 0755 "$dst_path/busybox"

rm -rf $BASEDIR/busybox
}

uperf_print_banner
uperf_install
injector_install
powerhal_stub_install
busybox_install
uperf_print_finish
exit 0

0 comments on commit aed0c0f

Please sign in to comment.