diff --git a/include/target.mk b/include/target.mk index c28b83e97c..f6e98cd136 100644 --- a/include/target.mk +++ b/include/target.mk @@ -16,7 +16,7 @@ DEVICE_TYPE?=router DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools uclient-fetch logd urandom-seed urngd \ coreutils kmod-nf-nathelper kmod-nf-nathelper-extra kmod-ipt-raw wget libustream-openssl ca-certificates \ default-settings luci luci-base luci-compat luci-lib-fs luci-lib-ipkg luci-proto-relay \ - luci-app-flowoffload + luci-app-cpufreq luci-app-flowoffload # For nas targets DEFAULT_PACKAGES.nas:=block-mount fdisk lsblk mdadm # For router targets diff --git a/package/lean/luci-app-cpufreq/Makefile b/package/lean/luci-app-cpufreq/Makefile index e1c90bebaa..f63196669f 100644 --- a/package/lean/luci-app-cpufreq/Makefile +++ b/package/lean/luci-app-cpufreq/Makefile @@ -6,11 +6,11 @@ include $(TOPDIR)/rules.mk -LUCI_TITLE:=LuCI for CPU IPQ40xx Freq -LUCI_DEPENDS:=@TARGET_ipq40xx +LUCI_TITLE:=LuCI for CPU Freq Setting +LUCI_DEPENDS:= PKG_NAME:=luci-app-cpufreq PKG_VERSION:=1 -PKG_RELEASE:=2 +PKG_RELEASE:=3 include $(TOPDIR)/feeds/luci/luci.mk diff --git a/package/lean/luci-app-cpufreq/luasrc/model/cbi/cpufreq.lua b/package/lean/luci-app-cpufreq/luasrc/model/cbi/cpufreq.lua index 640f0f6f0c..342a886608 100644 --- a/package/lean/luci-app-cpufreq/luasrc/model/cbi/cpufreq.lua +++ b/package/lean/luci-app-cpufreq/luasrc/model/cbi/cpufreq.lua @@ -1,3 +1,26 @@ +local fs = require "nixio.fs" + +cpu_freqs = fs.readfile("/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies") or "100000" +cpu_freqs = string.sub(cpu_freqs, 1, -3) + +cpu_governors = fs.readfile("/sys/devices/system/cpu/cpufreq/policy0/scaling_available_governors") or "performance" +cpu_governors = string.sub(cpu_governors, 1, -3) + +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 + +freq_array = string.split(cpu_freqs, " ") +governor_array = string.split(cpu_governors, " ") mp = Map("cpufreq", translate("CPU Freq Settings")) mp.description = translate("Set CPU Scaling Governor to Max Performance or Balance Mode") @@ -6,22 +29,19 @@ 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")) +for _, e in ipairs(governor_array) do + if e ~= "" then governor:value(e,string.upper(e)) end +end -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 +minfreq = s:option(ListValue, "minifreq", translate("Min Idle CPU Freq")) +for _, e in ipairs(freq_array) do + if e ~= "" then minfreq:value(e) end +end -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 +maxfreq = s:option(ListValue, "maxfreq", translate("Max Turbo Boost CPU Freq")) +for _, e in ipairs(freq_array) do + if e ~= "" then maxfreq:value(e) end +end upthreshold = s:option(Value, "upthreshold", translate("CPU Switching Threshold")) upthreshold.datatype="range(1,99)" @@ -37,5 +57,4 @@ factor.description = translate("The sampling rate determines how frequently the factor.placeholder = 10 factor.default = 10 - return mp