From bfee51741e4d6a9b6263033e8a63a4cc3f1bb69d Mon Sep 17 00:00:00 2001
From: Rolf Eike Beer <eike@sf-mail.de>
Date: Sat, 8 Sep 2012 17:25:03 +0200
Subject: [PATCH] SystemInformation: sum up all caches found in /proc/cpuinfo

Non-x86 architectures (namely PA-RISC) may not have the "cache size" line, but
others. Search for all and sum up their results.

Change-Id: Ie8e1c52e2b8be69b0b919bb029c1db95c04a9309
---
 SystemInformation.cxx | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 1077b11..7814529 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -3101,13 +3101,29 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
   this->ChipID.ModelName = this->ExtractValueFromCpuInfoFile(buffer,"model name").c_str();
 
   // L1 Cache size
-  kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,"cache size");
-  pos = cacheSize.find(" KB");
-  if(pos!=cacheSize.npos)
+  // Different architectures may show different names for the caches.
+  // Sum up everything we find.
+  kwsys_stl::vector<const char*> cachename;
+  cachename.clear();
+
+  cachename.push_back("cache size"); // e.g. x86
+  cachename.push_back("I-cache"); // e.g. PA-RISC
+  cachename.push_back("D-cache"); // e.g. PA-RISC
+
+  this->Features.L1CacheSize = 0;
+  for (size_t index = 0; index < cachename.size(); index ++)
     {
-    cacheSize = cacheSize.substr(0,pos);
+    kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,cachename[index]);
+    if (!cacheSize.empty())
+      {
+      pos = cacheSize.find(" KB");
+      if(pos!=cacheSize.npos)
+        {
+        cacheSize = cacheSize.substr(0,pos);
+        }
+      this->Features.L1CacheSize += atoi(cacheSize.c_str());
+      }
     }
-  this->Features.L1CacheSize = atoi(cacheSize.c_str());
   return 1;
 }
 
-- 
GitLab