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