mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
addfix
This commit is contained in:
parent
2bb0dca0e2
commit
8e11c19dc0
43 changed files with 2004 additions and 0 deletions
16
luci-app-cpufreq/Makefile
Normal file
16
luci-app-cpufreq/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
|||
# 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:=$(COMMITCOUNT)
|
||||
|
||||
include ../../luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
11
luci-app-cpufreq/luasrc/controller/cpufreq.lua
Normal file
11
luci-app-cpufreq/luasrc/controller/cpufreq.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
module("luci.controller.cpufreq", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/cpufreq") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "system", "cpufreq"}, cbi("cpufreq"), _("CPU Freq"), 90)
|
||||
page.dependent = false
|
||||
page.acl_depends = { "luci-app-cpufreq" }
|
||||
end
|
68
luci-app-cpufreq/luasrc/model/cbi/cpufreq.lua
Normal file
68
luci-app-cpufreq/luasrc/model/cbi/cpufreq.lua
Normal file
|
@ -0,0 +1,68 @@
|
|||
local fs = require "nixio.fs"
|
||||
|
||||
function string.split(input, delimiter)
|
||||
input = tostring(input)
|
||||
delimiter = tostring(delimiter)
|
||||
if (delimiter=='') then return false end
|
||||
local pos,arr = 0, {}
|
||||
for st,sp in function() return string.find(input, delimiter, pos, true) end do
|
||||
table.insert(arr, string.sub(input, pos, st - 1))
|
||||
pos = sp + 1
|
||||
end
|
||||
table.insert(arr, string.sub(input, pos))
|
||||
return arr
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
local policy_nums = luci.sys.exec("echo -n $(find /sys/devices/system/cpu/cpufreq/policy* -maxdepth 0 | grep -Eo '[0-9]+')")
|
||||
for _, policy_num in ipairs(string.split(policy_nums, " ")) do
|
||||
if not fs.access("/sys/devices/system/cpu/cpufreq/policy" .. policy_num .. "/scaling_available_frequencies") then return end
|
||||
|
||||
cpu_freqs = fs.readfile("/sys/devices/system/cpu/cpufreq/policy" .. policy_num .. "/scaling_available_frequencies")
|
||||
cpu_freqs = string.sub(cpu_freqs, 1, -3)
|
||||
|
||||
cpu_governors = fs.readfile("/sys/devices/system/cpu/cpufreq/policy" .. policy_num .. "/scaling_available_governors")
|
||||
cpu_governors = string.sub(cpu_governors, 1, -3)
|
||||
|
||||
|
||||
freq_array = string.split(cpu_freqs, " ")
|
||||
governor_array = string.split(cpu_governors, " ")
|
||||
|
||||
s:tab(policy_num, translate("Policy " .. policy_num))
|
||||
|
||||
governor = s:taboption(policy_num, ListValue, "governor" .. policy_num, translate("CPU Scaling Governor"))
|
||||
for _, e in ipairs(governor_array) do
|
||||
if e ~= "" then governor:value(e, translate(e, string.upper(e))) end
|
||||
end
|
||||
|
||||
minfreq = s:taboption(policy_num, ListValue, "minfreq" .. policy_num, translate("Min Idle CPU Freq"))
|
||||
for _, e in ipairs(freq_array) do
|
||||
if e ~= "" then minfreq:value(e) end
|
||||
end
|
||||
|
||||
maxfreq = s:taboption(policy_num, ListValue, "maxfreq" .. policy_num, translate("Max Turbo Boost CPU Freq"))
|
||||
for _, e in ipairs(freq_array) 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" .. policy_num, "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" .. policy_num, "ondemand")
|
||||
end
|
||||
|
||||
return mp
|
32
luci-app-cpufreq/po/zh-cn/cpufreq.po
Normal file
32
luci-app-cpufreq/po/zh-cn/cpufreq.po
Normal file
|
@ -0,0 +1,32 @@
|
|||
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 "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 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 占用率超过 (%) 的情况下触发内核切换频率"
|
3
luci-app-cpufreq/root/etc/config/cpufreq
Normal file
3
luci-app-cpufreq/root/etc/config/cpufreq
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
config settings 'cpufreq'
|
||||
|
27
luci-app-cpufreq/root/etc/init.d/cpufreq
Normal file
27
luci-app-cpufreq/root/etc/init.d/cpufreq
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
START=15
|
||||
|
||||
NAME="cpufreq"
|
||||
|
||||
config_get_cpufreq()
|
||||
{
|
||||
config_get "$NAME" "$1"
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
config_load "$NAME"
|
||||
|
||||
for i in $(find /sys/devices/system/cpu/cpufreq/policy* -maxdepth 0 | grep -Eo '[0-9]+')
|
||||
do
|
||||
[ -z "$(config_get_cpufreq "governor$i")" ] && return
|
||||
|
||||
config_get_cpufreq "governor$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_governor"
|
||||
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"
|
||||
fi
|
||||
done
|
||||
}
|
104
luci-app-cpufreq/root/etc/uci-defaults/10-cpufreq
Normal file
104
luci-app-cpufreq/root/etc/uci-defaults/10-cpufreq
Normal file
|
@ -0,0 +1,104 @@
|
|||
#!/bin/sh
|
||||
|
||||
uci_write_config() {
|
||||
uci -q set cpufreq.cpufreq.governor$1="$2"
|
||||
uci -q set cpufreq.cpufreq.minfreq$1="$3"
|
||||
uci -q set cpufreq.cpufreq.maxfreq$1="$4"
|
||||
[ -n "$5" ] && uci -q set cpufreq.cpufreq.sdfactor$1="$5"
|
||||
[ -n "$6" ] && uci -q set cpufreq.cpufreq.upthreshold$1="$6"
|
||||
uci -q commit cpufreq
|
||||
}
|
||||
|
||||
CPU_FREQS="$(cat '/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies')"
|
||||
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
|
||||
;;
|
||||
"bcm27xx/bcm2711")
|
||||
uci_write_config 0 ondemand 600000 1500000 10 50
|
||||
;;
|
||||
"ipq40xx/generic")
|
||||
uci_write_config 0 ondemand 200000 716000 10 50
|
||||
;;
|
||||
"ipq60xx/generic")
|
||||
if echo "$CPU_FREQS" | grep -q "1800000"; then
|
||||
# IPQ6010/18/28
|
||||
CPU_MAX_FREQ="1800000"
|
||||
else
|
||||
# IPQ6000
|
||||
CPU_MAX_FREQ="1200000"
|
||||
fi
|
||||
uci_write_config 0 ondemand 864000 $CPU_MAX_FREQ 10 50
|
||||
;;
|
||||
"ipq806x/generic")
|
||||
if echo "$CPU_FREQS" | grep -q "1725000"; then
|
||||
# IPQ8065
|
||||
CPU_MAX_FREQ="1725000"
|
||||
elif echo "$CPU_FREQS" | grep -q "1400000"; then
|
||||
# IPQ8064
|
||||
CPU_MAX_FREQ="1400000"
|
||||
else
|
||||
# IPQ8062
|
||||
CPU_MAX_FREQ="1000000"
|
||||
fi
|
||||
uci_write_config 0 ondemand 600000 $CPU_MAX_FREQ 10 50
|
||||
# IPQ8064/5
|
||||
echo "$CPU_POLICYS" | grep -q "1" && uci_write_config 1 ondemand 600000 1200000 10 50
|
||||
;;
|
||||
"ipq807x/generic")
|
||||
if echo "$CPU_FREQS" | grep -q "2208000"; then
|
||||
# IPQ8072/4/6/8A
|
||||
CPU_MAX_FREQ="2208000"
|
||||
else
|
||||
# IPQ8071A
|
||||
CPU_MAX_FREQ="1382400"
|
||||
fi
|
||||
uci_write_config 0 ondemand 1017600 $CPU_MAX_FREQ 10 50
|
||||
;;
|
||||
"mediatek/mt7622")
|
||||
uci_write_config 0 ondemand 600000 1350000 10 50
|
||||
;;
|
||||
"meson/meson8b")
|
||||
uci_write_config 0 schedutil 816000 1536000
|
||||
;;
|
||||
"rockchip/armv8")
|
||||
if echo "$CPU_POLICYS" | grep -q "4"; then
|
||||
# RK3399
|
||||
uci_write_config 0 schedutil 600000 1608000
|
||||
uci_write_config 4 schedutil 600000 2016000
|
||||
else
|
||||
if echo "$CPU_FREQS" | grep -q "1992000"; then
|
||||
# RK3568
|
||||
CPU_MAX_FREQ="1992000"
|
||||
elif echo "$CPU_FREQS" | grep -q "1800000"; then
|
||||
# RK3566
|
||||
CPU_MAX_FREQ="1800000"
|
||||
else
|
||||
# RK3328
|
||||
CPU_MAX_FREQ="1512000"
|
||||
fi
|
||||
uci_write_config 0 schedutil 816000 $CPU_MAX_FREQ
|
||||
fi
|
||||
;;
|
||||
"sunxi/cortexa53")
|
||||
if echo "$CPU_FREQS" | grep -q "1800000"; then
|
||||
# H6
|
||||
uci_write_config 0 schedutil 816000 1800000
|
||||
else
|
||||
# H5
|
||||
uci_write_config 0 ondemand 648000 1200000 10 50
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
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
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"luci-app-cpufreq": {
|
||||
"description": "Grant UCI access for luci-app-cpufreq",
|
||||
"read": {
|
||||
"uci": [ "cpufreq" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "cpufreq" ]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue