evilsong / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[PATCH] Support for CPU frequencies for Linux on POWER #454

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Current TCMalloc code at 'src/base/sysinfo.cc' does not know how to handle 
PowerPC frequency information and fallback to use 'EstimateCyclesPerSecond' 
function, which adds an additional second on program execution. The patch 
proposed makes the function 'InitializeSystemInfo' correctly handle PowerPC 
frequency information.

Index: src/base/sysinfo.cc
===================================================================
--- src/base/sysinfo.cc (revision 151)
+++ src/base/sysinfo.cc (working copy)
@@ -350,6 +350,22 @@
     if (newline != NULL)
       *newline = '\0';

+#if defined(__powerpc__) || defined(__ppc__)
+    // PowerPC cpus report the frequency in "clock" line
+    if (strncasecmp(line, "clock", sizeof("clock")-1) == 0) {
+      const char* freqstr = strchr(line, ':');
+      if (freqstr) {
+   // PowerPC frequencies are only reported as MHz (check 'show_cpuinfo'
+   // function at arch/powerpc/kernel/setup-common.c)
+   char *endp = strstr(line, "MHz");
+   if (endp) {
+     *endp = 0;
+     cpuinfo_cycles_per_second = strtod(freqstr+1, &err) * 1000000.0;
+          if (freqstr[1] != '\0' && *err == '\0' && cpuinfo_cycles_per_second 
> 0)
+            saw_mhz = true;
+   }
+      }
+#else
     // When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
     // accept postive values. Some environments (virtual machines) report zero,
     // which would cause infinite looping in WallTime_Init.
@@ -367,6 +383,7 @@
         if (freqstr[1] != '\0' && *err == '\0' && bogo_clock > 0)
           saw_bogo = true;
       }
+#endif
     } else if (strncasecmp(line, "processor", sizeof("processor")-1) == 0) {
       num_cpus++;  // count up every time we see an "processor :" entry
     }

Original issue reported on code.google.com by zatr...@gmail.com on 25 Jul 2012 at 4:20

GoogleCodeExporter commented 9 years ago
------------------------------------------------------------------------
r159 | chappedm@gmail.com | 2012-09-17 22:33:00 -0400 (Mon, 17 Sep 2012) | 1 
line

Adding support for CPU frequencies for Linux on PowerPC
------------------------------------------------------------------------

Original comment by chapp...@gmail.com on 18 Sep 2012 at 2:34