cpufreq.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Renninger <trenn@suse.de>
To: cpufreq@vger.kernel.org
Cc: Palmer Cox <p@lmercox.com>,
	linux@dominikbrodowski.net, rjw@sisk.pl,
	Thomas Renninger <trenn@suse.de>
Subject: [PATCH 6/8] cpupower tools: Fix warning and a bug with the cpu package count
Date: Tue,  9 Oct 2012 15:21:05 +0200	[thread overview]
Message-ID: <1349788867-65962-7-git-send-email-trenn@suse.de> (raw)
In-Reply-To: <1349788867-65962-1-git-send-email-trenn@suse.de>

From: Palmer Cox <p@lmercox.com>

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>
---
 tools/power/cpupower/utils/helpers/topology.c |   18 +++++++++++++-----
 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 4e2b583..c13120a 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)
  */
 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
-- 
1.7.6.1


  parent reply	other threads:[~2012-10-09 13:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-09 13:20 [PATCH 0/8] cpupower enhancements for 3.7 Thomas Renninger
2012-10-09 13:21 ` [PATCH 1/8] cpupower tools: Remove brace expansion from clean target Thomas Renninger
2012-10-09 13:21 ` [PATCH 2/8] cpupower tools: Update .gitignore for files created in the debug directories Thomas Renninger
2012-10-09 13:21 ` [PATCH 3/8] cpupower tools: Fix minor warnings Thomas Renninger
2012-10-09 13:21 ` [PATCH 4/8] cpupower tools: Fix issues with sysfs_topology_read_file Thomas Renninger
2012-10-09 13:21 ` [PATCH 5/8] cpupower tools: Fix malloc of cpu_info structure Thomas Renninger
2012-10-09 13:21 ` Thomas Renninger [this message]
2012-10-09 13:21 ` [PATCH 7/8] cpupower: Provide -c param for cpupower monitor to schedule process on all cores Thomas Renninger
2012-10-09 13:21 ` [PATCH 8/8] patch cpupower_ivy_bridge_support.patch Thomas Renninger
2012-11-24  9:49   ` Rafael J. Wysocki
2012-11-26 15:46     ` Thomas Renninger
2012-11-26 20:49       ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2012-11-27 12:17 [PATCH 0/8] cpupower enhancements for 3.8 Thomas Renninger
2012-11-27 12:17 ` [PATCH 6/8] cpupower tools: Fix warning and a bug with the cpu package count Thomas Renninger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1349788867-65962-7-git-send-email-trenn@suse.de \
    --to=trenn@suse.de \
    --cc=cpufreq@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=p@lmercox.com \
    --cc=rjw@sisk.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).