[PATCH v6 2/5] selftests/resctrl: Detect vendor to select memory controller sysfs name
From: Swapnil Sapkal
Date: Tue Dec 01 2026 - 03:36:03 EST
From: Babu Moger <babu.moger@xxxxxxx>
The test detects the number of memory controllers by scanning the perf
sysfs (DYN_PMU_PATH) for the vendor specific memory controller PMU name.
On Intel this PMU is named "uncore_imc_<n>".
Detect the vendor and select the memory controller PMU name accordingly
so that the rest of the code stays generic and can be extended to other
vendors. Bail out on vendors that are not yet supported. Rename the
UNCORE_IMC macro to INTEL_IMC to make the vendor it belongs to explicit.
While at it, match against the full "uncore_imc_" string and use
strlen() instead of sizeof() to advance past the prefix. This is clearer
than relying on sizeof() counting the terminating NULL to make up for the
trailing underscore.
Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
Co-developed-by: Swapnil Sapkal <swapnil.sapkal@xxxxxxx>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@xxxxxxx>
---
v5->v6:
- Renamed the UNCORE_IMC macro to INTEL_IMC so the vendor it belongs to
is explicit alongside AMD_UMC. (Reinette)
v4->v5:
- Rebased onto kselftest/next; the vendor detection now lives in
enumerate_mcs().
tools/testing/selftests/resctrl/resctrl_val.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
index ce670db02dbe..a97604e33609 100644
--- a/tools/testing/selftests/resctrl/resctrl_val.c
+++ b/tools/testing/selftests/resctrl/resctrl_val.c
@@ -10,7 +10,7 @@
*/
#include "resctrl.h"
-#define UNCORE_IMC "uncore_imc"
+#define INTEL_IMC "uncore_imc_"
#define READ_FILE_NAME "cas_count_read"
#define DYN_PMU_PATH "/sys/bus/event_source/devices"
#define SCALE 0.00006103515625
@@ -235,24 +235,29 @@ static int enumerate_mcs(void)
{
char mc_dir[512], *temp;
struct dirent *ep;
+ char *sysfs_name;
int ret;
DIR *dp;
+ if (get_vendor() == ARCH_INTEL) {
+ sysfs_name = INTEL_IMC;
+ } else {
+ ksft_print_msg("Unsupported vendor\n");
+ return -1;
+ }
+
dp = opendir(DYN_PMU_PATH);
if (dp) {
while ((ep = readdir(dp))) {
- temp = strstr(ep->d_name, UNCORE_IMC);
+ temp = strstr(ep->d_name, sysfs_name);
if (!temp)
continue;
/*
* mc counters are named as "uncore_imc_<n>", hence
- * increment the pointer to point to <n>. Note that
- * sizeof(UNCORE_IMC) would count for null character as
- * well and hence the last underscore character in
- * uncore_imc'_' need not be counted.
+ * increment the pointer to point to <n>.
*/
- temp = temp + sizeof(UNCORE_IMC);
+ temp = temp + strlen(sysfs_name);
/*
* Some directories under "DYN_PMU_PATH" could have
--
2.43.0