[sigar/f16: 2/3] Get correct CPU counts on non-x86 architectures

Zane Bitter zaneb at fedoraproject.org
Fri Oct 21 15:14:11 UTC 2011


commit f4df965f484690fb561d83fecf6227c54131bd35
Author: Zane Bitter <zbitter at redhat.com>
Date:   Fri Oct 21 17:04:56 2011 +0200

    Get correct CPU counts on non-x86 architectures

 bz746288-1-cpu-count-arch.patch |   74 +++++++++++++++++++++++++++++++++++++++
 sigar.spec                      |    7 +++-
 2 files changed, 80 insertions(+), 1 deletions(-)
---
diff --git a/bz746288-1-cpu-count-arch.patch b/bz746288-1-cpu-count-arch.patch
new file mode 100644
index 0000000..7151508
--- /dev/null
+++ b/bz746288-1-cpu-count-arch.patch
@@ -0,0 +1,74 @@
+commit 071a2eb9221ecad1ffc7e87e2cc8c4d8a25da519
+Author: Zane Bitter <zbitter at redhat.com>
+Date:   Tue Oct 18 18:56:24 2011 +0200
+
+    Parse /proc/cpuinfo correctly on non-x86 platforms
+    
+    S/390, PPC64 & Itanium have different formats for /proc/cpuinfo
+    
+    Signed-off-by: Zane Bitter <zbitter at redhat.com>
+
+diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c
+index e65abd6..7d0389f 100644
+--- a/src/os/linux/linux_sigar.c
++++ b/src/os/linux/linux_sigar.c
+@@ -1515,6 +1515,7 @@ static int get_cpu_info(sigar_t *sigar, processor_info_t *proc,
+     int found = 0;
+ 
+     memset(proc, 0, sizeof(*proc));
++    info->cores_per_socket = 1;
+ 
+ #ifdef __powerpc64__
+     SIGAR_SSTRCPY(info->vendor, "IBM");
+@@ -1525,6 +1526,30 @@ static int get_cpu_info(sigar_t *sigar, processor_info_t *proc,
+           case 'p': /* processor	: 0 */
+             if (strnEQ(ptr, "processor", 9)) {
+                 found = 1;
++
++#ifdef __s390__
++    /*
++     * Handle S/390 processors, in the format:
++     * processor 0: version = FF,  identification = 32C5C2,  machine = 2097
++     * processor 1: version = FF,  identification = 32C5C2,  machine = 2097
++     */
++                if (sscanf(ptr, "processor %d", &proc->socket) == 1) {
++                    ptr = cpu_info_strval(ptr);
++                    ptr = strstr(ptr, "machine = ");
++                    if (ptr) {
++                        char *s = NULL;
++                        ptr = strtok_r(ptr, ",\n", &s);
++                        size_t len = sizeof(info->model) - 1;
++                        ptr = strchr(ptr, '=') + 2;
++                        strncpy(info->model, ptr, sizeof(info->model));
++                        info->model[sizeof(info->model) - 1] = '\0';
++                        return found;
++                    }
++                }
++#else
++                ptr = cpu_info_strval(ptr);
++                proc->socket = sigar_strtoul(ptr);
++#endif
+             }
+             else if (strnEQ(ptr, "physical id", 11)) {
+                 ptr = cpu_info_strval(ptr);
+@@ -1591,6 +1616,20 @@ static int get_cpu_info(sigar_t *sigar, processor_info_t *proc,
+                     /* "POWER5 (gr)" -> "POWER5" */
+                     *ptr = '\0';
+                 }
++
++                if (strncmp(info->model, "POWER", 5) == 0) {
++                    switch (info->model[5]) {
++                        case '5': // POWER5
++                        case '6': // POWER6
++                            proc->socket /= 2; // 2 threads per core
++                            break;
++                        case '7': // POWER7
++                            proc->socket /= 4; // 4 threads per core
++                            break;
++                        default:
++                            break;
++                    }
++                }
+             }
+ #endif
+             break;
diff --git a/sigar.spec b/sigar.spec
index fac0c32..f07b636 100644
--- a/sigar.spec
+++ b/sigar.spec
@@ -1,6 +1,6 @@
 Name:		sigar
 Version:	1.6.5
-Release:	0.4.git58097d9%{?dist}
+Release:	0.5.git58097d9%{?dist}
 Summary:	System Information Gatherer And Reporter
 
 %global sigar_suffix  0-g4b67f57
@@ -26,6 +26,7 @@ BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires:	gcc cmake
 
 Patch100: bz714249-1-cpu-count.patch
+Patch101: bz746288-1-cpu-count-arch.patch
 
 %description
 The Sigar API provides a portable interface for gathering system
@@ -59,6 +60,7 @@ Header files for developing against the Sigar API
 %setup -q -n %{name}-%{version}
 
 %patch100 -p1 -b .bz714249
+%patch101 -p1 -b .bz746288
 
 %build
 
@@ -96,6 +98,9 @@ rm -rf $RPM_BUILD_ROOT
 %doc LICENSE NOTICE AUTHORS
 
 %changelog
+* Fri Oct 21 2011 Zane Bitter <zbitter at redhat.com> - 1.6.4-0.5.git833ca18
+- Get correct CPU counts on non-x86 architectures
+
 * Mon Aug 29 2011 Zane Bitter <zbitter at redhat.com> - 1.6.5-0.4.git833ca18
 - Get CPU counts from /proc/cpuinfo
   Resolves: #714249


More information about the scm-commits mailing list