2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2009, Adrian C. <anrxc.sysphere.org>
|
|
|
|
---------------------------------------------------
|
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 io = { open = io.open }
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local string = {
|
|
|
|
find = string.find,
|
|
|
|
match = string.match
|
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Cpufreq: provides freq, voltage and governor info for a requested CPU
|
|
|
|
module("vicious.cpufreq")
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ CPU frequency widget type
|
2009-08-07 17:41:10 +02:00
|
|
|
local function worker(format, cpuid)
|
2009-08-03 04:40:55 +02:00
|
|
|
--local governor_state = {
|
|
|
|
-- ["ondemand"] = "↯",
|
|
|
|
-- ["powersave"] = "⌁",
|
|
|
|
-- ["userspace"] = "°",
|
|
|
|
-- ["performance"] = "⚡",
|
|
|
|
-- ["conservative"] = "↯"
|
|
|
|
--}
|
|
|
|
|
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-10-02 20:21:21 +02:00
|
|
|
local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_cur_freq")
|
|
|
|
local freq = f:read("*line")
|
|
|
|
f:close()
|
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-10-02 20:21:21 +02:00
|
|
|
local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_voltages")
|
|
|
|
if f then for line in f:lines() do
|
2009-10-04 00:55:56 +02:00
|
|
|
if string.find(line, "^"..freq) then
|
2009-10-26 20:32:48 +01:00
|
|
|
voltage.mv = tonumber(string.match(line, "[%d]+[%s]([%d]+)"))
|
2009-08-03 04:40:55 +02:00
|
|
|
break
|
|
|
|
end
|
2009-10-02 20:21:21 +02:00
|
|
|
end
|
|
|
|
f:close()
|
2009-08-03 04:40:55 +02:00
|
|
|
|
2009-10-02 20:21:21 +02:00
|
|
|
-- Calculate voltage from mV
|
|
|
|
voltage.v = voltage.mv / 1000
|
|
|
|
end
|
2009-08-03 04:40:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Get the current governor
|
2009-10-02 20:21:21 +02:00
|
|
|
local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_governor")
|
|
|
|
local governor = f:read("*line")
|
|
|
|
f:close()
|
2009-08-03 04:40:55 +02:00
|
|
|
|
|
|
|
-- Represent the governor as a symbol
|
|
|
|
--local governor = governor_state[governor] or governor
|
|
|
|
|
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 })
|