aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPalmer Cox2012-11-27 06:17:47 -0600
committerRafael J. Wysocki2012-11-27 16:07:19 -0600
commitea1021ffa65a81da3d393fcbd7509d6e40d4d325 (patch)
tree65af69a0511ce4cc8d1f3a75c3a45cd4f6d823ff /tools/power
parent35a169737cdf9155e890d60eae2b8fffc16d16ba (diff)
downloadkernel-omap-ea1021ffa65a81da3d393fcbd7509d6e40d4d325.tar.gz
kernel-omap-ea1021ffa65a81da3d393fcbd7509d6e40d4d325.tar.xz
kernel-omap-ea1021ffa65a81da3d393fcbd7509d6e40d4d325.zip
cpupower tools: Fix warning and a bug with the cpu package count
The pkgs member of cpupower_topology is being used as the number of cpu packages. As the comment in get_cpu_topology notes, the package ids are not guaranteed to be contiguous. So, simply setting pkgs to the value of the highest physical_package_id doesn't actually provide a count of the number of cpu packages. Instead, calculate pkgs by setting it to the number of distinct physical_packge_id values which is pretty easy to do after the core_info structs are sorted. Calculating pkgs this way also has the nice benefit of getting rid of a sign comparison warning that GCC 4.6 was reporting. Signed-off-by: Palmer Cox <p@lmercox.com> Signed-off-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/cpupower/utils/helpers/topology.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/tools/power/cpupower/utils/helpers/topology.c b/tools/power/cpupower/utils/helpers/topology.c
index 4e2b583ea17b..c13120af519b 100644
--- a/tools/power/cpupower/utils/helpers/topology.c
+++ b/tools/power/cpupower/utils/helpers/topology.c
@@ -64,7 +64,7 @@ static int __compare(const void *t1, const void *t2)
64 */ 64 */
65int get_cpu_topology(struct cpupower_topology *cpu_top) 65int get_cpu_topology(struct cpupower_topology *cpu_top)
66{ 66{
67 int cpu, cpus = sysconf(_SC_NPROCESSORS_CONF); 67 int cpu, last_pkg, cpus = sysconf(_SC_NPROCESSORS_CONF);
68 68
69 cpu_top->core_info = malloc(sizeof(struct cpuid_core_info) * cpus); 69 cpu_top->core_info = malloc(sizeof(struct cpuid_core_info) * cpus);
70 if (cpu_top->core_info == NULL) 70 if (cpu_top->core_info == NULL)
@@ -78,20 +78,28 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
78 "physical_package_id", 78 "physical_package_id",
79 &(cpu_top->core_info[cpu].pkg)) < 0) 79 &(cpu_top->core_info[cpu].pkg)) < 0)
80 return -1; 80 return -1;
81 if ((int)cpu_top->core_info[cpu].pkg != -1 &&
82 cpu_top->core_info[cpu].pkg > cpu_top->pkgs)
83 cpu_top->pkgs = cpu_top->core_info[cpu].pkg;
84 if(sysfs_topology_read_file( 81 if(sysfs_topology_read_file(
85 cpu, 82 cpu,
86 "core_id", 83 "core_id",
87 &(cpu_top->core_info[cpu].core)) < 0) 84 &(cpu_top->core_info[cpu].core)) < 0)
88 return -1; 85 return -1;
89 } 86 }
90 cpu_top->pkgs++;
91 87
92 qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info), 88 qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info),
93 __compare); 89 __compare);
94 90
91 /* Count the number of distinct pkgs values. This works
92 because the primary sort of the core_info struct was just
93 done by pkg value. */
94 last_pkg = cpu_top->core_info[0].pkg;
95 for(cpu = 1; cpu < cpus; cpu++) {
96 if(cpu_top->core_info[cpu].pkg != last_pkg) {
97 last_pkg = cpu_top->core_info[cpu].pkg;
98 cpu_top->pkgs++;
99 }
100 }
101 cpu_top->pkgs++;
102
95 /* Intel's cores count is not consecutively numbered, there may 103 /* Intel's cores count is not consecutively numbered, there may
96 * be a core_id of 3, but none of 2. Assume there always is 0 104 * be a core_id of 3, but none of 2. Assume there always is 0
97 * Get amount of cores by counting duplicates in a package 105 * Get amount of cores by counting duplicates in a package