luci-app-cpufreq: add cpufreq luci for ipq40xx

This commit is contained in:
LEAN-ESX 2020-03-01 23:50:17 -08:00
parent c38bc05d13
commit b69fa370e6
9 changed files with 158 additions and 4 deletions

View File

@ -0,0 +1,17 @@
# Copyright (C) 2016 Openwrt.org
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI for CPU IPQ40xx Freq
LUCI_DEPENDS:=@TARGET_ipq40xx
PKG_NAME:=luci-app-cpufreq
PKG_VERSION:=1
PKG_RELEASE:=2
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,11 @@
module("luci.controller.cpufreq", package.seeall)
function index()
if not nixio.fs.access("/etc/config/cpufreq") then
return
end
entry({"admin", "services", "cpufreq"}, cbi("cpufreq"), _("CPU Freq"), 900).dependent=false
end

View File

@ -0,0 +1,41 @@
mp = Map("cpufreq", translate("CPU Freq Settings"))
mp.description = translate("Set CPU Scaling Governor to Max Performance or Balance Mode")
s = mp:section(NamedSection, "cpufreq", "settings")
s.anonymouse = true
governor = s:option(ListValue, "governor", translate("CPU Scaling Governor"))
governor:value("ondemand", translate("Ondemand Balance Mode"))
governor:value("performance", translate("Performance Mode"))
minifreq = s:option(Value, "minifreq", translate("Min Idle CPU Freq"))
minifreq.datatype="range(48000,716000)"
minifreq.rmempty = false
minifreq.description = translate("CPU Freq from 48000 to 716000 (Khz)")
minifreq.placeholder = 48000
minifreq.default = 48000
maxfreq = s:option(Value, "maxfreq", translate("Max Turbo Boost CPU Freq"))
maxfreq.datatype="range(48000,716000)"
maxfreq.rmempty = false
maxfreq.description = translate("CPU Freq from 48000 to 716000 (Khz)")
maxfreq.placeholder = 716000
maxfreq.default = 716000
upthreshold = s:option(Value, "upthreshold", translate("CPU Switching Threshold"))
upthreshold.datatype="range(1,99)"
upthreshold.rmempty = false
upthreshold.description = translate("Kernel make a decision on whether it should increase the frequency (%)")
upthreshold.placeholder = 50
upthreshold.default = 50
factor = s:option(Value, "factor", translate("CPU Switching Sampling rate"))
factor.datatype="range(1,100000)"
factor.rmempty = false
factor.description = translate("The sampling rate determines how frequently the governor checks to tune the CPU (ms)")
factor.placeholder = 10
factor.default = 10
return mp

View File

@ -0,0 +1,39 @@
msgid "CPU Freq"
msgstr "CPU 性能优化调节"
msgid "CPU Freq Settings"
msgstr "CPU 性能优化调节设置"
msgid "Set CPU Scaling Governor to Max Performance or Balance Mode"
msgstr "设置路由器的 CPU 性能模式(高性能/均衡省电)"
msgid "CPU Scaling Governor"
msgstr "CPU 工作模式"
msgid "Ondemand Balance Mode"
msgstr "Ondemand 自动平衡模式"
msgid "Performance Mode"
msgstr "Performance 高性能模式(降低游戏转发延迟)"
msgid "CPU Freq from 48000 to 716000 (Khz)"
msgstr "CPU 频率范围为 48000 到 716000 (Khz)"
msgid "Min Idle CPU Freq"
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) 。注意:过于频繁的切换频率会引起网络延迟抖动"

View File

@ -0,0 +1,8 @@
config settings 'cpufreq'
option maxfreq '716000'
option upthreshold '50'
option factor '10'
option minifreq '300000'
option governor 'ondemand'

View File

@ -0,0 +1,29 @@
#!/bin/sh /etc/rc.common
START=50
NAME=cpufreq
uci_get_by_type() {
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
echo ${ret:=$3}
}
start()
{
config_load cpufreq
local governor=$(uci_get_by_type settings governor ondemand)
local minifreq=$(uci_get_by_type settings minifreq 48000)
local maxfreq=$(uci_get_by_type settings maxfreq 716000)
local upthreshold=$(uci_get_by_type settings upthreshold 50)
local factor=$(uci_get_by_type settings factor 10)
echo $governor > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo $minifreq > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq
echo $maxfreq > /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq
if [ "$governor" == "ondemand" ]; then
echo $upthreshold > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo $factor > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
fi
}

View File

@ -0,0 +1,11 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@cpufreq[-1]
add ucitrack cpufreq
set ucitrack.@cpufreq[-1].init=cpufreq
commit ucitrack
EOF
rm -f /tmp/luci-indexcache
exit 0

View File

@ -20,7 +20,7 @@ DEFAULT_PACKAGES += \
kmod-ath10k wpad-openssl \
kmod-usb3 kmod-usb-dwc3 ath10k-firmware-qca4019 \
automount autosamba luci-app-ipsec-vpnd v2ray shadowsocks-libev-ss-redir shadowsocksr-libev-server \
luci-app-unblockmusic luci-app-qbittorrent luci-app-zerotier luci-app-xlnetacc ca-certificates \
luci-app-unblockmusic luci-app-cpufreq luci-app-zerotier luci-app-pptp-server luci-app-xlnetacc ca-certificates \
htop fdisk e2fsprogs
$(eval $(call BuildTarget))

View File

@ -31,7 +31,5 @@ boot() {
echo "Linksys EA6350v3: boot_part=$(fw_printenv -n boot_part)"
;;
esac
echo 35 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
}