From d2bcbe11b83adb9f0106bb0c234194798b54773c Mon Sep 17 00:00:00 2001
From: Rolf Eike Beer <eike@sf-mail.de>
Date: Sat, 30 Nov 2013 01:50:16 +0100
Subject: [PATCH] SystemInformation: extract CPU information on Linux/Sparc

Change-Id: I9a6ce9af30dae548e860636ad64164200ba91f49
---
 SystemInformation.cxx | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 2f6c949..be9b6ea 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -3162,8 +3162,17 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
   kwsys_stl::string cores =
                         this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
   int numberOfCoresPerCPU=atoi(cores.c_str());
-  this->NumberOfPhysicalCPU=static_cast<unsigned int>(
-    numberOfCoresPerCPU*(maxId+1));
+  if (maxId > 0)
+    {
+    this->NumberOfPhysicalCPU=static_cast<unsigned int>(
+      numberOfCoresPerCPU*(maxId+1));
+    }
+  else
+    {
+    // Linux Sparc: get cpu count
+    this->NumberOfPhysicalCPU=
+            atoi(this->ExtractValueFromCpuInfoFile(buffer,"ncpus active").c_str());
+    }
 
 #else // __CYGWIN__
   // does not have "physical id" entries, neither "cpu cores"
@@ -3185,7 +3194,19 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
 
   // CPU speed (checking only the first processor)
   kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
-  this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
+  if(!CPUSpeed.empty())
+    {
+    this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
+    }
+#ifdef __linux
+  else
+    {
+    // Linux Sparc: CPU speed is in Hz and encoded in hexadecimal
+    CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"Cpu0ClkTck");
+    this->CPUSpeedInMHz = static_cast<float>(
+                                 strtoull(CPUSpeed.c_str(),0,16))/1000000.0f;
+    }
+#endif
 
   // Chip family
   kwsys_stl::string familyStr =
-- 
GitLab