Skip to content

Commit

Permalink
scripts: Properly handle non existent files
Browse files Browse the repository at this point in the history
Signed-off-by: Rem01Gaming <[email protected]>
  • Loading branch information
Rem01Gaming committed Nov 9, 2024
1 parent 6102425 commit c4339da
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
19 changes: 14 additions & 5 deletions src/scripts/encore-normal
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ apply() {
fi
}

change_permission() {
if [ -f $2 ]; then
chmod $1 $2
fi
}

# Disable battery saver module
if grep -qo '[0-9]\+' /sys/module/battery_saver/parameters/enabled; then
apply 0 /sys/module/battery_saver/parameters/enabled
else
apply N /sys/module/battery_saver/parameters/enabled
if [ -f /sys/module/battery_saver/parameters/enabled ]; then
if grep -qo '[0-9]\+' /sys/module/battery_saver/parameters/enabled; then
apply 0 /sys/module/battery_saver/parameters/enabled
else
apply N /sys/module/battery_saver/parameters/enabled
fi
fi

if [ -f "/sys/kernel/debug/sched_features" ]; then
Expand Down Expand Up @@ -69,7 +77,7 @@ done &
for path in /sys/devices/system/cpu/cpufreq/policy*; do
apply "$default_cpu_gov" "$path/scaling_governor"
done &
chmod 644 /sys/devices/virtual/thermal/thermal_message/cpu_limits
change_permission 644 /sys/devices/virtual/thermal/thermal_message/cpu_limits
apply 1 /sys/devices/system/cpu/cpu1/online

# I/O Tweaks
Expand Down Expand Up @@ -264,4 +272,5 @@ case "$soc" in
5) tensor_tweak ;;
esac

wait
exit 0
18 changes: 14 additions & 4 deletions src/scripts/encore-performance
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ apply() {
fi
}

change_permission() {
if [ -f $2 ]; then
chmod $1 $2
fi
}

# Disable battery saver module
if grep -qo '[0-9]\+' /sys/module/battery_saver/parameters/enabled; then
apply 0 /sys/module/battery_saver/parameters/enabled
else
apply N /sys/module/battery_saver/parameters/enabled
if [ -f /sys/module/battery_saver/parameters/enabled ]; then
if grep -qo '[0-9]\+' /sys/module/battery_saver/parameters/enabled; then
apply 0 /sys/module/battery_saver/parameters/enabled
else
apply N /sys/module/battery_saver/parameters/enabled
fi
fi

if [ -f "/sys/kernel/debug/sched_features" ]; then
Expand Down Expand Up @@ -67,6 +75,7 @@ for path in /sys/devices/system/cpu/cpufreq/policy*; do
apply "cpu$(awk '{print $1}' $path/affected_cpus) $cpu_maxfreq" /sys/devices/virtual/thermal/thermal_message/cpu_limits
apply "$cpu_maxfreq" $path/scaling_max_freq
done &
change_permission 000 /sys/devices/virtual/thermal/thermal_message/cpu_limits
apply 1 /sys/devices/system/cpu/cpu1/online

# I/O Tweaks
Expand Down Expand Up @@ -251,4 +260,5 @@ case "$soc" in
5) tensor_tweak ;;
esac

wait
exit 0
19 changes: 13 additions & 6 deletions src/scripts/encore-powersave
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ apply() {
}

# Enable battery saver module
if grep -qo '[0-9]\+' /sys/module/battery_saver/parameters/enabled; then
apply 1 /sys/module/battery_saver/parameters/enabled
else
apply Y /sys/module/battery_saver/parameters/enabled
if [ -f /sys/module/battery_saver/parameters/enabled ]; then
if grep -qo '[0-9]\+' /sys/module/battery_saver/parameters/enabled; then
apply 1 /sys/module/battery_saver/parameters/enabled
else
apply Y /sys/module/battery_saver/parameters/enabled
fi
fi

# Disable cpu1 to save some power
Expand Down Expand Up @@ -45,8 +47,12 @@ mediatek_tweak() {
fi

# DRAM frequency
apply "$(cat /sys/devices/platform/10012000.dvfsrc/helio-dvfsrc/dvfsrc_opp_table | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+' | sort -nr | head -n 1)" /sys/devices/platform/10012000.dvfsrc/helio-dvfsrc/dvfsrc_req_ddr_opp
apply "$(cat /sys/kernel/helio-dvfsrc/dvfsrc_opp_table | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+' | sort -nr | head -n 1)" /sys/kernel/helio-dvfsrc/dvfsrc_force_vcore_dvfs_opp
if [ -f /sys/devices/platform/10012000.dvfsrc/helio-dvfsrc/dvfsrc_opp_table ]; then
apply "$(cat /sys/devices/platform/10012000.dvfsrc/helio-dvfsrc/dvfsrc_opp_table | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+' | sort -nr | head -n 1)" /sys/devices/platform/10012000.dvfsrc/helio-dvfsrc/dvfsrc_req_ddr_opp
elif [ -f /sys/kernel/helio-dvfsrc/dvfsrc_opp_table ]; then
apply "$(cat /sys/kernel/helio-dvfsrc/dvfsrc_opp_table | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+' | sort -nr | head -n 1)" /sys/kernel/helio-dvfsrc/dvfsrc_force_vcore_dvfs_opp
fi

apply "powersave" /sys/class/devfreq/mtk-dvfsrc-devfreq/governor
apply "powersave" /sys/devices/platform/soc/1c00f000.dvfsrc/mtk-dvfsrc-devfreq/devfreq/mtk-dvfsrc-devfreq/governor
}
Expand Down Expand Up @@ -168,4 +174,5 @@ case "$soc" in
5) tensor_tweak ;;
esac

wait
exit 0

0 comments on commit c4339da

Please sign in to comment.