2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
2009-08-03 04:40:55 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2009-10-26 20:32:48 +01:00
|
|
|
local tonumber = tonumber
|
2009-08-03 04:40:55 +02:00
|
|
|
local setmetatable = setmetatable
|
2009-11-11 03:15:56 +01:00
|
|
|
local string = { match = string.match }
|
|
|
|
local helpers = require("vicious.helpers")
|
2009-08-03 04:40:55 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Cpufreq: provides freq, voltage and governor info for a requested CPU
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.cpufreq
|
|
|
|
local cpufreq = {}
|
2009-08-03 04:40:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- {{{ CPU frequency widget type
|
2010-03-14 03:37:40 +01:00
|
|
|
local function worker(format, warg)
|
|
|
|
if not warg then return end
|
|
|
|
|
2012-06-15 18:07:05 +02:00
|
|
|
local _cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..warg.."/cpufreq")
|
2009-11-11 03:15:56 +01:00
|
|
|
local governor_state = {
|
2010-03-06 22:12:47 +01:00
|
|
|
["ondemand\n"] = "↯",
|
|
|
|
["powersave\n"] = "⌁",
|
|
|
|
["userspace\n"] = "¤",
|
|
|
|
["performance\n"] = "⚡",
|
2012-01-15 00:17:47 +01:00
|
|
|
["conservative\n"] = "⊚"
|
2009-11-11 03:15:56 +01:00
|
|
|
}
|
2012-05-19 17:07:25 +02:00
|
|
|
-- Default frequency and voltage values
|
|
|
|
local freqv = {
|
|
|
|
["mhz"] = "N/A", ["ghz"] = "N/A",
|
|
|
|
["v"] = "N/A", ["mv"] = "N/A",
|
|
|
|
}
|
2009-10-02 20:21:21 +02:00
|
|
|
|
2009-08-03 04:40:55 +02:00
|
|
|
-- Get the current frequency
|
2012-06-15 18:07:05 +02:00
|
|
|
local freq = tonumber(_cpufreq.scaling_cur_freq)
|
2009-08-03 04:40:55 +02:00
|
|
|
-- Calculate MHz and GHz
|
2012-05-16 18:37:15 +02:00
|
|
|
if freq then
|
2012-05-19 17:07:25 +02:00
|
|
|
freqv.mhz = freq / 1000
|
|
|
|
freqv.ghz = freqv.mhz / 1000
|
2012-05-16 18:37:15 +02:00
|
|
|
|
2012-05-20 04:19:51 +02:00
|
|
|
-- Get the current voltage
|
2012-06-15 18:07:05 +02:00
|
|
|
if _cpufreq.scaling_voltages then
|
|
|
|
freqv.mv = tonumber(string.match(_cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
|
2012-05-20 04:19:51 +02:00
|
|
|
-- Calculate voltage from mV
|
|
|
|
freqv.v = freqv.mv / 1000
|
|
|
|
end
|
2009-10-02 20:21:21 +02:00
|
|
|
end
|
2009-08-03 04:40:55 +02:00
|
|
|
|
|
|
|
-- Get the current governor
|
2012-06-15 18:07:05 +02:00
|
|
|
local governor = _cpufreq.scaling_governor
|
2009-08-03 04:40:55 +02:00
|
|
|
-- Represent the governor as a symbol
|
2012-05-16 18:37:15 +02:00
|
|
|
governor = governor_state[governor] or governor or "N/A"
|
2009-08-03 04:40:55 +02:00
|
|
|
|
2012-05-19 17:07:25 +02:00
|
|
|
return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor}
|
2009-08-03 04:40:55 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2012-06-15 18:07:05 +02:00
|
|
|
return setmetatable(cpufreq, { __call = function(_, ...) return worker(...) end })
|