From 24a1e64fafbc807c3b4073ed357dbf7a42789b7d Mon Sep 17 00:00:00 2001 From: Kamil Iskra Date: Wed, 26 Jul 2023 15:45:09 -0500 Subject: [PATCH] powercap: test counter read permissions Check that the files inside /sys/class/powercap/intel-rapl: directories not only exist, but are readable. On recent Linux kernels, "energy_uj" is by default readable by root only, which is something that PAPI fails to detect, resulting in 0 being returned for that counter without any indication of a problem. --- src/components/powercap/linux-powercap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/powercap/linux-powercap.c b/src/components/powercap/linux-powercap.c index 9ac12144f..5d72f739a 100644 --- a/src/components/powercap/linux-powercap.c +++ b/src/components/powercap/linux-powercap.c @@ -238,7 +238,7 @@ static int _powercap_init_component( int cidx ) if (strErr > sizeof(event_path)) HANDLE_STRING_ERROR; // not a valid pkg event path so continue - if (access(event_path, F_OK) == -1) { continue; } + if (access(event_path, R_OK) == -1) { continue; } strErr=snprintf(powercap_ntv_events[num_events].name, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d", pkg_event_names[e], s); powercap_ntv_events[num_events].name[sizeof(powercap_ntv_events[num_events].name)-1]=0; @@ -286,7 +286,7 @@ static int _powercap_init_component( int cidx ) if (strErr > sizeof(event_path)) HANDLE_STRING_ERROR; // not a valid pkg event path so continue - if (access(event_path, F_OK) == -1) { continue; } + if (access(event_path, R_OK) == -1) { continue; } strErr=snprintf(powercap_ntv_events[num_events].name, sizeof(powercap_ntv_events[num_events].name), "%s:ZONE%d_SUBZONE%d", component_event_names[e], s, c); powercap_ntv_events[num_events].name[sizeof(powercap_ntv_events[num_events].name)-1]=0;