cpufreq: rework new exception handlers

Now that we are so nice to provide default frequency values check if
frequency exists before calculating voltage, not to screw up *those*
default values.

Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
This commit is contained in:
Adrian C. (anrxc) 2012-05-19 17:07:25 +02:00
parent 30db4bea7b
commit 97e54d60f8
1 changed files with 11 additions and 14 deletions

View File

@ -27,28 +27,25 @@ local function worker(format, warg)
["performance\n"] = "",
["conservative\n"] = ""
}
-- Default voltage values
local voltage = { v = "N/A", mv = "N/A" }
local freqmhz = "N/A"
local freqghz = "N/A"
-- Default frequency and voltage values
local freqv = {
["mhz"] = "N/A", ["ghz"] = "N/A",
["v"] = "N/A", ["mv"] = "N/A",
}
-- Get the current frequency
local freq = tonumber(cpufreq.scaling_cur_freq)
-- Calculate MHz and GHz
if freq then
freqmhz = freq / 1000
freqghz = freqmhz / 1000
freqv.mhz = freq / 1000
freqv.ghz = freqv.mhz / 1000
end
-- Get the current voltage
if cpufreq.scaling_voltages then
voltage.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
if cpufreq.scaling_voltages and freq then
freqv.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
-- Calculate voltage from mV
voltage.v = voltage.mv / 1000
freqv.v = freqv.mv / 1000
end
-- Get the current governor
@ -56,7 +53,7 @@ local function worker(format, warg)
-- Represent the governor as a symbol
governor = governor_state[governor] or governor or "N/A"
return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor}
end
-- }}}