public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Len Brown <lenb@kernel.org>
To: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 09/13] tools/power turbostat: Process HT siblings in CPU order
Date: Sat, 25 Apr 2026 14:42:12 -0400	[thread overview]
Message-ID: <58839fdbd441dc079800f2575013f2c438159d5a.1777141988.git.len.brown@intel.com> (raw)
In-Reply-To: <feffac1874820d501e51cd8dcee697063b792c82.1777141988.git.len.brown@intel.com>

From: Len Brown <len.brown@intel.com>

On large systems with HT sibling cpu#'s more than 32 apart,
HT siblings were processed and displayed in reverse order.

This was due to how set_thread_siblings() parsed the
sibling-bit-mask.

Update set_thread_siblings to instead parse the sibling-list,
like other cpu lists, and to thus order HT siblings
by ascending CPU number, no matter the size of the system.

Signed-off-by: Len Brown <len.brown@intel.com>
---
 tools/power/x86/turbostat/turbostat.c | 80 +++++++++++----------------
 1 file changed, 31 insertions(+), 49 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index f8e9aa8c9e54..d46878c63a80 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -6219,55 +6219,6 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size)
 	return 0;
 }
 
-int set_thread_siblings(struct cpu_topology *thiscpu)
-{
-	char path[80], character;
-	FILE *filep;
-	unsigned long map;
-	int so, shift, sib_core;
-	int cpu = thiscpu->cpu_id;
-	int offset = topo.max_cpu_num + 1;
-	size_t size;
-	int ht_id = 0;
-
-	thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
-	if (thiscpu->ht_id < 0)
-		thiscpu->ht_id = 0;	/* first CPU in core */
-	if (!thiscpu->put_ids)
-		return -1;
-
-	size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
-	CPU_ZERO_S(size, thiscpu->put_ids);
-
-	sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu);
-	filep = fopen(path, "r");
-
-	if (!filep) {
-		warnx("%s: open failed", path);
-		return -1;
-	}
-	do {
-		offset -= BITMASK_SIZE;
-		if (fscanf(filep, "%lx%c", &map, &character) != 2)
-			err(1, "%s: failed to parse file", path);
-		for (shift = 0; shift < BITMASK_SIZE; shift++) {
-			if ((map >> shift) & 0x1) {
-				so = shift + offset;
-				sib_core = get_core_id(so);
-				if (sib_core == thiscpu->core_id) {
-					CPU_SET_S(so, size, thiscpu->put_ids);
-					cpus[so].ht_id = ht_id;
-					cpus[cpu].ht_sibling_cpu_id[ht_id] = so;
-					ht_id += 1;
-				}
-			}
-		}
-	} while (character == ',');
-	fclose(filep);
-
-	return CPU_COUNT_S(size, thiscpu->put_ids);
-}
-
 /*
  * run func(thread, core, package) in topology order
  * skip non-present cpus
@@ -9539,6 +9490,37 @@ int dir_filter(const struct dirent *dirp)
 		return 0;
 }
 
+int set_thread_siblings(struct cpu_topology *thiscpu)
+{
+	char path[80];
+	int cpu = thiscpu->cpu_id;
+	size_t size;
+	int ht_id = 0;
+	int i;
+
+	thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
+	if (thiscpu->ht_id < 0)
+		thiscpu->ht_id = 0;	/* first CPU in core */
+	if (!thiscpu->put_ids)
+		return -1;
+
+	size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
+	CPU_ZERO_S(size, thiscpu->put_ids);
+
+	sprintf(path, "/sys/devices/system/cpu/cpu%d/topology", cpu);
+
+	initialize_cpu_set_from_sysfs(thiscpu->put_ids, path, "thread_siblings_list");
+
+	for (i = 0; i <= topo.max_cpu_num; ++i)
+		if (CPU_ISSET_S(i, size, thiscpu->put_ids)) {
+			cpus[i].ht_id = ht_id;
+			cpus[cpu].ht_sibling_cpu_id[ht_id] = i;
+			ht_id += 1;
+		}
+
+	return (ht_id - 1);
+}
+
 void topology_probe(bool startup)
 {
 	int i;
-- 
2.45.2


  parent reply	other threads:[~2026-04-25 18:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-25 18:42 [PATCH 0/13] Power Utilities update for Linux-7.1 Len Brown
2026-04-25 18:42 ` [PATCH 01/13] tools/power/x86: Add SOC slider and platform profile support Len Brown
2026-04-25 18:42   ` [PATCH 02/13] tools/power turbostat: Fix AMD RAPL regression on big systems Len Brown
2026-04-25 18:42   ` [PATCH 03/13] tools/power turbostat: Fix unrecognized option '-P' Len Brown
2026-04-25 18:42   ` [PATCH 04/13] tools/power turbostat: Fix --cpu-set 0 regression on HT systems Len Brown
2026-04-25 18:42   ` [PATCH 05/13] tools/power turbostat: Fix --cpu-set 1 " Len Brown
2026-04-25 18:42   ` [PATCH 06/13] tools/power turbostat: Cleanup print helper functions Len Brown
2026-04-25 18:42   ` [PATCH 07/13] tools/power turbostat: Print core_id and apic_id in hex Len Brown
2026-04-25 18:42   ` [PATCH 08/13] tools/power turbostat: Show module_id column Len Brown
2026-04-25 18:42   ` Len Brown [this message]
2026-04-25 18:42   ` [PATCH 10/13] tools/power turbostat: v2026.04.21 Len Brown
2026-04-25 18:42   ` [PATCH 11/13] tools/power x86_energy_perf_policy: Enhances SoC Slider related checks Len Brown
2026-04-25 18:42   ` [PATCH 12/13] tools/power x86_energy_perf_policy.8: Document SoC Slider Options Len Brown
2026-04-25 18:42   ` [PATCH 13/13] tools/power x86_energy_perf_policy: Version 2026.04.25 Len Brown

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=58839fdbd441dc079800f2575013f2c438159d5a.1777141988.git.len.brown@intel.com \
    --to=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@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