From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.4 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796114174; b=u0kqNqFDa/z2W5/vsO7xJ4lyORSCUv1HrUbeaBPGHSO8bB4usXZZEf4UIB6V/OuNmF6x 7E1HNpAPMHnLmjHPl/4MDz4eYp8xnB5WaK3GQfpkDC50FlTeGKzW5i2f+pKg8CxFhDXUU QnXXrDIRpJAn2MTbQjegOIXudiDcgKV9pNnmmWU2UWVrgcRzR3+V13NTE6dH0QoweJrXD Se25vn47mJsdLKHDayUfnP3lKoTx22H8FV4pYYLYAnWnhagOLw+jFdxNVNSUtXUXhrDP2 rWGkvCKq6C06yYXqjcpMX8q7TFTaF+N7mc4MtzR61HhFV34kOZBCamq6Z5cgQrjoD0A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796114174; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=nV+GKxMi6wEV81cI15ts2pcWt1ZsXMZS6AYMFoPnP5U=; b=b+oH0DLCJcLX9a0LI1W9GqUHbASl20BwrqEjGc/kLXuYjep0g6OMzgLncbuDrsUrRTcD Lma2w2I/GJlrynbz+ZHJ8SMywDgbAk5NvUGDDk/TvaOInvyl8qHlAvL34OaW4MtS2EGCD ABlP/x6FWyoZZiOU8g5MUGEamJi623Vgo4YWnDighP2ndH8m9L2KcK2lW5jb4WdoXvd8Q Wdb0sotLnHEdgE0o1kPpJyH8LuciNCT95MIoLU2d/wYOkxSmn4Pxegds4ndRTpdTHDuX5 JCmYMewcGMBrHomvVHJiJN0U+SjbL6A3Hj4ybUQMoBFLf7ssk9ABRg/Pb4oYSNGgxqw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=1mxPSUN7; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.4 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012004.outbound.protection.outlook.com [52.101.43.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A756F606A327; Tue, 1 Dec 2026 08:36:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A756F606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=1mxPSUN7 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HBKwWUGpoVjEBXyd8y+uPSvqcUH4oRY/3IjyEoH4IvYpz9CKu613FRwYpd6EjWGl0vgmXFNWSs4Om96NRYplGbSzEj0FFROOx2EeBNrNSE6tJ8w9xcFvFuwOGRKFs9U5Q1oil6bQdu9pGN4da2fgxViwvFG2V1/3wuWYUq4K0f0IWLMZXBuVNKvM/oBKtzV/F26Ck9J+ITtQ4sHVLzPOpMeLdy1fKElRYQzgmP8CTP1zs/XcCBMRVDPHE60Xm/xJFpxDYi/sEKfS8VWhjl7rc2LcNkmyrd8+BtMGWSXTH6F/aHsOTCdaJyXVtzBhse3IrdBVeyGmzks1XuXw88oyVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nV+GKxMi6wEV81cI15ts2pcWt1ZsXMZS6AYMFoPnP5U=; b=dIgMtV/235SwDO4JkO8fuePdWRUus+Rjm6XS8EUetT2s6kR25KC64mG3u7c7dvMp4swdb5qukYy2IOwiVxkHm2xk7fd+06vDDCcWbfJfzljatILW60QeV58ZMhXmbvhciAxVsn68ADIaVcAromSm7gXBE4ds4xbd7ew3Dwb446AmGUjllcQXgqyCoT5P2XpWA/SqxZADALlpw51dmNEyzjDvgnQ+wYYoqc/3MMAYsDNqGpzSDxUfTbfXHSv40ZlbcrrTX1yX3rrWSmpnnlJCQyvwY+dbp+Y6VyTcCWPwdJxpU+GmcQ1FnElKYHMWr/SMCn1zX60JY5w3ltB0ikTSUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nV+GKxMi6wEV81cI15ts2pcWt1ZsXMZS6AYMFoPnP5U=; b=1mxPSUN7hXPhNWoaw/l5PLHwal2+B8nhqkjVJEaJoCN5eb0W9CE2WM8l6uTvPF2ji9EqYwwNiHZh8owB1lLJOiQOHcDPKt+PHri/gBCHMpqOeQNzI0KxDdeiDCrvrNlyDVbinPgFe6PybiERzxG00mcblJt+dwxqfHht9LYUSQg= Received: from BY5PR03CA0003.namprd03.prod.outlook.com (2603:10b6:a03:1e0::13) by CY5PR12MB6623.namprd12.prod.outlook.com (2603:10b6:930:41::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 08:36:07 +0000 Received: from SJ1PEPF000037A6.namprd04.prod.outlook.com (2603:10b6:a03:1e0:cafe::8f) by BY5PR03CA0003.outlook.office365.com (2603:10b6:a03:1e0::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.13 via Frontend Transport; Tue, 1 Dec 2026 08:36:06 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SJ1PEPF000037A6.mail.protection.outlook.com (10.167.244.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 08:36:06 +0000 Received: from tapi.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 02:36:02 -0600 From: Swapnil Sapkal To: , , , , CC: , , , , , , , , Subject: [PATCH v6 3/5] selftests/resctrl: Add support for MBM and MBA tests on AMD Date: Tue, 1 Dec 2026 08:34:24 +0000 Message-ID: <20261201083426.26730-4-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201083426.26730-1-swapnil.sapkal@amd.com> References: <20261201083426.26730-1-swapnil.sapkal@amd.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000037A6:EE_|CY5PR12MB6623:EE_ X-MS-Office365-Filtering-Correlation-Id: ceba9f8a-5591-454c-5ed7-08df4f8624a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700016|1800799024|23010399003|11063799006|6133799003|261009223027099003|22082099003|18002099003|3023799007|56012099006|261026121527099003|261021123027099003|10067099003|261028144727099003|261021121427099003|261022075727099003|261102123227099003|261026140227099003|261022105027099003; X-Microsoft-Antispam-Message-Info: ibpqxSOzIxTX3pPhrBKMdSdI/0JCop1HM2yxK2Aw3ZW2XjSzZOS6MFg6KD8aITKQOP/cLFv6jZVPOORVMA2rAEx1a45hcdy7x3pSO7ZI5CLQif/w3lm7toTo6Rn1zbfOvxmBjZZ9DeNszD03glLCbScEvZRefzRWEem9Fsm/tzHow7CP2VDJbCvQI2GxZdtkHj4YuzYRmMgBrPqO2TU7AicW36SFsxnNs7E1aFwujYClzjaC+xqS0DYz0UC5ht5voN3PmhQ89wh8t4SIuiHT2OJ1ZsnYwdKtgL4X4ZlEdEiX0PVxefnQ4iXjZ8+5z3WU6GxE9rePgZsDVkEvhDbGW1JSittNIefdhO+LerL32zzLgLVCRot8uzv2B2Vbhl41R3/QwFxror3MSgGqNBPCgzT7XEQqF3LD2IWOFKXBxJ6bvsFBCMFxVVlCvJjUk4lsPMw/lSSuW1rb9ZWaiVSDG5Vahc2lO9afU4U+8mcw2l2R/vxfdljRCHgHy3sEaR9nCd9xrYcA9xRvO1TRgaO6A45Uhh4IHg7Yjz6jOF26M3s9S1a1WOKigReQmPdbzhRPP7CeBBg70jAGBxlB/FWAnjlRJE20/nK8s+HrSlfNPd4Si0cE+Lv82WEo7Tg2F/nAzPRv0PqPVgg+yvdcO1j4GRuSXwqbQH96bp0yQnuJ5Y1hMwvJ1NlkWs0+wNVrnMxQwWr6GkFFii0NO0kQCiP1Bg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700016)(1800799024)(23010399003)(11063799006)(6133799003)(261009223027099003)(22082099003)(18002099003)(3023799007)(56012099006)(261026121527099003)(261021123027099003)(10067099003)(261028144727099003)(261021121427099003)(261022075727099003)(261102123227099003)(261026140227099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sIv5XpKKGnokhIjplaa8RpuV27NangAuIQiZKKf/RxgS1+sBXxT/92kk3bDd/RchOXHM7Dm0VvzQom1an5HbB3QXbOfvHQ47oZVNfnuYTo/pGf86vrrQeJ7KphI5jZ26MJCQwJaR1t8j7keHZC1PYrngtkNc3qca51GIyXDwjBgfei++GgPRmAvF6hrQJg8wswaMC6SNF1471H2LU+WncgEo5Hmw46m5aG3sgXndXpDzcneHY31qhVhvLyWeFGvLzOOzSdND/HW87UUQRjeRgA5Y0E/qvRlb//UlUYh4cEwgPR2c7UvjqoA8HU0lw7OggkNGoP0nYnZLEbZwFo+ikq0C5qJEUHJxKvVHApSz7wnyxmYLTscYvSavXd+mHT2r5uJNBJE4R6R4W9N2qZrZ4ByfbcwTreKUljCyoR0OUIyJbhQVQ+F38kNmzGBapOns X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 08:36:06.7505 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ceba9f8a-5591-454c-5ed7-08df4f8624a3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF000037A6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6623 From: Babu Moger The MBM and MBA tests validate the resctrl memory bandwidth numbers against the memory controller performance counters. On Intel these are the iMC (Integrated Memory Controller) counters and the read event and umask are discovered from the PMU's sysfs event files. Commit 25e56847821f ("perf/x86/amd/uncore: Add memory controller support") added support for the UMC (Unified Memory Controller) perf events on AMD. Unlike Intel, the UMC PMU does not expose the CAS command events via sysfs, so program the read event directly: Number of CAS commands sent for reads: EventCode = 0x0a, umask = 0x1. Keep all the vendor detection contained in enumerate_mcs() and dispatch to a vendor specific routine to initialize the counter configuration. Only reading the counter's perf "type" is common to both vendors, so factor that out into a shared helper. On AMD each memory controller (UMC) is exposed as its own PMU (amd_umc_) that is tied to a specific NUMA node, whereas on Intel opening an iMC event on the benchmark CPU always resolves to the local memory controllers. A UMC PMU can only be opened from a CPU that belongs to the same node and returns -ENODEV otherwise. The benchmark is bound to a single CPU for the duration of the test, so a UMC that cannot be opened will never become usable. Drop such memory controllers from mc_counters_list so that later runs do not retry them and the remaining users of the list can rely on every entry being valid. This both avoids the perf_event_open() failure and matches the local traffic accounted by mbm_local_bytes. Signed-off-by: Babu Moger Co-developed-by: Swapnil Sapkal Signed-off-by: Swapnil Sapkal --- v5->v6: - Named the function pointer read_from_mc_dir to avoid the unnecessary churn at the call site. (Reinette) - Drop memory controllers that fail perf_event_open() with -ENODEV from mc_counters_list instead of leaving them with fd == -1. The benchmark is bound to a single CPU, so such a counter can never become usable. This avoids retrying them on every measurement and lets the remaining list walkers rely on every entry being valid, removing the fd checks in do_mc_read_mem_bw_test() and get_read_mem_bw_mc() and the 'opened' tracking (now list_empty()). (Reinette) v4->v5: - Reworked for the linked-list counter management and the AMD per-node UMC PMU topology. tools/testing/selftests/resctrl/resctrl_val.c | 123 ++++++++++++++---- 1 file changed, 101 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index a97604e33609..8e96a67b63ab 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -11,6 +11,7 @@ #include "resctrl.h" #define INTEL_IMC "uncore_imc_" +#define AMD_UMC "amd_umc_" #define READ_FILE_NAME "cas_count_read" #define DYN_PMU_PATH "/sys/bus/event_source/devices" #define SCALE 0.00006103515625 @@ -94,12 +95,8 @@ static int open_perf_read_event(int cpu_no, struct mc_counter_config *mc_counter mc_counter->fd = perf_event_open(&mc_counter->pe, -1, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); - if (mc_counter->fd == -1) { - fprintf(stderr, "Error opening leader %llx\n", - mc_counter->pe.config); - - return -1; - } + if (mc_counter->fd == -1) + return -errno; return 0; } @@ -183,16 +180,14 @@ static int parse_mc_read_bw_events(char *mc_dir, unsigned int type) return ret; } -/* Get type and config of an MC counter's read event. */ -static int read_from_mc_dir(char *mc_dir) +/* Get the perf "type" of a memory controller counter. Shared by all vendors. */ +static int get_mc_counter_type(const char *mc_dir, unsigned int *type) { char mc_counter_type[PATH_MAX]; - unsigned int type; int path_len; FILE *fp; int ret; - /* Get type of MC counter */ path_len = snprintf(mc_counter_type, sizeof(mc_counter_type), "%s%s", mc_dir, "type"); if (path_len >= sizeof(mc_counter_type)) { @@ -206,12 +201,29 @@ static int read_from_mc_dir(char *mc_dir) return -1; } - ret = fscanf(fp, "%u", &type); + ret = fscanf(fp, "%u", type); fclose(fp); if (ret <= 0) { ksft_perror("Could not get MC type"); return -1; } + + return 0; +} + +/* + * Intel: get type and config of an iMC counter's read event. The read event + * and umask are discovered from the PMU's sysfs event files. + */ +static int read_from_intel_mc_dir(char *mc_dir) +{ + unsigned int type; + int ret; + + ret = get_mc_counter_type(mc_dir, &type); + if (ret) + return ret; + ret = parse_mc_read_bw_events(mc_dir, type); if (ret) { ksft_print_msg("Unable to parse bandwidth event and umask\n"); @@ -222,10 +234,42 @@ static int read_from_mc_dir(char *mc_dir) } /* - * Discover the properties of the available MC (Memory Controller) - * counters in support of needed performance measurement via perf. For each MC - * counter get it's type and config. Also obtain each counter's event and umask - * for the memory read events that will be measured. + * AMD: get type and config of a UMC counter's read event. The UMC PMU does + * not expose the CAS command events via sysfs, so program them directly: + * Number of CAS commands sent for reads: EventCode = 0x0a, umask = 0x1 + */ +static int read_from_amd_mc_dir(char *mc_dir) +{ + struct mc_counter_config *mc_counter; + unsigned int type; + int ret; + + ret = get_mc_counter_type(mc_dir, &type); + if (ret) + return ret; + + mc_counter = calloc(1, sizeof(*mc_counter)); + if (!mc_counter) { + ksft_perror("Unable to allocate memory for MC counters"); + return -1; + } + + mc_counter->type = type; + mc_counter->event = 0xa; + mc_counter->umask = 0x1; + list_add(&mc_counter->entry, &mc_counters_list); + + return 0; +} + +/* + * Discover the properties of the available MC (Memory Controller) counters. + * On Intel the memory controller is called Integrated Memory Controller (iMC) + * and on AMD it is called Unified Memory Controller (UMC). Discover the + * properties of the available counters in support of needed performance + * measurement via perf. For each MC counter get it's type and config. Also + * obtain each counter's event and umask for the memory read events that will + * be measured. * * Enumerate all these details into a linked list of structures. * @@ -233,6 +277,7 @@ static int read_from_mc_dir(char *mc_dir) */ static int enumerate_mcs(void) { + int (*read_from_mc_dir)(char *mc_dir); char mc_dir[512], *temp; struct dirent *ep; char *sysfs_name; @@ -241,6 +286,10 @@ static int enumerate_mcs(void) if (get_vendor() == ARCH_INTEL) { sysfs_name = INTEL_IMC; + read_from_mc_dir = read_from_intel_mc_dir; + } else if (get_vendor() == ARCH_AMD) { + sysfs_name = AMD_UMC; + read_from_mc_dir = read_from_amd_mc_dir; } else { ksft_print_msg("Unsupported vendor\n"); return -1; @@ -254,8 +303,9 @@ static int enumerate_mcs(void) continue; /* - * mc counters are named as "uncore_imc_", hence - * increment the pointer to point to . + * MC counters are named as "uncore_imc_" on Intel + * and "amd_umc_" on AMD, hence increment the pointer + * to point to . */ temp = temp + strlen(sysfs_name); @@ -277,7 +327,9 @@ static int enumerate_mcs(void) } closedir(dp); if (list_empty(&mc_counters_list)) { - ksft_print_msg("Unable to find MC counters\n"); + ksft_print_msg("Unable to find memory controller counters\n"); + if (get_vendor() == ARCH_AMD) + ksft_print_msg("Try loading amd_uncore module\n"); return -1; } @@ -334,16 +386,43 @@ static void perf_close_mc_read_mem_bw(void) */ static int perf_open_mc_read_mem_bw(int cpu_no) { - struct mc_counter_config *mc_counter; + struct mc_counter_config *mc_counter, *tmp; int ret; list_for_each_entry(mc_counter, &mc_counters_list, entry) mc_counter->fd = -1; - list_for_each_entry(mc_counter, &mc_counters_list, entry) { + list_for_each_entry_safe(mc_counter, tmp, &mc_counters_list, entry) { ret = open_perf_read_event(cpu_no, mc_counter); - if (ret) - goto close_fds; + if (!ret) + continue; + + /* + * On AMD each memory controller (UMC) has its own PMU that is + * tied to a specific NUMA node, unlike Intel where opening an + * iMC event on the benchmark CPU always resolves to the local + * memory controllers. A UMC PMU can only be opened from a CPU + * that belongs to the same node and returns -ENODEV otherwise. + * The benchmark is bound to a single CPU for the duration of + * the test, so a UMC that cannot be opened now will never be + * usable. Drop it to measure only the memory controllers local + * to the benchmark. This matches what mbm_local_bytes accounts + * for on the resctrl side. + */ + if (ret == -ENODEV && get_vendor() == ARCH_AMD) { + list_del(&mc_counter->entry); + free(mc_counter); + continue; + } + + ksft_print_msg("Error opening memory bandwidth performance counter: %s\n", + strerror(-ret)); + goto close_fds; + } + + if (list_empty(&mc_counters_list)) { + ksft_print_msg("Could not open any memory controller counters\n"); + goto close_fds; } return 0; -- 2.43.0