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

From: Zhang Rui
Date: Tue Jun 17 2025 - 08:49:46 EST


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.

Reported-by: Artem Bityutskiy <artem.bityutskiy@xxxxxxxxxxxxxxx>
Signed-off-by: Zhang Rui <rui.zhang@xxxxxxxxx>
Reviewed-by: Len Brown <len.brown@xxxxxxxxx>
---
tools/power/x86/turbostat/turbostat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 5f8ab899b552..46f6a696b434 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -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))
--
2.43.0