From 74d875b68bdf8cdcb1ab5bf055b0ee64fc93bea8 Mon Sep 17 00:00:00 2001 From: Palmer Cox
Date: Tue, 27 Nov 2012 13:17:47 +0100 Subject: [PATCH] --- yaml --- r: 336756 b: refs/heads/master c: ea1021ffa65a81da3d393fcbd7509d6e40d4d325 h: refs/heads/master v: v3 --- [refs] | 2 +- .../power/cpupower/utils/helpers/topology.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index 85ee4c631c6c..ba39032d5f53 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 35a169737cdf9155e890d60eae2b8fffc16d16ba +refs/heads/master: ea1021ffa65a81da3d393fcbd7509d6e40d4d325 diff --git a/trunk/tools/power/cpupower/utils/helpers/topology.c b/trunk/tools/power/cpupower/utils/helpers/topology.c index 4e2b583ea17b..c13120af519b 100644 --- a/trunk/tools/power/cpupower/utils/helpers/topology.c +++ b/trunk/tools/power/cpupower/utils/helpers/topology.c @@ -64,7 +64,7 @@ static int __compare(const void *t1, const void *t2) */ int get_cpu_topology(struct cpupower_topology *cpu_top) { - int cpu, cpus = sysconf(_SC_NPROCESSORS_CONF); + int cpu, last_pkg, cpus = sysconf(_SC_NPROCESSORS_CONF); cpu_top->core_info = malloc(sizeof(struct cpuid_core_info) * cpus); if (cpu_top->core_info == NULL) @@ -78,20 +78,28 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) "physical_package_id", &(cpu_top->core_info[cpu].pkg)) < 0) return -1; - if ((int)cpu_top->core_info[cpu].pkg != -1 && - cpu_top->core_info[cpu].pkg > cpu_top->pkgs) - cpu_top->pkgs = cpu_top->core_info[cpu].pkg; if(sysfs_topology_read_file( cpu, "core_id", &(cpu_top->core_info[cpu].core)) < 0) return -1; } - cpu_top->pkgs++; qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info), __compare); + /* Count the number of distinct pkgs values. This works + because the primary sort of the core_info struct was just + done by pkg value. */ + last_pkg = cpu_top->core_info[0].pkg; + for(cpu = 1; cpu < cpus; cpu++) { + if(cpu_top->core_info[cpu].pkg != last_pkg) { + last_pkg = cpu_top->core_info[cpu].pkg; + cpu_top->pkgs++; + } + } + cpu_top->pkgs++; + /* Intel's cores count is not consecutively numbered, there may * be a core_id of 3, but none of 2. Assume there always is 0 * Get amount of cores by counting duplicates in a package