From 3dc4e52844905e2cf2a767478bc7afe7866b34a7 Mon Sep 17 00:00:00 2001 From: "K.C. Wong" Date: Mon, 29 Aug 2016 16:21:17 -0700 Subject: [PATCH] Handle the case when the `cpufreq` sysfs does not exist * on virtualized host, this may happen. * but we may have a value from parsing `/proc/cpuinfo` * in this case, we do not return the error if we fail to extra a value from `cpufreq/cpuinfo_max_freq` --- cpu/cpu_linux.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 14e0796..71d3884 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -80,12 +80,22 @@ func finishCPUInfo(c *InfoStat) error { // of the value from /proc/cpuinfo because we want to report the maximum // clock-speed of the CPU for c.Mhz, matching the behaviour of Windows lines, err = common.ReadLines(sysCPUPath(c.CPU, "cpufreq/cpuinfo_max_freq")) + // if we encounter errors below but has a value from parsing /proc/cpuinfo + // then we ignore the error if err != nil { - return err + if c.Mhz == 0 { + return err + } else { + return nil + } } value, err = strconv.ParseFloat(lines[0], 64) if err != nil { - return err + if c.Mhz == 0 { + return err + } else { + return nil + } } c.Mhz = value/1000.0 // value is in kHz return nil