From: Swapnil Sapkal <swapnil.sapkal@amd.com>
To: <tony.luck@intel.com>, <reinette.chatre@intel.com>,
<babu.moger@amd.com>, <fenghua.yu@intel.com>, <shuah@kernel.org>
Cc: <Dave.Martin@arm.com>, <james.morse@arm.com>,
<peternewman@google.com>, <eranian@google.com>,
<tan.shaopeng@fujitsu.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <x86@kernel.org>,
Swapnil Sapkal <swapnil.sapkal@amd.com>
Subject: [PATCH v5 2/5] selftests/resctrl: Detect vendor to select memory controller sysfs name
Date: Thu, 22 Oct 2026 13:25:13 +0000 [thread overview]
Message-ID: <20261022132517.46805-3-swapnil.sapkal@amd.com> (raw)
In-Reply-To: <20261022132517.46805-1-swapnil.sapkal@amd.com>
From: Babu Moger <babu.moger@amd.com>
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.
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.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Babu Moger <babu.moger@amd.com>
Co-developed-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
v4->v5:
- Rebased onto kselftest/next; the vendor detection now lives in
enumerate_mcs() (previously num_of_mem_controllers()).
v3->v4:
- Reworded the subject and changelog. (Reinette)
- Dropped the local vendor variable and call get_vendor() directly.
(Reinette)
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 c9cac957726b..fdbbe2155cea 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 UNCORE_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 = UNCORE_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
next prev parent reply other threads:[~2026-10-22 13:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 13:25 [PATCH v5 0/5] selftests/resctrl: Add MBM and MBA test support for AMD Swapnil Sapkal
2026-10-22 13:25 ` [PATCH v5 1/5] selftests/resctrl: Rename variables and functions to generic names Swapnil Sapkal
2026-10-28 18:38 ` Reinette Chatre
2026-10-22 13:25 ` Swapnil Sapkal [this message]
2026-10-28 18:39 ` [PATCH v5 2/5] selftests/resctrl: Detect vendor to select memory controller sysfs name Reinette Chatre
2026-10-22 13:25 ` [PATCH v5 3/5] selftests/resctrl: Add support for MBM and MBA tests on AMD Swapnil Sapkal
2026-10-28 18:41 ` Reinette Chatre
2026-10-22 13:25 ` [PATCH v5 4/5] selftests/resctrl: Use bandwidth values for AMD MBA schemata Swapnil Sapkal
2026-10-28 18:45 ` Reinette Chatre
2026-10-22 13:25 ` [PATCH v5 5/5] selftests/resctrl: Enable MBM and MBA tests on AMD Swapnil Sapkal
2026-10-28 18:45 ` Reinette Chatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022132517.46805-3-swapnil.sapkal@amd.com \
--to=swapnil.sapkal@amd.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=eranian@google.com \
--cc=fenghua.yu@intel.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=peternewman@google.com \
--cc=reinette.chatre@intel.com \
--cc=shuah@kernel.org \
--cc=tan.shaopeng@fujitsu.com \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®