luci-app-cpufreq: add default tweak for firstboot

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
Tianling Shen 2021-05-09 21:47:56 +08:00
parent 4f57d8891a
commit df6df28676
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
5 changed files with 50 additions and 20 deletions

View File

@ -1,16 +1,15 @@
# Copyright (C) 2016 Openwrt.org
#
# This is free software, licensed under the Apache License, Version 2.0 .
# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright (C) 2021 ImmortalWrt.org
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI for CPU Freq Setting
LUCI_DEPENDS:=@(arm||aarch64)
PKG_NAME:=luci-app-cpufreq
PKG_VERSION:=1
PKG_RELEASE:=6
PKG_RELEASE:=$(COMMITCOUNT)
include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -50,20 +50,19 @@ for _, policy_num in ipairs(string.split(policy_nums, " ")) do
if e ~= "" then maxfreq:value(e) end
end
sdfactor = s:taboption(policy_num, Value, "sdfactor" .. policy_num, translate("CPU Switching Sampling rate"))
sdfactor.datatype="range(1,100000)"
sdfactor.description = translate("The sampling rate determines how frequently the governor checks to tune the CPU (ms)")
sdfactor.placeholder = 10
sdfactor.default = 10
sdfactor:depends("governor", "ondemand")
upthreshold = s:taboption(policy_num, Value, "upthreshold" .. policy_num, translate("CPU Switching Threshold"))
upthreshold.datatype="range(1,99)"
upthreshold.description = translate("Kernel make a decision on whether it should increase the frequency (%)")
upthreshold.placeholder = 50
upthreshold.default = 50
upthreshold:depends("governor", "ondemand")
factor = s:taboption(policy_num, Value, "factor" .. policy_num, translate("CPU Switching Sampling rate"))
factor.datatype="range(1,100000)"
factor.description = translate("The sampling rate determines how frequently the governor checks to tune the CPU (ms)")
factor.placeholder = 10
factor.default = 10
factor:depends("governor", "ondemand")
end
return mp

View File

@ -19,14 +19,14 @@ msgstr "待机 CPU 最小频率"
msgid "Max Turbo Boost CPU Freq"
msgstr "最大 Turbo Boost CPU 频率"
msgid "CPU Switching Threshold"
msgstr "CPU 切换频率触发阈值"
msgid "Kernel make a decision on whether it should increase the frequency (%)"
msgstr "当 CPU 占用率超过 (%) 的情况下触发内核切换频率"
msgid "CPU Switching Sampling rate"
msgstr "CPU 切换周期"
msgid "The sampling rate determines how frequently the governor checks to tune the CPU (ms)"
msgstr "CPU 检查切换的周期 (ms)。注意:过于频繁的切换频率会引起网络延迟抖动"
msgid "CPU Switching Threshold"
msgstr "CPU 切换频率触发阈值"
msgid "Kernel make a decision on whether it should increase the frequency (%)"
msgstr "当 CPU 占用率超过 (%) 的情况下触发内核切换频率"

View File

@ -20,8 +20,8 @@ start()
config_get_cpufreq "minfreq$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_min_freq"
config_get_cpufreq "maxfreq$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_max_freq"
if [ "$(config_get_cpufreq "governor$i")" = "ondemand" ]; then
config_get_cpufreq "sdfactor$i" > "/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"
config_get_cpufreq "upthreshold$i" > "/sys/devices/system/cpu/cpufreq/ondemand/up_threshold"
config_get_cpufreq "factor$i" > "/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"
fi
done
}

View File

@ -1,5 +1,37 @@
#!/bin/sh
uci_write_config() {
uci set cpufreq.cpufreq.governor$1="$2"
uci set cpufreq.cpufreq.minfreq$1="$3"
uci set cpufreq.cpufreq.maxfreq$1="$4"
[ -n "$5" ] && uci set cpufreq.cpufreq.sdfactor$1="$5"
[ -n "$6" ] && uci set cpufreq.cpufreq.upthreshold$1="$6"
uci commit cpufreq
}
CPU_POLICYS="$(find '/sys/devices/system/cpu/cpufreq/policy'* -maxdepth 0 | grep -Eo '[0-9]+')"
source "/etc/openwrt_release"
case "$DISTRIB_TARGET" in
"bcm27xx/bcm2710")
uci_write_config 0 ondemand 600000 1200000 10 50
;;
"ipq40xx")
uci_write_config 0 ondemand 300000 716000 10 50
;;
"ipq806x")
uci_write_config 0 ondemand 600000 716000 10 50
echo "$CPU_POLICYS" | grep -q "1" && uci_write_config 1 ondemand 600000 716000 10 50
;;
"rockchip/armv8")
if echo "$CPU_POLICYS" | grep -q "4"; then
uci_write_config 0 schedutil 600000 1608000
uci_write_config 4 schedutil 600000 2016000
else
uci_write_config 0 schedutil 816000 1512000
fi
;;
esac
uci -q batch <<-EOF >/dev/null
delete ucitrack.@cpufreq[-1]
add ucitrack cpufreq