From e6de0dd8aac16fae86672213fbe93ae5ae7aa588 Mon Sep 17 00:00:00 2001 From: Pradipta Kumar Date: Wed, 20 May 2015 18:13:07 +0000 Subject: [PATCH] Add support for parsing CPU speed from /proc/cpuinfo on Power (ppc64) systems. /proc/cpuinfo format varies between architectures. For example On Intel the cpu speed is shown like the following cpu MHz : 3000 whereas on Power systems its shown like the following clock : 3000MHz This patch enables support for /proc/cpuinfo parsing on Power systems Signed-off-by: Pradipta Kr. Banerjee --- manager/machine.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manager/machine.go b/manager/machine.go index ea83fa19..cbc2f186 100644 --- a/manager/machine.go +++ b/manager/machine.go @@ -62,7 +62,12 @@ func getClockSpeed(procInfo []byte) (uint64, error) { // Fall back to /proc/cpuinfo matches := CpuClockSpeedMHz.FindSubmatch(procInfo) if len(matches) != 2 { - return 0, fmt.Errorf("could not detect clock speed from output: %q", string(procInfo)) + //Check if we are running on Power systems which have a different format + CpuClockSpeedMHz, _ = regexp.Compile("clock\\t*: +([0-9]+.[0-9]+)MHz") + matches = CpuClockSpeedMHz.FindSubmatch(procInfo) + if len(matches) != 2 { + return 0, fmt.Errorf("could not detect clock speed from output: %q", string(procInfo)) + } } speed, err := strconv.ParseFloat(string(matches[1]), 64) if err != nil {