cpufreq: handle not existing frequency/governer

In some cases not all cpu informations will be provided.
(ex. in virtual machines)
Therefore default to "N/A".

Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
This commit is contained in:
jinleileiking 2012-05-16 18:37:15 +02:00 committed by Adrian C. (anrxc)
parent 13cec6d35a
commit 30db4bea7b
1 changed files with 10 additions and 3 deletions

View File

@ -29,13 +29,20 @@ local function worker(format, warg)
}
-- Default voltage values
local voltage = { v = "N/A", mv = "N/A" }
local freqmhz = "N/A"
local freqghz = "N/A"
-- Get the current frequency
local freq = tonumber(cpufreq.scaling_cur_freq)
-- Calculate MHz and GHz
local freqmhz = freq / 1000
local freqghz = freqmhz / 1000
if freq then
freqmhz = freq / 1000
freqghz = freqmhz / 1000
end
-- Get the current voltage
if cpufreq.scaling_voltages then
@ -47,7 +54,7 @@ local function worker(format, warg)
-- Get the current governor
local governor = cpufreq.scaling_governor
-- Represent the governor as a symbol
governor = governor_state[governor] or governor
governor = governor_state[governor] or governor or "N/A"
return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
end