Skip to content

Commit

Permalink
powercap: ignore the psys entry
Browse files Browse the repository at this point in the history
This is a bit of a workaround for newer Intel CPUs that, in addition to
the traditional "package-<n>" entries in /sys/class/powercap/, also
contain a "psys" entry that controls the platform domain (see, e.g.,
https://lkml.kernel.org/lkml/1458516392-2130-3-git-send-email-srinivas.pandruvada@linux.intel.com/).

PAPI currently assumes that entries starting with "intel-rapl:0"
correspond to socket 0 and "intel-rapl:1" to socket 1.  With "psys"
around that unfortunately need not be the case; on at least one system
relevant to DOE (I can't post the details as it's not public yet)
intel-rapl:0 corresponds to socket 0, intel-rapl:1 corresponds to
*psys*, and intel-rapl:2 corresponds to socket 1 (what a mess!).  What
currently happens is that PAPI entirely misses the counters for socket
1.

This PR works around the problem by exhaustively searching for the right
"intel-rapl:<n>" directory.  It preserves the current PAPI assumption
that ZONE0 events correspond to socket 0 and ZONE1 to socket 1.  On the
other hand, it completely ignores the "psys" entry, while one could
argue that the data it contains should ideally be made available as
well...
  • Loading branch information
iskra-anl committed Jul 26, 2023
1 parent 7dda808 commit ca89fb0
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/components/powercap/linux-powercap.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,31 @@ static int _powercap_init_component( int cidx )
num_events = 0;
for(s = 0; s < num_sockets; s++) {

// Find the directory corresponding to the socket number. There may be other top-level entries in there
// besides packages, such as "psys", that mess up the numbering, so we conduct an exhaustive search.
int s_dir, found = 0;
for(s_dir = 0; ; s_dir++) {
strErr=snprintf(event_path, sizeof(event_path), "/sys/class/powercap/intel-rapl:%d/%s", s_dir, pkg_sys_names[PKG_NAME]);
event_path[sizeof(event_path)-1]=0;
if (strErr > sizeof(event_path)) HANDLE_STRING_ERROR;

int event_fd;
event_fd = open(event_path, pkg_sys_flags[PKG_NAME]);
if (event_fd == -1) { break; }

int sz = pread(event_fd, read_buff, PAPI_MAX_STR_LEN, 0);
read_buff[sz] = '\0';
close(event_fd);

if (strncmp(read_buff, "package-", strlen("package-")) == 0 && strtol(read_buff + strlen("package-"), NULL, 10) == s) {
found = 1;
break;
}
}
if (!found) { continue; }

// compose string of a pkg directory path
strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d/", s);
strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d/", s_dir);
events_dir[sizeof(events_dir)-1]=0;
if (strErr > sizeof(events_dir)) HANDLE_STRING_ERROR;

Expand Down Expand Up @@ -248,7 +271,7 @@ static int _powercap_init_component( int cidx )

// reset component count for each socket
c = 0;
strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s, c);
strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s_dir, c);
events_dir[sizeof(events_dir)-1]=0;
if (strErr > sizeof(events_dir)) HANDLE_STRING_ERROR;
while((events = opendir(events_dir)) != NULL) {
Expand Down Expand Up @@ -298,7 +321,7 @@ static int _powercap_init_component( int cidx )
c++;

// compose string of an pkg directory path
strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s, c);
strErr=snprintf(events_dir, sizeof(events_dir), "/sys/class/powercap/intel-rapl:%d:%d/", s_dir, c);
events_dir[sizeof(events_dir)-1]=0;
if (strErr > sizeof(events_dir)) HANDLE_STRING_ERROR;
}
Expand Down

0 comments on commit ca89fb0

Please sign in to comment.