Skip to contentSkip to conversation

tools/power turbostat: Fix bogus SysWatt for forked program

PATCH Applied Zhang Rui 2 participants 4 messages Jun 17, 2025 – Jun 18, 2025 Turbostat utility

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

PATCH 1/2 tools/power turbostat: Fix bogus SysWatt for forked program

Similar to delta_cpu(), delta_platform() is called in turbostat main loop. This ensures accurate SysWatt readings in periodic monitoring mode

$ sudo turbostat -S -q --show power -i 1
CoreTmp	PkgTmp	PkgWatt	CorWatt	GFXWatt	RAMWatt	PKG_%	RAM_%	SysWatt
60	61	6.21	1.13	0.16	0.00	0.00	0.00	13.07
58	61	6.00	1.07	0.18	0.00	0.00	0.00	12.75
58	61	5.74	1.05	0.17	0.00	0.00	0.00	12.22
58	60	6.27	1.11	0.24	0.00	0.00	0.00	13.55

However, delta_platform() is missing for forked program and causes bogus SysWatt reporting,

$ sudo turbostat -S -q --show power sleep 1
1.004736 sec
CoreTmp	PkgTmp	PkgWatt	CorWatt	GFXWatt	RAMWatt	PKG_%	RAM_%	SysWatt
57	58	6.05	1.02	0.16	0.00	0.00	0.00	0.03

Add missing delta_platform() for forked program.

Fixes e5f687b89bc2 ("tools/power turbostat: Add RAPL psys as a built-in counter")
---
 tools/power/x86/turbostat/turbostat.c | 1 +
 1 file changed, 1 insertion(+)
tools/power/x86/turbostat/turbostat.c +1 -0
index 5230e072e414..5f8ab899b552 100644
@@ -9817,6 +9817,7 @@ int fork_it(char **argv)
 	timersub(&tv_odd, &tv_even, &tv_delta);
 	if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS))
 		fprintf(outf, "%s: Counter reset detected\n", progname);
+	delta_platform(&platform_counters_odd, &platform_counters_even);
 
 	compute_average(EVEN_COUNTERS);
 	format_all_counters(EVEN_COUNTERS);
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 2/2 tools/power turbostat: Enhance legacy uncore detection

Currently, legacy uncore probe is done by checking the permission for /sys/devices/system/cpu/intel_uncore_frequency/package_X_die_Y/ However, legacy uncore runtime update needs to access /sys/devices/system/cpu/intel_uncore_frequency/package_X_die_Y/current_freq_khz which demands higher privileges.

This discrepancy can lead to situations where turbostat incorrectly detects legacy uncore support but fails to access it during runtime when executed without root privileges.

Fix the problem by checking the same sysfs entry used for runtime update to decide if legacy uncore support can be probed or not.

---
 tools/power/x86/turbostat/turbostat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +1 -1
index 5f8ab899b552..46f6a696b434 100644
@@ -6737,7 +6737,7 @@ static void probe_intel_uncore_frequency_legacy(void)
 			int k, l;
 			char path_base[128];
 
-			sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d", i,
+			sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/current_freq_khz", i,
 				j);
 
 			if (access(path_base, R_OK))
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw

Re: [PATCH 2/2] tools/power turbostat: Enhance legacy uncore detection

Applied

thanks!
-Len