linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: lenb@kernel.org, Prarit Bhargava <prarit@redhat.com>,
	Len Brown <len.brown@intel.com>
Subject: [PATCH 1/7] turbostat: set max_num_cpus equal to the cpumask length
Date: Tue, 25 Jul 2017 08:24:23 -0400	[thread overview]
Message-ID: <1500985469-23493-2-git-send-email-prarit@redhat.com> (raw)
In-Reply-To: <1500985469-23493-1-git-send-email-prarit@redhat.com>

Future fixes will use sysfs files that contain cpumask output.  The code
needs to know the length of the cpumask in order to determine which cpus
are set in a cpumask.  Currently topo.max_cpu_num is the maximum cpu
number.  It can be increased the the maximum value of cpus represented in
cpumasks.

Set max_num_cpus to the length of a cpumask.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: Len Brown <len.brown@intel.com>
---
 tools/power/x86/turbostat/turbostat.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 0dafba2c1e7d..6d368e744d27 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2413,6 +2413,20 @@ void re_initialize(void)
 	printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus);
 }
 
+void set_max_cpu_num(void)
+{
+	FILE *filep;
+	unsigned long dummy;
+
+	topo.max_cpu_num = 0;
+	filep = fopen_or_die(
+			"/sys/devices/system/cpu/cpu0/topology/thread_siblings",
+			"r");
+	while (fscanf(filep, "%lx,", &dummy) == 1)
+		topo.max_cpu_num+=32;
+	fclose(filep);
+	topo.max_cpu_num--; /* 0 based */
+}
 
 /*
  * count_cpus()
@@ -2420,10 +2434,7 @@ void re_initialize(void)
  */
 int count_cpus(int cpu)
 {
-	if (topo.max_cpu_num < cpu)
-		topo.max_cpu_num = cpu;
-
-	topo.num_cpus += 1;
+	topo.num_cpus++;
 	return 0;
 }
 int mark_cpu_present(int cpu)
@@ -4320,8 +4331,8 @@ void topology_probe()
 	} *cpus;
 
 	/* Initialize num_cpus, max_cpu_num */
+	set_max_cpu_num();
 	topo.num_cpus = 0;
-	topo.max_cpu_num = 0;
 	for_all_proc_cpus(count_cpus);
 	if (!summary_only && topo.num_cpus > 1)
 		BIC_PRESENT(BIC_CPU);
-- 
1.8.5.5

  reply	other threads:[~2017-07-25 12:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 12:24 [PATCH 0/7 RESEND] turbostat: Fix AMD output by making turbostat aware of nodes Prarit Bhargava
2017-07-25 12:24 ` Prarit Bhargava [this message]
2017-07-25 12:24 ` [PATCH 2/7] turbostat: Fix node and siblings lookup data Prarit Bhargava
2017-07-25 12:24 ` [PATCH 3/7] turbostat: Calculate additional node information for a package Prarit Bhargava
2017-07-25 12:24 ` [PATCH 4/7] turbostat: track thread ID in cpu_topology Prarit Bhargava
2017-07-25 12:24 ` [PATCH 5/7] turbostat: rename num_cores_per_pkg to num_cores_per_node Prarit Bhargava
2017-07-25 12:24 ` [PATCH 6/7] turbostat: remove num_ from cpu_topology struct Prarit Bhargava
2017-07-25 12:24 ` [PATCH 7/7] turbostat: add node information into turbostat calculations Prarit Bhargava
  -- strict thread matches above, loose matches on Subject: below --
2017-07-16 20:49 [PATCH 0/7] turbostat, Fix AMD output by making turbostat aware of nodes Prarit Bhargava
2017-07-16 20:49 ` [PATCH 1/7] turbostat: set max_num_cpus equal to the cpumask length Prarit Bhargava

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=1500985469-23493-2-git-send-email-prarit@redhat.com \
    --to=prarit@redhat.com \
    --cc=len.brown@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).