Skip to content

Commit

Permalink
v2 (20210102)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Yang <yccy@outlook.com>
  • Loading branch information
yc9559 committed Jan 2, 2021
1 parent 2019ea5 commit 818443c
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 338 deletions.
27 changes: 27 additions & 0 deletions magisk/common/system.prop
@@ -1,3 +1,30 @@
# This file will be read by resetprop
# Example: Change dpi
# ro.sf.lcd_density=320

# unify surfaceflinger props
debug.sf.latch_unsignaled=1
ro.surface_flinger.max_frame_buffer_acquired_buffers=3
# app phase
ro.surface_flinger.vsync_event_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
# 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
# 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
# early SF phase(90Hz+)
debug.sf.high_fps_early_phase_offset_ns=1000000
# 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
5 changes: 3 additions & 2 deletions magisk/initsvc_uperf.sh
Expand Up @@ -8,11 +8,12 @@ BASEDIR="$(dirname $(readlink -f "$0"))"

wait_until_login()
{
# we doesn't have the permission to rw "/sdcard" before the user unlocks the screen
while [ ! -d "/sdcard/Android" ]; do
# in case of /data encryption is disabled
while [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep 1
done

# 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"
while [ ! -f "$test_file" ]; do
Expand Down
2 changes: 1 addition & 1 deletion magisk/module.prop
@@ -1,6 +1,6 @@
id=uperf
name=Uperf
version=v1 (20200516)
version=v2 (20210102)
versionCode=1
author=Matt Yang
description=Userspace performance controller for android. Repo: https://github.com/yc9559/uperf/
Expand Down
152 changes: 152 additions & 0 deletions magisk/script/libcgroup.sh
@@ -0,0 +1,152 @@
#!/system/bin/sh
# Cgroup Library
# https://github.com/yc9559/
# Author: Matt Yang
# Version: 20201230

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

# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
# 16490 grep kswapd

# $1:task_name $2:cgroup_name $3:"cpuset"/"stune"
change_task_cgroup()
{
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) -> cgroup:$2"
echo "$temp_tid" > "/dev/$3/$2/tasks"
done
done
}

# $1:process_name $2:cgroup_name $3:"cpuset"/"stune"
change_proc_cgroup()
{
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep -i "$1" | awk '{print $1}'); do
comm="$(cat /proc/$temp_pid/comm)"
log "change $comm($temp_pid) -> cgroup:$2"
echo $temp_pid > "/dev/$3/$2/cgroup.procs"
done
}

# $1:task_name $2:thread_name $3:cgroup_name $4:"cpuset"/"stune"
change_thread_cgroup()
{
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)"
if [ "$(echo $comm | grep -i "$2")" != "" ]; then
log "change $1/$comm($temp_tid) -> cgroup:$3"
echo "$temp_tid" > "/dev/$4/$3/tasks"
fi
done
done
}

# $1:task_name $2:hex_mask(0x00000003 is CPU0 and CPU1)
change_task_affinity()
{
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) -> mask:$2"
taskset -p "$2" "$temp_tid" >> $LOG_FILE
done
done
}

# $1:task_name $2:thread_name $3:hex_mask(0x00000003 is CPU0 and CPU1)
change_thread_affinity()
{
local ps_ret
local comm
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)"
if [ "$(echo $comm | grep -i "$2")" != "" ]; then
log "change $1/$comm($temp_tid) -> mask:$3"
taskset -p "$3" "$temp_tid" >> $LOG_FILE
fi
done
done
}

# $1:task_name $2:nice(relative to 120)
change_task_nice()
{
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
renice "$2" -p "$temp_tid" >> $LOG_FILE
done
done
}

# $1:task_name $2:thread_name $3:priority(100-x, 2-99)
change_thread_rt()
{
local ps_ret
local comm
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)"
if [ "$(echo $comm | grep -i "$2")" != "" ]; then
log "change $1/$comm($temp_tid) -> RT policy"
chrt -f -p "$3" "$temp_tid" >> $LOG_FILE
fi
done
done
}

# $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()
{
change_thread_affinity "$1" "$2" "f0"
}

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

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

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

# $1:task_name
unpin_proc()
{
change_task_cgroup "$1" "" "cpuset"
}
92 changes: 12 additions & 80 deletions magisk/script/libcommon.sh
Expand Up @@ -2,7 +2,7 @@
# Basic Tool Library
# https://github.com/yc9559/
# Author: Matt Yang
# Version: 20200516
# Version: 20201206

BASEDIR="$(dirname "$0")"
. $BASEDIR/pathinfo.sh
Expand Down Expand Up @@ -51,7 +51,7 @@ read_cfg_value()
{
local value=""
if [ -f "$PANEL_FILE" ]; then
value="$(grep "^$1=" "$PANEL_FILE" | head -n 1 | tr -d ' ' | cut -d= -f2)"
value="$(grep -i "^$1=" "$PANEL_FILE" | head -n 1 | tr -d ' ' | cut -d= -f2)"
fi
echo "$value"
}
Expand All @@ -69,11 +69,12 @@ clear_panel()

wait_until_login()
{
# we doesn't have the permission to rw "/sdcard" before the user unlocks the screen
while [ ! -d "/sdcard/Android" ]; do
# in case of /data encryption is disabled
while [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep 1
done

# 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"
while [ ! -f "$test_file" ]; do
Expand All @@ -84,87 +85,18 @@ wait_until_login()
}

###############################
# Cgroup functions
# Log
###############################

# $1:task_name $2:cgroup_name $3:"cpuset"/"stune"
change_task_cgroup()
{
# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
# 16490 grep kswapd
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep "$1" | awk '{print $1}'); do
for temp_tid in $(ls "/proc/$temp_pid/task/"); do
echo "$temp_tid" > "/dev/$3/$2/tasks"
done
done
}

# $1:process_name $2:cgroup_name $3:"cpuset"/"stune"
change_proc_cgroup()
{
# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
# 16490 grep kswapd
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep "$1" | awk '{print $1}'); do
echo $temp_pid > "/dev/$3/$2/cgroup.procs"
done
}

# $1:task_name $2:thread_name $3:cgroup_name $4:"cpuset"/"stune"
change_thread_cgroup()
{
# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
# 16490 grep kswapd
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep "$1" | awk '{print $1}'); do
for temp_tid in $(ls "/proc/$temp_pid/task/"); do
if [ "$(grep "$2" /proc/$temp_pid/task/$temp_tid/comm)" != "" ]; then
echo "$temp_tid" > "/dev/$4/$3/tasks"
fi
done
done
}

# $1:task_name $2:hex_mask(0x00000003 is CPU0 and CPU1)
change_task_affinity()
# $1:content
log()
{
# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
# 16490 grep kswapd
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep "$1" | awk '{print $1}'); do
for temp_tid in $(ls "/proc/$temp_pid/task/"); do
taskset -p "$2" "$temp_tid" > /dev/null
done
done
echo "$1" >> "$LOG_FILE"
}

# $1:task_name $2:nice(relative to 120)
change_task_nice()
clear_log()
{
# avoid matching grep itself
# ps -Ao pid,args | grep kswapd
# 150 [kswapd0]
# 16490 grep kswapd
local ps_ret
ps_ret="$(ps -Ao pid,args)"
for temp_pid in $(echo "$ps_ret" | grep "$1" | awk '{print $1}'); do
for temp_tid in $(ls "/proc/$temp_pid/task/"); do
renice "$2" -p "$temp_tid"
done
done
true > "$LOG_FILE"
}

###############################
Expand All @@ -174,7 +106,7 @@ change_task_nice()
# $1:"4.14" return:string_in_version
match_linux_version()
{
echo "$(cat /proc/version | grep "$1")"
echo "$(cat /proc/version | grep -i "$1")"
}

# return:platform_name
Expand Down
30 changes: 0 additions & 30 deletions magisk/script/libpowercfg.sh
Expand Up @@ -24,10 +24,6 @@ KSGL="/sys/class/kgsl/kgsl-3d0"
DEVFREQ="/sys/class/devfreq"
LPM="/sys/module/lpm_levels/parameters"
MSM_PERF="/sys/module/msm_performance/parameters"
ST_TOP="/dev/stune/top-app"
ST_FORE="/dev/stune/foreground"
ST_BACK="/dev/stune/background"
ST_RT="/dev/stune/rt"
SDA_Q="/sys/block/sda/queue"

if [ "$(match_linux_version 4.19)" != "" ]; then
Expand Down Expand Up @@ -129,32 +125,6 @@ set_corectl_param()
done
}

# array not working in sh shell
# $1:func $2:percluster_vals
# set_percluster()
# {
# local cpuids
# local prev_maxf="0"
# local now_maxf="0"
# for i in $(seq 0 9); do
# now_maxf="$(get_maxfreq $i)"
# if [ "$now_maxf" != "" ] && [ "$now_maxf" != "$prev_maxf" ]; then
# prev_maxf="$now_maxf"
# cpuids[${#cpuids[@]}]="$i"
# fi
# done

# local vals
# vals=($2)

# local composed=""
# for i in ${!cpuids[@]}; do
# composed="$composed ${cpuids[$i]}:${vals[$i]}"
# done

# $($1 "$composed")
# }

# $1:upmigrate $2:downmigrate $3:group_upmigrate $4:group_downmigrate
set_sched_migrate()
{
Expand Down
1 change: 1 addition & 0 deletions magisk/script/pathinfo.sh
Expand Up @@ -8,4 +8,5 @@ BIN_DIR="/bin"
MODULE_PATH="$(dirname $(readlink -f "$0"))"
MODULE_PATH="${MODULE_PATH%$SCRIPT_DIR}"
PANEL_FILE="/sdcard/Android/panel_uperf.txt"
LOG_FILE="$MODULE_PATH/log.txt"
PATH="/sbin/.magisk/busybox:/sbin:/system/sbin:/product/bin:/apex/com.android.runtime/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"

0 comments on commit 818443c

Please sign in to comment.