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
|
2010-03-14 01:55:33 +01:00
|
|
|
module("vicious.widgets.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
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2009-10-02 20:21:21 +02:00
|
|
|
-- Default voltage values
|
|
|
|
local voltage = { v = "N/A", mv = "N/A" }
|
|
|
|
|
|
|
|
|
2009-08-03 04:40:55 +02:00
|
|
|
-- Get the current frequency
|
2009-11-11 03:15:56 +01:00
|
|
|
local freq = tonumber(cpufreq.scaling_cur_freq)
|
2009-08-03 04:40:55 +02:00
|
|
|
-- Calculate MHz and GHz
|
|
|
|
local freqmhz = freq / 1000
|
|
|
|
local freqghz = freqmhz / 1000
|
|
|
|
|
|
|
|
-- Get the current voltage
|
2009-11-11 03:15:56 +01:00
|
|
|
if cpufreq.scaling_voltages then
|
|
|
|
voltage.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
|
|
|
|
-- Calculate voltage from mV
|
|
|
|
voltage.v = voltage.mv / 1000
|
2009-10-02 20:21:21 +02:00
|
|
|
end
|
2009-08-03 04:40:55 +02:00
|
|
|
|
|
|
|
-- Get the current governor
|
2009-11-11 03:15:56 +01:00
|
|
|
local governor = cpufreq.scaling_governor
|
2009-08-03 04:40:55 +02:00
|
|
|
-- Represent the governor as a symbol
|
2009-11-11 03:15:56 +01:00
|
|
|
governor = governor_state[governor] or governor
|
2009-08-03 04:40:55 +02:00
|
|
|
|
2009-10-02 20:21:21 +02:00
|
|
|
return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
|
2009-08-03 04:40:55 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|