From nobody Fri Oct 10 09:14:55 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2043.outbound.protection.outlook.com [40.107.92.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C01E8271472; Fri, 13 Jun 2025 21:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848746; cv=fail; b=OLxDmg3z4BuBULWq6afehGwjkaXNiS5GDbhPtxOG6cDUBg7Pb+Sg1jT4AxIl81iGgUb7mJSFCNuI+l81cgclyApDExAgZylmU22KLVzLPGusAeqPlYmq7Q9Tnx+ufSSWDyqCzALi2hocYGSkercmgt7NRhiBrsDDFUum45AY7lU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848746; c=relaxed/simple; bh=WiKCl0SwoUTli2Iy/euPBQgi5EppML5K+W4vrUFcxl4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K9WrueoCl0db4JQp87N2VWjvcNCP13A4KKGJU7+de6EARoN8SURTgQmLrV5nvJfaHpfQHvGkY0tUAIYuBQDli1s9BW1bQxq1xrH2OG3+x6ojMRYaMRMEHT7yNEw3kdkP3+p6CmoV4Ei6IlVrhPhYlXeZmH8vvA+XATMVqlKTDt4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AJuV5gcZ; arc=fail smtp.client-ip=40.107.92.43 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) header.d=amd.com header.i=@amd.com header.b="AJuV5gcZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ggs91MtBb7S+k35LiQjaj/TNxIvhYeo5KRUo6IJLEAsGXcsCjNXq8wfNkxyKjzqn4NfBGWk97yjrJISItxf7CEWEKCm5J/ZfYLKkMZVfY+mzI4eVj1yQHe753QBBM4xejOSbNFifrSIUIQR0ZJMbGMwz7Dt7dz8GCAOPeJUVC4uw5Iv3FckSIForV+j++EQESZ9Xrj/bw7JM83jX7ES0k6oRE7gJnrMO+u2Rq8yj7lbtqVYBfLdcQOuRXJ1kUuH8SnrEsrgPE4nMG+UxPMCZ0e/5UJRHZOnmib9WFPPkpsdf5IqeL0XMEDwmxNGzIrQlEvZvtRwpH6+yPBdR0QZ67Q== 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=0IHhqKt8aPRl6VYhsSb2eYBYO2c4OifZNCw6orCbIO0=; b=CY81P5MXXoyfbSasI4dfFgbraT09mNdxF5jZtwXGu+u8vrbujqLarQsP5OP88qEdFUIBR0u2Q4VpGJtzGZto+phJMxdOSl4OYC2DrQuQCN0Xg/UoLte9RtgkWUHTg+tZU8M6tgdwSd0i6/9de7zv7AhbdkijuZzhdkghIXRIuK2SieFLk+zBAb2kBZFqLkCmHFQ/CKcKa22ctQOKg5/pDcnRJwUf2rW9F1aocm3u0JUdxnprpSTPp3XEuPQkdqQbnvpVUuVynAF29rbRLP2+YMd/uXazfUN+krLeE5pXkJBKrcC4gOxfgIoHJ9kSbyBF/FnnqumsmX5zlEpMiyISIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=0IHhqKt8aPRl6VYhsSb2eYBYO2c4OifZNCw6orCbIO0=; b=AJuV5gcZ+PDC5EstdqTdimw3auxCKrJROFOV4yZYxUUK1IfJF4uzzp7KFAo80XxMt2590CZBqTkUHpLtTi6JP0KWu/InFLguB7frxZUZ3Dz4oTz71frtCTI9zCPHKf3s79a1gj6mUs8mortniDRcPJscd4c7mMD8ODaGH0rhHiQ= Received: from BY5PR17CA0028.namprd17.prod.outlook.com (2603:10b6:a03:1b8::41) by IA1PR12MB8467.namprd12.prod.outlook.com (2603:10b6:208:448::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:05:42 +0000 Received: from CY4PEPF0000EDD6.namprd03.prod.outlook.com (2603:10b6:a03:1b8:cafe::cb) by BY5PR17CA0028.outlook.office365.com (2603:10b6:a03:1b8::41) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8746.40 via Frontend Transport; Fri, 13 Jun 2025 21:05:41 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD6.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:05:41 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:05:39 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 01/32] x86,fs/resctrl: Remove unappropriate references to cacheinfo in the resctrl subsystem. Date: Fri, 13 Jun 2025 16:04:45 -0500 Message-ID: <3b69215942497729345ec4281c0a4850c8adb71b.1749848714.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD6:EE_|IA1PR12MB8467:EE_ X-MS-Office365-Filtering-Correlation-Id: cb6b49e7-6a61-47b2-0802-08ddaabe0e24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?GjPN6gilQvLJPOESEwBD+WPbtMGaHXTGWGrWRYc/6VDQDfQX4rW+Saw5NWc0?= =?us-ascii?Q?G5g9kU+QnLejK350kHgaBcvdSpMLmhZV6xhXx/ji5Tz2AUvWpwbQM7OLefqR?= =?us-ascii?Q?IMDcO9RQ3ci8XNqnWeGjtjB00NIyJR15qIdFo++A5hAxVZypa6IVmEIN4KTx?= =?us-ascii?Q?4vwYh3w+K75JlaXMd4qeGGBcuUOqTd7rt3zwkmRSqHji6Iub/G8oNsUori2M?= =?us-ascii?Q?Wczw96AiBKmPa3wmRgNXN0NiNDHoDrUkPVYcjq+zbPmhnIqoF9mawqduE9xb?= =?us-ascii?Q?yC/2Lk/qb0VY8+kPVjdU3t0uwZJp2wWr0rKPO6Lz7HuvUbrUkkmfNzvJqRPz?= =?us-ascii?Q?lgzo56m5ze4gx4Ph5P8AY1C/bVE3m8ZXWwnY79V/vR5RJcXjNuenXyEgnz7Z?= =?us-ascii?Q?hKsDKkCGUX54j6i/R+dKEEMIi63cODsSeeqKnXJPnYjt0PSzR3cn1ajmOoe8?= =?us-ascii?Q?kPBypdhYh1n9uA2EgfqZBMVq0s5MQm8cq/RkV2AlWwZZF6qT0xBfhLArEl59?= =?us-ascii?Q?tklElDWu8Lw9ohlWbe/j5RnEnlFL0tYzlsRUPdMtl6FDBlFqmgYWlnujT+7C?= =?us-ascii?Q?5zYklxK82wGR05FrifcntSIVik1pX2ervRQuiU44+gpoe8s4OOLbCjL7fCZY?= =?us-ascii?Q?1HQbZh1ePyL3mcWnonYShSKu5NEAoVpoltMNT+E2uOC2ICciU/yjVUUXvFbj?= =?us-ascii?Q?2oStzYQy0t4lZCPjGx3SsOHmdpjHHJBGb3AkGowpqX7mxOHmJnNAS7diamOb?= =?us-ascii?Q?S+hr5oTBfVtFOZWyIZ5UJ6nCk0UojEVYqCY5st85zK+1twvrFh3q6TmcJWnJ?= =?us-ascii?Q?G5aD2fYE6pMASOVQNB8JBBofKXZbp9zZxU2uwBpN3kdWMsZ3PJduDMaA9Zls?= =?us-ascii?Q?CjK4PrgkbfQLcFc5hoQBCIjfNliT+lA1UKjmXQBZqaWRdoMLQdLJhlDlldJF?= =?us-ascii?Q?swyDdFWkdfSLE834QYKuPghR6UIH3XWP1/uje6z97QRyWKuNra4y90y6t6m9?= =?us-ascii?Q?NpJhWLg5hGvmjj8qe45+evWDWL6YT3zdgCyDsGs1qSMepJTvMHuYaOfdlJ3U?= =?us-ascii?Q?4Yxw2WaoTwD3HPeZRZu8/7KwD1XtgtUHvj2WQIB/R49vLSAbZ9ZydAYDOT44?= =?us-ascii?Q?8EIuoQZ9kIsOSadjIES5HWU/oVyqI7bUQ34WwUD2nsNzKZcIR5qigUHAOJ4O?= =?us-ascii?Q?Iaym5JYu3w5urar7DtkYpjrC37LiyY4EOQl43qouYsgtLwV7mitUTfwdFRIP?= =?us-ascii?Q?q7kTeHU1u8nSapklXYghBdqH4FedVMGzl75vXYlrsBnwedBCyTUTtvv0HIFJ?= =?us-ascii?Q?udrgiZqrryBgiH641fpbxDaqyUhSXxafX4rXzJtBG3QBIEKbU5VzWUxU5Mp8?= =?us-ascii?Q?AERFe/LkP7ruxHHT8xzWvqsLs2wdnB7iHk/oXm4KpqrSvvyrplafQ7TPeidH?= =?us-ascii?Q?e4yOPbEN624qEce2C7q8h7vfNrai5kAKQdUcp4EGyWwHcKiZpes5/ahYdYPL?= =?us-ascii?Q?yvSN6rF9lGsURybBM/7Yor0FB2U0W8cUlt+nLqWSEVUTjkT9mkWoYW0UAA?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:05:41.3230 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb6b49e7-6a61-47b2-0802-08ddaabe0e24 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8467 Content-Type: text/plain; charset="utf-8" From: Qinyun Tan In the resctrl subsystem's Sub-NUMA Cluster (SNC) mode, the rdt_mon_domain structure representing a NUMA node relies on the cacheinfo interface (rdt_mon_domain::ci) to store L3 cache information (e.g., shared_cpu_map) for monitoring. The L3 cache information of a SNC NUMA node determines which domains are summed for the "top level" L3-scoped events. rdt_mon_domain::ci is initialized using the first online CPU of a NUMA node. When this CPU goes offline, its shared_cpu_map is cleared to contain only the offline CPU itself. Subsequently, attempting to read counters via smp_call_on_cpu(offline_cpu) fails (and error ignored), returning zero values for "top-level events" without any error indication. Replace the cacheinfo references in struct rdt_mon_domain and struct rmid_read with the cacheinfo ID (a unique identifier for the L3 cache). rdt_domain_hdr::cpu_mask contains the online CPUs associated with that domain. When reading "top-level events", select a CPU from rdt_domain_hdr::cpu_mask and utilize its L3 shared_cpu_map to determine valid CPUs for reading RMID counter via the MSR interface. Considering all CPUs associated with the L3 cache improves the chances of picking a housekeeping CPU on which the counter reading work can be queued, avoiding an unnecessary IPI. Fixes: 328ea68874642 ("x86/resctrl: Prepare for new Sub-NUMA Cluster (SNC) = monitor files") Signed-off-by: Qinyun Tan Tested-by: Tony Luck Reviewed-by: Reinette Chatre --- v14: Picked up this patch on Tony's recomendation. This is expected to be merged soon. Don't need to be reviwed. --- arch/x86/kernel/cpu/resctrl/core.c | 6 ++++-- fs/resctrl/ctrlmondata.c | 13 +++++++++---- fs/resctrl/internal.h | 4 ++-- fs/resctrl/monitor.c | 6 ++++-- fs/resctrl/rdtgroup.c | 6 +++--- include/linux/resctrl.h | 4 ++-- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 7109cbfcad4f..187d527ef73b 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -498,6 +498,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) struct rdt_hw_mon_domain *hw_dom; struct rdt_domain_hdr *hdr; struct rdt_mon_domain *d; + struct cacheinfo *ci; int err; =20 lockdep_assert_held(&domain_list_lock); @@ -525,12 +526,13 @@ static void domain_add_cpu_mon(int cpu, struct rdt_re= source *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_MON_DOMAIN; - d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); - if (!d->ci) { + ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); + if (!ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); mon_domain_free(hw_dom); return; } + d->ci_id =3D ci->id; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 arch_mon_domain_online(r, d); diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 6ed2dfd4dbbd..d98e0d2de09f 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -594,9 +594,10 @@ int rdtgroup_mondata_show(struct seq_file *m, void *ar= g) struct rmid_read rr =3D {0}; struct rdt_mon_domain *d; struct rdtgroup *rdtgrp; + int domid, cpu, ret =3D 0; struct rdt_resource *r; + struct cacheinfo *ci; struct mon_data *md; - int domid, ret =3D 0; =20 rdtgrp =3D rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { @@ -623,10 +624,14 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) * one that matches this cache id. */ list_for_each_entry(d, &r->mon_domains, hdr.list) { - if (d->ci->id =3D=3D domid) { - rr.ci =3D d->ci; + if (d->ci_id =3D=3D domid) { + rr.ci_id =3D d->ci_id; + cpu =3D cpumask_any(&d->hdr.cpu_mask); + ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); + if (!ci) + continue; mon_event_read(&rr, r, NULL, rdtgrp, - &d->ci->shared_cpu_map, evtid, false); + &ci->shared_cpu_map, evtid, false); goto checkresult; } } diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 9a8cf6f11151..0a1eedba2b03 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -98,7 +98,7 @@ struct mon_data { * domains in @r sharing L3 @ci.id * @evtid: Which monitor event to read. * @first: Initialize MBM counter when true. - * @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing d= omains. + * @ci_id: Cacheinfo id for L3. Only set when @d is NULL. Used when summin= g domains. * @err: Error encountered when reading counter. * @val: Returned value of event counter. If @rgrp is a parent resource = group, * @val includes the sum of event counts from its child resource groups. @@ -112,7 +112,7 @@ struct rmid_read { struct rdt_mon_domain *d; enum resctrl_event_id evtid; bool first; - struct cacheinfo *ci; + unsigned int ci_id; int err; u64 val; void *arch_mon_ctx; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index bde2801289d3..f5637855c3ac 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -361,6 +361,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) { int cpu =3D smp_processor_id(); struct rdt_mon_domain *d; + struct cacheinfo *ci; struct mbm_state *m; int err, ret; u64 tval =3D 0; @@ -388,7 +389,8 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) } =20 /* Summing domains that share a cache, must be on a CPU for that cache. */ - if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) + ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); + if (!ci || ci->id !=3D rr->ci_id) return -EINVAL; =20 /* @@ -400,7 +402,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) */ ret =3D -EINVAL; list_for_each_entry(d, &rr->r->mon_domains, hdr.list) { - if (d->ci->id !=3D rr->ci->id) + if (d->ci_id !=3D rr->ci_id) continue; err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx); diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 1beb124e25f6..77d08229d855 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -3036,7 +3036,7 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rdt= _resource *r, char name[32]; =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; - sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); + sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci_id : d->hdr.id); if (snc_mode) sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id); =20 @@ -3061,7 +3061,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_mon_domain *d, return -EPERM; =20 list_for_each_entry(mevt, &r->evt_list, list) { - domid =3D do_sum ? d->ci->id : d->hdr.id; + domid =3D do_sum ? d->ci_id : d->hdr.id; priv =3D mon_get_kn_priv(r->rid, domid, mevt, do_sum); if (WARN_ON_ONCE(!priv)) return -EINVAL; @@ -3089,7 +3089,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, lockdep_assert_held(&rdtgroup_mutex); =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; - sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); + sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci_id : d->hdr.id); kn =3D kernfs_find_and_get(parent_kn, name); if (kn) { /* diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 9ba771f2ddea..6fb4894b8cfd 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -159,7 +159,7 @@ struct rdt_ctrl_domain { /** * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types - * @ci: cache info for this domain + * @ci_id: cache info id for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth @@ -170,7 +170,7 @@ struct rdt_ctrl_domain { */ struct rdt_mon_domain { struct rdt_domain_hdr hdr; - struct cacheinfo *ci; + unsigned int ci_id; unsigned long *rmid_busy_llc; struct mbm_state *mbm_total; struct mbm_state *mbm_local; --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2077.outbound.protection.outlook.com [40.107.220.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0743271472; Fri, 13 Jun 2025 21:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848755; cv=fail; b=KfbcSPNKYtMqFugV8HbObBKcFiXmpJT4SsFMmc5ZP+T7YOrclU8SoI2Cu+BsthQWfLXAI1dg7s6S+HefNhQGbkcc0h8+zmAbcyOG05CYJVkU79ehXRhAqcliU+RUWejeaRcyxcyAVFOWt1C8vN05vkseynresQKXawJ95DW0+14= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848755; c=relaxed/simple; bh=7jPxaM7RSwRUkhyI8ytDuSGMFfcYA49Vbyse4ztYPuw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=InZ1Vs5sjoVl1+8g6nY01Pno4uz8iN6pUHIjHOapvcCdwErWlIRekhfiqiHEcKD7uxwD5M7kFeEqPSC1rluUVhR2GCVUpbEgyFsI8UbgmQ0xwgHAMctcb7Lylxiui1s9fYJWWM8ltTGcesdAc2Ki+nRF6BypLZZQ3nzIz1a1Zfw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=1cVubemM; arc=fail smtp.client-ip=40.107.220.77 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) header.d=amd.com header.i=@amd.com header.b="1cVubemM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MBWUKa0cr1YZjut7U6de/1klcqbQTR74DppNkjEMAgO33XsK1llZNxRYGTSXF/xYcu2mzRA1MI8Dsb69WsrK4u60/EYCmfHqkdd7B/CKycfDs3SKbFgJmJLEEBPP9ebOLSa+ggBUtJ1fAZCl5/sJ6T7rppJoKi30iis2j1YroJwbbC3pkzUv+gHFtn6CxJN4xXLwIGhTK6ATFfa0xPDRDxQjRKynHkvv4qzpD3q7zCBekebZP3pM52yjyIGZ6beFrskrRNwWh8rJUk5MKE/wH/kO341ij2h4j8cL/KFnkBUk48AfHvvcznJbPbevOvUSNuJjfCKbXIyoO+wwnqIcVg== 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=053J/fIPKScCvT7n3uo5wrYKPnA4p4BDsOviX/kNuTw=; b=Wx2WvS1kAWJz9DmN0giKqF+3TJEDd7sUiG7YFLPDzRqZy6GmYWgg8CiUE81FQF5bulHl8JBURnsu7lM4YandXaUwhLesrdN5mEtQV2xahzs7oATFsu/T95PHc0lcwDW2JRbBiRWZPWRTJuhdOVCOz0KJXLBISB6RwshqLo8DfkXYuqux6C1mTAMrTIW0vHKk2LBCAa090dp2iR/5IuUkfaVJ1J/y2WAYSPcnfktMLq0TGFxKk2Qd7adsHJIjyUQi5NxBtKXDB8DfsExIWWjwqfTbYPp6ScS4jgdLa9o48NE3Q5dcHP4rmxJotGNGsgDgfrAZmo/tfwALNv8QnXHffQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=053J/fIPKScCvT7n3uo5wrYKPnA4p4BDsOviX/kNuTw=; b=1cVubemMJnVTEUA0KjLkTd0Nft34m/mTHuCEt+MjqGLiRrXDKUMMVu9XKUZCpVj2A3+MaUIrTg82M8xJwdtDh6M7koM5B0cvBAG6cMtfUviRc3EZ2dNr1wK+9XeLMI+63qK93UqH3GhR1a21YO9TDUO5tyDp1QQ9roy9p4+QW/o= Received: from PH0PR07CA0041.namprd07.prod.outlook.com (2603:10b6:510:e::16) by LV9PR12MB9782.namprd12.prod.outlook.com (2603:10b6:408:2f2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.23; Fri, 13 Jun 2025 21:05:50 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:510:e:cafe::26) by PH0PR07CA0041.outlook.office365.com (2603:10b6:510:e::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Fri, 13 Jun 2025 21:05:50 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:05:50 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:05:47 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 02/32] x86,fs/resctrl: Consolidate monitor event descriptions Date: Fri, 13 Jun 2025 16:04:46 -0500 Message-ID: <80689a762e59137f0d0297ee4ce0d31f070a3655.1749848714.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|LV9PR12MB9782:EE_ X-MS-Office365-Filtering-Correlation-Id: 8aae3d05-8627-4905-91ce-08ddaabe1354 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mjPO2ZsrFst4RY28c1psWRSqOz+fq4YoMggt/cNPWMwWMFMttsvjrh5NnK+0?= =?us-ascii?Q?QgNHi2EWlWKPt6aal6gVvvLS+9YUiWVMfE8uVvArXdMMpDWoN0Pf5xMtApCv?= =?us-ascii?Q?ev0EqSQd1dbwGUAkepGsf5YwVKiZuc9eKF6G2EXz1lnMJP8U0CZ4NSwqjxnn?= =?us-ascii?Q?9GOgSW5gXYL2FmjKzspDPkKlCC1ZPsTWMxMQ7XtMLRcmByM3+pmT1zN0T10p?= =?us-ascii?Q?e/z3dGbVyKTSGYuOGDlBVI7CX7ZDteakhAV1+BBIRaBznoM3XVaEXEP/VEru?= =?us-ascii?Q?90sSUQ0JnE/OqMijn0dN5A/ssR14Ml2Af5H1bRPWCP4c8SFB9P952CD3p5vf?= =?us-ascii?Q?IIUVzIeM2O1vKirlabcJvnSvMk8Sg+1EIDLtnZmCyihr7htYw1mQjH/ZgsRR?= =?us-ascii?Q?aTfzIfCfhujfeeM4Xfe1LIsq2AY7JI3kCMhEogmdh3Oqyr7SN/kywW0TXIfk?= =?us-ascii?Q?veQXFItIjDIqMefoY0xUuViOuISoxCEzuXc3jmSCpl+rPE3iaWU/TKxZ9B3a?= =?us-ascii?Q?1QKP7eEsObQIcpsJsCWo6ghlFqFJIjT6WFIvXWyDfaSGPaUUiQHYiycvcq65?= =?us-ascii?Q?C8+A1Ed54vhe9hg932SkYGkEDANa5U904/L+chUWAGOzCToYrxsoSO/oeARd?= =?us-ascii?Q?cFazplMAxhCWhMfa8S2GyRhHWEk2wHBbC2syz9ERcoiWagyftzouWcM2h3Wk?= =?us-ascii?Q?vbO/CWWLo3a5Y0H6sMs7WCHP6mH55HHvmvBmJc9BG65NbsUzYFSQGQ15PG+w?= =?us-ascii?Q?kmQ9wxeBhkiJL+X76AQaMTzkpdaxeaGMaEvw2KYxRs3XNxt9m2c8/nuysDSJ?= =?us-ascii?Q?A8kHh6Emnj31GIlHmoEufEFEM6g8/z+CaObpSeFGG8L45SxkEU+3kjLAvmMC?= =?us-ascii?Q?HjrKEw/8C4YPVbcLbHYmYdx4vshZOOI3ZsZQcg7es94p3q0gWlzWlExJ46SP?= =?us-ascii?Q?EH3WDvwtYyz1JdxqpdW62F+zq+kmu2AZnnYxiQ3VoaPjKDY9sMEgVcMRYBL1?= =?us-ascii?Q?NbJWwoOn8CzXZZRzK3u0ZtxRpS1iz6ZYvqGlK1+JLih+COUBkY9XF7wsQIQs?= =?us-ascii?Q?GJKutV9f3XclobOhdDPEmxX2vMlMuLTyc2Z3Zw1NWwG2HxaaID5ETkp39kFb?= =?us-ascii?Q?QsPTAKtu+aGMgCO4F4x8xHlLInzMaVgF4wqrOlKGozxKpWYuImloGpcHDM/0?= =?us-ascii?Q?oyJ6HZwEpgKf1XNDd1DZsJHmtdKbYhW1TcfcDhwTqMocNZs3/t5DJZYjvUQr?= =?us-ascii?Q?+E/LsjqjJr0ydMrYRHq1al4qHuqO+qaGRf1BTB6qYHbw2OfdwLUQMGZIfLbv?= =?us-ascii?Q?3XButwQKDteIhY0axYPeBJ1d61l4mKLAgy9YYMSZXzzPaqvPpafUJtPDoz+p?= =?us-ascii?Q?2fh7svkbrt9TWMnGVhZsdAR5WIw79di0Pj0LWPaoZvcvaaGHLF4SSjJ1ZK5L?= =?us-ascii?Q?8+X9vXQKXm4sJxkc+bE2zAVPuESVvLkxdQ4Ot3ZSWKA5j8kdcsAiZ7IUWLeS?= =?us-ascii?Q?zxPQLBeIaJPslzL9fuR9m6YX/7buPlfxaue0suUg5pgGTo1K6ScaIpQmmdEG?= =?us-ascii?Q?P3UEik+KBvQ2uU9Ke7s=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:05:50.0252 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8aae3d05-8627-4905-91ce-08ddaabe1354 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV9PR12MB9782 Content-Type: text/plain; charset="utf-8" From: Tony Luck There are currently only three monitor events, all associated with the RDT_RESOURCE_L3 resource. Growing support for additional events will be easier with some restructuring to have a single point in file system code where all attributes of all events are defined. Place all event descriptions into an array mon_event_all[]. Doing this has the beneficial side effect of removing the need for rdt_resource::evt_list. Add resctrl_event_id::QOS_FIRST_EVENT for a lower bound on range checks for event ids and as the starting index to scan mon_event_all[]. Drop the code that builds evt_list and change the two places where the list is scanned to scan mon_event_all[] instead using a new helper macro for_each_mon_event(). Architecture code now informs file system code which events are available with resctrl_enable_mon_event(). Signed-off-by: Tony Luck --- v14: This is Tony's work. This is part of Tony's telemetry series. https://lore.kernel.org/lkml/20250521225049.132551-1-tony.luck@intel.c= om/ Tony made special update for me to include in this series. https://lore.kernel.org/lkml/20250609162139.91651-1-tony.luck@intel.co= m/. --- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++-- fs/resctrl/internal.h | 13 ++++-- fs/resctrl/monitor.c | 63 +++++++++++++++--------------- fs/resctrl/rdtgroup.c | 11 +++--- include/linux/resctrl.h | 4 +- include/linux/resctrl_types.h | 12 ++++-- 6 files changed, 66 insertions(+), 49 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 187d527ef73b..7fcae25874fe 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -864,12 +864,18 @@ static __init bool get_rdt_mon_resources(void) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; =20 - if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) + if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) { + resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID); rdt_mon_features |=3D (1 << QOS_L3_OCCUP_EVENT_ID); - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) + } + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { + resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID); rdt_mon_features |=3D (1 << QOS_L3_MBM_TOTAL_EVENT_ID); - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) + } + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { + resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID); rdt_mon_features |=3D (1 << QOS_L3_MBM_LOCAL_EVENT_ID); + } =20 if (!rdt_mon_features) return false; diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 0a1eedba2b03..20e2c45cea64 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -52,19 +52,26 @@ static inline struct rdt_fs_context *rdt_fc2context(str= uct fs_context *fc) } =20 /** - * struct mon_evt - Entry in the event list of a resource + * struct mon_evt - Description of a monitor event * @evtid: event id + * @rid: index of the resource for this event * @name: name of the event * @configurable: true if the event is configurable - * @list: entry in &rdt_resource->evt_list + * @enabled: true if the event is enabled */ struct mon_evt { enum resctrl_event_id evtid; + enum resctrl_res_level rid; char *name; bool configurable; - struct list_head list; + bool enabled; }; =20 +extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; + +#define for_each_mon_event(mevt) for (mevt =3D &mon_event_all[QOS_FIRST_EV= ENT]; \ + mevt < &mon_event_all[QOS_NUM_EVENTS]; mevt++) + /** * struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list. diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index f5637855c3ac..2313e48de55f 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -844,38 +844,39 @@ static void dom_data_exit(struct rdt_resource *r) mutex_unlock(&rdtgroup_mutex); } =20 -static struct mon_evt llc_occupancy_event =3D { - .name =3D "llc_occupancy", - .evtid =3D QOS_L3_OCCUP_EVENT_ID, -}; - -static struct mon_evt mbm_total_event =3D { - .name =3D "mbm_total_bytes", - .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, -}; - -static struct mon_evt mbm_local_event =3D { - .name =3D "mbm_local_bytes", - .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, -}; - /* - * Initialize the event list for the resource. - * - * Note that MBM events are also part of RDT_RESOURCE_L3 resource - * because as per the SDM the total and local memory bandwidth - * are enumerated as part of L3 monitoring. + * All available events. Architecture code marks the ones that + * are supported by a system using resctrl_enable_mon_event() + * to set .enabled. */ -static void l3_mon_evt_init(struct rdt_resource *r) +struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { + [QOS_L3_OCCUP_EVENT_ID] =3D { + .name =3D "llc_occupancy", + .evtid =3D QOS_L3_OCCUP_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + }, + [QOS_L3_MBM_TOTAL_EVENT_ID] =3D { + .name =3D "mbm_total_bytes", + .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + }, + [QOS_L3_MBM_LOCAL_EVENT_ID] =3D { + .name =3D "mbm_local_bytes", + .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + }, +}; + +void resctrl_enable_mon_event(enum resctrl_event_id eventid) { - INIT_LIST_HEAD(&r->evt_list); + if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= )) + return; + if (mon_event_all[eventid].enabled) { + pr_warn("Duplicate enable for event %d\n", eventid); + return; + } =20 - if (resctrl_arch_is_llc_occupancy_enabled()) - list_add_tail(&llc_occupancy_event.list, &r->evt_list); - if (resctrl_arch_is_mbm_total_enabled()) - list_add_tail(&mbm_total_event.list, &r->evt_list); - if (resctrl_arch_is_mbm_local_enabled()) - list_add_tail(&mbm_local_event.list, &r->evt_list); + mon_event_all[eventid].enabled =3D true; } =20 /** @@ -902,15 +903,13 @@ int resctrl_mon_resource_init(void) if (ret) return ret; =20 - l3_mon_evt_init(r); - if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) { - mbm_total_event.configurable =3D true; + mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable =3D true; resctrl_file_fflags_init("mbm_total_bytes_config", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_LOCAL_EVENT_ID)) { - mbm_local_event.configurable =3D true; + mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].configurable =3D true; resctrl_file_fflags_init("mbm_local_bytes_config", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 77d08229d855..b95501d4b5de 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1152,7 +1152,9 @@ static int rdt_mon_features_show(struct kernfs_open_f= ile *of, struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); struct mon_evt *mevt; =20 - list_for_each_entry(mevt, &r->evt_list, list) { + for_each_mon_event(mevt) { + if (mevt->rid !=3D r->rid || !mevt->enabled) + continue; seq_printf(seq, "%s\n", mevt->name); if (mevt->configurable) seq_printf(seq, "%s_config\n", mevt->name); @@ -3057,10 +3059,9 @@ static int mon_add_all_files(struct kernfs_node *kn,= struct rdt_mon_domain *d, struct mon_evt *mevt; int ret, domid; =20 - if (WARN_ON(list_empty(&r->evt_list))) - return -EPERM; - - list_for_each_entry(mevt, &r->evt_list, list) { + for_each_mon_event(mevt) { + if (mevt->rid !=3D r->rid || !mevt->enabled) + continue; domid =3D do_sum ? d->ci_id : d->hdr.id; priv =3D mon_get_kn_priv(r->rid, domid, mevt, do_sum); if (WARN_ON_ONCE(!priv)) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 6fb4894b8cfd..2944042bd84c 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -269,7 +269,6 @@ enum resctrl_schema_fmt { * @mon_domains: RCU list of all monitor domains for this resource * @name: Name to use in "schemata" file. * @schema_fmt: Which format string and parser is used for this schema. - * @evt_list: List of monitoring events * @mbm_cfg_mask: Bandwidth sources that can be tracked when bandwidth * monitoring events can be configured. * @cdp_capable: Is the CDP feature available on this resource @@ -287,7 +286,6 @@ struct rdt_resource { struct list_head mon_domains; char *name; enum resctrl_schema_fmt schema_fmt; - struct list_head evt_list; unsigned int mbm_cfg_mask; bool cdp_capable; }; @@ -372,6 +370,8 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r); u32 resctrl_arch_system_num_rmid_idx(void); int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid); =20 +void resctrl_enable_mon_event(enum resctrl_event_id eventid); + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 /** diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index a25fb9c4070d..2dadbc54e4b3 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -34,11 +34,15 @@ /* Max event bits supported */ #define MAX_EVT_CONFIG_BITS GENMASK(6, 0) =20 -/* - * Event IDs, the values match those used to program IA32_QM_EVTSEL before - * reading IA32_QM_CTR on RDT systems. - */ +/* Event IDs */ enum resctrl_event_id { + /* Must match value of first event below */ + QOS_FIRST_EVENT =3D 0x01, + + /* + * These values match those used to program IA32_QM_EVTSEL before + * reading IA32_QM_CTR on RDT systems. + */ QOS_L3_OCCUP_EVENT_ID =3D 0x01, QOS_L3_MBM_TOTAL_EVENT_ID =3D 0x02, QOS_L3_MBM_LOCAL_EVENT_ID =3D 0x03, --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2054.outbound.protection.outlook.com [40.107.236.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C869427146D; Fri, 13 Jun 2025 21:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848764; cv=fail; b=iy17Cnkks8Lvb9jYDQWrq9Ng0ekNKXLpKnKFGjxev49g/FuXIf30qzDdHDNvjZ+chTAHEdcdx3b+7fnDE9Y2ZjEVIvFDPxDtEM7dVq9CZmduZwTwDDoWZeFkLxT/DHk4B/Jd+7+5zExl1uGl+KVjzLDEWxwonztKmChaupCawYw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848764; c=relaxed/simple; bh=f10zETfLq/4fAK09b5lqH/745VS1vjLiMTZoTrCn/8o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pJvOqUp7oiV4vQYQzseRsY/mXqxKUK2aBbJHu+Kxg832L0YmRj5cY5D8T4cKI5zfHvJBIMHMFVJ46O4gP6AEX0kw83j4oG54m7a6igLSH8ggaFK4c2Zj5Kr8Rc6FZK0dVcUsncPqjcg0dyAJcvwbItKkmNINuoCnL8arGSsPJ3I= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=y3oYr1i1; arc=fail smtp.client-ip=40.107.236.54 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) header.d=amd.com header.i=@amd.com header.b="y3oYr1i1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gYPkODn4f4sjiw57w9QQufXY+7b88rPojOk6LbRNl0Naj0y6IlgspmsmGI6JtcAkvmg6yXKgKNAufMg4n9LSoH1/rQj6yOKD+8HAkZ9g/g7dRLP9hHMs+jy4iFnhx7ZOr3TcAtH1r878XarT76ZRzucPwI7j6z2tNi/2LBRgbLUxAXivY0hdMIAYDkUbQWBzi/7pE0jJ7jAPBBjtPc6U/uLp6YWL9f/QXS2SLek23Ht9Hi/yisKlaGaNix97JmqksGO5DXk3OrwExs+StUV3YoCf3//sZLr047SqwYgmp+7/fM9N+v7pqgr5aIz90oDLboUm6WGh29QfFCBACcVMTA== 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=QbcfbFuJO2K4O0Eey5ocGfj27PjsOicxurrTvWGUMSs=; b=A5wbzuICWxfPt29vhMmaJhvHXYC2AlDk5IdgILglV7i8b4xiAxaj2nTUWo3Reg6jQj8m8NUFgXgrySkuUGpEtEC8gE3nCdkRsBOvgsVZZeDKcc5y0aI+y6qiiv3RW808oJDZQyfzF7AOEzo1P5Z5/B1oLFJwewSOceo5+D2TWgy2gE4aQVNmJleicldz+l6TFz8gvFT3Rf7PkJ/8dYw47Dhqh78JWt5s+gIC7MD/Maje4I1RDbOIffE6cYHBc9uvBSoRK2QlnMM/j2+/fcWSvLULQOlQPI3u6kFJb0bUgBzQTbVwMClUK2vBmG9NMymidNz7tHn4fITShMzKy8JU6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=QbcfbFuJO2K4O0Eey5ocGfj27PjsOicxurrTvWGUMSs=; b=y3oYr1i1duoUoCXwHjmto9UUIlMmG3k30OwDwdp8raotTSgzP3pxnsLlUn8dAGPNdjU5crWvzb/G7ZUY+QYtnksrsZ/D6YnKxdw/b9PbEVCd8/raFxqgHbpzwIuhdEkQoNLUzYSZso4WSl2jeQTKofLtQ4V7C/zEA+AKqY9oLBc= Received: from DM6PR05CA0064.namprd05.prod.outlook.com (2603:10b6:5:335::33) by IA0PR12MB8088.namprd12.prod.outlook.com (2603:10b6:208:409::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.26; Fri, 13 Jun 2025 21:05:59 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335:cafe::77) by DM6PR05CA0064.outlook.office365.com (2603:10b6:5:335::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:05:58 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:05:57 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:05:55 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 03/32] x86,fs/resctrl: Replace architecture event enabled checks Date: Fri, 13 Jun 2025 16:04:47 -0500 Message-ID: <56733e6ae9b3d5848bd78e04abf71f84e474a4be.1749848714.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: a33bb84d-5955-4646-8544-08ddaabe17c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|1800799024|36860700013|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?IXOzTObUVTsa5KKEaD4e5OG/hmMq7FDZXu52R1TRRDGLgxbYxJhG9yuCNyEG?= =?us-ascii?Q?QkZF4rWPOE++10AKtkZG8X2xiscAChiw4bkOtIIWS+6lUt1TTs4f57yquZ4t?= =?us-ascii?Q?FVAR4/7Q07sRdj8xRC/nurx+1aQ7Tka2HtFeSjpmCOtZJbr+Vghcmx9NCbKy?= =?us-ascii?Q?Hsu0va98LcmMv8NNK15uAtU9Kpio7gd5KWqikFa7HEZcP7LS1pRDPtGVaIUP?= =?us-ascii?Q?jVfR4P4br8JT3XG4XBXPIfeGvWMYu+LL0PRCuFsyw+47dFxTUkVuKvHDWvMq?= =?us-ascii?Q?fUf1tOnbdaEy3wddmYm4DYMs8wK2r6hTrNXiDt5zkrKBCuO3jIrDOn2jxym1?= =?us-ascii?Q?b2bxvsg1pS7sOl7EOricxp4push3cfyRTvo0OVuyx/YLCo9JtSNdS90trstQ?= =?us-ascii?Q?yR/o27ARPhYuHxrCGptUUyDZzDKbaRGPyO8ApNUxf2m43vgOdMcpw/j8Kj+J?= =?us-ascii?Q?wo1EA34+flGx93mW2ugywqZ6/8FrfX/vOwcSU3L5XS+XVOYZBkl0pAmOyB9p?= =?us-ascii?Q?3ZekIjcJ51oh5a1lZZcAys5G/GxdR6YkBqImqiJ+g25sCMWRsh0KA+tQe8Fh?= =?us-ascii?Q?ZhA+qXy/9xrf8AlQn/SJbOTaxGi2TKye+Q3kLmz48VbRpv+cmuJJn+b37/u2?= =?us-ascii?Q?Ep6OKSUg4nxOSfcZRR6cjDWDaxhuit/qyEiN3vU8nXQqiyUpBgLBD/zV36oI?= =?us-ascii?Q?ilayd+lf/kGyFbpRQbcYA17A4Y4PNo4C8R6I2AsivgJpjFoleKdIQwcexGZ+?= =?us-ascii?Q?zFBalE6cXCNq7iujxy4VEggjDPJKRm7JY+E186KvnOneYlh9DH6PKtqJHLmN?= =?us-ascii?Q?yKNekHv2z7Q+gI9RJUgT2cHE8IEB/DQSE0m1/+t5WuBqGfXsN3xJvaB3or4s?= =?us-ascii?Q?X7HNzd6Qaj9RTvQK+ZQ2TM84+4oC08CASrZRICNxXTOwotm74OaYB0x1pnna?= =?us-ascii?Q?Rr5H+XnCNdpQk2+6kKvzA89fYDqDEibMxKn8f+qZkIYk53OnFA5wr3U0SamF?= =?us-ascii?Q?CGYMl+Zgd/o7HjvSayH99vJIRGsP7tilzVZqjtIJhGBF07WhZv02FEu2sjGl?= =?us-ascii?Q?7w8EakwrdupZShKSBulCjLaOlLmWw+Mwe8eho5Ss39Fnq+ey7REMZc3zPEdx?= =?us-ascii?Q?7OzeSQsbjie30rZODMrCiNE/D5h2odpf70eOmqjSLITk3iSuH8SZOSp/m867?= =?us-ascii?Q?Pbp/vvmAtJ/mF/Ssl0sQZ8a2h+6VDiyIovyCLBP4UqovoIjvb8oDRASpKjFl?= =?us-ascii?Q?2NJQoyZACQ+5oJp0EsPUS4+CWQIhYRzXXxsaxEcnLJ7kjYiOim11nYTmfH3R?= =?us-ascii?Q?Z+HvTLgd6v1+L59wJPFJkUdZJKqf/Ez0vc81e4DBhBXzf+3RPQe+pi946Ac3?= =?us-ascii?Q?l6LyrNQeJO78CiQxNhUAtYHIhi21jpp6mad3GdYZm0XjwPA59Q2/xllOEEiL?= =?us-ascii?Q?9+NYUN5zlTbvF81UATISUR7zOFcjnLp7xZ7n17xvnNe7Gi0Cci8MoDnbeMtc?= =?us-ascii?Q?E5BUUUGaNjAcTE6A1TGm1iRmSUFghJ98beJHp6a6flZh20mFhhH3MYQ5FAE9?= =?us-ascii?Q?OEH3DJZrhHKQGtpRuxs=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(1800799024)(36860700013)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:05:57.4481 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a33bb84d-5955-4646-8544-08ddaabe17c0 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Content-Type: text/plain; charset="utf-8" From: Tony Luck The resctrl file system now has complete knowledge of the status of every event. So there is no need for per-event function calls to check. Replace each of the resctrl_arch_is_{event}enabled() calls with resctrl_is_mon_event_enabled(QOS_{EVENT}). No functional change. Signed-off-by: Tony Luck --- v14: This is Tony's work. This is part of Tony's telemetry series. https://lore.kernel.org/lkml/20250521225049.132551-1-tony.luck@intel.c= om/ Tony made special update for me to include in this series. https://lore.kernel.org/lkml/20250609162139.91651-1-tony.luck@intel.co= m/ --- arch/x86/include/asm/resctrl.h | 15 --------------- arch/x86/kernel/cpu/resctrl/core.c | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- fs/resctrl/ctrlmondata.c | 4 ++-- fs/resctrl/monitor.c | 16 +++++++++++----- fs/resctrl/rdtgroup.c | 18 +++++++++--------- include/linux/resctrl.h | 2 ++ 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index feb93b50e990..b1dd5d6b87db 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -84,21 +84,6 @@ static inline void resctrl_arch_disable_mon(void) static_branch_dec_cpuslocked(&rdt_enable_key); } =20 -static inline bool resctrl_arch_is_llc_occupancy_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID)); -} - -static inline bool resctrl_arch_is_mbm_total_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID)); -} - -static inline bool resctrl_arch_is_mbm_local_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID)); -} - /* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR * diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 7fcae25874fe..1a319ce9328c 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -402,13 +402,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct= rdt_hw_mon_domain *hw_dom) { size_t tsize; =20 - if (resctrl_arch_is_mbm_total_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { tsize =3D sizeof(*hw_dom->arch_mbm_total); hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_total) return -ENOMEM; } - if (resctrl_arch_is_mbm_local_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { tsize =3D sizeof(*hw_dom->arch_mbm_local); hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_local) { diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index c261558276cd..61d38517e2bf 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -207,11 +207,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource = *r, struct rdt_mon_domain * { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); =20 - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) memset(hw_dom->arch_mbm_total, 0, sizeof(*hw_dom->arch_mbm_total) * r->num_rmid); =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) memset(hw_dom->arch_mbm_local, 0, sizeof(*hw_dom->arch_mbm_local) * r->num_rmid); } diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index d98e0d2de09f..ad7ffc6acf13 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -473,12 +473,12 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_o= pen_file *of, rdt_last_cmd_clear(); =20 if (!strcmp(buf, "mbm_local_bytes")) { - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) rdtgrp->mba_mbps_event =3D QOS_L3_MBM_LOCAL_EVENT_ID; else ret =3D -EINVAL; } else if (!strcmp(buf, "mbm_total_bytes")) { - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) rdtgrp->mba_mbps_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; else ret =3D -EINVAL; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 2313e48de55f..9e988b2c1a22 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -336,7 +336,7 @@ void free_rmid(u32 closid, u32 rmid) =20 entry =3D __rmid_entry(idx); =20 - if (resctrl_arch_is_llc_occupancy_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) add_rmid_to_limbo(entry); else list_add_tail(&entry->list, &rmid_free_lru); @@ -637,10 +637,10 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_mon_domain *d, * This is protected from concurrent reads from user as both * the user and overflow handler hold the global mutex. */ - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID); =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID); } =20 @@ -879,6 +879,12 @@ void resctrl_enable_mon_event(enum resctrl_event_id ev= entid) mon_event_all[eventid].enabled =3D true; } =20 +bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid) +{ + return eventid >=3D QOS_FIRST_EVENT && eventid < QOS_NUM_EVENTS && + mon_event_all[eventid].enabled; +} + /** * resctrl_mon_resource_init() - Initialise global monitoring structures. * @@ -914,9 +920,9 @@ int resctrl_mon_resource_init(void) RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_LOCAL_EVENT_ID; - else if (resctrl_arch_is_mbm_total_enabled()) + else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; =20 return 0; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index b95501d4b5de..a7eeb33501da 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -123,8 +123,8 @@ void rdt_staged_configs_clear(void) =20 static bool resctrl_is_mbm_enabled(void) { - return (resctrl_arch_is_mbm_total_enabled() || - resctrl_arch_is_mbm_local_enabled()); + return (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID) || + resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)); } =20 static bool resctrl_is_mbm_event(int e) @@ -196,7 +196,7 @@ static int closid_alloc(void) lockdep_assert_held(&rdtgroup_mutex); =20 if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) && - resctrl_arch_is_llc_occupancy_enabled()) { + resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { cleanest_closid =3D resctrl_find_cleanest_closid(); if (cleanest_closid < 0) return cleanest_closid; @@ -4051,7 +4051,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d =20 if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); - if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) { + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { /* * When a package is going down, forcefully * decrement rmid->ebusy. There is no way to know @@ -4087,12 +4087,12 @@ static int domain_setup_mon_state(struct rdt_resour= ce *r, struct rdt_mon_domain u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize; =20 - if (resctrl_arch_is_llc_occupancy_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { d->rmid_busy_llc =3D bitmap_zalloc(idx_limit, GFP_KERNEL); if (!d->rmid_busy_llc) return -ENOMEM; } - if (resctrl_arch_is_mbm_total_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { tsize =3D sizeof(*d->mbm_total); d->mbm_total =3D kcalloc(idx_limit, tsize, GFP_KERNEL); if (!d->mbm_total) { @@ -4100,7 +4100,7 @@ static int domain_setup_mon_state(struct rdt_resource= *r, struct rdt_mon_domain return -ENOMEM; } } - if (resctrl_arch_is_mbm_local_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { tsize =3D sizeof(*d->mbm_local); d->mbm_local =3D kcalloc(idx_limit, tsize, GFP_KERNEL); if (!d->mbm_local) { @@ -4145,7 +4145,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_mon_domain *d) RESCTRL_PICK_ANY_CPU); } =20 - if (resctrl_arch_is_llc_occupancy_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); =20 /* @@ -4220,7 +4220,7 @@ void resctrl_offline_cpu(unsigned int cpu) cancel_delayed_work(&d->mbm_over); mbm_setup_overflow_handler(d, 0, cpu); } - if (resctrl_arch_is_llc_occupancy_enabled() && + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && cpu =3D=3D d->cqm_work_cpu && has_busy_rmid(d)) { cancel_delayed_work(&d->cqm_limbo); cqm_setup_limbo_handler(d, 0, cpu); diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 2944042bd84c..40aba6b5d4f0 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -372,6 +372,8 @@ int resctrl_arch_update_domains(struct rdt_resource *r,= u32 closid); =20 void resctrl_enable_mon_event(enum resctrl_event_id eventid); =20 +bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid); + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 /** --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2074.outbound.protection.outlook.com [40.107.96.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CA0C271468; Fri, 13 Jun 2025 21:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848780; cv=fail; b=EHlYqBkR2kzhQy8eyAf18V7q9NOkDGrRviM/aicsJe5oRfXCS6ukQkaaTMqD6JuaBB5cdFs2BSQ93iPymtX6cDXCkWBaQlDvzlHBXE7EUcvxnd9hRXQkeySX92k+Uxjzk7HtGzvIyNf7hKzCuEwVE2b3T2i274kH4GSjz71edhA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848780; c=relaxed/simple; bh=2AfXIMJAbzSCSvbFbO9mr/rIknpI29fWB31TWz3qi/g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AQWusx4xq2npHisSm+ux20XbCFIPgrT5pGJAG3fRjDVf05WzoDHfk8AgY6Z4e6+csNTwMZTTCDlcBZB7Rhbwt93yFjuVTx/FgER4axIP8IWjh6wStGDI1v1cb7jNe8+tJO7narX8URXv6i5J/imcafU74VQWutnN1vEenBQu4dE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ExviOeYv; arc=fail smtp.client-ip=40.107.96.74 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) header.d=amd.com header.i=@amd.com header.b="ExviOeYv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A3S0Xx6YTQl+ybo0fj4t0yiFI8UxJ4M6Jw1HJCXCBEd7axH189beeTY0iyfKtUBfvZxeT5H5QX2TPESMB3DETx7F0Jx7u9+6zSVegXx4TipSuH8OOxps1fecbz7VBFU4DhRBlDRmneskbLYkO6NZ8BozgdhJKY1es6LvfM0rM055SEi8bMvSYgrHc6xp8mj6ZA/6O98npNg0jla2wNn0auRJ6FMvIEJY6H6nkcnetG9+K1BYImte6N1/p6rcUJgnhelazI/lOA68Cw3UWmgWR9Z5pSlZvZBdt0ak5t9HQAAG7TsJ36kTZATiC6itt1X3SeS54plCmm4A+2l1m3t+sw== 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=kZUV5kIkSWaQKQ8B+hqZjhwK0i3SYQ8kduGeRRdgIgo=; b=RwShy8YJ/wbCioE/O8kGUnDk50TCix/GtBXJL0pu3f8efJAwQonsoPHlArQk7iTK3hHMFNYQgcJm7Ho14Ux0/O5FgpSx2q1scTRB8gFc2GyCUx+yVCJMERTh6R/dBALO7QM/2f7VskvqTLBrERR+gg2dGgU7cjqRcU1cfYa2XnS8vyGR76859AmVxJC/odPMFBnOxAer+GIRbaAdlJ8MTklCVBkeeKL83KKs+NB+otYIgDba6YXaMbMnhgXzOFSkX6HUoe2mtCc+UVUAbxAJ7nUNKWaGHq4ttKJ4dDshpipWb6MJ1M0dO55zJinPv/Wraz/5PEmoNGmgooBjGP2jaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=kZUV5kIkSWaQKQ8B+hqZjhwK0i3SYQ8kduGeRRdgIgo=; b=ExviOeYvfoC/OeX9VQMO1ubRqXA3jwxy7srYAvqIuwXX+EQ/PaTww0grZ4Gv7vQwGXVrW2Kr2bf6qEU/OO1k9aFc7SSh6AX2qdINaw/Lb/3fE54Qjsv2HKJSkhy7JUQha67qAPdmiOeWvXbJGp9TvQN1PlDsuEF9G+FVB6XbWOI= Received: from BY5PR17CA0028.namprd17.prod.outlook.com (2603:10b6:a03:1b8::41) by IA1PR12MB9523.namprd12.prod.outlook.com (2603:10b6:208:595::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.25; Fri, 13 Jun 2025 21:06:12 +0000 Received: from CY4PEPF0000EDD6.namprd03.prod.outlook.com (2603:10b6:a03:1b8:cafe::66) by BY5PR17CA0028.outlook.office365.com (2603:10b6:a03:1b8::41) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8746.40 via Frontend Transport; Fri, 13 Jun 2025 21:06:11 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD6.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:11 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:03 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 04/32] x86/resctrl: Remove 'rdt_mon_features' global variable Date: Fri, 13 Jun 2025 16:04:48 -0500 Message-ID: <4afa6237d750493d81391173379b12d02f17f7e7.1749848714.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD6:EE_|IA1PR12MB9523:EE_ X-MS-Office365-Filtering-Correlation-Id: f7939d86-b2d0-4460-a93d-08ddaabe1ff9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?kDhYLmd8E3x5ISgL2+hKpJ6WagceNYk6DsGW496PGHRRmtaHuDmpFAGWqs3s?= =?us-ascii?Q?AoDTSOqTPWuKMGxfR3pskFNBtFe+nKKc1yu+02M9zNVoYDvAf7Fm4GWVBYie?= =?us-ascii?Q?0jCIdAwlDVjaIi/R92QAELEiyvMcUZ1CBlLsr9+/ggR1O9YlBiN16aArCWSZ?= =?us-ascii?Q?Pl9GvS7jR60VtnlXQWKckNgCB/5ixJXPX6L7M8R/RJsqBSFMCUrKdKRJbJlv?= =?us-ascii?Q?/1vZNkjUpJvUIfyxAAV4JoJMUiipCASN+83qne5/BszhidYDsp/C0T/UExcH?= =?us-ascii?Q?Q/JSoglPpl1hFG0MojpuxXdiZL90qzxd06hSC14ZKUaoTFnst7q9vgRu372o?= =?us-ascii?Q?qaxNKJCJanFaS30xOX/KQz/HFS2JaYBtd4qfX4RG1vj5wuy69818p//fSPSz?= =?us-ascii?Q?nNGR7vwCEtUmDSkJkTlKQ4ED82p2Mdwhp1RxSg2hsd2EShI7d/k0CQiXI2g2?= =?us-ascii?Q?3YP3QrWcVuqFdkiKzbN26c4fKLlpgcKpK5sax7X/qikVtxWUPqI71gqF16ug?= =?us-ascii?Q?tFR78knXi2SjLo77VyIyj9jaB/mD3wI6Ps7o7xkhWQnn+s9wC64JRw0Y9jYU?= =?us-ascii?Q?8KoBMGXzKRGAV9v16vmJbZ0wv85mtJsXSL65ljOpOknrwMTGmcDe/MQlibm+?= =?us-ascii?Q?c0Z69Ic4CNzKHhTtdBRIFZUINokh6LUcCSDXOfdGKDOjuYSl1bBog1B7edM6?= =?us-ascii?Q?s11n9z3xyBNtXiIwr1l9uIHq55VCKWthVMxdpJnKRG7jId4yOOc9QBWVBBaJ?= =?us-ascii?Q?1plSsQUV5gnToOooUDoQ+BOeIY26GxuBYCmtdRyiQNGttazrsql+DOhtBcey?= =?us-ascii?Q?Iv6BiHMU4mHuMBUa+7a7zU6pwegk8GzJT/dNK04yGuq3U/OTF9axXJ+RNLrA?= =?us-ascii?Q?YOkmWGq/tw0a5hVD9faDGGnt8jV/dfQYUGLAngfwOytCtoz2mvJhgYXi6jUw?= =?us-ascii?Q?8Jxic/WfYt6jZSK+JvlUlbfanHWyB6FGlfye+Rip3GY0796EEw/R/HHJKSnm?= =?us-ascii?Q?WgAqjnvOGyuv5lfqRTub9/TauzDH4xXEVbwShlw+I38HxP/JVLIrGPBYaLMl?= =?us-ascii?Q?JZ4q4EB+VDl2V0I6IJcXAlJf8lzyAQRIZag6DxXqMisif8wXOgfKrMRprsG1?= =?us-ascii?Q?V3fB7J1TJJVUCw/efH8gTXWlXmyw98YvAB8Q6yTuVkrXPyyhAxrz33akhDCk?= =?us-ascii?Q?EnV7U5D4rv8l+Y+Yf5Lpdz79TrGuOcotw8k4UJrWiUxY5BDnMUR1BKmi8q4j?= =?us-ascii?Q?HnQ0Ng2kw9q+T1/3aS2YBZ2jDKRJf0TPQwjeXS8jNWrbLKM4dGxk/mR9KK0A?= =?us-ascii?Q?5lr5K0YczjGacUW4m62HHaXOREvMjXdcvHvksow6C0KqDCdneoNk+GxV+CYk?= =?us-ascii?Q?dm5H2iDcw3/hRrBhlEEbsmPR5pPMa3FLhOSN6RoIBrMc8sj3tlpmrtAC5uDs?= =?us-ascii?Q?NKrplGtSF5ylzpzfx3HqqCP1ssSMdKXYmabaF/8yeqXnf6f55H/V27qNucb5?= =?us-ascii?Q?c0bIz9lo7BfAb++ntJQhSa2W9aIhXcyRGXECCHuaYJf7BReCfCvzGmtkNQ5G?= =?us-ascii?Q?VIJuQbnUP08D1HWPQbI=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(7416014)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:11.2453 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7939d86-b2d0-4460-a93d-08ddaabe1ff9 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9523 Content-Type: text/plain; charset="utf-8" From: Tony Luck rdt_mon_features is used as a bitmask of enabled monitor events. A monitor event's status is now maintained in mon_evt::enabled with all monitor events' mon_evt structures found in the filesystem's mon_event_all[] array. Remove the remaining uses of rdt_mon_features. Signed-off-by: Tony Luck --- v14: This is Tony's work. This is part of Tony's telemetry series. https://lore.kernel.org/lkml/20250521225049.132551-1-tony.luck@intel.c= om/ Tony made special update for me to include in this series. https://lore.kernel.org/lkml/20250609162139.91651-1-tony.luck@intel.co= m/. --- arch/x86/include/asm/resctrl.h | 1 - arch/x86/kernel/cpu/resctrl/core.c | 9 +++++---- arch/x86/kernel/cpu/resctrl/monitor.c | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index b1dd5d6b87db..575f8408a9e7 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -44,7 +44,6 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); =20 extern bool rdt_alloc_capable; extern bool rdt_mon_capable; -extern unsigned int rdt_mon_features; =20 DECLARE_STATIC_KEY_FALSE(rdt_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 1a319ce9328c..5d14f9a14eda 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -863,21 +863,22 @@ static __init bool get_rdt_alloc_resources(void) static __init bool get_rdt_mon_resources(void) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + bool ret =3D false; =20 if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) { resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID); - rdt_mon_features |=3D (1 << QOS_L3_OCCUP_EVENT_ID); + ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID); - rdt_mon_features |=3D (1 << QOS_L3_MBM_TOTAL_EVENT_ID); + ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID); - rdt_mon_features |=3D (1 << QOS_L3_MBM_LOCAL_EVENT_ID); + ret =3D true; } =20 - if (!rdt_mon_features) + if (!ret) return false; =20 return !rdt_get_mon_l3_config(r); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 61d38517e2bf..07f8ab097cbe 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -31,11 +31,6 @@ */ bool rdt_mon_capable; =20 -/* - * Global to indicate which monitoring events are enabled. - */ -unsigned int rdt_mon_features; - #define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5)) =20 static int snc_nodes_per_l3_cache =3D 1; --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2087.outbound.protection.outlook.com [40.107.237.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C42EC27146E; Fri, 13 Jun 2025 21:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848778; cv=fail; b=uMIubQ4PY7+75J0Ep47YfuvjzAsme+jJ+NRp//JxaAw6BNb0sPEBedVuizSWvedkFi6ZcVL/eJQ7pBgRgK3uXWebZFshNv3/mwtJPiA/drStZ09zaNPoGo/3+OZVGu2euS1IsryPU8ynh77fdVYgl3wxtBpDdekB83etzgpwzcQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848778; c=relaxed/simple; bh=Jd8t5ZMKBzbcU0rMbKC0yT8Nxo0IM8vNIVU4usZPjZM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o2+oC3ACIGL1brDbFibiKFKRUb8LTsWUG3JjBdFEVfmei5fKeF+0rZPBkEbILq4ZQ9wGZwxcZvA9Oj1mqvcmvmQLaONDMzcQpOIgi7Ncw5+VRogkf4Z7K1Kffkq3qCRyEDZkoxAh25KP1aTlWpo0feEiiwYjCPPJVPjDsCjAHuU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=5WNHKCLi; arc=fail smtp.client-ip=40.107.237.87 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) header.d=amd.com header.i=@amd.com header.b="5WNHKCLi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qiezmWf1DYpzMgq58eQtk+Pp9jvOWauY2V06izIKAjegxnLK/iYebkXDQUulFThXW2Ge5SCsTFNKkiUMJTQn3Z3Gb0kS9RtlrSD8PaHOZCsvz8XX8qBvqaGBajLl2/s4ije7d3PxcUgACzxtUwu0udO0HgTnrlon4N8pI3lfcNNNhlsB3gTg29yol3MGxb84oAMB1qJTA821rE4yFvRZIZk84ekglCllSTidRUYBWc1nzczE7PxEtnKApWdeoioekqndWtG0L0J1dqBTcS7aAHzM7pG78/ytdtqnM7mzxfhGGPr/GkLl7wwwj3OOeLeUY+YcYitbTnNpem+wEIvzzg== 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=BtNYv2aQ7/Ns5PymFf5g2ESmYK+bKmN7RjZ1vgPwrvc=; b=TG+Hih0JcWBTpbt3Lh8ckZoj4db2mIaTCLlyUpxYTYxXSuL2yA/FNZC+ifUcm2IbRjNgMFNLhKhHX0JIvyPIaveP8OaoXEKXG+IaeIZdux+2vI1V9N/enNxcE99Jn0hNuU16jAeV1Jc9aKrEh+udeE4DH3DQNB8DPUIjvkx1LDOPzUSvgUcJfKi7eyRL+eozkP2xwzS8sW+s8WgsWE49ofh5bkE0qFXm07s6/6mlijKXZAWOUhm3Pk2SOZCZZ2k3I6a2OfShKiGBuUa4lux9Bxa91I1jcyC5l1BKafnTKClHxbyDm5Bk/Nyk3Z3/89wpCXoObQMbAHxrYXsrm3WEvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=BtNYv2aQ7/Ns5PymFf5g2ESmYK+bKmN7RjZ1vgPwrvc=; b=5WNHKCLiql4fuhyyNcswNZxjMlmwFPiYclM3qn0RHcujBVAcHDB5i1Kteg24AV8Cm6RDviPUzZncLziI4Beppz1KseV/ymjsICGWMBVZioCr0Pg09tnkevPQgwtK12HezDVHi0dRatPqQdcBgTo6qR7T5U7z9QbSGoDjhqoqt4w= Received: from BY5PR17CA0015.namprd17.prod.outlook.com (2603:10b6:a03:1b8::28) by MW4PR12MB5644.namprd12.prod.outlook.com (2603:10b6:303:189::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.23; Fri, 13 Jun 2025 21:06:13 +0000 Received: from CY4PEPF0000EDD6.namprd03.prod.outlook.com (2603:10b6:a03:1b8:cafe::af) by BY5PR17CA0015.outlook.office365.com (2603:10b6:a03:1b8::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.35 via Frontend Transport; Fri, 13 Jun 2025 21:06:13 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD6.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:13 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:11 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 05/32] x86,fs/resctrl: Prepare for more monitor events Date: Fri, 13 Jun 2025 16:04:49 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD6:EE_|MW4PR12MB5644:EE_ X-MS-Office365-Filtering-Correlation-Id: ec667f86-59e1-4f0e-662d-08ddaabe212e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9byxxku94wYwoDVOz0WuBSQc7n1O7lBKH8YNxoYjEl873RrGIX1yDbh4CsKr?= =?us-ascii?Q?tfkQOoIKZN537h2ovIo5laxqsvi7x8cl+2FjoyAtS8yPAekg4xKUZx5F6S2w?= =?us-ascii?Q?1RlMlwjHlVLViFaJKeNayeUTRSAeMB019Ec1CWXvB1EgCbFaTLEtpMSXbnRJ?= =?us-ascii?Q?rfAa33CNvWBE/1zeazgY7XEMFRBzQCjdeiKc8yn4N0Ygk8DnmKAXLUEu+q0R?= =?us-ascii?Q?UpIynkgOhLockezJ6l2EKhBok6dVbxnXaYHYAyFMZrB7LQwuY4wkjHMCoEqO?= =?us-ascii?Q?Y+CXJ/lzZgKuQZ2DlG0WGzVeNJxDyVHACsmTxsxHvQDdZHn/5nsAWkBFjGFY?= =?us-ascii?Q?aOW4v2x2cdlU2u6b80nk4JxBHS7jMtxQL9nL8fLazsKMAVmYVJI+41p5IE/W?= =?us-ascii?Q?MYSTq74wUAIr2PbRcDFzVRFYHOUJ8nvkaCaq4mcwCuO12idIipknoPtZzEOX?= =?us-ascii?Q?KW0cCeFd7cNghzprOG0UvaxQ1F7HbCxZkS93/T0lb6wsQBHh/o9Lxn3SxiXS?= =?us-ascii?Q?dXVKGRYJvUAR8uBQwGYCn8IwugIEbqHtxLRMZ9n3ZG/rHX4QvTdB6AyZxE8w?= =?us-ascii?Q?60YSEaORoF9jarSdEPuTxejE5mgI29laKdcv9PE3Xbr7SqzfQgeZb0FyUTzn?= =?us-ascii?Q?eYJ3/YxF92fuMZX7oONK4d8ZoNUaz61p4eL8UDHHcFc6Z6pJBe+vmXRd32Pw?= =?us-ascii?Q?tM3NOtTN27RcDeAr28KEqEsxwZ7ATQmAvT8T3QgQIdmElreA9M1ca7FgZSPx?= =?us-ascii?Q?wGIUYlcnC3w7mO/kQV9c4AyJNRz41KdTI8hlQWcN9zEL1NEalbiwaOBHpX4m?= =?us-ascii?Q?DDitW2OwC0vWXccTG8M6ePIBGUh9pvGUb3072W5U+Y1N8JaPu3AwdQ6ZvJBs?= =?us-ascii?Q?gsJUEpkcviV5urjV3OlBdzXqq6okbTjtnYbgszpDW8hcGQRYF0WbTvZccS5U?= =?us-ascii?Q?6ohAGloO+lEhcd2q2GshyCM5XHQo7CV4dFigXoMtF40Ju0iqd240y0vdP33D?= =?us-ascii?Q?kmFcuIfInmtjnjzoYVdGoeOQxVxZ0lheyuadv8/blrgcJwQMY3QfPP2krpc3?= =?us-ascii?Q?S3jBR5rUMi38wVqwovdPqNhdLa6DR5GMvaF/AlbP7sfWBvqI98RROfaXsSvV?= =?us-ascii?Q?SvAIdOElIE7JykVgR3XKwinNtjNCqQq1iJ/EVwIflyUOk7nsjRvlZ19wNRZQ?= =?us-ascii?Q?xTcHzOlZM4oSiJ8E1A+rfW/DKDEHPO5g/DxgVSQ//DXCFAlf/B4Pkpr4XBro?= =?us-ascii?Q?hKgO8AXOpdhvHV8E+bv2bYp9E/n9AKIGzQptFDrJgGXBe4P6fxBiE37qfsL5?= =?us-ascii?Q?Hsm9tgCuHD7KPVxhcWYUNgeItmuaPXkfaMav5aWSZflaQGQC8eTZrABdoqiE?= =?us-ascii?Q?YY05XjD4YjVQFvb3CM3t1FZ3VdO2mzKysAwRSwc3djksv3jbJBESe4AbeBp0?= =?us-ascii?Q?tChDJwToar0KJxjAvPa6PuJH2ksLHH2cjB0YhKhojPOh/bLKykm6AwVcT/CO?= =?us-ascii?Q?+fvUt2Xt0Qmj/f2hblJC2L080QdqLMfDnaeD/vNn4jYNI+580MdvxIeTF+Jn?= =?us-ascii?Q?pogOErRx23vE8vsTR1U=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:13.2672 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec667f86-59e1-4f0e-662d-08ddaabe212e 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5644 Content-Type: text/plain; charset="utf-8" From: Tony Luck There's a rule in computer programming that objects appear zero, once, or many times. So code accordingly. There are two MBM events and resctrl is coded with a lot of if (local) do one thing if (total) do a different thing Change the rdt_mon_domain and rdt_hw_mon_domain structures to hold arrays of pointers to per event data instead of explicit fields for total and local bandwidth. Simplify by coding for many events using loops on which are enabled. Move resctrl_is_mbm_event() to so it can be used more widely. Also provide a for_each_mbm_event_id() helper macro. Cleanup variable names in functions touched to consistently use "eventid" for those with type enum resctrl_event_id. Signed-off-by: Tony Luck --- v14: This is Tony's work. This is part of Tony's telemetry series. https://lore.kernel.org/lkml/20250521225049.132551-1-tony.luck@intel.c= om/ Tony made special update for me to include in this series. https://lore.kernel.org/lkml/20250609162139.91651-1-tony.luck@intel.co= m/. --- arch/x86/kernel/cpu/resctrl/core.c | 38 ++++++++++---------- arch/x86/kernel/cpu/resctrl/internal.h | 9 ++--- arch/x86/kernel/cpu/resctrl/monitor.c | 36 +++++++++---------- fs/resctrl/monitor.c | 13 ++++--- fs/resctrl/rdtgroup.c | 48 ++++++++++++-------------- include/linux/resctrl.h | 18 +++++++--- include/linux/resctrl_types.h | 3 ++ 7 files changed, 88 insertions(+), 77 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 5d14f9a14eda..6bf2103aac27 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -365,8 +365,8 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) =20 static void mon_domain_free(struct rdt_hw_mon_domain *hw_dom) { - kfree(hw_dom->arch_mbm_total); - kfree(hw_dom->arch_mbm_local); + for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) + kfree(hw_dom->arch_mbm_states[i]); kfree(hw_dom); } =20 @@ -400,25 +400,27 @@ static int domain_setup_ctrlval(struct rdt_resource *= r, struct rdt_ctrl_domain * */ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *h= w_dom) { - size_t tsize; - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { - tsize =3D sizeof(*hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); - if (!hw_dom->arch_mbm_total) - return -ENOMEM; - } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { - tsize =3D sizeof(*hw_dom->arch_mbm_local); - hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); - if (!hw_dom->arch_mbm_local) { - kfree(hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =3D NULL; - return -ENOMEM; - } + size_t tsize =3D sizeof(*hw_dom->arch_mbm_states[0]); + enum resctrl_event_id eventid; + int idx; + + for_each_mbm_event_id(eventid) { + if (!resctrl_is_mon_event_enabled(eventid)) + continue; + idx =3D MBM_STATE_IDX(eventid); + hw_dom->arch_mbm_states[idx] =3D kcalloc(num_rmid, tsize, GFP_KERNEL); + if (!hw_dom->arch_mbm_states[idx]) + goto cleanup; } =20 return 0; +cleanup: + while (--idx >=3D 0) { + kfree(hw_dom->arch_mbm_states[idx]); + hw_dom->arch_mbm_states[idx] =3D NULL; + } + + return -ENOMEM; } =20 static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 5e3c41b36437..44ef0d94131e 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -54,15 +54,16 @@ struct rdt_hw_ctrl_domain { * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share * a resource for a monitor function * @d_resctrl: Properties exposed to the resctrl file system - * @arch_mbm_total: arch private state for MBM total bandwidth - * @arch_mbm_local: arch private state for MBM local bandwidth + * @arch_mbm_states: arch private state for each MBM event + * @arch_mbm_states: Per-event pointer to the MBM event's saved state. + * An MBM event's state is an array of struct arch_mbm_state + * indexed by RMID on x86 or combined CLOSID, RMID on Arm. * * Members of this structure are accessed via helpers that provide abstrac= tion. */ struct rdt_hw_mon_domain { struct rdt_mon_domain d_resctrl; - struct arch_mbm_state *arch_mbm_total; - struct arch_mbm_state *arch_mbm_local; + struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS]; }; =20 static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct r= dt_ctrl_domain *r) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 07f8ab097cbe..0add57b29a4d 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -161,18 +161,14 @@ static struct arch_mbm_state *get_arch_mbm_state(stru= ct rdt_hw_mon_domain *hw_do u32 rmid, enum resctrl_event_id eventid) { - switch (eventid) { - case QOS_L3_OCCUP_EVENT_ID: - return NULL; - case QOS_L3_MBM_TOTAL_EVENT_ID: - return &hw_dom->arch_mbm_total[rmid]; - case QOS_L3_MBM_LOCAL_EVENT_ID: - return &hw_dom->arch_mbm_local[rmid]; - default: - /* Never expect to get here */ - WARN_ON_ONCE(1); + struct arch_mbm_state *state; + + if (!resctrl_is_mbm_event(eventid)) return NULL; - } + + state =3D hw_dom->arch_mbm_states[MBM_STATE_IDX(eventid)]; + + return state ? &state[rmid] : NULL; } =20 void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, @@ -201,14 +197,16 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, = struct rdt_mon_domain *d, void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d) { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) - memset(hw_dom->arch_mbm_total, 0, - sizeof(*hw_dom->arch_mbm_total) * r->num_rmid); - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) - memset(hw_dom->arch_mbm_local, 0, - sizeof(*hw_dom->arch_mbm_local) * r->num_rmid); + enum resctrl_event_id eventid; + int idx; + + for_each_mbm_event_id(eventid) { + if (!resctrl_is_mon_event_enabled(eventid)) + continue; + idx =3D MBM_STATE_IDX(eventid); + memset(hw_dom->arch_mbm_states[idx], 0, + sizeof(struct arch_mbm_state) * r->num_rmid); + } } =20 static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int widt= h) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 9e988b2c1a22..dcc6c00eb362 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -346,15 +346,14 @@ static struct mbm_state *get_mbm_state(struct rdt_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); + struct mbm_state *state; =20 - switch (evtid) { - case QOS_L3_MBM_TOTAL_EVENT_ID: - return &d->mbm_total[idx]; - case QOS_L3_MBM_LOCAL_EVENT_ID: - return &d->mbm_local[idx]; - default: + if (!resctrl_is_mbm_event(evtid)) return NULL; - } + + state =3D d->mbm_states[MBM_STATE_IDX(evtid)]; + + return state ? &state[idx] : NULL; } =20 static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index a7eeb33501da..bd6718f0ffd6 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -127,12 +127,6 @@ static bool resctrl_is_mbm_enabled(void) resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)); } =20 -static bool resctrl_is_mbm_event(int e) -{ - return (e >=3D QOS_L3_MBM_TOTAL_EVENT_ID && - e <=3D QOS_L3_MBM_LOCAL_EVENT_ID); -} - /* * Trivial allocator for CLOSIDs. Use BITMAP APIs to manipulate a bitmap * of free CLOSIDs. @@ -4024,8 +4018,10 @@ static void rdtgroup_setup_default(void) static void domain_destroy_mon_state(struct rdt_mon_domain *d) { bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - kfree(d->mbm_local); + for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) { + kfree(d->mbm_states[i]); + d->mbm_states[i] =3D NULL; + } } =20 void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d) @@ -4085,32 +4081,34 @@ void resctrl_offline_mon_domain(struct rdt_resource= *r, struct rdt_mon_domain *d static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); - size_t tsize; + size_t tsize =3D sizeof(*d->mbm_states[0]); + enum resctrl_event_id eventid; + int idx; =20 if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { d->rmid_busy_llc =3D bitmap_zalloc(idx_limit, GFP_KERNEL); if (!d->rmid_busy_llc) return -ENOMEM; } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { - tsize =3D sizeof(*d->mbm_total); - d->mbm_total =3D kcalloc(idx_limit, tsize, GFP_KERNEL); - if (!d->mbm_total) { - bitmap_free(d->rmid_busy_llc); - return -ENOMEM; - } - } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { - tsize =3D sizeof(*d->mbm_local); - d->mbm_local =3D kcalloc(idx_limit, tsize, GFP_KERNEL); - if (!d->mbm_local) { - bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - return -ENOMEM; - } + + for_each_mbm_event_id(eventid) { + if (!resctrl_is_mon_event_enabled(eventid)) + continue; + idx =3D MBM_STATE_IDX(eventid); + d->mbm_states[idx] =3D kcalloc(idx_limit, tsize, GFP_KERNEL); + if (!d->mbm_states[idx]) + goto cleanup; } =20 return 0; +cleanup: + bitmap_free(d->rmid_busy_llc); + while (--idx >=3D 0) { + kfree(d->mbm_states[idx]); + d->mbm_states[idx] =3D NULL; + } + + return -ENOMEM; } =20 int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 40aba6b5d4f0..bbe57eff962b 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -161,8 +161,9 @@ struct rdt_ctrl_domain { * @hdr: common header for different domain types * @ci_id: cache info id for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold - * @mbm_total: saved state for MBM total bandwidth - * @mbm_local: saved state for MBM local bandwidth + * @mbm_states: Per-event pointer to the MBM event's saved state. + * An MBM event's state is an array of struct mbm_state + * indexed by RMID on x86 or combined CLOSID, RMID on Arm. * @mbm_over: worker to periodically read MBM h/w counters * @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters @@ -172,8 +173,7 @@ struct rdt_mon_domain { struct rdt_domain_hdr hdr; unsigned int ci_id; unsigned long *rmid_busy_llc; - struct mbm_state *mbm_total; - struct mbm_state *mbm_local; + struct mbm_state *mbm_states[QOS_NUM_L3_MBM_EVENTS]; struct delayed_work mbm_over; struct delayed_work cqm_limbo; int mbm_work_cpu; @@ -376,6 +376,16 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_i= d eventid); =20 bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 +static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid) +{ + return (eventid >=3D QOS_L3_MBM_TOTAL_EVENT_ID && + eventid <=3D QOS_L3_MBM_LOCAL_EVENT_ID); +} + +#define for_each_mbm_event_id(eventid) \ + for (eventid =3D QOS_L3_MBM_TOTAL_EVENT_ID; \ + eventid <=3D QOS_L3_MBM_LOCAL_EVENT_ID; eventid++) + /** * resctrl_arch_mon_event_config_write() - Write the config for an event. * @config_info: struct resctrl_mon_config_info describing the resource, d= omain diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index 2dadbc54e4b3..d98351663c2c 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -51,4 +51,7 @@ enum resctrl_event_id { QOS_NUM_EVENTS, }; =20 +#define QOS_NUM_L3_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTA= L_EVENT_ID + 1) +#define MBM_STATE_IDX(evt) ((evt) - QOS_L3_MBM_TOTAL_EVENT_ID) + #endif /* __LINUX_RESCTRL_TYPES_H */ --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2076.outbound.protection.outlook.com [40.107.243.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 595DA271A84; Fri, 13 Jun 2025 21:06:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848788; cv=fail; b=C3PyaPmMYF4oxsYUChqk/k+R21ADkMwxX9/nrh9gpd6yHNe2KkOC/GFnechW6oH3d/Qnh8VErhP638Kf2LcwGapkf+g6H9bEtZo7O0kq1pFID2fjB4CJJBnJSKOCNgngYQ4rbH1h6x4pIHe41gMuv5H0dx3/VIgnWQ2+diOnE3g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848788; c=relaxed/simple; bh=MoAbk1nEXwmKkkfeLK2LdiUAwxJK55FTXHKdwnEF/Bs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ePuBwdx83sbAyImKRV+7dOoPEqu1nngAVsadII0vFjSeqyA1WYx+6SL0e046GaJGQkNdZeECAhH3JlftSwVzaSgtZeyAH2yNs/ziovLLtLiAwehGXhi7xy1B8kMJGiKSX3UFY5rZbNo791nesHlYlCDct+N1ILa96OU/eLrbrWo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=j/mdemX2; arc=fail smtp.client-ip=40.107.243.76 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) header.d=amd.com header.i=@amd.com header.b="j/mdemX2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=U1WCi7w5P3GwuO5pQUh0JL/534PqjD1YlXBxuXNoEv9REeSl8Hy5dMlKjtTdE9hxQmlFVB4anY1eEpZ/8qN6A+JQunjg864tGMtJou1vtgKPEdPSdc+2WCcNZ2fS6aETjUEG0z/naieujPI+G1RG60eNwRYAAYYp0LySOhf5lSTsOk+u5omzbucs00tmPlk6m+dqaDThtjHUPrhWNaUDQQj5sPTSLDqBjMBAc6Dtsq3Zki3Wpb+Qaz0i04tZ5VrZClcxeDYTCaZhV+oUt5lMgJx2TES8GZylxExMbhPcjMIyP44Vxl9K7BpxWYgviW3yLxvkARJ9KVjWY4e5EXbUlw== 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=gtzFJvqzMUELqaySWL/j2JzAswxcVP0as/ID9+S0Kmk=; b=kjEqROL+pARmCuxFLZ6V7nHYwToGBViloXG0NN9YchEpuxo9j3nOmyknwYbQtVt7Z6hzsTyKczixPji45sAnQqBEwBP3VVQNePsJ9GZ6cueo/s419HF60/H2blrv7HB79OuStiQe5aAENtjU2tCmlYBgi2liNzUeu46ToUZ4LeQ/kxUEd0JV7FtykMx4LBEURHd9dF7dmkiikpDp7+pv7N4xgDOJBNq/j1loHZUwn9v1bS5hsjPQnj9wDMMLBBR8Xq5vBGOM2yUPy22vdzPAMYUhTCfY6cxpUeLzsOMtEWS6a84815WNXEeCy+cZuASOxHcKDow8pqNpQr+z2VeAsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=gtzFJvqzMUELqaySWL/j2JzAswxcVP0as/ID9+S0Kmk=; b=j/mdemX2ih3+u5E0AI97Rde7uKD9Xs0jp54IpRQFfSK/xU9J7HiS4Tm3kybu5fWCaeJrVimrJGjBJXViNkRYXpmsdEng5tZefV0A8CylX5+KSWSR5TGAgGd9cOM5F5FI5TJPUBk0PM4wCxvLbQksdHrojRZ9ArmYPvS3f47A5/g= Received: from PH7P220CA0085.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32c::26) by CY5PR12MB9055.namprd12.prod.outlook.com (2603:10b6:930:35::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.23; Fri, 13 Jun 2025 21:06:23 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:32c:cafe::7d) by PH7P220CA0085.outlook.office365.com (2603:10b6:510:32c::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.25 via Frontend Transport; Fri, 13 Jun 2025 21:06:22 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:22 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:19 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 06/32] x86/cpufeatures: Add support for Assignable Bandwidth Monitoring Counters (ABMC) Date: Fri, 13 Jun 2025 16:04:50 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|CY5PR12MB9055:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f539753-c64a-43a4-635c-08ddaabe267b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?jATu5zK1e6J9+2F7oVMSIfOKfZN3yTi7ZbMSS2DpcoKMa/HNMANcarf9z55C?= =?us-ascii?Q?3Lmz9io1rYJXXJtC6qxLzFm4riXQno03cV33MShi7sGbyync1s1NhBYCkKQi?= =?us-ascii?Q?L6xNpvTpBem50O39a/kX1TP0WbXgikmPOIMLHkz3E19i4V0d4mmR2yXm6wxx?= =?us-ascii?Q?uowL0KHO7IvcaZg5/sO8auR0kO0SUfjXjtJyCtYxA8ZWWLIwXeG1vt7DvtZf?= =?us-ascii?Q?fxHGL0qYPit0F35tJlDzxcMYLZTA1uPsTYP05aEAMD1Sh9tVt3iIuhQTX3pc?= =?us-ascii?Q?ygX/fpuOJ6/xaDP4X2SJSoVgjB0Ls7UO0wLjh/NACsWnYBbe0h9j43gc+Sba?= =?us-ascii?Q?p+acTm35ZbmZR5i6tt3GNTdg/VNi0Jzsmwq6FAPCJzt/StcxBdciBW+rGujh?= =?us-ascii?Q?OvPjLss+jDL5LMrLBQPcws0AEIH74o7wdFyHCck+nLMjhBIx9V2NlXWodvGA?= =?us-ascii?Q?EKB2dznYkpYbUzyv4yxO8ccKDONHfuuV3lwlB4gxzKfoEdFCpx/LmLD74QOT?= =?us-ascii?Q?dsTEuFruuHcFKz1ToiBgPvm6EIWtAG+G/E7YNbGAB954u5cryEK/BVAlABrr?= =?us-ascii?Q?QP8jluOMVnkAgEV3NDbiMwMftPZ5tkqkQbIQhqrla/HrAA0gtcJOuJ+XpyYt?= =?us-ascii?Q?Eeupai6RJdyC66CqdceTjUhvwkh4xr992sTOYEEUDKJIPoB2bc9U8A6OIumJ?= =?us-ascii?Q?4VAc3FedZdHzHmGTgxQrYZZ+6zlRrqUx8K6lzkuYusZ4Q7L5go9t7crGGzo8?= =?us-ascii?Q?zC71Kui9F5UIOxNFak51JvdCHeUR2vPaiRCyxhl+3Q2ILrtJTzG4i+jh9TcT?= =?us-ascii?Q?6MB8dJd/3eftPVg9bsuSv5RD/o4PLKirW1sqA9zzSJ0LmA/5k5g95hb7xzZb?= =?us-ascii?Q?BWiCvIfKpYy+GtUMRrzAnax3nzwthsER4itzxGY/aG4fIYgd1lEcMDzTu7B7?= =?us-ascii?Q?U2aTuZENteqfsw/hZE/52/oNzJqxZPW0HrJWz6oV9rTY5jXVwGlbOZTFMrSE?= =?us-ascii?Q?arHs97tt8xQkgsXJvLJ8bmoJ/9UE26eKCpgPnMPCaDfp6xj2OOzKn8aMUx9k?= =?us-ascii?Q?4aKkL6ufKJ0AChYaiDEGgdAXrHfhYEOzwwr/0JDksogharnEuwpJ6rG/gB8m?= =?us-ascii?Q?r5GIs3ki92mgLftLHf1Lj3XKp2FoGaI5Nv9Suyqx6cPKMXBdxJ54oQjxkxfn?= =?us-ascii?Q?Lg3d7rKlt6sMm6OUdDQ11/CJMYWwDpZUD1igQB4uFDAc6w91LkRn7m2GN8+F?= =?us-ascii?Q?QcF+++EnTlkeXDSxMDvS2Xqhwxx4Z90nMD3OuzS+HbausCOScBgL5PvmrVxA?= =?us-ascii?Q?UpVCutmzov7oCLWwGx/HStqZH7B9ZcX4OvHsfAPaD583X9sqAQ+N/wQXo5E5?= =?us-ascii?Q?qVKVwYqIArXBITz98wiTKgGG1MQ6ztEd0OWvFUMwIM38q+ZwnUYeYJqmQJd2?= =?us-ascii?Q?OtK2tt54dFSUkMgY5FsSvcP1e8xCDUeVOzEy342y/nzzq4EZJTyPIGAIoR/Y?= =?us-ascii?Q?80J0dZxhhQLT7tJrHJsAa2l2TeW6hcWIFWqateHxVD8cP3JVCBf8Bhgf1YpQ?= =?us-ascii?Q?83CcpICzfsjsVG+Tgi8=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:22.1557 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f539753-c64a-43a4-635c-08ddaabe267b 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9055 Content-Type: text/plain; charset="utf-8" Users can create as many monitor groups as RMIDs supported by the hardware. However, bandwidth monitoring feature on AMD system only guarantees that RMIDs currently assigned to a processor will be tracked by hardware. The counters of any other RMIDs which are no longer being tracked will be reset to zero. The MBM event counters return "Unavailable" for the RMIDs that are not tracked by hardware. So, there can be only limited number of groups that can give guaranteed monitoring numbers. With ever changing configurations there is no way to definitely know which of these groups are being tracked for certain point of time. Users do not have the option to monitor a group or set of groups for certain period of time without worrying about RMID being reset in between. The ABMC feature allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. There is no need to worry about counters being reset during this period. Additionally, the user can specify a particular type of memory transactions for the counter to track. Without ABMC enabled, monitoring will work in current mode without assignment option. The Linux resctrl subsystem provides an interface that allows monitoring of up to two memory bandwidth events per group, selected from a combination of available total and local events. When ABMC is enabled, two events will be assigned to each group by default, in line with the current interface design. Users will also have the option to configure which types of memory transactions are counted by these events. Due to the limited number of available counters (32), users may quickly exhaust the available counters. If the system runs out of assignable ABMC counters, the kernel will report an error. In such cases, users will need to unassign one or more active counters to free up counters for new assignments. resctrl will provide options to assign or unassign events through the group-specific interface file. The feature is detected via CPUID_Fn80000020_EBX_x00 bit 5. Bits Description 5 ABMC (Assignable Bandwidth Monitoring Counters) The feature details are documented in APM listed below [1]. [1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger --- Note: Checkpatch checks/warnings are ignored to maintain coding style. v14: Removed the dependancy on X86_FEATURE_CQM_MBM_TOTAL and X86_FEATURE_CQ= M_MBM_LOCAL. as discussed in https://lore.kernel.org/lkml/5f8b21c6-5166-46a6-be14-0= c7c9bfb7cde@intel.com/ Need to re-work on ABMC enumeration during the init. Updated changelog with few text update. v13: Updated the commit log with Linux interface details. v12: Removed the dependancy on X86_FEATURE_BMEC. Removed the Reviewed-by tag as patch has changed. v11: No changes. v10: No changes. v9: Took care of couple of minor merge conflicts. No other changes. v8: No changes. v7: Removed "" from feature flags. Not required anymore. https://lore.kernel.org/lkml/20240817145058.GCZsC40neU4wkPXeVR@fat_crat= e.local/ v6: Added Reinette's Reviewed-by. Moved the Checkpatch note below ---. v5: Minor rebase change and subject line update. v4: Changes because of rebase. Feature word 21 has few more additions now. Changed the text to "tracked by hardware" instead of active. v3: Change because of rebase. Actual patch did not change. v2: Added dependency on X86_FEATURE_BMEC. --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index ee176236c2be..44ae69a8748d 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -487,6 +487,7 @@ #define X86_FEATURE_PREFER_YMM (21*32+ 8) /* Avoid ZMM registers due to d= ownclocking */ #define X86_FEATURE_APX (21*32+ 9) /* Advanced Performance Extensions */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32+10) /* Use thunk for indirec= t branches in lower half of cacheline */ +#define X86_FEATURE_ABMC (21*32+11) /* Assignable Bandwidth Monitoring Co= unters */ =20 /* * BUG word(s) diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index dbf6d71bdf18..d5d4a573aaf7 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -50,6 +50,7 @@ static const struct cpuid_bit cpuid_bits[] =3D { { X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 }, { X86_FEATURE_SMBA, CPUID_EBX, 2, 0x80000020, 0 }, { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 }, + { X86_FEATURE_ABMC, CPUID_EBX, 5, 0x80000020, 0 }, { X86_FEATURE_AMD_WORKLOAD_CLASS, CPUID_EAX, 22, 0x80000021, 0 }, { X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 }, --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061.outbound.protection.outlook.com [40.107.220.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00F1C2737F2; Fri, 13 Jun 2025 21:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848793; cv=fail; b=CohIBqont3irbgidto/aYtP0o34En9nyMBBLNA8RitiBkG+Sg1V1isFCWSTuNjvNaxahNUyDhSmdXivAc0EswLtkks/LsNv3+CwuxJNNQuv+4IV1Jpdbi/codHNgra+ysBFG1JqU6Wr9S3+bFOTkrgl/2Youto6zPlF1UBuyFtA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848793; c=relaxed/simple; bh=UU6h7b3oQJkNDWIATPvKClK78sXJOxP2PfPFlLDo05w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d4Mc2OT89LlYqsCCmtldc92CEfMYwj8GfyKSIEpRLAH/pLFg2X4WQvt0cgOiYpPcrnw1LiDtA2oNEoCdmbLTFb/Xa2GjNac1FNqEMI77iSIlJJVIZRu9myqMVqHC0UWhK3CQ6tKA3nciNv/KhK0eHAX6Vyod6L2gBEPRVu1QTHw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=IWjDT7Xt; arc=fail smtp.client-ip=40.107.220.61 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) header.d=amd.com header.i=@amd.com header.b="IWjDT7Xt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XjkwT//rDqhKzhGXTQ4bfgtvdQyQRn0sQJNvamVZE5XUwDhnaPPPpJMhus6ODdDpQtJWTUl4I+07TXmwkJgYyqZb7gBAmM6MI/Fvp0W0btIEEdGkW3k23pB2/eDG4NOqY7+2JcT+nc6NfqMOzWki/9NLmiAbEk+rmNmwLPh06A0q+GiZWcDQWri0MoEBavZt4Fz05ujs0vmvNTru1BjaSZNmf9MBBJJ4bsqtx+JfZbRb1ociizp5/0LM19wdtapcyugCVTX4BpfinpF5L7IvzpD2j8vM4Z5Mwj0ilHp0AOlO2z2WABuz2Rt1qYdnMNVgSF7c2cnmA6k2Lc8+KpLa9g== 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=nmbJ2f6XXELujln3jGLGuWcqN4PGgtq9NCKdXf9K6Qw=; b=fP2H/AucAV+idHdxm9Tg6fPOWkG3N720lZ82lboYI5JAVlAS42I/SjSEr8Kzu3TeDFUfTEH7H+ShIwSttfsMymChrYKBjPChcET+33zHRdf18P2K+4dSX6GwqWeGY4tDnNscuhwWRFGSKPceCBSijQvbPk7+A2Wih/2610SlnMKhfPuJ+Mm//6ANZWIHZJXoL6g9NJ+aGnbFl3vmvflfI0zOlTi5P+ikZ/wKw0apkyKhkJJednSmAkfAhj2NeLs34az1yIupdZqiNXsbAO2z32R+v/SMpWoNqbSTDti4UMBmhRlJG1luY9uKqzMU8ECumCjnhwdMgKOJMkKTPn9PTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=nmbJ2f6XXELujln3jGLGuWcqN4PGgtq9NCKdXf9K6Qw=; b=IWjDT7XtJfM8Q0gTRrIN4GW7LXN1hgGWv6/1VJYQBT2u2K8iN54q1XzOWTw6aJ0EjL+CzA9z8NR12Rd0FwrbpD2KseDItnElUdHU47XzX4c0oKR5xXQP3f9NuPUDOnwcSGEQJD2c4BRddBSxehoKCD2dKVTLKN616OmWyFogImo= Received: from DM6PR02CA0112.namprd02.prod.outlook.com (2603:10b6:5:1b4::14) by SN7PR12MB7786.namprd12.prod.outlook.com (2603:10b6:806:349::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:06:29 +0000 Received: from CY4PEPF0000EDD5.namprd03.prod.outlook.com (2603:10b6:5:1b4:cafe::eb) by DM6PR02CA0112.outlook.office365.com (2603:10b6:5:1b4::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Fri, 13 Jun 2025 21:06:29 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD5.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:28 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:27 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 07/32] x86/resctrl: Add ABMC feature in the command line options Date: Fri, 13 Jun 2025 16:04:51 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD5:EE_|SN7PR12MB7786:EE_ X-MS-Office365-Filtering-Correlation-Id: 06bc8c8d-c873-4aef-b3ff-08ddaabe2a87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|1800799024|7416014|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pkyx8yntxF4ceNEi/Ny/k4lJbRtRGHlXoQyZczo8eJb25piF7jllTV8D+5WJ?= =?us-ascii?Q?CJaIBs4IxJ7h06wQwyjAKmY6wUNLTI+RrPq5o4yh/zzDdcw2BQv2wXP10vHb?= =?us-ascii?Q?+1sPkC6j4BrVp5pNCCZ2eGqYMZU3yFiuVraADQ2geYb3XGBBY76Il0GI8Z2Y?= =?us-ascii?Q?ZhteUoy8Lyvet89CxoTjILqYsqO5/zrf6+bv//nRrHF8R36LsjMyYcBo0LkO?= =?us-ascii?Q?3uV16+Tcl1UIWMPHolyaKueppxE8IR4Y8K2xS3g7469IppvDtvhXOsEJyeoY?= =?us-ascii?Q?c1DD1ksBadsMyQvo1YPHCvvRJOgltwaFmWtXtsAPglvRhg1h55X2zqgipUSU?= =?us-ascii?Q?PhNBFSmjBuesV/BW4gh4ihzJjMpgozghnMOXXm7VwNC8r51I/l+DWE0txuEp?= =?us-ascii?Q?JGhuRBbZ0KtMyS6uAlJ96U3FmreP5NA5c8sAVenItpxvR+VkwFM/OCxhWysl?= =?us-ascii?Q?lXkuWaRWpsdlsdW0FJ8uDyy1rMSmEkhfFK08NgZqCEAYm7sqeTKBuXnnq/xD?= =?us-ascii?Q?uyYGiktJBi2fBy7Q2LLP+WmZahkTLYFQwOuyJ0k3QmStxd3dlkIWXsLje8UF?= =?us-ascii?Q?iNJMemXit4nON5qMct1280tnm52PH9qyEsyuciM6H7JrpdLqQIhemf94zDSM?= =?us-ascii?Q?IauXZJWXuKwUGDLsfCvCTuixo/yTW2BlDqlA0PD2RqWu61FlVxRdmD/gRzQ7?= =?us-ascii?Q?1bJMZjyiLx5BF/fzDDFkM+psAhkl4HEAYMeQs14UkjkP2Gz53XgrBn1qzeb/?= =?us-ascii?Q?OVD3j9NJ6u1Svd1RnFMp6Pfq3ICBYtq920GQdmg5KQTbYwEO/yl29XLBJfyO?= =?us-ascii?Q?VHclA0gAyklmzP9thWnHp6uW0DMlPlfWoDqhMczQ2SEmx464GyQZ33GgWuWG?= =?us-ascii?Q?3ktJlcF/E/yoaBMX5rVOrBERJrQ+BkBmcHIRQYlf+e60Xp9h8qXqUcjnKg9P?= =?us-ascii?Q?8tEakHq0DmXPLSQskUvUnrw+h3Bw/YghcS1IjmaEtIv4yZx6YFOEv97BHeZr?= =?us-ascii?Q?YqLPnA0XrPZroctkLiNzAReB1hURV1tJHO7k/IUZUgIPu+CM25XJu6A3Cs26?= =?us-ascii?Q?xgKkhmXEABBglwI2UjKlvlNtUVK1FkJZbckd3olDHDmyCPmo7IUQ6hGPr5/u?= =?us-ascii?Q?6pZZk1BQMdPDmOYJCrrD4LXv15bYsjoWp7+WjPLDufVbzMmof4I4dZ9BSm9l?= =?us-ascii?Q?Fr/gsyaBi24llyZJV17Vh21EMQGz5jPJkAT8jCv4eRGa817n4/iHgVzcVDtb?= =?us-ascii?Q?9QJweJ8PDrrBcu/pfH2PSBNoIwiymH5/P1jKMfrgWAmE1wfNI4yqtvcdwgxz?= =?us-ascii?Q?vXseZIN0uC/QihNUf5nrfg2AlA8eE5laW/X37EDONZXEZOFwpkRro44YVo2M?= =?us-ascii?Q?1hrhi76dZ6zAq4nj8f5C7AgbqqNb90Klihfdlb9ErPzWT8kq/GFHeZ+XHl5K?= =?us-ascii?Q?75La441DJRHqpxfz6+Ych5nDb46iQ+Yf0EDgGmjaZQ73tFXjF45P80rHdkQ2?= =?us-ascii?Q?9Ld3eVmx38ZoNJTWHDrP6BjURLxJKwT7/+g7/1+m48v1YPggmXQR718Yqw?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(1800799024)(7416014)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:28.9518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06bc8c8d-c873-4aef-b3ff-08ddaabe2a87 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7786 Content-Type: text/plain; charset="utf-8" Add a kernel command-line parameter to enable or disable the exposure of the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature to resctrl. Signed-off-by: Babu Moger --- v14: Slight changelog modification. v13: Removed the Reviewed-by as the file resctrl.rst is moved to Documentation/filesystems/resctrl.rst. In that sense patch has changed. v12: No changes. v11: No changes. v10: No changes. v9: No code changes. Added Reviewed-by. v8: Commit message update. v7: No changes v6: No changes v5: No changes v4: No changes v3: No changes v2: No changes --- Documentation/admin-guide/kernel-parameters.txt | 2 +- Documentation/filesystems/resctrl.rst | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index f1f2c0874da9..f2f2511b0ec3 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6066,7 +6066,7 @@ rdt=3D [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec. + mba, smba, bmec, abmc. E.g. to turn on cmt and turn off mba use: rdt=3Dcmt,!mba =20 diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index c7949dd44f2f..c97fd77a107d 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -26,6 +26,7 @@ MBM (Memory Bandwidth Monitoring) "cqm_mbm_total", "cqm_= mbm_local" MBA (Memory Bandwidth Allocation) "mba" SMBA (Slow Memory Bandwidth Allocation) "" BMEC (Bandwidth Monitoring Event Configuration) "" +ABMC (Assignable Bandwidth Monitoring Counters) "" =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D =20 Historically, new features were made visible by default in /proc/cpuinfo. = This diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 6bf2103aac27..6426b92492dc 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -709,6 +709,7 @@ enum { RDT_FLAG_MBA, RDT_FLAG_SMBA, RDT_FLAG_BMEC, + RDT_FLAG_ABMC, }; =20 #define RDT_OPT(idx, n, f) \ @@ -734,6 +735,7 @@ static struct rdt_options rdt_options[] __ro_after_ini= t =3D { RDT_OPT(RDT_FLAG_MBA, "mba", X86_FEATURE_MBA), RDT_OPT(RDT_FLAG_SMBA, "smba", X86_FEATURE_SMBA), RDT_OPT(RDT_FLAG_BMEC, "bmec", X86_FEATURE_BMEC), + RDT_OPT(RDT_FLAG_ABMC, "abmc", X86_FEATURE_ABMC), }; #define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options) =20 --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2059.outbound.protection.outlook.com [40.107.100.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2966227146D; Fri, 13 Jun 2025 21:06:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848805; cv=fail; b=Tkf30+uRcrOoZeRk/0SRSgdQPyx2ohJ/3PhdczW/suiPbfprlY+7cXMqVFirJaUxWv5f2gnw0CabYtSXwalFdR3Di1SGC3dBf+1PdlNeEa/O280g9jwP6/4M7d1tuAFV2MWEPeYwBvLStGFheZiH1thqOsAipZQhyRE5QAz2GqM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848805; c=relaxed/simple; bh=/p6nXyhU27NgWBn7LqGaSJ5EMyy+06lSBS8TVK/Klac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QWGr/B5EcgvRQFbxIWJgqKVfMgb4yGYStJL8UINCLp4UUR13TyTAj2AA+wKCMpYycB4eHtFtRXsdvD+FT1Xfe/T6islff+QTzej1BqPKRsJsJTcfYNQGQVCtvhCP6QfaIxBVkP8j6DeazeF3j1YY1HuMseFWv1yImcuBIne3tA4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AYykandH; arc=fail smtp.client-ip=40.107.100.59 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) header.d=amd.com header.i=@amd.com header.b="AYykandH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hZvonxS5SBtA9lwdaO3L46Y5sJli7YvB1VT4mNuLaIQqLoAizp3SM7jUOFqjFJbuJJAikPwoW2qXQDWGpdPZmHqQTt63Ht9JrBLD1LfKQNzshp9YadfbGFm+8eFYRoex2ovG83LVdqAKgkBtvKI53NHa27QHxpqbQ9J7FJXITJwOAGmEdtFwJSqrwq+mFUiuasaYBhYAhLhNPrsngkJN3MOkMSdzVywx7sDf20AY8Ihvtb6mVqTsIFiUtJmgueYt8iI5WM1Z2i5hDrxY/aqf8OASzrr0oBDYj0Fhtqmk0HMcXgzqKvSQEx4Pzw9dGMIA4ho/wRrLnCZzP764iJL1pA== 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=OEWMJ53VAilOA8CLLL64Lwylod+n7dt0vGjyg/rmdO0=; b=ax1F8xPLQAslR2eMt7I3K3jnvKs1zxi2EUGMXpqDR1Kva+8ZQAAglWGqVhD79d0uoiKvbIzduKv0TXJ+UqPh9TRBq5Am0tn5GOiRVuIL2urkAAxPpMN9aLRrgxcn3xlTYJqX4yEzLuCK2H6a2jradUsZ6JYmyi2BzEdz2mPIfa+5vp6MSVdPkI6YcpWrzBHAD9Lsxn/QnX//+fO+fmlQTpKKxe8nH1pRl1g8gVmnLFUVwqrKoLzBwPsgvJksfg8kSMDEbezRwc+XWmbhE18jI7IW7U4Ja3z48Z3frayk8ChL6TfACxR/1LtuSd5wNCr/vPCXvZusb1g2IgH4QeAKFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=OEWMJ53VAilOA8CLLL64Lwylod+n7dt0vGjyg/rmdO0=; b=AYykandH7jpb/axHhmKd3j+YJxB3ewl1ixDeYHyA21znroz8fQLLujMeqKyE6Lsv1UIFYaumKtCKE5xXMTaj45i2i5mOY19GKZtT/YgCFm0hI1MI/in8vmf1anW/L8OOp7vcZlrIPwEYlGOHpu/4vrwXUp7n7fMyIEYxMpAV2NM= Received: from PH7P220CA0063.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32c::30) by CH3PR12MB9121.namprd12.prod.outlook.com (2603:10b6:610:1a1::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.26; Fri, 13 Jun 2025 21:06:38 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:32c:cafe::16) by PH7P220CA0063.outlook.office365.com (2603:10b6:510:32c::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.25 via Frontend Transport; Fri, 13 Jun 2025 21:06:37 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:37 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:35 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 08/32] x86,fs/resctrl: Consolidate monitoring related data from rdt_resource Date: Fri, 13 Jun 2025 16:04:52 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|CH3PR12MB9121:EE_ X-MS-Office365-Filtering-Correlation-Id: 6428e093-cebf-489a-182d-08ddaabe2fb8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?P1vW8vkhQUmWM9W7DsWYx5DH13SzPCWCiYt7ies9Vi+Os+IuPUlJkLC5ZGTb?= =?us-ascii?Q?z0satIiauATvGAP3kvP5sYOz1VkH6U6OhcSZVdhEoJ/0GqHhvlddgJMpkF6F?= =?us-ascii?Q?noCu2w3/sl3WSRvtGM6VAZ6Cj8+jxUqxdJ+hx18PM0XHTySR5KpZDuyOR1Uy?= =?us-ascii?Q?79BO4PtTVdz3Litw20bPCXDLq4wYck1z22H3H5A7uMSywdImYHzVzIcZMThK?= =?us-ascii?Q?g77tW8lth1zt77pG7JClPbDe01Kcckf9ADGwBRU7ioB6zdsmDMtQzfQ9Ql/r?= =?us-ascii?Q?hO8f6ANlvxen9V+ixBbMHEyoKVnmw1EdTdyHiJrB70UYOoD2FtoEY26n/Hsq?= =?us-ascii?Q?e8UL+WIOvcZWC3AgnDN1nmpsKTN/twgZuJYgg5FA0kZA026bJBX6CCUu/J+W?= =?us-ascii?Q?hhRdYkoBeCVH4HbhNDL7AoyoKMGxItPDRtIFDASgcMOMYu+ITFLa5mnefD2b?= =?us-ascii?Q?u7kJY6b3NIC35UqYxuItarxxzj7lDnsYpzEDHGHKe1ko+PiGkdfMI8EHseMK?= =?us-ascii?Q?E/9qwkaIOFhNAxaPAf3Wg2tvajwFs5anYQWR1QCEvuMaVJn50bjsapegtGzG?= =?us-ascii?Q?sbDLHGh89ZlNG9tZ6QfrXY+0PAOX4QTtP8hCrYsWZvG6C8mE2cWCNFFUgf/g?= =?us-ascii?Q?UV0OIANdqfSikVMYWASUy+nUcaDy7Zz0ZDC1y9VmSoXeWNhwO3PxqQh/JdSN?= =?us-ascii?Q?y5PIlj3ypp5NT4rieKNMXrWdXVt/pqp31QwWz/LSXvQrA6SN4aPrveHEGlxj?= =?us-ascii?Q?SUwkSkEbVL90UixrErm8ATdpC6z/xyP3DZuMTUhNmtZoaOsOrFZXCVcRoyLJ?= =?us-ascii?Q?PZWUZG2p7nobWgR/NwvpsjpAy/Y8k+x4B1kg/ILY9L38PT4Vl2jvhMJ0r+Cv?= =?us-ascii?Q?fY8fuK3zpLTV5w4kMBM7ImqnCool4cxKMQvFWzuXvDPp77H4NvtVMzlfe/aG?= =?us-ascii?Q?uHoL6KMfMjimT8Wj6VPzpz5kxENGqFJ8+fqAgGCwz6tBVseAs50rJVLC9CqG?= =?us-ascii?Q?F96cX9oyXJVeFli61KXe+adTQfGgs41YWpl5x6ygLCn3pllVhv69z5mzm0sa?= =?us-ascii?Q?8oW3dT0aCSD1sBhHUrYdAiNIsPgmeKDVrMytFIba1tD6LHLFHH6+rp3Gw1Uo?= =?us-ascii?Q?byWMwE0O7w6YGNeog5+BOkqGkSvs7D+B0mnyogzZ0vVNMnVOX6y/k0QrM5ta?= =?us-ascii?Q?uzHrcJsmuW8hxOhQilT9JkjYymTKU6+ySr6QGjZqVhZ5bAmMe/VQB/YaVc+S?= =?us-ascii?Q?XGvV2nrahTArln7sllscPj/JGE4ZB4nNKbvbvH3Ge/bqBc7RzNs7Po+b7P7T?= =?us-ascii?Q?teQQE2rRma2rJm6OtC1bvhc+yZ6p5Oa5oc1LpIv10jiShDh81wxmm/WSK3mi?= =?us-ascii?Q?LDvU2OxyWC4/j5T5JSXpQUeKFmp3TNygdtQ/uDrTNxMQxb4nf//BUwjZNisg?= =?us-ascii?Q?IV2twOheqgtXbw0dB1AnBKiRVcUcnY4z+/VtZinAdOWt3a/q4SlgCIyMmmYR?= =?us-ascii?Q?ZJQ4Qdqnd17gBU2TnzSxtOGKh/TD11WnUimjpR8zk3JF8MJUJy/mxyrG+Q?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(7416014)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:37.6518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6428e093-cebf-489a-182d-08ddaabe2fb8 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9121 Content-Type: text/plain; charset="utf-8" The cache allocation and memory bandwidth allocation feature properties are consolidated into struct resctrl_cache and struct resctrl_membw respectively. In preparation for more monitoring properties that will clobber the existing resource struct more, re-organize the monitoring specific properties to also be in a separate structure. Suggested-by: Reinette Chatre Signed-off-by: Babu Moger --- v14: Updated the code comment in resctrl.h. v13: Changes due to FS/ARCH restructure. v12: Fixed the conflicts due to recent changes in rdt_resource data structu= re. Added new mbm_cfg_mask field to resctrl_mon. Removed Reviewed-by tag as patch has changed. v11: No changes. v10: No changes. v9: No changes. v8: Added Reviewed-by from Reinette. No other changes. v7: Added kernel doc for data structure. Minor text update. v6: Update commit message and update kernel doc for rdt_resource. v5: Commit message update. Also changes related to data structure updates does to SNC support. v4: New patch. --- arch/x86/kernel/cpu/resctrl/core.c | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 10 +++++----- fs/resctrl/rdtgroup.c | 6 +++--- include/linux/resctrl.h | 18 +++++++++++++----- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 6426b92492dc..22a414802cbb 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -107,7 +107,7 @@ u32 resctrl_arch_system_num_rmid_idx(void) struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; =20 /* RMID are independent numbers for x86. num_rmid_idx =3D=3D num_rmid */ - return r->num_rmid; + return r->mon.num_rmid; } =20 struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) @@ -539,7 +539,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) =20 arch_mon_domain_online(r, d); =20 - if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { + if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) { mon_domain_free(hw_dom); return; } diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 0add57b29a4d..42a9e3cc6654 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -130,7 +130,7 @@ static int logical_rmid_to_physical_rmid(int cpu, int l= rmid) if (snc_nodes_per_l3_cache =3D=3D 1) return lrmid; =20 - return lrmid + (cpu_to_node(cpu) % snc_nodes_per_l3_cache) * r->num_rmid; + return lrmid + (cpu_to_node(cpu) % snc_nodes_per_l3_cache) * r->mon.num_r= mid; } =20 static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 = *val) @@ -205,7 +205,7 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r= , struct rdt_mon_domain * continue; idx =3D MBM_STATE_IDX(eventid); memset(hw_dom->arch_mbm_states[idx], 0, - sizeof(struct arch_mbm_state) * r->num_rmid); + sizeof(struct arch_mbm_state) * r->mon.num_rmid); } } =20 @@ -344,7 +344,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) =20 resctrl_rmid_realloc_limit =3D boot_cpu_data.x86_cache_size * 1024; hw_res->mon_scale =3D boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l= 3_cache; - r->num_rmid =3D (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3= _cache; + r->mon.num_rmid =3D (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_pe= r_l3_cache; hw_res->mbm_width =3D MBM_CNTR_WIDTH_BASE; =20 if (mbm_offset > 0 && mbm_offset <=3D MBM_CNTR_WIDTH_OFFSET_MAX) @@ -359,7 +359,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) * * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC. */ - threshold =3D resctrl_rmid_realloc_limit / r->num_rmid; + threshold =3D resctrl_rmid_realloc_limit / r->mon.num_rmid; =20 /* * Because num_rmid may not be a power of two, round the value @@ -373,7 +373,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) =20 /* Detect list of bandwidth sources that can be tracked */ cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx); - r->mbm_cfg_mask =3D ecx & MAX_EVT_CONFIG_BITS; + r->mon.mbm_cfg_mask =3D ecx & MAX_EVT_CONFIG_BITS; } =20 r->mon_capable =3D true; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index bd6718f0ffd6..5874cfdf8d8d 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1135,7 +1135,7 @@ static int rdt_num_rmids_show(struct kernfs_open_file= *of, { struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); =20 - seq_printf(seq, "%d\n", r->num_rmid); + seq_printf(seq, "%d\n", r->mon.num_rmid); =20 return 0; } @@ -1731,9 +1731,9 @@ static int mon_config_write(struct rdt_resource *r, c= har *tok, u32 evtid) } =20 /* Value from user cannot be more than the supported set of events */ - if ((val & r->mbm_cfg_mask) !=3D val) { + if ((val & r->mon.mbm_cfg_mask) !=3D val) { rdt_last_cmd_printf("Invalid event configuration: max valid mask is 0x%0= 2x\n", - r->mbm_cfg_mask); + r->mon.mbm_cfg_mask); return -EINVAL; } =20 diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index bbe57eff962b..22766b8b670b 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -255,38 +255,46 @@ enum resctrl_schema_fmt { RESCTRL_SCHEMA_RANGE, }; =20 +/** + * struct resctrl_mon - Monitoring related data of a resctrl resource. + * @num_rmid: Number of RMIDs available. + * @mbm_cfg_mask: Memory transactions that can be tracked when bandwidth + * monitoring events are configured. + */ +struct resctrl_mon { + int num_rmid; + unsigned int mbm_cfg_mask; +}; + /** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine - * @num_rmid: Number of RMIDs available * @ctrl_scope: Scope of this resource for control functions * @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. + * @mon: Monitoring related data. * @ctrl_domains: RCU list of all control domains for this resource * @mon_domains: RCU list of all monitor domains for this resource * @name: Name to use in "schemata" file. * @schema_fmt: Which format string and parser is used for this schema. - * @mbm_cfg_mask: Bandwidth sources that can be tracked when bandwidth - * monitoring events can be configured. * @cdp_capable: Is the CDP feature available on this resource */ struct rdt_resource { int rid; bool alloc_capable; bool mon_capable; - int num_rmid; enum resctrl_scope ctrl_scope; enum resctrl_scope mon_scope; struct resctrl_cache cache; struct resctrl_membw membw; + struct resctrl_mon mon; struct list_head ctrl_domains; struct list_head mon_domains; char *name; enum resctrl_schema_fmt schema_fmt; - unsigned int mbm_cfg_mask; bool cdp_capable; }; =20 --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2045.outbound.protection.outlook.com [40.107.95.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F9E92737F2; Fri, 13 Jun 2025 21:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848812; cv=fail; b=nZAFAfth3st+nWhonXQr+yKxU/MEzGC/IX+7MTH0JK1LyxQFVX1BLm62tU5kSbIHCJBxMKvLX5vHvuDmaKEJsFAtTm+NmcxENv2IHu1Np9GP28VyzAbet7RBUniZIUGFGS5mvrlRhJ00z29VUFjqzKZG2DrWEbxN/2/HUztF74I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848812; c=relaxed/simple; bh=EdU0bJ/lB/x9FnR0AhjnmPoHEoszK4q9Iwc/qfObI7U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZPVPfVlI4zT9r6oC0lQEOhFNIBkOBaAR/utWi8eZEl/VEbxJChW/j6P557auszPqzXniAVFCAHxHqNcVW7G7thGIhegY+Wm38KoMvrIj4IW1HH8h5tCXhuQ9BEhh3PAUP1Jju2ZoTIe0Q03fM2YoV0bRgf9jZr/8bglEOmHPGZ4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=X090SMTq; arc=fail smtp.client-ip=40.107.95.45 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) header.d=amd.com header.i=@amd.com header.b="X090SMTq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hNAiXj2YyWHrzGs7idDMoUjY0qg7436yZ15MZuy+amtVwnLPHrIYaSSQeqtRTQuOIY6yeOStXRh1sQ+k2hXD91F6XYmOEQdXyjfuffD/cNvLIGLbm0zEKe0akCSZOKa2n3OjdyBiIIPIJQ5CM3Rz/1lpvYKCU+AhDUinqYtsh9CxQsQfcN5q157Z2LIwhRI2tNe4GCwfySQh+7afI3mAETaJtAa+KfApROL+uN5oStrZxUYfzrrFuP9dJ8Ao5GR0Ey8DtUzwOPvNZdDQ+E/MuhqlzUDBC2AwO9SUaaJBZT6L5wyyFLEjU0TMb5uDM5lk+gRcTvJXOdW6TXzXlijm5Q== 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=EzVQxq23P9wIjz/W/+k93+GWu4bkuPjW5Hf7VbkPw6k=; b=AF4uMQt+M/MGgCxFySbhiWdtlNJWxAEv2CO7zVAyZJGjeFq89II4ji0ZqyieDnNyYiiF5P3PedEWjsiEmq6gXuFw0c0TzoMuLgVGFW7U8oI2gHkowSH94MAFMC+uvoUnxSPi5B2ZMtbCVF4TD3OUDYuJdp38b2AaBfcc+RJyBUgLnlVaHfOvFZ3SSp/UWE9kw+sin8NZc2UcXflRoiHQfxCbwVceV3rgfd9xus8IiBVDD/OfRffoR6t3A4nJ0Nmz2r1410mBWwG+vSaPjpa/gT/v2z4wlRb+2JENSQciRbzr+8REzoU6WOL5UVqdRTB4JMG/c0dUH7SGkTg6V+Q0fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=EzVQxq23P9wIjz/W/+k93+GWu4bkuPjW5Hf7VbkPw6k=; b=X090SMTq4pwh1IMIzkQGaN7pb81p6OQ6araJrFckvd0XDqVVtGpn1AqV+IhmL2l5G6dubX9JkYqMqHWdxf9Psz09wBAKT+GlJIdUZpZVrPePHuqkaFvdkzpzgyc5ZDIinka/XrMD9zGyDNMB1MZ5YAN1sK5s7oDIP6E7RNeFs+g= Received: from DM6PR05CA0046.namprd05.prod.outlook.com (2603:10b6:5:335::15) by MW6PR12MB7085.namprd12.prod.outlook.com (2603:10b6:303:238::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:06:45 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335:cafe::85) by DM6PR05CA0046.outlook.office365.com (2603:10b6:5:335::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:06:44 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:44 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:42 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 09/32] x86/resctrl: Detect Assignable Bandwidth Monitoring feature details Date: Fri, 13 Jun 2025 16:04:53 -0500 Message-ID: <31b14155abb7a66aace3dabfa4cc481bfd9e6647.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|MW6PR12MB7085:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a6c2c03-be90-443b-26f1-08ddaabe33f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|7416014|1800799024|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?k+1p00FQCkzB3IEero05aVaxnOva1FjbpJPPa/TY+4QmE6bphyycbnGV/+N3?= =?us-ascii?Q?kYXiSf0p/xXMyohQbX8rPXObGIezqdwcbeVRvBxTnYpRWlcayaRz/ar2P17c?= =?us-ascii?Q?GdT+sKM143Av81ZKIkb6Eaf5DqB6OtdXn7Qko1xrfRwOHTRfqKtl1LkgiOk5?= =?us-ascii?Q?bUNA0A3p0xTGb9xwg3+Q2qK13CxBoCBGyWoaFBlRasz3ddDJzSvDG+690+zv?= =?us-ascii?Q?eaHQVRgl6c6OL+qhuQE9AHpMu1VNFFbucztj7ixJSfyk7C0dL4gdEiDB0swk?= =?us-ascii?Q?9UxnK9lJeNUSzArxVpjOyyhjziryeuWU1sI4o6ONr/qOH8R5/OVHYXB4aQIs?= =?us-ascii?Q?LJnNON4PHVeUzip4JQs/PSaA4L+88qbGpLPmW7uoBvkFv9QqrszfU1oaeqey?= =?us-ascii?Q?liFip+NS32vpDWydhaiYFkuS9iYQIbvdUz4VkAL4kymwV92WBcBX+TnuEtDq?= =?us-ascii?Q?T6o1RZMD+UD9a/FJKcG8+VfIaGFts13KaqiEr8hHavV8SHpmKAby9oyIwPdB?= =?us-ascii?Q?ndVuvexU9A2WWo75D41aooqyOWP8UKjm4A4CY1VFGZ7b/eEMJYUuoYEjcfJx?= =?us-ascii?Q?AHwFfqhBX7bUZ4KDvSgvsw5n2a/uc1hyteir7+fZlB0AO/Ven5NLXTJipZLr?= =?us-ascii?Q?huq4U5EXqb9ZtqHi/6cgivYIpE4aRqE1FzUxcNKLKpfsa5haJawKzZ0cuSVy?= =?us-ascii?Q?OcPwM6bP4YQPdRzdzBPl0lxuYoALO4y/DT2nlckacIW3LAy6cLQG2MpZGJ2K?= =?us-ascii?Q?cJG0yFT4kBXrKWyNPphOdBpVPC1oATGBMHXu3AqqL35dIL5wz0tqLxNngu0m?= =?us-ascii?Q?Mxy8fe8+qRrzKbmxV2unxndVlC2wP/l/lBn1L7Fh0nYrvuOHxI9J9uwgPfKz?= =?us-ascii?Q?+fir0Jum/pYGnkUWRhSYTPsQTtogvaKFRKhBMXfJfs63h9EoxRX1gEi6IuOT?= =?us-ascii?Q?MYMd/Y6BHgPU8Ae05Jsk1ObKWiu6144pZEMFcfZXCIr1r+heCeCWRZ43aCAk?= =?us-ascii?Q?8cPG8TgdTjzIndYnsjpDyeV8vorn8U86t61Ar3BuRqlEjCFYJmTqYvMRNyB7?= =?us-ascii?Q?IfqwI11MnEDr5ax35YRzvrLjChjokd2aW+c8JJYyzcFcS926hL5R6si5ulSf?= =?us-ascii?Q?wUKxR9zS4M/mDt8GrM7FOaPGTDZrEp7oGjhtKj0u3AUDf5n0CHG64xjGOZXB?= =?us-ascii?Q?mBWYxBK2Q0kQ1gJvAYvuNRgPum2rMs3Es/5Ha4Ux/ZVG8cjkQb3doBV1Eawr?= =?us-ascii?Q?PIDUJpgy0j3r2e8FRF9vEwPOYTvJpQn6N3GH8bumJQwDGN5SuWCv9DLmf+iz?= =?us-ascii?Q?il3wlMxphpAgHy8viltV/7NIxrOZjDECtKuVGD/lJGuDOrYwuzN1Ohv7uoRA?= =?us-ascii?Q?DcDWR2ol8ZmTfDty+2460cpUoaIfLsrk6kBXKPl3b/OaVzGQ2xVYJaA8hbWc?= =?us-ascii?Q?JeSTQFkCxGSIwoPCGDtpK9Sk68IRolrRSp90TQvJSRzGpTVSasxCeQCTW6Hk?= =?us-ascii?Q?nTtORZXmY1YJoBhxm40+EZpgQuAwHC5K7SFLW60tufJ5zgScUtN2511KsQ?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700013)(7416014)(1800799024)(921020)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:44.7515 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a6c2c03-be90-443b-26f1-08ddaabe33f3 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB7085 Content-Type: text/plain; charset="utf-8" ABMC feature details are reported via CPUID Fn8000_0020_EBX_x5. Bits Description 15:0 MAX_ABMC Maximum Supported Assignable Bandwidth Monitoring Counter ID + 1 The feature details are documented in APM listed below [1]. [1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). Detect the feature and number of assignable counters supported. Also, enable QOS_L3_MBM_TOTAL_EVENT_ID and QOS_L3_MBM_LOCAL_EVENT_ID upon detecting the ABMC feature. The current expectation is to support these two events by default when ABMC is enabled. Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger --- v14: Updated enumeration to support ABMC regardless of MBM total and local = support. Updated the changelog accordingly. v13: No changes. v12: Resolved conflicts because of latest merge. Removed Reviewed-by as the patch has changed. v11: No changes. v10: No changes. v9: Added Reviewed-by tag. No code changes v8: Used GENMASK for the mask. v7: Removed WARN_ON for num_mbm_cntrs. Decided to dynamically allocate the bitmap. WARN_ON is not required anymore. Removed redundant comments. v6: Commit message update. Renamed abmc_capable to mbm_cntr_assignable. v5: Name change num_cntrs to num_mbm_cntrs. Moved abmc_capable to resctrl_mon. v4: Removed resctrl_arch_has_abmc(). Added all the code inline. We dont need to separate this as arch code. v3: Removed changes related to mon_features. Moved rdt_cpu_has to core.c and added new function resctrl_arch_has_abm= c. Also moved the fields mbm_assign_capable and mbm_assign_cntrs to rdt_resource. (James) v2: Changed the field name to mbm_assign_capable from abmc_capable. --- arch/x86/kernel/cpu/resctrl/core.c | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 11 ++++++++--- include/linux/resctrl.h | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 22a414802cbb..01b210febc7d 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -873,11 +873,11 @@ static __init bool get_rdt_mon_resources(void) resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID); ret =3D true; } - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) || rdt_cpu_has(X86_FEATURE_ABM= C)) { resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID); ret =3D true; } - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL) || rdt_cpu_has(X86_FEATURE_ABM= C)) { resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID); ret =3D true; } diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 42a9e3cc6654..a6b9a6ba036d 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -339,6 +339,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) unsigned int mbm_offset =3D boot_cpu_data.x86_cache_mbm_width_offset; struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); unsigned int threshold; + u32 eax, ebx, ecx, edx; =20 snc_nodes_per_l3_cache =3D snc_get_config(); =20 @@ -368,14 +369,18 @@ int __init rdt_get_mon_l3_config(struct rdt_resource = *r) */ resctrl_rmid_realloc_threshold =3D resctrl_arch_round_mon_val(threshold); =20 - if (rdt_cpu_has(X86_FEATURE_BMEC)) { - u32 eax, ebx, ecx, edx; - + if (rdt_cpu_has(X86_FEATURE_BMEC) || rdt_cpu_has(X86_FEATURE_ABMC)) { /* Detect list of bandwidth sources that can be tracked */ cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx); r->mon.mbm_cfg_mask =3D ecx & MAX_EVT_CONFIG_BITS; } =20 + if (rdt_cpu_has(X86_FEATURE_ABMC)) { + r->mon.mbm_cntr_assignable =3D true; + cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx); + r->mon.num_mbm_cntrs =3D (ebx & GENMASK(15, 0)) + 1; + } + r->mon_capable =3D true; =20 return 0; diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 22766b8b670b..c0195498bd4a 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -260,10 +260,14 @@ enum resctrl_schema_fmt { * @num_rmid: Number of RMIDs available. * @mbm_cfg_mask: Memory transactions that can be tracked when bandwidth * monitoring events are configured. + * @num_mbm_cntrs: Number of assignable counters. + * @mbm_cntr_assignable:Is system capable of supporting counter assignment? */ struct resctrl_mon { int num_rmid; unsigned int mbm_cfg_mask; + int num_mbm_cntrs; + bool mbm_cntr_assignable; }; =20 /** --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2051.outbound.protection.outlook.com [40.107.237.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78D92272E59; Fri, 13 Jun 2025 21:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848817; cv=fail; b=IgorZf+mBheT9Q6tlSjDQvcuGS+sR2gy2BzUmhgBNQOtnfvEXRJaNOFOxUMoIUrAMImabKfVoW/3CqedIrVU8+faPrL1U9CYGrn2AFXykGMfeXcsFvSHodbZhKRcukWWiB2zDgFA2qLsz485pNmc5gzLYVgobUQTyTOfSocCi7c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848817; c=relaxed/simple; bh=Afskno8kyqo7YjoacOlGg0iuMaUlXY392WHzBmCVz08=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e2yg/9UDqvyvW9z2vFU/diM+JhbgMzyw8u/0Fd2X4dTuR2vUzBNTiHNB/szjLJEF/w5gOwwZnEFavks9azgWEzYt40UmJfHt9MmIFt77PgZhD6Vd6M0F9MSgcXxPLy7HuOthhix3xsYx/DFEw3gMBBbxkoLutJZkTSy2gjYqln4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=MmjyAOVn; arc=fail smtp.client-ip=40.107.237.51 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) header.d=amd.com header.i=@amd.com header.b="MmjyAOVn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LRYM29VFC+wSY/gnG7hGuTq/zeDg92j1Oi2GWz5oOO5FZwvbyGq6cqmFyCqnKQg3ynhC2gzFU/5BTFh3+F5WSvRtU1r2VbtfMRY1XoMvbLXfTtA6u3b/aa583Wy/kw6gA5XNAaKkENNWkQ+NxweDbV0jODwTlrwGnMim7pZ3YdnufooATwTzqmEuZ81Bkz0tDyHFjPcaQWFnkWZbcA584lTvGIDtfOD2kipqqJgJwS+nYqyEs9UOpvQJvLGKMok+EgAvgrVH1WtASkq48s75qMc1peGGG8LYwKXKOLJaOPnUm7nWkY1AqfCOCnTVNZKQhsOtQMbuUsU80kmobC1huQ== 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=emLHUt62lYytrDS2iZ1Hwe0iL5DvcadKNCWKViJbAn8=; b=joDhqo2IKlgnh2+TJsCYv69PmdUdZmVrzlB9a7tcEVRN5mbOzTFPk3n363oGexyJjZeo9KX8D+CSEhgAoBoaa1iSQptZOMCIivGAhz+L55as5KxWFfDzwULPcY9A8K+AZZ8mfaZmhweBdQeNeNpnJrSQ90BDtpcOX3AzvWS2iDCEAFUFYpixxyHTaRwlJ4jhTmLk7sE/KENjn/ol/+Rrudcq2kwttwr2LG0xXzbIxL1JsTGgFFihfw/V1AZOuYd+Ddl+ORSsw2Iz4TwBOyT/klLGOwxow4j0/lin16fRUQXj4J3sC58KU6c1fUqNC+C59FcZdiMp7eN9c3E6MAg9og== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=emLHUt62lYytrDS2iZ1Hwe0iL5DvcadKNCWKViJbAn8=; b=MmjyAOVn9Dd1inkXJTfzN9HSS+tLB6l9dtq/yAhfswZ7HubaP5etnTLNvPvdIYBc8H69XldZ5OhDhAJP6GvwBQeHlO0p2nYxf9wz3aDUqeF7njEyHTfSus5HzhvBp2QYBSa/M8BR2pKT28G5RC0f/ltqxi7DgQbj8dSopioLVB4= Received: from BY5PR17CA0031.namprd17.prod.outlook.com (2603:10b6:a03:1b8::44) by CY3PR12MB9553.namprd12.prod.outlook.com (2603:10b6:930:109::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.18; Fri, 13 Jun 2025 21:06:52 +0000 Received: from CY4PEPF0000EDD6.namprd03.prod.outlook.com (2603:10b6:a03:1b8:cafe::4c) by BY5PR17CA0031.outlook.office365.com (2603:10b6:a03:1b8::44) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Fri, 13 Jun 2025 21:06:52 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD6.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:06:52 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:50 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 10/32] x86/resctrl: Add support to enable/disable AMD ABMC feature Date: Fri, 13 Jun 2025 16:04:54 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD6:EE_|CY3PR12MB9553:EE_ X-MS-Office365-Filtering-Correlation-Id: ac63a099-3b7c-4fbc-8124-08ddaabe389f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WC4vddLW3PoF5hoIFtx4VhPFVYTmymibb7eXsNioBfGLpHjT0HCxWW0o7v3G?= =?us-ascii?Q?1Es9MovlJxhFSaZIzCm4O7g1I1UHeAkGNB+BPdHQM5V4csdqjkzbjB0s5PlJ?= =?us-ascii?Q?7MJu9aZbsE3YE1d0QNwQ1dcxBUd23hVwWH2WdWL3ktxHVyBO7NUj2yUyh0kt?= =?us-ascii?Q?7o5S49qWT71O1uKQuARQQuD3jCQV3Jgz8uTh0SwPw9JAhTsWWPNQjYwglr9W?= =?us-ascii?Q?vFMehfzNuk6lCuk9yUdIRCl7UZvhDiHQWP/WAgxisbRsiri2gtwYpH8dPNJx?= =?us-ascii?Q?sGM0e/tL8hd32WNZ2/ZqbflvydSbiY3y8A/ZaCxu1qdg7tmxcySCrOMzmKt/?= =?us-ascii?Q?Zqi2DSct28cFbkeAq4dmmXx7pw11vBIqke6MkZT7y9sFdEQcO+5gFX30Mf7B?= =?us-ascii?Q?ZQtfK50GskPmfWTsFyy+pn9dP6nrh1z79/otOSssdqAk2IGBF0tFaJYNZV+I?= =?us-ascii?Q?kDiGc+cMmQl+lF7BeeNw+G7zlcJY3B/OmyGUlqDeiiWq0bFeO9kbtUvLGrE/?= =?us-ascii?Q?n+45BBPJMQJ9ZgT5yds7xCcGEOs5DKLNXnl2yOkUCs5Eh8d5KdLUgMDc0m5D?= =?us-ascii?Q?9sdqmSwxMTLu/0yKpuw0LJg5nYt6H9aLQWxXUgr3A1JtLk5Wjb6XCOxmwkPJ?= =?us-ascii?Q?yKEuSU30XezFUIA477z0ZN7DaRhA91QOQCX9RTA+FfMyExIUNJlb6EbJXIW0?= =?us-ascii?Q?pkbm37vLqNFTF4MB2SavTt6T9c81r4o/GikaqRvLcxjkS++Ty/9nFggDS1yk?= =?us-ascii?Q?9YxRxk+Fv2JPrY7xRKAzXb2FAf8F8mCkG/qevVbigcEBDkFL9qy/mAca8m2O?= =?us-ascii?Q?JgpM+USIe/a9Zo4YB3MUd5i9e+xEGwTCS3mynOx8RnATVzFaeDf5Was6s73O?= =?us-ascii?Q?2cvCLJowR9QjGbqJop3BWisoZG/1YuA005iEIwalk+OF4G+5Q7MXbdwyvnuR?= =?us-ascii?Q?mOxs/kztBKU8FBcMM7m5S/q+BecFydgP4CxavkbFkoGRE8cXvKl8YbguNfIl?= =?us-ascii?Q?MOl26sXZElL873d01XQzP8lzVwvHFsHfzyyKqs4+CiaUxrG94G5zsJhJLQGV?= =?us-ascii?Q?EZfgNysqOl5AADHs6y4jNhdKSaWxLCNNADzGd2ZdiUljt3Zl7GL6eCaD/NqU?= =?us-ascii?Q?LoCtOyJOFHrg4RGTCQxKK6ygyR91uSw94+JtKLAx3oNn6dCQWQdAGR0RD16T?= =?us-ascii?Q?Hrk/JVyrBXUa38fYBYsvR+8tCutpVGkOzLlrXv7lM11qln2XAypQY1ZlnCAr?= =?us-ascii?Q?871s80Xv18DcQjlrXNibo5nW3Fr5CenDZKXhtyqYOOa1H8to9jT6dGynjdjv?= =?us-ascii?Q?Tb3gEgeSalOq4zU4rl4xUv4Y1RNtvG2Ej0hXKcMFcovJ/U28GTfkMb7faw4C?= =?us-ascii?Q?tn+piL3+2bPPx7msZLmdYj9BLOqAWHV90v1siKBCMUxqsB6Txsk3s/t5z4nS?= =?us-ascii?Q?sV/uhR77RzH8sQ4Q2U9+CusK+vziM1cHChl71sFVsfOVBqOaFHUMuorwJsZx?= =?us-ascii?Q?YcWa1QqkwyAbGLX3Z6RuZ1K4/hTZHRh0C8MIyMhLJyWLay+/pAaApwQNoQ?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:06:52.5927 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac63a099-3b7c-4fbc-8124-08ddaabe389f 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY3PR12MB9553 Content-Type: text/plain; charset="utf-8" Add the functionality to enable/disable AMD ABMC feature. AMD ABMC feature is enabled by setting enabled bit(0) in MSR L3_QOS_EXT_CFG. When the state of ABMC is changed, the MSR needs to be updated on all the logical processors in the QOS Domain. Hardware counters will reset when ABMC state is changed. The ABMC feature details are documented in APM listed below [1]. [1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger --- v14: Added lockdep_assert_cpus_held() in _resctrl_abmc_enable(). Removed inline for resctrl_arch_mbm_cntr_assign_enabled(). Added prototype descriptions for resctrl_arch_mbm_cntr_assign_enabled() and resctrl_arch_mbm_cntr_assign_set() in include/linux/resctrl.h. v13: Resolved minor conflicts with recent FS/ARCH restructure. v12: Clarified the comment on _resctrl_abmc_enable(). Added the code to reset arch state in _resctrl_abmc_enable(). Resolved the conflicts with latest merge. v11: Moved the monitoring related calls to monitor.c file. Moved the changes from include/linux/resctrl.h to arch/x86/kernel/cpu/resctrl/internal.h. Removed the Reviewed-by tag as patch changed. Actual code did not change. v10: No changes. v9: Re-ordered the MSR and added Reviewed-by tag. v8: Commit message update and moved around the comments about L3_QOS_EXT_CFG to _resctrl_abmc_enable. v7: Renamed the function resctrl_arch_get_abmc_enabled() to resctrl_arch_mbm_cntr_assign_enabled= (). Merged resctrl_arch_mbm_cntr_assign_disable, resctrl_arch_mbm_cntr_assi= gn_disable and renamed to resctrl_arch_mbm_cntr_assign_set(). Moved the function definition to linux/resctrl.h. Passed the struct rdt_resource to these functions. Removed resctrl_arch_reset_rmid_all() from arch code. This will be done from the caller. v6: Renamed abmc_enabled to mbm_cntr_assign_enabled. Used msr_set_bit and msr_clear_bit for msr updates. Renamed resctrl_arch_abmc_enable() to resctrl_arch_mbm_cntr_assign_enab= le(). Renamed resctrl_arch_abmc_disable() to resctrl_arch_mbm_cntr_assign_dis= able(). Made _resctrl_abmc_enable to return void. v5: Renamed resctrl_abmc_enable to resctrl_arch_abmc_enable. Renamed resctrl_abmc_disable to resctrl_arch_abmc_disable. Introduced resctrl_arch_get_abmc_enabled to get abmc state from non-arch code. Renamed resctrl_abmc_set_all to _resctrl_abmc_enable(). Modified commit log to make it clear about AMD ABMC feature. v3: No changes. v2: Few text changes in commit message. --- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 5 +++ arch/x86/kernel/cpu/resctrl/monitor.c | 45 ++++++++++++++++++++++++++ include/linux/resctrl.h | 20 ++++++++++++ 4 files changed, 71 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index b7dded3c8113..b92b04fa9888 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1215,6 +1215,7 @@ /* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200 #define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_L3_QOS_EXT_CFG 0xc00003ff #define MSR_IA32_EVT_CFG_BASE 0xc0000400 =20 /* AMD-V MSRs */ diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 44ef0d94131e..1a4e96044aac 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -37,6 +37,9 @@ struct arch_mbm_state { u64 prev_msr; }; =20 +/* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */ +#define ABMC_ENABLE_BIT 0 + /** * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs th= at share * a resource for a control function @@ -103,6 +106,7 @@ struct msr_param { * @mon_scale: cqm counter * mon_scale =3D occupancy in bytes * @mbm_width: Monitor width, to detect and correct for overflow. * @cdp_enabled: CDP state of this resource + * @mbm_cntr_assign_enabled: ABMC feature is enabled * * Members of this structure are either private to the architecture * e.g. mbm_width, or accessed via helpers that provide abstraction. e.g. @@ -116,6 +120,7 @@ struct rdt_hw_resource { unsigned int mon_scale; unsigned int mbm_width; bool cdp_enabled; + bool mbm_cntr_assign_enabled; }; =20 static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resou= rce *r) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index a6b9a6ba036d..0ad9c731c13e 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -399,3 +399,48 @@ void __init intel_rdt_mbm_apply_quirk(void) mbm_cf_rmidthreshold =3D mbm_cf_table[cf_index].rmidthreshold; mbm_cf =3D mbm_cf_table[cf_index].cf; } + +static void resctrl_abmc_set_one_amd(void *arg) +{ + bool *enable =3D arg; + + if (*enable) + msr_set_bit(MSR_IA32_L3_QOS_EXT_CFG, ABMC_ENABLE_BIT); + else + msr_clear_bit(MSR_IA32_L3_QOS_EXT_CFG, ABMC_ENABLE_BIT); +} + +/* + * ABMC enable/disable requires update of L3_QOS_EXT_CFG MSR on all the CP= Us + * associated with all monitor domains. + */ +static void _resctrl_abmc_enable(struct rdt_resource *r, bool enable) +{ + struct rdt_mon_domain *d; + + lockdep_assert_cpus_held(); + + list_for_each_entry(d, &r->mon_domains, hdr.list) { + on_each_cpu_mask(&d->hdr.cpu_mask, resctrl_abmc_set_one_amd, + &enable, 1); + resctrl_arch_reset_rmid_all(r, d); + } +} + +int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) +{ + struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); + + if (r->mon.mbm_cntr_assignable && + hw_res->mbm_cntr_assign_enabled !=3D enable) { + _resctrl_abmc_enable(r, enable); + hw_res->mbm_cntr_assign_enabled =3D enable; + } + + return 0; +} + +bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r) +{ + return resctrl_to_arch_res(r)->mbm_cntr_assign_enabled; +} diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index c0195498bd4a..f078ef24a8ad 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -440,6 +440,26 @@ static inline u32 resctrl_get_config_index(u32 closid, bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l); int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable); =20 +/** + * resctrl_arch_mbm_cntr_assign_enabled() - Check if MBM counter assignment + * mode is enabled. + * @r: Pointer to the resource structure. + * + * Return: + * true if the assignment mode is enabled, false otherwise. + */ +bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r); + +/** + * resctrl_arch_mbm_cntr_assign_set() - Configure the MBM counter assignme= nt mode. + * @r: Pointer to the resource structure. + * @enable: Set to true to enable, false to disable the assignment mode. + * + * Return: + * 0 on success, non-zero on failure. + */ +int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable); + /* * Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060.outbound.protection.outlook.com [40.107.223.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAE46272E43; Fri, 13 Jun 2025 21:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848827; cv=fail; b=mdmMIV6klvc65IqGcTbDqw2oo8GyIRa9/BsmnnsWTOVG29w16LWa40QBVSIVLF00K9giXpuUD77dpKEyF46y3/+IAiz883WtzRgLlgTm5PuKNS1lSPS6n/u194seIKZfJ++whhVEzpNCIOOHZInkhSmFaq46J0RDm6B6LpOczM4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848827; c=relaxed/simple; bh=zaDuNVaUsH+fg6W8NzZai8/383Q47wJwQs2G9WqHG8g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eqCwkMiBrv7MMO8WQSUbGH7CH/vB44zm645nWGma8foBphhSjGA/foNobREsKSGJ/OmwlFXjXLDrR1dLzTCZCHSl1Fup0+CMctDhwnodiWrj2d8hsHv5nvYSKLCFqv4Y+hmTb2giMW2wRnhuCc6EXbu/ZvPeeAAfUw1c98JlfJ4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AQ5C1lw+; arc=fail smtp.client-ip=40.107.223.60 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) header.d=amd.com header.i=@amd.com header.b="AQ5C1lw+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y5N8qob1xTkv4EfBIcFLtaCaUw1+Vhp7oud82vt7V2ypZUjMyOiNniAZMWef9kB7RyJBpxHJhZicIyEDmhnj/45d0YmsckPJkmes3k2Of0WXlDePeKidws5NTj4nsP9oJ9SQoFg/fnOUuc5KptHS/GL2L6DKUcC3aKIpzeyTg4GE8HOACswuBm6WuxVS7+9VVcIT93u5tgBrkjyuQxhiyIFryfljddOMJFstOTxmP58JvCGRN3J2QxxEBQ4Lup0aQ3Yl54JyHsafq0QhPEkM4kvzHMunZiNOGOeFuNS6owcppXKsCLErABLIHlM+TtHNpPecO/WuX4RRtMUWFb72Lw== 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=Pl4KGpDih1UlzVaqpyiP8pVDptgEp4syaGVNg51TqWs=; b=vzycuT4SUG4prWhquZWC94gAW/2b/U0akqt+jT7YbVGbbNY092pCFiJkEDaE9Y92PXiZBy4HxA7tr+v2t4eUIfbnFzHzv/MkEqt/MYv8NCM2b385e8HmwG0b8yl5REJjtbMw21FNJd01axJ23HpqkQXfLgitk0SrTgrDZ9GEMOagd8sShTVKFmKJ0o2TnwgqoHqnfKSyllBIpn8AMZ/X/GmHP1e1JHGY2MUoxkVlVCeoleLL4GiyNLjhtiWlR/tf/rC44ku/B7HOPqH9PR7rshG5itXN4QbTRTA8AkkbZXBa2+sspG3Fa+FIo1JLMiGFubzNMXCzk33HV5JNSUoAfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=Pl4KGpDih1UlzVaqpyiP8pVDptgEp4syaGVNg51TqWs=; b=AQ5C1lw+PnPeaosEnTwkaQC8sGjpJLGs1Vkh0Z/bDGIb+YcyBpMyY8CXFkaYBVwt5Ns8FxrOrR1r3eQ1Vrha6Gx2iQtEP5JnlZgmwN8aXT7ZhPORSJXXRwA92+/3DM76CkKTIHITSwfmb1V2RAAOnbN9OhtCF2/3dOGqMKdGXVA= Received: from SJ0PR03CA0023.namprd03.prod.outlook.com (2603:10b6:a03:33a::28) by DM3PR12MB9414.namprd12.prod.outlook.com (2603:10b6:0:47::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:07:02 +0000 Received: from CY4PEPF0000EDD2.namprd03.prod.outlook.com (2603:10b6:a03:33a:cafe::58) by SJ0PR03CA0023.outlook.office365.com (2603:10b6:a03:33a::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.29 via Frontend Transport; Fri, 13 Jun 2025 21:07:02 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD2.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:00 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:06:58 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 11/32] fs/resctrl: Introduce the interface to display monitoring modes Date: Fri, 13 Jun 2025 16:04:55 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD2:EE_|DM3PR12MB9414:EE_ X-MS-Office365-Filtering-Correlation-Id: 76491a61-6bcd-4275-85c5-08ddaabe3d5c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|7416014|376014|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?2J3RsmXH5yWFn+Ki5r0c1k8SbAd856TD15vYXFoqVZJQQ+gf68gfYNB2Iv/+?= =?us-ascii?Q?CoolgnsZKeNKFRV/qGzfGPG+hMvoQQsTjKbeE7NTf9cBQXR/Bf+iHKMwTbnT?= =?us-ascii?Q?WIWw/77lbUiVRmcgpfvpK67aDf6Fz+H3CGcHxklF0zp1VIulL7GQxNLuJWnj?= =?us-ascii?Q?s+Qw4aj87cMksOU+Mj6XoxFMR+pLTn85u0kbP7tQCHuYx+4PrYCqv9fARdIN?= =?us-ascii?Q?vATwArG8qI9Xo6Knhf7/HEq5FA0cCkL/aABJ6xJNzLFQJ6IryiszkGk1caLg?= =?us-ascii?Q?XcpcmqHpdLm0z8faBQ1ySC9xAJwv/J7ye6qzTtAfobJ6XtHKaW+RhK1uQw2W?= =?us-ascii?Q?3OgwYFk/rT6jS0WjAK4gKJF9tNQnCKoGc/peEjycWTtgNBFCamf6gqOgdXTC?= =?us-ascii?Q?jMz9Dx59Io3scZIj1f/gs9RygBAPurhayEU3becvUM5VCQJpfOq/9DOYEC9l?= =?us-ascii?Q?1whj1wPE3nJhhTirKnlzmDqpCctjwD8Chn7NSy619azXj+bOS0remKhOzeOA?= =?us-ascii?Q?+puc3PZCJ8nnKLuS8mJnMZNFyIaFPGw3ZnqJrLZuj4GCdOXuBopO7nK7T0b7?= =?us-ascii?Q?P9rIwL7bM8XvRf8tiD3ZRuCZL0fz4E1tzmvYYbyVT4Io8YNZBXpW7wIkgwF9?= =?us-ascii?Q?h3/JBS8+6H4b9dokP6uuajHR7t/vsB/fJFqVCw022904RMYUWjagUOcFqqFK?= =?us-ascii?Q?hRxMPP6F+xb390qOdm6gMzc/GD8JbRLKbHZtTLLNQydV0M/wQbk8YOiDZn6H?= =?us-ascii?Q?21ZzW4WgdmwIqfZr8mwJpmZOoEVl8aQwIr4nTo1oSivV43F2NZsU8mxLgpQi?= =?us-ascii?Q?d1s3TtRe3iOr48OmCzFRJQYnbV/QqIU8E3AO92mYRTkanmpX3QJ584+KewPt?= =?us-ascii?Q?ZPuAt2YAbpvnzZCGxNX5gWLYF60OY6lnrO9Ai8zsH8x6J3o/9Lz//eZyLnwJ?= =?us-ascii?Q?Kp9zNWXOlYXZWsXNfGT6GkALwir9y2zmQ4TtjNf6ksc+h7o5ykluUbi0m4zm?= =?us-ascii?Q?UVENSP+CdsHiSF7YT1S7U+66WGlHYADb/9YhfLiCR++G74BYI9q+N26Z2r6k?= =?us-ascii?Q?r2wg905U9bjQeH7STQ8C4T0xj3GEuoGn5YWoFrXqpjv86/v0k4100AP4SRwY?= =?us-ascii?Q?cl/QRkqp+mjzQGkg8hYxSl+u3sEvvjGtX+oJGp5qtGRbVG2YOVGRgOMFzBMq?= =?us-ascii?Q?+the0u8c8RVp7IArcIgsAnCY4XQT1jd0fbBWtTDftl/+txqVKuISw/5tODKW?= =?us-ascii?Q?JV3iioxkuSuVkXky0V21fWj/7LZxXGzW5EzTwK0wHF0o1COTkxhGdr6cyinS?= =?us-ascii?Q?x712OkGhCFDzDmlsnrLtgK8BRv0++txBc0p8i9JeZJGCIhLtr9O/yfMf1sPw?= =?us-ascii?Q?/SFis0ZZslgVaqN9nfq8bS1jsgFa/G+Ylxn+uMvQ2HLWcfjleBwGCwk1+alE?= =?us-ascii?Q?Qyqpx8UN7xR5t898rBhzruFRE445BpruRwfL2bDfLae3sxBD9aDRnTfPCuQz?= =?us-ascii?Q?o+O5jx6feYR5uIh2a4AbgaMiS3fHOqhafxqhaXPZuT0b9egEPs+uP71RrA?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(7416014)(376014)(921020)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:00.5453 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76491a61-6bcd-4275-85c5-08ddaabe3d5c 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9414 Content-Type: text/plain; charset="utf-8" Introduce the resctrl file "mbm_assign_mode" to list the supported monitoring modes. The "mbm_event" mode allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Each event within a resctrl group can be assigned independently in this mode. On AMD systems "mbm_event" mode is backed by the ABMC (Assignable Bandwidth Monitoring Counters) hardware feature and is enabled by default. The "default" mode is the existing mode that works without the explicit counter assignment, instead relying on dynamic counter assignment by hardware that may result in hardware not dedicating a counter resulting in monitoring data reads returning "Unavailable". Provide an interface to display the monitor modes on the system. $ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_event] default Add IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED) check to support Arm64. On x86, CONFIG_RESCTRL_ASSIGN_FIXED is not defined. On Arm64, it will be defined when the "mbm_event" mode is supported. Add IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED) check early to ensure the user interface remains compatible with upcoming Arm64 support. IS_ENABLED() safely evaluates to 0 when the configuration is not defined. As a result, for MPAM, the display would be either: [default] or [mbm_event] Signed-off-by: Babu Moger --- v14: Changed the name of the monitor mode to mbm_cntr_evt_assign based on t= he discussion. https://lore.kernel.org/lkml/7628cec8-5914-4895-8289-027e7821777e@amd.= com/ Changed the name of the mbm_assign_mode's. Updated resctrl.rst for mbm_event mode. Changed subject line to fs/resctrl. v13: Updated the commit log with motivation for adding CONFIG_RESCTRL_ASSIG= N_FIXED. Added fflag RFTYPE_RES_CACHE for mbm_assign_mode file. Updated user doc. Removed the references to "mbm_assign_control". Resolved the conflicts with latest FS/ARCH code restructure. v12: Minor text update in change log and user documentation. Added the check CONFIG_RESCTRL_ASSIGN_FIXED to take care of arm platfo= rms. This will be defined only in arm and not in x86. v11: Renamed rdtgroup_mbm_assign_mode_show() to resctrl_mbm_assign_mode_sho= w(). Removed few texts in resctrl.rst about AMD specific information. Updated few texts. v10: Added few more text to user documentation clarify on the default mode. v9: Updated user documentation based on comments. v8: Commit message update. v7: Updated the descriptions/commit log in resctrl.rst to generic text. Thanks to James and Reinette. Rename mbm_mode to mbm_assign_mode. Introduced mutex lock in rdtgroup_mbm_mode_show(). v6: Added documentation for mbm_cntr_assign and legacy mode. Moved mbm_mode fflags initialization to static initialization. v5: Changed interface name to mbm_mode. It will be always available even if ABMC feature is not supported. Added description in resctrl.rst about ABMC mode. Fixed display abmc and legacy consistantly. v4: Fixed the checks for legacy and abmc mode. Default it ABMC. v3: New patch to display ABMC capability. --- Documentation/filesystems/resctrl.rst | 31 ++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 37 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index c97fd77a107d..4e76e4ac5d3a 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -257,6 +257,37 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config 0=3D0x30;1=3D0x30;3=3D0x15;4=3D0x15 =20 +"mbm_assign_mode": + The supported monitoring modes. The enclosed brackets indicate which mode + is enabled. + :: + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_event] + default + + "mbm_event": + + mbm_event mode allows users to assign a hardware counter ID to an RMID, e= vent + pair and monitor the bandwidth usage as long as it is assigned. The hardw= are + continues to track the assigned counter until it is explicitly unassigned= by + the user. Each event within a resctrl group can be assigned independently. + + In this mode, a monitoring event can only accumulate data while it is bac= ked + by a hardware counter. Use "mbm_L3_assignments" found in each CTRL_MON an= d MON + group to specify which of the events should have a counter assigned. The = number + of counters available is described in the "num_mbm_cntrs" file. Changing = the + mode may cause all counters on the resource to reset. + + "default": + + In default mode, resctrl assumes there is a hardware counter for each + event within every CTRL_MON and MON group. On AMD platforms, it is + recommended to use the mbm_event mode, if supported, to prevent reset of = MBM + events between reads resulting from hardware re-allocating counters. This= can + result in misleading values or display "Unavailable" if no counter is ass= igned + to the event. + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5874cfdf8d8d..ba7a9a68c5a6 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1799,6 +1799,36 @@ static ssize_t mbm_local_bytes_config_write(struct k= ernfs_open_file *of, return ret ?: nbytes; } =20 +static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + bool enabled; + + mutex_lock(&rdtgroup_mutex); + enabled =3D resctrl_arch_mbm_cntr_assign_enabled(r); + + if (r->mon.mbm_cntr_assignable) { + if (enabled) + seq_puts(s, "[mbm_event]\n"); + else + seq_puts(s, "[default]\n"); + + if (!IS_ENABLED(CONFIG_RESCTRL_ASSIGN_FIXED)) { + if (enabled) + seq_puts(s, "default\n"); + else + seq_puts(s, "mbm_event\n"); + } + } else { + seq_puts(s, "[default]\n"); + } + + mutex_unlock(&rdtgroup_mutex); + + return 0; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -1911,6 +1941,13 @@ static struct rftype res_common_files[] =3D { .seq_show =3D mbm_local_bytes_config_show, .write =3D mbm_local_bytes_config_write, }, + { + .name =3D "mbm_assign_mode", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D resctrl_mbm_assign_mode_show, + .fflags =3D RFTYPE_MON_INFO | RFTYPE_RES_CACHE, + }, { .name =3D "cpus", .mode =3D 0644, --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2043.outbound.protection.outlook.com [40.107.243.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 117D0271A6A; Fri, 13 Jun 2025 21:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848844; cv=fail; b=fv7z0Fs9j59g2DUk/i79hSmL1+8jXw/eBkrM/BeO7BADL2j+yW2TogiGCCaiyvnMo9a9Gl4QU+h0pXRFlpnk9yOuh3YsVJtuug7SX8/zMkCa8SvGlVl1XL1z9IbT3N7v2Ig5hRMx/F6Xa6eEv2hyWu2ZqzAcn6mFle9usOSLkRw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848844; c=relaxed/simple; bh=aDx2Rcgp+dukOExyf63UTiJ4q9QINxLx36PdKYiCbwY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jtnie3uJe2jnM9KcN1/prvSiA/WLnZbRZjGAXs2RNgYryvtlwc2bqhePacD2/gWiZJOaWZPanDaCFy+LVZjnLGAVVQQ4YdSsKrQqo+VW83OL3t2pOjBlwbpUbr1dbsjXRmE3DkPGotrjUBmojDQdb/rZGQdHr/1kYl5IUenuX/s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=pBDaYXDy; arc=fail smtp.client-ip=40.107.243.43 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) header.d=amd.com header.i=@amd.com header.b="pBDaYXDy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JpWAZvFgeXPKQlpLOhKJ4KIIab9i1byBSa2RR8+J592juCe+dEDYRbLc/fjsRsZsQ9eCcTlWv5EC3DVYVtCYrzKAbJiqj7m4jfwNtFI0yQZtJ/YZNcNWQTOq+/qrh/Kn5WpmUdBeQD8vgToEjBiV1b4GTiYo19+0QNsnm+5UU6m9FeaKgE6M1U38KuERbiqlmuRSVC7awy9dBqmp546koT52Ng1QhvmKemU3qXKuzov9SwYRoyqddHUP+Nbo7SAoRQjHYB9ikqIxJWwnfrPSDP6Ks7SyBvW/jdgNp66nuBYi/0BHutrGa5/ECCi41Dj7Ob4YLy69/1Q1r6FmSbIf9w== 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=HiYP5cY5U63qi0ORPgxrOU047QYJEvtrlFfmiE9r2A8=; b=a/z6j2ro3wGJwCbeZp+qK3gFrAnvCq7bBR7jXGUHhvSe2KqMWlxTXkMF3630HLakZd8t60cFezukE24a2AbyBRdsNg0toOoJGMypszYclOhrcwoQgB5Z/BTe+uOt5hslaOBUEuPKMU/ybOrpnHTgQzYvWsZ1CVnGaBpOeGvSmxh/7NhqIvPBDOYwNkXBQquwmX1K04sZdjD9npP1v8/+m4x8vCJf9esClKYTy/pTajbb5uVDEs2A0uGPhCluYYyg2XfWM8dMfiSJNj2GfZGuGWS5JBmL5vcMusWwTEWLWI76e//g+DCGK8GZ/e5SdAIAk3yQmuDOeX69kgCJCdj0oQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=HiYP5cY5U63qi0ORPgxrOU047QYJEvtrlFfmiE9r2A8=; b=pBDaYXDyZgbaDCRJ+NBpfkwbX2HTpH1uP+GJh0+JJSleMe6M1k9ER4fInEHBTG0fio2Ge26XiJqB9qFUq+GWYhSq4U02efhShe7ObOFWbc3xZEWJ/XAGCkUMFldK8KZfm1xncq4s6+kPTO/4hZCGeboh3SHkX9dn/OiRRYhF0Ys= Received: from SJ0PR03CA0010.namprd03.prod.outlook.com (2603:10b6:a03:33a::15) by IA0PPFD78AA37BB.namprd12.prod.outlook.com (2603:10b6:20f:fc04::be6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8699.26; Fri, 13 Jun 2025 21:07:20 +0000 Received: from CY4PEPF0000EDD2.namprd03.prod.outlook.com (2603:10b6:a03:33a:cafe::b4) by SJ0PR03CA0010.outlook.office365.com (2603:10b6:a03:33a::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Fri, 13 Jun 2025 21:07:19 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD2.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:18 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:06 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 12/32] fs/resctrl: Introduce interface to display number of assignable counter IDs Date: Fri, 13 Jun 2025 16:04:56 -0500 Message-ID: <4ad1bac79c6100d347e333b9781b1c76196326fd.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD2:EE_|IA0PPFD78AA37BB:EE_ X-MS-Office365-Filtering-Correlation-Id: ad676b03-7200-4cbc-79e2-08ddaabe4841 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|7416014|376014|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?n/7tkdLfVS2nCfMQZlYRlqjl0FcAanrYqXZ8/oGeNuzOSDJUtlLVSchd/RWB?= =?us-ascii?Q?vM615CRZ1HvkraGpbyrg6Usl8padohpkdb2cPlBZWGr158MlwNUT7+cIKE49?= =?us-ascii?Q?Cpk7utBOojamvt6/fKOncnnw08vOKfU0hB/6BNoXao+58VAAUR2yQfbXkrUw?= =?us-ascii?Q?eT5Rq3rl1y7LXB9RENgZHTVUXvK9ALy6xg37aBjp0dDToyPPTwnq7cIB5u88?= =?us-ascii?Q?RpRsh9u0dKDHCSvaxOcT+4HV0z4hSYr9ahv0UJMinmy2t2j8G1sDvac+K5dx?= =?us-ascii?Q?WJaiQSpDLzZ94sBuwn1x19g9vo3pZroMW2vLX4DP7sShbNKIgwKlEFoo28KP?= =?us-ascii?Q?R3sWJNx3KBbnI7NjvFJXahKhVjv7DAuJum4+DcSdEQC4Bp1oQm2702gRkuHr?= =?us-ascii?Q?3AJ56Focqyt/4cK8NzrdejRIlQ5pR7SDO+l7M5suFXpfS6cpLH0zIkTOiadH?= =?us-ascii?Q?oxfOp/Zw+zxldX/F4uutBz0KL5b8VoO8SwUiqdmct9kW2eMzT75ECzF6rhNU?= =?us-ascii?Q?OQqb1Ff6FgLqUGh5qmA1rxa4IG6UJLG/DpRsfuWo4muQLcCbcNQRllYfPwA7?= =?us-ascii?Q?xanGKCqtDk/A+0paQl5CMd9xmu25pIICMAQPFnMIViIOBDlaoyItFMvul9S4?= =?us-ascii?Q?AvbbtqFiAnaECIyklYTyWZUfgfq1KDpNmBhTev7mYr7HHeIwVp7CiweMTT1v?= =?us-ascii?Q?FXlL6vLTvQ0cDyzkU7CL6O9NxTfP4QzMHkUuqDFCZs32/9CtdBm5tk55yPnh?= =?us-ascii?Q?G0d8YnI6XuxyMewTVmWijo1YV4/uhH8e8lAl8x4mHtF/V7BGLmfRhbbyvBdm?= =?us-ascii?Q?1nF6+ECTeBP6jzMAgvQLp6avKCy8xmUyc5UipiencSQqHVU+rxzGkYA/dYAy?= =?us-ascii?Q?e7LBZOscN3n7bCYuXGZQe5TuRt2n2QzUP39QmEdfSorQkCMCw4EQJOOrSzZ3?= =?us-ascii?Q?ZTpyTsbwpsuC9I5YuPvC887YUtwZQaWEqCM0rHjNUnfxY2oZjrWwMdS2CRAI?= =?us-ascii?Q?P/h4V2qbACozzU7XKGA1mCZoC6k2EQ9qcWDRZ/aWZ3toq5ujX7Vgih52bgbF?= =?us-ascii?Q?+17VXivcQj88s3esnWTJAxbfey3++PEAQJFWRQU1inbLx/EXX9YekoefuiqI?= =?us-ascii?Q?uSFHWzzXzR1si7hlMWyDlKEzSNbbCXoS9R26dtDbppTPlKsRw7ETRv6i36G7?= =?us-ascii?Q?7CJ3N7N1TgCPrrF0RwfZ0U3fTWxgVu5D6Qd+0x1FSbP9tb9dT9u8741qUwxl?= =?us-ascii?Q?6swsoJ0L7/DdaBtCL+RdnEqi50bSEB+IyL7PFVYvJ9R7DC/BZrf8JrZabJOA?= =?us-ascii?Q?InlYmp8E2HbXa7OKs3Rc16Z4CalH1JUVcT0Cof9GeGVbToYr9lJXAMarl3o8?= =?us-ascii?Q?jyC5pMY+cuYuhNzNIcYF4HlFstBH37eKhtf/NQzvaKCti85PhkoJ/DPXTX6d?= =?us-ascii?Q?qI60OLGEH4NQVUc4i9dND48rOQTCicnr9Z+gpBlJNi+ufKfwDDjZXFxsnQru?= =?us-ascii?Q?TsVzubePobIZWleUhhzWpqak9c8Z6pcfa14jXCln+eOe4f4Sq4SzBICbsQ?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(7416014)(376014)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:18.8241 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ad676b03-7200-4cbc-79e2-08ddaabe4841 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PPFD78AA37BB Content-Type: text/plain; charset="utf-8" The "mbm_event" mode allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Create 'num_mbm_cntrs' resctrl file that displays the number of counter IDs supported in each domain. 'num_mbm_cntrs' is only visible to user space when the system supports "mbm_event" mode. Signed-off-by: Babu Moger --- v14: Minor update to changelog and user doc (resctrl.rst). Changed subject line to fs/resctrl. v13: Updated the changelog. Added fflags RFTYPE_RES_CACHE to the file num_mbm_cntrs. Replaced seq_puts from seq_putc where applicable. Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c/rdtgroup.c have been split between FS and ARCH dir= ectories. v12: Changed the code to display the max supported monitoring counters in each domain. Also updated the documentation. Resolved the conflict with the latest code. v11: Renamed rdtgroup_num_mbm_cntrs_show() to resctrl_num_mbm_cntrs_show(). Few monor text updates. v10: No changes. v9: Updated user document based on the comments. Will add a new file available_mbm_cntrs later in the series. v8: Commit message update and documentation update. v7: Minor commit log text changes. v6: No changes. v5: Changed the display name from num_cntrs to num_mbm_cntrs. Updated the commit message. Moved the patch after mbm_mode is introduced. v4: Changed the counter name to num_cntrs. And few text changes. v3: Changed the field name to mbm_assign_cntrs. v2: Changed the field name to mbm_assignable_counters from abmc_counter. --- Documentation/filesystems/resctrl.rst | 11 ++++++++++ fs/resctrl/monitor.c | 4 ++++ fs/resctrl/rdtgroup.c | 30 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index 4e76e4ac5d3a..801914de0c81 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -288,6 +288,17 @@ with the following files: result in misleading values or display "Unavailable" if no counter is ass= igned to the event. =20 +"num_mbm_cntrs": + The maximum number of counter IDs (total of available and assigned counte= rs) + in each domain when the system supports mbm_event mode. + + For example, on a system with maximum of 32 memory bandwidth monitoring + counters in each of its L3 domains: + :: + + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs + 0=3D32;1=3D32 + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index dcc6c00eb362..92a87aa97b0f 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -924,6 +924,10 @@ int resctrl_mon_resource_init(void) else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; =20 + if (r->mon.mbm_cntr_assignable) + resctrl_file_fflags_init("num_mbm_cntrs", + RFTYPE_MON_INFO | RFTYPE_RES_CACHE); + return 0; } =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index ba7a9a68c5a6..967e4df62a19 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1829,6 +1829,30 @@ static int resctrl_mbm_assign_mode_show(struct kernf= s_open_file *of, return 0; } =20 +static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + struct rdt_mon_domain *dom; + bool sep =3D false; + + cpus_read_lock(); + mutex_lock(&rdtgroup_mutex); + + list_for_each_entry(dom, &r->mon_domains, hdr.list) { + if (sep) + seq_putc(s, ';'); + + seq_printf(s, "%d=3D%d", dom->hdr.id, r->mon.num_mbm_cntrs); + sep =3D true; + } + seq_putc(s, '\n'); + + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + return 0; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -1866,6 +1890,12 @@ static struct rftype res_common_files[] =3D { .seq_show =3D rdt_default_ctrl_show, .fflags =3D RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE, }, + { + .name =3D "num_mbm_cntrs", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D resctrl_num_mbm_cntrs_show, + }, { .name =3D "min_cbm_bits", .mode =3D 0444, --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2066.outbound.protection.outlook.com [40.107.93.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C3C0272816; Fri, 13 Jun 2025 21:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848848; cv=fail; b=Uj5nashW8bn+PiXPL75Mc7BHdjcLtkeoEKrAMHzqhplvQgMEbdSZoN/6okBCI2RjlkBkyg9XqI2lsfu5zcrrj8lHDIPiv89DUuzdwnlguoF+fQOxno64k9KqeYXWcf7hJzisQZaZ4QAYXVvpvll7n/BF4r2ntrWAxxxxuj03uZc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848848; c=relaxed/simple; bh=+HprEXmAWKCz7llhNlfLPpNotXlaJCmC3sbgqjyIFTI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f6o4YaXBiwUJxrvWVVMltsPoLb6pig9HKMJQ2sUa855vPz53lSi7sa1BJ7bJZ3rWBQ/IbV2+d7ydM9AZhU9yrP6AJDwu1RRThi6/mjPNiKQv0XLSKN7h1OGvlE7IJpWIHSoPQC4w4Gp/IS6clnVtSzY1bKoVyM3F+D9llxaQiBI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=V06YkyiS; arc=fail smtp.client-ip=40.107.93.66 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) header.d=amd.com header.i=@amd.com header.b="V06YkyiS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=miB00hIkudYuvMu//DWmy+0MFDkbUA3zjSoupswMOU11ENeHOl7pEGx3BLu2blVhMUHrwJ2nVC9Rtj5z+r/VP3kSu/H4cKVLl/nxr+v+QKxktb6jbps7IgSnnqmwUX7MlG7py3NBWo2tO+RGFlSOc8Xp8FrCxutmSS0+9n3NqZOaCw7ioJzLFnCv/BIbMfOtj41IKJLOw9zlFbTGopxBmu7orDzAyTsqBXhOyUw+ipvfaf2KWiOa4ynfeyIWFCQLSyJKMbBbcRM0x5ZMHlR2+NRkOtRjC+xq/QN7KtZGNO68g3dFdjJT5PpWVms90lqayrnMlD6j/5Hdrkv7zvR85w== 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=W7xlm0IdtoOXjDJUsmm7Zmmgm/gnuiTLrOavDohgWro=; b=siO63z15Cac5lY51eNDnyFv0iIheUN/Vh/JgvfxFyM96+GeQZIGcCsvvXoGI9ay5Z+/8CVxgRCo7QUDLSXP5gqmvNcqJcgT9ZvW/i+YYiuBAeviAkTNuQA+cJgcjiIfi9hhFQEzAiknO3GwHEmI1WwQxPYxOCN30huMYWcYsPY89dmO98pVqPfzk1Ag2Pa9whoPPL6+p58X90KfHS+XPLip0jSj+jxfmmy2L62cN4RDyhCKdaUkun2rdVSD/5VW9/dbTMia5a1d1oI4Do8/3nhm14WWi0h2CB8+0XO2DhHb2ek7PXlqwzUxAQC3M0HdJI9Mfx6MWdJsqTLDzsequKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=W7xlm0IdtoOXjDJUsmm7Zmmgm/gnuiTLrOavDohgWro=; b=V06YkyiS/Fxp8AwaeSB5xrsrWtwPf1d0mBEnd07CFMsreYouw3V21D8Ks8efYXb/SasX0cdo+o+r566VfIo9z3QVi2h749B6zOiwWt7rQIkQvOaSdUlUWoGG2iZtYE+T2JyTibu8jiEaTQCkWhjamp6BHcE6NKfC/Vf1ghMK5uA= Received: from DM6PR02CA0117.namprd02.prod.outlook.com (2603:10b6:5:1b4::19) by CY5PR12MB6597.namprd12.prod.outlook.com (2603:10b6:930:43::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.22; Fri, 13 Jun 2025 21:07:24 +0000 Received: from CY4PEPF0000EDD5.namprd03.prod.outlook.com (2603:10b6:5:1b4:cafe::25) by DM6PR02CA0117.outlook.office365.com (2603:10b6:5:1b4::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:07:23 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD5.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:23 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:14 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 13/32] fs/resctrl: Introduce mbm_cntr_cfg to track assignable counters per domain Date: Fri, 13 Jun 2025 16:04:57 -0500 Message-ID: <1a3ed4abaaebbcf2399068ef5004760e8722d9e0.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD5:EE_|CY5PR12MB6597:EE_ X-MS-Office365-Filtering-Correlation-Id: 593a696b-62c2-44fb-78e0-08ddaabe4b36 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sO8l1MPSqaRG1XF3foz9qd9b01BHp5+nDJnHePnvBtud407BaSraWjLxRH1P?= =?us-ascii?Q?ga+JzAVty4pnJFApCkOksSFINvfC3CUUIDtdphw7tqgyavteII+vPGPqf3dd?= =?us-ascii?Q?w0ozneMhg/cT+4FjqPXgma2/dHbD3appdgROYpjO6/4EMqanRVlNSQdPtv2t?= =?us-ascii?Q?ib22G1x+JBi+0H9P1etnJT+hNJQpRZTaGzuzk6tQui8xloKF84y71JOSZd1B?= =?us-ascii?Q?uch/4BlJp8om5ofJ0CQSdoLV04ipspAn2IVL/jUUoouG4cFG8UtSd7E/lk7x?= =?us-ascii?Q?Jr84rDwpP72pPfutDcPcm8katEfnJusR5W4NQ+b8Bpk8EbR1zHtqu0I/Zae7?= =?us-ascii?Q?OoWUtvYv1YO8u2LXRbYVqtJb4UZhJCzdlpN/KQeWqF7SwmXi6IL701yoQsNm?= =?us-ascii?Q?1q+mV62br/I1wxLBnpwfFOLaNmEfTeWaG+8YcsW8kRVS24Gtg22CEUH3NwdM?= =?us-ascii?Q?nAn16PWD2fSjm3CNMfkQbUP2NTFGNzQbwXJycZYwHtTyn4jHxPZ6p4l/AerQ?= =?us-ascii?Q?Blt1FH6r0cUwMlMW4yE1ZmWwL8xdAzJcNwRhjEBeMhG9sL97qIz/0FmD6TW7?= =?us-ascii?Q?YVzEczn8zTECyoqLDAZ5L1Sfr0Ykvi1GZUmGPJwbPjmPLso5MXy1hSi7L4KC?= =?us-ascii?Q?ToZMhjb/STjbTfOG4+EVUc9uPTOu2Ung676V1aFGnt6n6uRVWCQyx2asVUvi?= =?us-ascii?Q?ZgAmj4/Berrb/UiKjC7RW8fd1Pi+Ku0h36CqnKhhghK6qS/r9GyIja5CUIYf?= =?us-ascii?Q?HU4tWAquJir6iy/r3utuGHeANfWfdZi9R91p2Zhj7/2mTZyMKzgpVY/MfsLL?= =?us-ascii?Q?sJw7+QTJxVvpC3yap1WVnYxGd4lwi/hA5zKhIsjPZjgxgUJkzUEHSUv+559e?= =?us-ascii?Q?UDhWeeTqd5cL3nddT8baVL6v6AZNFW6yD9UsCzb5IW49qDI6ApMyhfGyYAfL?= =?us-ascii?Q?ab6zeHLCezrx54CBTup/OFgXzTPtzKKVzMU2NJor/W3IXITWfFWj6dpNy6rN?= =?us-ascii?Q?pQOxOrO4zjb+JZmLBeaarJ62K3wCsb2XNZJBSvAvRznSlODc0k5/aKl2AQaQ?= =?us-ascii?Q?GsM4cVXIXgQJO5xtC77PaN/SMM4KTFzXkdRyro48jc3az1WkPf18nZgSq9za?= =?us-ascii?Q?1AMa5OeK9Q6H+L24i2iJjtDgWPL/A79Ql/V32BR2R4sXVNkJRvnOPfDMLZyV?= =?us-ascii?Q?fwlvOMFOuDINZ4HtKjcrKiII5RsmpHquxqgVUIU+hMUJrDB4aw3qHnleby3v?= =?us-ascii?Q?Z/h+zsZayJCRvCfiOIIBSfbAmIyMALP2JdXCNetherum98N5P35RLRqSDsbK?= =?us-ascii?Q?nzttYofQxtoWnioDEhZ1tVWT8g+cZn+OmbsmFeu7iH4NwlaJT0Qws0jgCgGu?= =?us-ascii?Q?ZdUesDzJv3Y2Aa7DVxrRxLskajAZClXgwkO/4dvRy4Gy6JL79jxtnUS6Dch6?= =?us-ascii?Q?aAcMzcrxAjRcxEfiCOQUFuFUhJ9kTPIWLAbElMe4GF5vePpzpV8sASMTcez8?= =?us-ascii?Q?HlE8Qeww0ahrb0MHzvujaxXEdK5nIaenWqiFX+ZnpqVE/ScwCOtMf7MQzQ?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:23.7809 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 593a696b-62c2-44fb-78e0-08ddaabe4b36 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6597 Content-Type: text/plain; charset="utf-8" The "mbm_event" mode allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Counters are assigned/unassigned at monitoring domain level. Manage a monitoring domain's hardware counters using a per monitoring domain array of struct mbm_cntr_cfg that is indexed by the hardware counter ID. A hardware counter's configuration contains the MBM event ID and points to the monitoring group that it is assigned to, with a NULL pointer meaning that the hardware counter is available for assignment. There is no direct way to determine which hardware counters are assigned to a particular monitoring group. Check every entry of every hardware counter configuration array in every monitoring domain to query which MBM events of a monitoring group is tracked by hardware. Such queries are acceptable because of a very small number of assignable counters (32 to 64). Suggested-by: Peter Newman Signed-off-by: Babu Moger --- v14: Updated code documentation and changelog. Fixed up the indentation in resctrl.h. Changed subject line to fs/resctrl. v13: Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c/rdtgroup.c have been split between FS and ARCH dir= ectories. v12: Fixed the struct mbm_cntr_cfg code documentation. Removed few strange charactors in changelog. Added the counter range for better understanding. Moved the struct mbm_cntr_cfg definition to resctrl/internal.h as suggested by James. v11: Refined the change log based on Reinette's feedback. Fixed few style issues. v10: Patch changed completely to handle the counters at domain level. https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5A= FgD9cQDCUg@mail.gmail.com/ Removed Reviewed-by tag. Did not see the need to add cntr_id in mbm_state structure. Not used i= n the code. v9: Added Reviewed-by tag. No other changes. v8: Minor commit message changes. v7: Added check mbm_cntr_assignable for allocating bitmap mbm_cntr_map v6: New patch to add domain level assignment. --- fs/resctrl/rdtgroup.c | 8 ++++++++ include/linux/resctrl.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 967e4df62a19..90b52593ef29 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4084,6 +4084,7 @@ static void rdtgroup_setup_default(void) =20 static void domain_destroy_mon_state(struct rdt_mon_domain *d) { + kfree(d->cntr_cfg); bitmap_free(d->rmid_busy_llc); for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) { kfree(d->mbm_states[i]); @@ -4167,6 +4168,13 @@ static int domain_setup_mon_state(struct rdt_resourc= e *r, struct rdt_mon_domain goto cleanup; } =20 + if (resctrl_is_mbm_enabled() && r->mon.mbm_cntr_assignable) { + tsize =3D sizeof(*d->cntr_cfg); + d->cntr_cfg =3D kcalloc(r->mon.num_mbm_cntrs, tsize, GFP_KERNEL); + if (!d->cntr_cfg) + goto cleanup; + } + return 0; cleanup: bitmap_free(d->rmid_busy_llc); diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index f078ef24a8ad..468a4ebabc64 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -156,6 +156,22 @@ struct rdt_ctrl_domain { u32 *mbps_val; }; =20 +/** + * struct mbm_cntr_cfg - Assignable counter configuration. + * @evtid: MBM event to which the counter is assigned. Only valid + * if @rdtgroup is not NULL. + * @evt_cfg: Event configuration created using the READS_TO_LOCAL_MEM, + * READS_TO_REMOTE_MEM, etc. bits that represent the memory + * transactions being counted. + * @rdtgrp: resctrl group assigned to the counter. NULL if the + * counter is free. + */ +struct mbm_cntr_cfg { + enum resctrl_event_id evtid; + u32 evt_cfg; + struct rdtgroup *rdtgrp; +}; + /** * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types @@ -168,6 +184,8 @@ struct rdt_ctrl_domain { * @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters + * @cntr_cfg: array of assignable counters' configuration (indexed + * by counter ID) */ struct rdt_mon_domain { struct rdt_domain_hdr hdr; @@ -178,6 +196,7 @@ struct rdt_mon_domain { struct delayed_work cqm_limbo; int mbm_work_cpu; int cqm_work_cpu; + struct mbm_cntr_cfg *cntr_cfg; }; =20 /** --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2075.outbound.protection.outlook.com [40.107.96.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 338A8271A6A; Fri, 13 Jun 2025 21:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848858; cv=fail; b=L67+SOxBC3utuqKHrYkDMuKULb8KRxNOb4WeaQ4W6tpTLVFDXjNj80+/301lCqr8rI9DA+VQzDLv3frHcGCGG44loTPuM6TP6fDqBhC5Df71uvmu7VuasIhjpkrfGrdbIJYCeneGYKd4kf0N0kXDExA3eUlrGui2gd5wQTRNB/8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848858; c=relaxed/simple; bh=avDxoKntVHya4Nn1QAAPzvqzeCCuIH74pf0g1JE8O/w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nd+t4ts16OPL2kjR3FRh6ZJy2CunAhEF+40/W8Ad7XrnpRQW+dfeIYPygTZyOUx2Va9d8WGwCiHwRa5FEB1qDuNzQffIl+FN1RVThm8mfj8ub3mi3MdxN0wLc93qPVefvDS8vplaKkvfZ42Ku7JcZDjiNWhvfggooCW4843rghw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=1Eikw+gO; arc=fail smtp.client-ip=40.107.96.75 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) header.d=amd.com header.i=@amd.com header.b="1Eikw+gO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Pxt9WsQaUPjYxhMZj1jF4xM8k08DhY8oMSIaYdBdA450nqM3vwlGcEzITNCgqSm/YRQ7Agf7miANuPwGad9vuIV6yit7kO2EnQ9ew9XZTjNjHEdTkpcl605DHTjx5EuRgn4f+wOr+iD8xYTED6hKFmMV2LKa0DX3vOPuXCMPX2/vQc5CFzyKajT3fb3+O1KW/b59V7Y8X5BD7UBP10qkAX/GKvZ6UX+TsTet0o+uL2EIZoOnY3rr0NIWUXrBQWgpMvk2Ap2m5KJLd9Cp0Kilfqg/aIa1NyAtOrh7pSLIBQ5ps9ybHZEWpErNkqoIqHx0xeobF+asTAIGCw3mXu4DwA== 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=8zkqRYZ1pP6kCegRWRtnxZgQpLnGhYQo5vOXahBWaGk=; b=Pln53bUCLcwgLWai0S/u2Y6uPlmewnlM4B97mYDTqzf4Bqc0KBHxyv8kNNqBdS0zX+XnJp842qF9xpggFP1VfwKtRAnI5b/O0YIvLiTaPQrvMeSkkSXbWylgaM2os0k6WgZPPWQJFMPbvh7MSwEO9eZFvC0UrzAMLf5OYVptyPi+1mRD1PjWHAze3X4Y37HmuM4p+/nxjAE+uQ3yOCpW6n/sq8TVhhYmbgqIzLHquGA1KGmQny2l9OQ+WDogzAML0Vlyp3YW4bsbJQt62ulXd008wXTM8+HAlSGgx89xDJwufXc1Q4d5k+mKHytO1NLvbHW7ZCNgIaWG5ysqr9vqvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=8zkqRYZ1pP6kCegRWRtnxZgQpLnGhYQo5vOXahBWaGk=; b=1Eikw+gOIVt2O3unh5Lwz/RpkRQWmybO3tDmG4NH7kjC8egZyq79vtM/0+wbLZRuQQzjDh41rR5VhoWfIALzX1obyMqhiEjHfd7malPj9EUvotkGzTS7Hb6PRKSpWGfizpui7BefCgvCsH9JOQjp5ARBmfBXxQ1In9S745E/Yxk= Received: from PH8PR21CA0010.namprd21.prod.outlook.com (2603:10b6:510:2ce::10) by DM4PR12MB7719.namprd12.prod.outlook.com (2603:10b6:8:101::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.24; Fri, 13 Jun 2025 21:07:29 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:2ce:cafe::75) by PH8PR21CA0010.outlook.office365.com (2603:10b6:510:2ce::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:07:28 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:28 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:22 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 14/32] fs/resctrl: Introduce interface to display number of free MBM counters Date: Fri, 13 Jun 2025 16:04:58 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|DM4PR12MB7719:EE_ X-MS-Office365-Filtering-Correlation-Id: 55cee885-69ff-4d8f-993d-08ddaabe4e35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?kfWlwBlSg1wV1BOzGh99VgLfIP2WaUz6mVV+g72jtgz3Y3fyGKo/6XYF0XBA?= =?us-ascii?Q?VJQPQzCeoPixqyC1Sa4Ay92ID4z1ZQczsQKnfk9kkvjqyJReKaDrc5WALiRM?= =?us-ascii?Q?M5DzxTNYFbJmSku52HX4usHRQtQK5SOlXp7EylolF1ktl/kqqqLHa1aUJcgx?= =?us-ascii?Q?jw7/WaoxeR3ihh3RayRhRzNziTlxGAMOQRsr3ntDJuQOYGLWjUCPBmp/s10v?= =?us-ascii?Q?yxpuYHPYLuIYV52HXC96rPlnaPJKdEJpHisephW1YPSmSucUWRuEaA64ojx4?= =?us-ascii?Q?pyyGs0ys7VMgKAjxaMk+FJrMmjoC3YeIlxCBkS6c2zCj/sRlzoppkHh9BKrn?= =?us-ascii?Q?oIgvwFcgSwEFdSyD/dnM715TKqCV/DabfutcsYFgWC70lXyc3cZulSMsQcEY?= =?us-ascii?Q?emYZRcvRClsGZl+M70quOK4u/C84DJvWuKZ+RBgJfr/hJPK/+aRU8K0NHwHT?= =?us-ascii?Q?hTFXJpiRq3bOtxXdwmRLo9MMqag7Py2u7MeErvGkaOWYNqcZSpOLeJiLe2gu?= =?us-ascii?Q?LGRGrL273gQYY50qQ5pBv2x2W8UQsMpFIyqXk/TSQ+6+IyfU4iXF4N0TitA2?= =?us-ascii?Q?IOvkPTlao9LvvxiHd1eIuSOnUYFe7gGLLKMS8xUtUw918le3PjgVv1S0wIAu?= =?us-ascii?Q?O0BG9kUk4zXutKQWy9ag/+7hFOEGidtx7bCs9LWW2oJV4lihR0dtaiwyaiIT?= =?us-ascii?Q?teiQ9IDtRUGTGJfwp50ZKvWwTqNr52HdSYZNUIpSvzaq1Its6fLTjfdK1JPz?= =?us-ascii?Q?eXmt5/yTshZMQgpZIPg0rJyCKSx2BjNTFEh42LTqghvs9RzoHUdqxF8xpxtP?= =?us-ascii?Q?jm0eqHSPizeEoGx0yI6nhHFZT9bRRtv1xVBoWwFR5C8gf+PelIQxtuvxnC5K?= =?us-ascii?Q?mZcGZGhCouKClMOl43XkRmJD3OiMlF0HXa+/ZhHRqKbOhsnYxspRpoLgq0wp?= =?us-ascii?Q?RncHe6H9Evs2VMjY1qXaVsxCW8jlS+7m5pKXYdkt2ivCbWabyirluDJ9DX53?= =?us-ascii?Q?r7ufdsAXHnUmurgyEkYsciomBYGd/0sMM/x7Dv27tSRiRfIY55pCWnH4QMI/?= =?us-ascii?Q?1Qnhk9J1auiuGS31Z+i5t5q0aWTO6LYnZ9Zq44b1N0OLmw1NsQ/z67EGlC1O?= =?us-ascii?Q?Bys6M6vQP8CmZOlEpaoipetVmoc6eIZx+mXbXK8URZoKHr1iHXr6n/xT6HtF?= =?us-ascii?Q?oultHx4xb/c0CVS4Jrf9Izn9LGT7cUdGhoW+JR+DQvfGTf5nGPwVA7KxMBPI?= =?us-ascii?Q?MWEBDqxXJU/DdnZisOnubdbO8GnSOzapVSKxY4RrSMkU/bLOnB4So9EJL6q4?= =?us-ascii?Q?Pitpx3CXW5lI34MwE1EEzR13ubF7t1/jD23VFtmG0HM6NF8nQWe/WWbQ+n03?= =?us-ascii?Q?v+Yoze0+OeiSct1Ic7NAkZ1r2A9NqpFeMi/h5xPrLeiAsuwsFJHoqkZtGlTU?= =?us-ascii?Q?ya8X4wiosv5T71bh4KXXxzVEHO23qMQx4iMLt5JsXY5lgQ5IbxufLV15RwsM?= =?us-ascii?Q?fj9KfxAAdGQlWdDHkwPOeivL4GLHCM3vJ7wNSqyMdyL0vjFNK8YLT4fZhg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:28.8079 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55cee885-69ff-4d8f-993d-08ddaabe4e35 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7719 Content-Type: text/plain; charset="utf-8" Provide the interface to display the number of counters IDs available for assignment in each domain when "mbm_event" mode is enabled. Signed-off-by: Babu Moger --- v14: Minor changelog update. Changed subject line to fs/resctrl. v13: Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c and rdtgroup.c file has now been split between the FS and ARCH directories. v12: Minor change to change log. Updated the documentation text with an example. Replaced seq_puts(s, ";") with seq_putc(s, ';'); Added missing rdt_last_cmd_clear() in resctrl_available_mbm_cntrs_show= (). v11: Rename rdtgroup_available_mbm_cntrs_show() to resctrl_available_mbm_cn= trs_show(). Few minor text changes. v10: Patch changed to handle the counters at domain level. https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5A= FgD9cQDCUg@mail.gmail.com/ So, display logic also changed now. v9: New patch --- Documentation/filesystems/resctrl.rst | 11 ++++++ fs/resctrl/monitor.c | 5 ++- fs/resctrl/rdtgroup.c | 48 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index 801914de0c81..8a2050098091 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -299,6 +299,17 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs 0=3D32;1=3D32 =20 +"available_mbm_cntrs": + The number of assignable counters available in each domain when + mbm_event mode is enabled on the system. + + For example, on a system with 30 available [hardware] assignable counters + in each of its L3 domains: + :: + + # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs + 0=3D30;1=3D30 + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 92a87aa97b0f..2893da994f3c 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -924,9 +924,12 @@ int resctrl_mon_resource_init(void) else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; =20 - if (r->mon.mbm_cntr_assignable) + if (r->mon.mbm_cntr_assignable) { resctrl_file_fflags_init("num_mbm_cntrs", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); + resctrl_file_fflags_init("available_mbm_cntrs", + RFTYPE_MON_INFO | RFTYPE_RES_CACHE); + } =20 return 0; } diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 90b52593ef29..08bcca9bd8b6 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1853,6 +1853,48 @@ static int resctrl_num_mbm_cntrs_show(struct kernfs_= open_file *of, return 0; } =20 +static int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + struct rdt_mon_domain *dom; + bool sep =3D false; + u32 cntrs, i; + int ret =3D 0; + + cpus_read_lock(); + mutex_lock(&rdtgroup_mutex); + + rdt_last_cmd_clear(); + + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { + rdt_last_cmd_puts("mbm_cntr_assign mode is not enabled\n"); + ret =3D -EINVAL; + goto unlock_cntrs_show; + } + + list_for_each_entry(dom, &r->mon_domains, hdr.list) { + if (sep) + seq_putc(s, ';'); + + cntrs =3D 0; + for (i =3D 0; i < r->mon.num_mbm_cntrs; i++) { + if (!dom->cntr_cfg[i].rdtgrp) + cntrs++; + } + + seq_printf(s, "%d=3D%u", dom->hdr.id, cntrs); + sep =3D true; + } + seq_putc(s, '\n'); + +unlock_cntrs_show: + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + + return ret; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -1876,6 +1918,12 @@ static struct rftype res_common_files[] =3D { .seq_show =3D rdt_mon_features_show, .fflags =3D RFTYPE_MON_INFO, }, + { + .name =3D "available_mbm_cntrs", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D resctrl_available_mbm_cntrs_show, + }, { .name =3D "num_rmids", .mode =3D 0444, --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2040.outbound.protection.outlook.com [40.107.220.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFC61273D78; Fri, 13 Jun 2025 21:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848863; cv=fail; b=IZme6jihjTY4H1VNgKKfkOQunsS00Je6V1Em2waASVICMILpTW27xKBGo6iu/LPrMcJ9UJuSEjS43dSiTmwygRNJltMBvwl79xAZJg/ZolGAUwHtvhV7bGvVxRC0qEyL5iZ1WiweEif6CaFmnCq88ufAf6iQuv7YmNqw8l+i0o4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848863; c=relaxed/simple; bh=iHQVfLx1ASC5IJqnJM+veZW2SHqcnEikvbHDc+WRdK0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NMSzwG0z42WT4zfEhT9KGbtaNf7OdZuPqznmkwmRUeco5ksDRQapn16rjMLzafM0FIjG8uWIDLKpp8C8uDOOB0JvxfhydB8Es2LtdQ5PMhUpmFFz5vfnlDxpdu02PaGZia0/zlddX6Kz+i3Zn7H8pekIbWGuImcykuRREq3w7cM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Mk/XXjiG; arc=fail smtp.client-ip=40.107.220.40 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) header.d=amd.com header.i=@amd.com header.b="Mk/XXjiG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BNnmkEwzIzkJWxhi+qOAqesJ4QF43zz+ksQk/LDOwj7dQlVDEqnhsxyVGBS/jL+so9ZwGyUw6X1AAUyqQIcQplh0qKzJtKJkJq3qdxkn7BXyk7AHbLu5CRPeiVH2JZ3b2SY6/DGIiXJ5JKE7bWzaAzLwZhAXBnK3e7Wt/LBEhazVrOxO4EzQJW1571wcye0JSvai9ihRhBLj3IMq7TguHOGz5rL/yuQjqaw0XzLXeSJRur/AFG4i1eg0/1jck6cij6H43XojrYB0iu+0qU2ZtREGBCFky3vw2hxgSJcP9QPEYe6Rlf4tui5ISO6gxj8VMwoqfn/L2RulEc0kyOyM2g== 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=GTs8lj/1SLzljbIVWJPPCpcR6PJcc7KlqeQ6VLuOXD4=; b=adxKvn7ORzUWFCqxrZonsAhfQzMi5ixqiKw1A9XDMfUZA/neLmtf6kgGxq1c1upWsJMP3z1PTCL88LfnFRn+ub0jl0YCub3uMvwzhqiOhmG8RuLTpxVtb2VciU3guKrC5AO60NnrIOiZ5P6HEz+Xpa9e9kYxG7YNNcuYqaEjKKeUSFNYWvCn5MtyFNUF77kngw86uqn8NF9Sw9cp0KmbmL93YTwqZ2otudB2HJrOHNizbPXiOZXbPYR7ByMeJe2958tBdtbGqY/jl4t3DblJO60SXbuRcDhy0fHsZ13DVvJ5vGGprOGeLRG4Bmbhkv6o5/sl7kpuCpe3PlZaR+g+uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=GTs8lj/1SLzljbIVWJPPCpcR6PJcc7KlqeQ6VLuOXD4=; b=Mk/XXjiGri9y+8jtWYMu18JZsSaMuL0GA/U5af4bbziicRyk3vYVD55SRsi/Ibhzpx4g8R8SlqhUXpd/W/nedxdCnhPEpzU/oGf1A5UQ+pARqFNPCujTfUmhON2gHQc8a+tfJhQHIwzSrNQh/TqMTQG7fpYsbzcp51z+ak47KF8= Received: from CY5PR17CA0042.namprd17.prod.outlook.com (2603:10b6:930:12::29) by IA0PR12MB7627.namprd12.prod.outlook.com (2603:10b6:208:437::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.42; Fri, 13 Jun 2025 21:07:37 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:930:12:cafe::98) by CY5PR17CA0042.outlook.office365.com (2603:10b6:930:12::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Fri, 13 Jun 2025 21:07:37 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:35 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:30 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 15/32] x86/resctrl: Add data structures and definitions for ABMC assignment Date: Fri, 13 Jun 2025 16:04:59 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD3:EE_|IA0PR12MB7627:EE_ X-MS-Office365-Filtering-Correlation-Id: 29c77df8-0822-4c7e-068f-08ddaabe524c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|7416014|82310400026|13003099007|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?B?c3dSZDIrVUVaT1JVVWRVR2ljV2RwOFJmS0NyeEdMdzcwY3RoSnpZT1o4L2ow?= =?utf-8?B?SlNhT3I0MWpiM00xOEEyL1pXNjlIRzJFcDVrbHRKc00rQmNldDZIMVZTQW1J?= =?utf-8?B?bXpsTlROSHVkT0hQNjdrYlhoWDdoaGVXTUJGa2tNbWJnTXR1MW4zaVlpRGx5?= =?utf-8?B?cVhveHVEMVI0ZHhWRGN5elB2Ums5NFhralpYTEZkeG56eDR3MGxPMUtJdldy?= =?utf-8?B?eDBodXNXWEIwRkxWK0QxMTJ3dnkxRG83aXptVlJmYTZWY0E0ZlE2Nm0xVmsz?= =?utf-8?B?VGgvNkQrVVJUZUZWbzlLZWJtbjk4K1cvUk1LVFh6SEtRWUV4YWRlZnVDeFRh?= =?utf-8?B?MkJZNGExNlUzR2hQMGMxN052RWhPa3dXTnZpaXZpZStWMm03ejdaL3A3MmRj?= =?utf-8?B?UTBzMW9OaTNqVWhGSHk2V0pzZytSdGplMWdNc0U1Q0dQRDh2RGdyOEZ6Tnpl?= =?utf-8?B?M3U3RUhDelFvSjNodW1pcG1IdnI4WWlJaUpiU2tnVGswMGMwaVo4NlRXSWZy?= =?utf-8?B?ZVRJaVJVd045L3lIMzV2MG9OQXhobE9kdXg1TGdNRW9TN1NGWVl3aWI5SGg3?= =?utf-8?B?MTRnWTRTdmd1Z1NXR3JXVUgyb1AzQmYvOGwyS09GMGNQRUExQ0ZLYjBtRFJt?= =?utf-8?B?Nzd6ckdQcEl4VlR1ejJFNDVOaEx2aEhlR2Rjc05wYTFjZGgwUGtBamZRWUdu?= =?utf-8?B?RXEyd1QrT3UxZUt5aTJmUCtZM1N4aXp1Z2t4NHg3MGdRSHh6WnZWUEYyaU14?= =?utf-8?B?RG1LQy9zbXY1Ykt6K2ZpOHo2QkFlaE1hNnNOdlF2bGVCNCtidGFIRjNhdS91?= =?utf-8?B?V1NaL2JGb3pqYlFtUDg5eHB0RTV4MzVsVHc1WHZOakVNVnkzWlBreVZVTHhu?= =?utf-8?B?Zis1T3pRK3NRcHNJQzJ0WFE3eTdtSENIc3ZrdGx3bC8vdUJoaktoOC9aK01I?= =?utf-8?B?QjVIWG1RQkRxdVFGdHVmSW5Vd1Q4NXQ0ME5VczZkVjFjdFFlTVhjMmdDT0pv?= =?utf-8?B?ZjdmNDlzbktBdTduVTNGZ2J5SzJocGhQcUxicDBOeG8rbklBdmNJNmRzSlhG?= =?utf-8?B?WndTMjVMbzhuNmlGcVpwWnVrdnk2aXFneld6eXMzaG05RHprNlNOL0dIVkQ5?= =?utf-8?B?c0tlVWR1UWlMMVV0VjNEOGNKQ1pQZnpSWGNhWmcrTy9aTDBXRXdVdDV4TzY4?= =?utf-8?B?Ly9JWTNIMnAyRkZuaTdkZkhBdTJiWWJEaXRsNTR2R3ZUTVhRUXA1R0ZmcHFI?= =?utf-8?B?d05hNG5GandSbCt6K1Q5SHVQSk1iOHgzZWRxZE5pb0tqMTA4STR5NHh0L3RH?= =?utf-8?B?Q09XUkllOEV3a1ZFd0UxWG93Wnd5YjMxeUpzMHArWE9zUGZtT2cvMkxReTJm?= =?utf-8?B?anJHeWl3ajNoeVprY095bmdtcHdUUUZRY3RSaXM2WkxqWkNlbXE1R2l1S2hw?= =?utf-8?B?YTJoUm9yZ1h0a3ZuS3RzbDZDbnFlWUZCK2hITlg5cXRINGRPcFVFTEYwdStl?= =?utf-8?B?TkJwT1pOZVUyZGtJQzh6MHRLbjR5Z1dDT09LaXA4WGIrQkE2WmdaZ3VJMERT?= =?utf-8?B?ZnVRTVB4aURINUt5QWdLRTBUV1BmLzYwSUhYU2RkVnl2WUs4Ymh4MHh0S0ox?= =?utf-8?B?V0RFYVN6T0IwQW4xRkVDN0hXNHRFYk1BNzY1bmVtVkVYS05NRk1kQmVmbnJI?= =?utf-8?B?dElHQ3JZd0NLcXYrNXZqMGNEQmFpUXFxem1sZmxQK1NFMUlOVDBXdE1RSElH?= =?utf-8?B?SmFFRDBMVU8xcUVuZ3NWV1RxN2JNMWxzb1RXMkRyL3BUMDF2YjB2cmgzUHNp?= =?utf-8?B?aVF2YWRFS3lXV3Nrekp0M1g5Z3c0STluUFdoTjNWSXU1YnFRNlRBa3BKTHVp?= =?utf-8?B?YmlaK285SFgydjVJOGlJWU83aTlmSGU2ak5OYU5EWXg5RlBFVmprZUtSYlIr?= =?utf-8?B?Sk93MzNKTmp0anVmUDJTc0pTckdIbm1xL0YrNlpTQzJTUEdyamlpbHRRemtF?= =?utf-8?B?ZDcrY04waGwxQ2pZNlgvZERHZzlWNUo2VWVHZy9HY3BpMlZWNURqWlQxY1Nu?= =?utf-8?B?RXRheUFPME8xUWxHajFiUk5Xa1VPeWd1MWIwQT09?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026)(13003099007)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:35.6655 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 29c77df8-0822-4c7e-068f-08ddaabe524c 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7627 The ABMC feature allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. The ABMC feature implements an MSR L3_QOS_ABMC_CFG (C000_03FDh). ABMC counter assignment is done by setting the counter id, bandwidth source (RMID) and bandwidth configuration. Attempts to read or write the MSR when ABMC is not enabled will result in a #GP(0) exception. Introduce the data structures and definitions for MSR L3_QOS_ABMC_CFG (0xC000_03FDh): =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Bits Mnemonic Description Access Reset Type Value =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 63 CfgEn Configuration Enable R/W 0 62 CtrEn Enable/disable counting R/W 0 61:53 =E2=80=93 Reserved MBZ 0 52:48 CtrID Counter Identifier R/W 0 47 IsCOS BwSrc field is a CLOSID R/W 0 (not an RMID) 46:44 =E2=80=93 Reserved MBZ 0 43:32 BwSrc Bandwidth Source R/W 0 (RMID or CLOSID) 31:0 BwType Bandwidth configuration R/W 0 tracked by the CtrID =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The feature details are documented in the APM listed below [1]. [1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger --- v14: Removed BMEC reference internal.h. Updated the changelog and code documentation. v13: Removed the Reviewed-by tag as there is commit log change to remove BMEC reference. v12: No changes. v11: No changes. v10: No changes. v9: Removed the references of L3_QOS_ABMC_DSC. Text changes about configuration in kernel doc. v8: Update the configuration notes in kernel_doc. Few commit message update. v7: Removed the reference of L3_QOS_ABMC_DSC as it is not used anymore. Moved the configuration notes to kernel_doc. Adjusted the tabs for l3_qos_abmc_cfg and checkpatch seems happy. v6: Removed all the fs related changes. Added note on CfgEn,CtrEn. Removed the definitions which are not used. Removed cntr_id initialization. v5: Moved assignment flags here (path 10/19 of v4). Added MON_CNTR_UNSET definition to initialize cntr_id's. More details in commit log. Renamed few fields in l3_qos_abmc_cfg for readability. v4: Added more descriptions. Changed the name abmc_ctr_id to ctr_id. Added L3_QOS_ABMC_DSC. Used for reading the configuration. v3: No changes. v2: No changes. --- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 36 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index b92b04fa9888..7342ff03a5a0 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1215,6 +1215,7 @@ /* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200 #define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_L3_QOS_ABMC_CFG 0xc00003fd #define MSR_IA32_L3_QOS_EXT_CFG 0xc00003ff #define MSR_IA32_EVT_CFG_BASE 0xc0000400 =20 diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 1a4e96044aac..23c17ce172d3 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -165,6 +165,42 @@ union cpuid_0x10_x_edx { unsigned int full; }; =20 +/* + * ABMC counters are configured by writing to L3_QOS_ABMC_CFG. + * + * @bw_type : Event configuration that represent the memory + * transactions being tracked by the @cntr_id. + * @bw_src : Bandwidth source (RMID or CLOSID). + * @reserved1 : Reserved. + * @is_clos : @bw_src field is a CLOSID (not an RMID). + * @cntr_id : Counter identifier. + * @reserved : Reserved. + * @cntr_en : Counting enable bit. + * @cfg_en : Configuration enable bit. + * + * Configuration and counting: + * Counter can be configured across multiple writes to MSR. Configuration + * is applied only when @cfg_en =3D 1. Counter @cntr_id is reset when the + * configuration is applied. + * @cfg_en =3D 1, @cntr_en =3D 0 : Apply @cntr_id configuration but do not + * count events. + * @cfg_en =3D 1, @cntr_en =3D 1 : Apply @cntr_id configuration and start + * counting events. + */ +union l3_qos_abmc_cfg { + struct { + unsigned long bw_type :32, + bw_src :12, + reserved1: 3, + is_clos : 1, + cntr_id : 5, + reserved : 9, + cntr_en : 1, + cfg_en : 1; + } split; + unsigned long full; +}; + void rdt_ctrl_update(void *arg); =20 int rdt_get_mon_l3_config(struct rdt_resource *r); --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26F3727381C; Fri, 13 Jun 2025 21:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848880; cv=fail; b=e/QV2gbcvE20AJXV2S92lN4jDAu4PqWeb8j+wNIn+ig5LmNpJeEGVAjrPeIAek5nBfOCpW0rzGuH2DYSXrn2632xfBfx1no2VUOq/hQqkwl3pniL4KfCztontvsQzXpXzr9Mnf6ITl4Ow8gbMFAkajuDofHpeiDT0DHUIL3PL+0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848880; c=relaxed/simple; bh=5BfU9iDZwCYnFThbeRy8s0CXWAmyd9U56lkCWiPlbVM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=doFsPyVD+mwWmmoy3Vwkb6Oonz21xIIjCaUywXZpLxf0eP1KSd6xXW+8G2CVlk8FnXHpUlBi8hgOX9jqwwKZ4sd9uv9JimKGjs+HmodtRVm7x3BSUTrfYGiPJ3ZHjYolKVs0yaaenenCV+iA/FwJWd5rnz0vESsz8JOckGq8dzc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KJ3LFCN/; arc=fail smtp.client-ip=40.107.92.46 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) header.d=amd.com header.i=@amd.com header.b="KJ3LFCN/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mdNzjU9lyQwKIveV3K2wKVlU4M9DJWjlQDSLTSCP/RYvOc2pmx7JfBe8jea1C7DWGIXGBxSp8d40x7Zx3+KZB7h73mMOcMIHSC9L7E02xpmtS48ai4cLQokoH6Urwn0L9xx/e8IADQ/ZXgqT8ht0B28V/s45d/tE39Z4w+PHoP2lh1hAHKLhT26LmcufZSGfRDAd5EijpxE9ELBibgZYrDC1sIQeO1V2l6MaN23gWSFjLHEUUSfK6DWBUMw+hRBECIXj74zRxjn74G6lQ+K3FwqTr2cjsgiTaZ9g8xG5sqne99xAdwlDNuYUjzUYjkmnO/FNw6sxpZK09/6s1PQ0PA== 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=RR0oJZ6rUNt4Dy6jyVO/bBDv7d7klwtolNdhOELvpsc=; b=wsLyq8n8VyqCAIfOJfDEmUjMbUPAEAspb6+uIZZBII8yeFxTCNElYTvHqaP5OPjn5ic3wu4ucW5RLKAXPFep+tNfNEtamSM9D9GuGawX0YVsGbt0gEwidOHrAr9qS2mesltfLbHSL766dRMvw4U3pN+07Le6X3CzFGaS+NhzyaiAlPmC2M3Ab4wLuaNUQfNC8v9Y9tK3qP1NtNtDyRZxzUwa2zgs6KN6YBym7bz47kOUJNOmV2p57FdzNA1fshRGVoQJlTTTQZihjLG1DRkgOqBWTe4/WakO18Hy/QUy2exkNynokAcOldP6OSBzbLxInfslbvzRwNE8UqLPVK67BQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=RR0oJZ6rUNt4Dy6jyVO/bBDv7d7klwtolNdhOELvpsc=; b=KJ3LFCN/2+TlTR82RlZnjzkCH8RSqnwjJww0IEID4s2xGzoQ4aVytFVnWRMWFalUHRyeeORWIA/QYrBjTsq06wKGYuvZYBsk6vdIy4X+2KCEo2paGChVNnvoorSHpPYz5QtSkCy2ZmUvPsUXKfYi48WXW2Mga6QvyfUKDzBNTw0= Received: from DM6PR05CA0046.namprd05.prod.outlook.com (2603:10b6:5:335::15) by SA3PR12MB9198.namprd12.prod.outlook.com (2603:10b6:806:39f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:07:55 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335:cafe::59) by DM6PR05CA0046.outlook.office365.com (2603:10b6:5:335::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:07:54 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:54 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:38 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 16/32] x86,fs/resctrl: Introduce event configuration field in struct mon_evt Date: Fri, 13 Jun 2025 16:05:00 -0500 Message-ID: <1b9d6c39f654c2a4fe500d7e9be4a13221ac4910.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|SA3PR12MB9198:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c5464e9-3ff7-495d-c7fb-08ddaabe5db4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|13003099007|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BArEYXw5NorWnJYluK3QLrmomdC+FsTYD7zvw8qFP5KwGM6NoY6cBjVVX3lv?= =?us-ascii?Q?z0o+pYldhdMkL3PGdPIz+ZqavIkA3YEnFq1Bq+n03qEFv7DPJh/9tdLVIzAq?= =?us-ascii?Q?fN8m/aJO1TyHPtLSzmO47tdhioETk2IdTT9/Os4t449AhVEeV2L4upma2uxx?= =?us-ascii?Q?h/odGH5TwZHn9lHF+U8zN+WDjX/hpC5fxoinKUCW2yoW9eORfCvTAenIpaZ3?= =?us-ascii?Q?lrfGfPBb/ObIaGHtoyeYVdgTcRTrOSldjo0i92y+L28V1GARP7/4yWRSxzpW?= =?us-ascii?Q?An9S6/tKQRPPyoxgsRza24SJMWhwBdP3rlZ0qZERl8XeztetUV9cwdqqrTCQ?= =?us-ascii?Q?/4ahV01CGXhGNe5PG49JMipHB0o/lTChWhKVONLKbEyzOJTetyRBduZNWYzZ?= =?us-ascii?Q?XL8LiLT6E/psHeH7OA56cJ656Jc6i/78Gg8+NL5VEq6OBf5TXkJo8ocL94CT?= =?us-ascii?Q?8aJP94WMmFRP04KThmtkKI3X2BLpBckjtUbsL3cxriNBTmIg1Go7t7J6n+mB?= =?us-ascii?Q?dC+VXG6lvyq3ktnUYZJc/1EzfsiaWhHHKuKAu8k8kRCsZr9sq2EyaMO3pt63?= =?us-ascii?Q?nmWE+qPLP9yn36sCBURCXpCJe383UqF9rUw10BZ92m13x+rRA/TE78efbruE?= =?us-ascii?Q?nOK0JASka22N5xeBFxU5BvxT38yNvvmyo5E/TpcgnYaP/JGhOlqFr8Ysj9yV?= =?us-ascii?Q?Ny1NMpHRY5dO41pd4U7zNr/TAXn5j05gTGfmt4fS4SMoBNMXEb119mrRPWds?= =?us-ascii?Q?OZdksb8P9q/b3b+5qpKHV9IZaaKGQQEZB0c9mcPiysf2/04FxZABc0/I+mdX?= =?us-ascii?Q?wqruhWj2x5yyqTVllgAk4zs+wklbLpqo1jNYfhGAhGMsynNI6ChR2Cab0jxt?= =?us-ascii?Q?ddNnEoIozBitCXzuf+YURjl1MuoDvMRuuUxiIaXMuU2gQhBG1PgnFTxUhkIu?= =?us-ascii?Q?hIk4sE0lCdqDIAvjKWUFOn2Ael2Wlh8hZvYsX+XhSeZbvTeFtCPXtrvr2bVg?= =?us-ascii?Q?eJYMplYieCUlZuk2mtF63D3600iPrbMsdeBJj+QTqmbHEmanZkzkil+0GDE0?= =?us-ascii?Q?CFkz24SAvYgqu24Z3tnKdX8jUwtqh536WK+B+B6vIEdkrbxrOwB202zk0FQy?= =?us-ascii?Q?OAsELoB8MmJqSLMsXK7aNh+NehYCqNrCVZuOj1PSjuLalSILTUpaT1Fsh9dV?= =?us-ascii?Q?6Qh2xMr6QL10ibaFRnhsyW0446KG+ns9YfdyEZjZzx7+HiEfcT4r14POolBD?= =?us-ascii?Q?3BMAMPwmtW8H2oHmZ2hAiPPu3xcHN1xYw6jPJwAF1SjtsRO3hwNEn1oCWu60?= =?us-ascii?Q?7oMm2jSeYOlOCPpOVRGMSQR+mP4LUKn7Q3qUOzI8IpMl0N9R5tcxPLG81yCK?= =?us-ascii?Q?MAxqg7wrpz32Nz//OL5NJLnhpUFPFdB3lTzj/m3o/H3FjcxOtsDtjN8FUe5C?= =?us-ascii?Q?Gdr7uioV8AgqFEDzuWse1fH1HCkvuvaexwAr4NTflvHQAdomCdAne5D3ogUv?= =?us-ascii?Q?bBeNt0Z9UWE6Gv8=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(13003099007)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:54.8116 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c5464e9-3ff7-495d-c7fb-08ddaabe5db4 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9198 Content-Type: text/plain; charset="utf-8" When supported, mbm_assign_mode allows the user to configure events to track specific types of memory transactions. Introduce the evt_cfg field in struct mon_evt to define the type of memory transactions tracked by a monitoring event. Also add helper functions to get and set the evt_cfg value. Signed-off-by: Babu Moger --- v14: This is updated patch from previous patch. https://lore.kernel.org/lkml/95b7f4e9d72773e8fda327fc80b429646efc3a8a.= 1747349530.git.babu.moger@amd.com/ Removed mbm_mode as it is not required anymore. Added resctrl_get_mon_evt_cfg() and resctrl_set_mon_evt_cfg(). v13: New patch to handle different event configuration types with mbm_cntr_assign mode. --- arch/x86/kernel/cpu/resctrl/core.c | 4 ++++ fs/resctrl/internal.h | 4 ++++ fs/resctrl/monitor.c | 10 ++++++++++ include/linux/resctrl.h | 3 +++ 4 files changed, 21 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 01b210febc7d..1df171d04bea 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -875,10 +875,14 @@ static __init bool get_rdt_mon_resources(void) } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) || rdt_cpu_has(X86_FEATURE_ABM= C)) { resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID); + resctrl_set_mon_evt_cfg(QOS_L3_MBM_TOTAL_EVENT_ID, MAX_EVT_CONFIG_BITS); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL) || rdt_cpu_has(X86_FEATURE_ABM= C)) { resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID); + resctrl_set_mon_evt_cfg(QOS_L3_MBM_LOCAL_EVENT_ID, + READS_TO_LOCAL_MEM | READS_TO_LOCAL_S_MEM | + NON_TEMP_WRITE_TO_LOCAL_MEM); ret =3D true; } =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 20e2c45cea64..71059c2cda16 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -56,6 +56,9 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) * @evtid: event id * @rid: index of the resource for this event * @name: name of the event + * @@evt_cfg: Event configuration value that represents the + * memory transactions (e.g., READS_TO_LOCAL_MEM, + * READS_TO_REMOTE_MEM) being tracked by @evtid. * @configurable: true if the event is configurable * @enabled: true if the event is enabled */ @@ -63,6 +66,7 @@ struct mon_evt { enum resctrl_event_id evtid; enum resctrl_res_level rid; char *name; + u32 evt_cfg; bool configurable; bool enabled; }; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 2893da994f3c..3e1a8239b0d3 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -884,6 +884,16 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_i= d eventid) mon_event_all[eventid].enabled; } =20 +u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id evtid) +{ + return mon_event_all[evtid].evt_cfg; +} + +void resctrl_set_mon_evt_cfg(enum resctrl_event_id evtid, u32 evt_cfg) +{ + mon_event_all[evtid].evt_cfg =3D evt_cfg; +} + /** * resctrl_mon_resource_init() - Initialise global monitoring structures. * diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 468a4ebabc64..a58dd40b7246 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -413,6 +413,9 @@ static inline bool resctrl_is_mbm_event(enum resctrl_ev= ent_id eventid) eventid <=3D QOS_L3_MBM_LOCAL_EVENT_ID); } =20 +u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id eventid); +void resctrl_set_mon_evt_cfg(enum resctrl_event_id eventid, u32 evt_cfg); + #define for_each_mbm_event_id(eventid) \ for (eventid =3D QOS_L3_MBM_TOTAL_EVENT_ID; \ eventid <=3D QOS_L3_MBM_LOCAL_EVENT_ID; eventid++) --=20 2.34.1 From nobody Fri Oct 10 09:14:55 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2057.outbound.protection.outlook.com [40.107.236.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 781B527146E; Fri, 13 Jun 2025 21:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848875; cv=fail; b=kV7JWa/23k5Kny95NhP3ZYBogiURNo8++JQ9IBtjUlNPRNB2wyTB5tlqFDGaq2OOa6ffwA8bTIV1rHbuk/7aDvkmLD0w7WN366FiNfnElL0375dDOySLbQSu4bNyTtZ8Z6vDV1nZqdIgmFon16v3NhovueUpWdqb4m+oCCkw6Og= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848875; c=relaxed/simple; bh=vT+2G5M+CJ/8Lb64LuCeVUoQNWyNEkOzAvpS+x4OXU8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uMIYZfSh0lOIMsudeV9beqde/7NFKqzRTs3Y3pJKaPiBDoRhZ4HD+5Qig+lMH95gnEZGl9sYRY0JZTVKQLrZntjYp/MNyAGaj1RFOYJgjchYpWKu8Yf9r8H8n8dvWZlb9NIOf/thjHl1W63QP2GLb2c81OFMUJdaT19ONi/PvA0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=XOKRxQ5j; arc=fail smtp.client-ip=40.107.236.57 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) header.d=amd.com header.i=@amd.com header.b="XOKRxQ5j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t0i+1ecg3BZ7P1ZlNG6C8ivigi7fUpRbBwhVg0L8AHOlddQLPOOhZew6J4waAFIfexy3xujVtuyTyW1yYZQHKNtlrItU0VjWIP470m59b8ZI6syGly8fBqz4ja7jopEpF+9LnUAiEUvP4rTDGRqoRjklYjO3UMuh9raIEaKHTAUDG2WvBBusY9qW5aHAoQIUezUNNg11J/51meYWdvrxFJMjabWbCnPyM4cJq0/6QoqtSL+54vNkfs+RN0DMhrCAWLOmDw7gOHlwfvfEqxYRGjyEW+7AH6Ms1t8TAEUqNHXucx2Yw+ckz/TbwLHEw7yKOAcRXDh2KchAbB4NnspIxA== 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=eQCk2tJG1DkrCIWt2s4kOJxkGXDEgZithkT92CTR1gc=; b=bF1ujndU1CRSRNcfgqTkXnLANwhcq3M/W6pcZGKcCtaFtO3+P/hJ4s+g6fMtRYCF60kpPBQmzrRjXCx0XnJXGJXNaMXiOeeRKGmMDAlWfAsMlBdh6IueKEnQim8ZhAWhI2uj/70bvdpNCIhhgr3/s6apEmbZKwKVgO3ONOdktI0qMU+BEHUO++ji98lFO+dnSLDkZHAeVl9DrUlrMWvc7HNtne/goavT0AHvB5ZQfHLjmjiti5mhLtrwgqnR0btBz4TN+Uojy4yOVSken9P0w3LwDrL6+n06Vks2dVLIRUkgkujL0ZTvvN5n6ESx3hipJIL7OnGST+e+I1T1ebDlHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=eQCk2tJG1DkrCIWt2s4kOJxkGXDEgZithkT92CTR1gc=; b=XOKRxQ5jkbljYFx/M2FPfSVs0xU25XVPtZvUXdOdbks3c0HznMYL4vRhhwFqnFTsWDTUjvlmOgOaB0OykZZb2A7T8EwcbEAG/JDsz2DoaEgCPAympFlYLr1iq1+yW185mFqVm6H+HUeC08ouE8nmyiVohhSslL8OVwGM6gx5AOc= Received: from CYZPR17CA0001.namprd17.prod.outlook.com (2603:10b6:930:8c::27) by PH0PR12MB8125.namprd12.prod.outlook.com (2603:10b6:510:293::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.40; Fri, 13 Jun 2025 21:07:47 +0000 Received: from CY4PEPF0000EDD4.namprd03.prod.outlook.com (2603:10b6:930:8c:cafe::31) by CYZPR17CA0001.outlook.office365.com (2603:10b6:930:8c::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.25 via Frontend Transport; Fri, 13 Jun 2025 21:07:47 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD4.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:47 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:45 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 17/32] x86/resctrl: Implement resctrl_arch_config_cntr() to assign a counter with ABMC Date: Fri, 13 Jun 2025 16:05:01 -0500 Message-ID: <72b62da44d72938a33b58fe3e853da2e41dfd67f.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD4:EE_|PH0PR12MB8125:EE_ X-MS-Office365-Filtering-Correlation-Id: 2674f935-68f9-4b98-577f-08ddaabe5978 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mJX5WvIyVaoPySypmjo8BbQiQS1LFId1zNdrlHKlW5jf/+GCnmUYd4I1ZLoF?= =?us-ascii?Q?UGIX5khBTIyIIDxM73vZbFp3mhTw2zHyTIDp+F8UPN2lPaGxwu2RfnOKmmCV?= =?us-ascii?Q?O9r02jJ/eZUOHJSjofzT+weKLyKGASHMOO3buK9UGS/COn9oIz4tFTDcWkf7?= =?us-ascii?Q?GHiAOu5FJypZX+roQy12ixqRCRxoTHJaOQZ4OfRuFbupve2U23RXCZMzFuyi?= =?us-ascii?Q?DJcGxT+r7zqsFltaohF1/Udd+8WJfzeIKu8suWhg67YBTwljPPsLJfbNG/uz?= =?us-ascii?Q?PQPXJyOyKCnU82wo5Bn+b/8rl4vXshfh0rjimvsjV3UOK7UhI+3HkfoGD7fw?= =?us-ascii?Q?VuOjYUPecnAGnU+QHlq5Xljfxsk2rsGvZ8Nv9oC0Muod9fmGTPxAnoMz+Tpm?= =?us-ascii?Q?kf/utUJ973yu2Y4eLRsGNa+be960VzfUrfZ4TkV625grxw06/0fGY3Ku6+x4?= =?us-ascii?Q?dEk5ICPGLUv4j7jyjc7MAUG41MB44nAeE55I+zPqBHNaWEKs8uMvZg9+Zz13?= =?us-ascii?Q?KrPDE9vpAUiXQFmF7FDLSCntXa7UyrKr1JTFa8AWUuRuaI5NQnkPd/z8PAQ4?= =?us-ascii?Q?0XAyJMbDCjHGHJRS+agnvGyK9NA9YIDXPHLGFtXIXlGWB2za4TdVPIAC0Qab?= =?us-ascii?Q?SYdz6G5yA7SOBUOAyz3r9T6ngigahzze0oMgvJqkiGZnNUVQCYUbz2AAVcFq?= =?us-ascii?Q?QEstNPtzH1sWFSA6HiyQMQrN29Gsu6sdk3KUxxL8vIhkd1ekyulG/ez6Y4JN?= =?us-ascii?Q?29hGuBmFAidn5rg2gJv9JP2vfGIU/vKOLUW55R2lVBQW3n5XvYb7KtyfdXzu?= =?us-ascii?Q?4hERbBOr4CwRhGsm5jpNcQaerc4HSL3YTBLiZnCCJIPCfMqcE0g4pHgmdMYS?= =?us-ascii?Q?kHtnz+Kdl0pLRHwmkXE9qTO3Rhp+JdynPMQxzaTNDSxfIvvIXj1Z5hQIkZG2?= =?us-ascii?Q?9EZyn9cjuPdDmJJeGW7QxL0pZTzELUG3HM6dlH2mz11w0qzIroC/LcWfsso2?= =?us-ascii?Q?IQQiRkhrwpitXbySrMcPa93ZGQ95LcedSRtjVghgCjVaEEzl6+cgUc1ICxGy?= =?us-ascii?Q?PSSUfIWdeFKa1wX8/EubB6sTo8t1X02TxBMG1Dl4ngwT7w+XeMcLaa5yXvYe?= =?us-ascii?Q?/HKBisMygY/hBuJWSUoGjKIE0ye8n4sMfXR4SZItG9UXApof7HPQ5ubtoZ4O?= =?us-ascii?Q?ZcOnmyNFbJrDphrS0CKioxkyYh7S3tkgcqMl+qUuCA0cdV4Z0HEmxyrtu8hI?= =?us-ascii?Q?mWzv9tXbI2UlEbxcnmigZ9zPHLpmPxUhETxsFPD2CfiHlpTa3TtGwpLecZk7?= =?us-ascii?Q?dtogA/UZd+m5I8LOK6Pu7cy6BLxqyI9yQ+kV9FZdJGwd7CM+Vpqb84IGpA21?= =?us-ascii?Q?vjXY7Gg94+o6bhXLbeq5JsLS60lVccRtyWrrZP1p01zpMRoKPtEzwVu0e+E7?= =?us-ascii?Q?kVZZWiVTzCe5qXmP//UjgYM9juS5XXrTO0DlW7QFDEf5tp76VYzYPMcLtYIh?= =?us-ascii?Q?ynxqb39qEPTb0kAAypWx2/3y4P0ZNI0eTADwESh3Bor+Llnl1MB5jsHS6Q?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(921020)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:47.7008 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2674f935-68f9-4b98-577f-08ddaabe5978 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8125 Content-Type: text/plain; charset="utf-8" The ABMC feature allows users to assign a hardware counter ID to an RMID, event pair and monitor bandwidth usage as long as it is assigned. The hardware continues to track the assigned counter until it is explicitly unassigned by the user. Implement an architecture-specific handler to assign and unassign the counter. Configure counters by writing to the L3_QOS_ABMC_CFG MSR, specifying the counter ID, bandwidth source (RMID), and event configuration. The feature details are documented in the APM listed below [1]. [1] AMD64 Architecture Programmer's Manual Volume 2: System Programming Publication # 24593 Revision 3.41 section 19.3.3.3 Assignable Bandwidth Monitoring (ABMC). Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger --- v14: Removed evt_cfg parameter in resctrl_arch_config_cntr(). Get evt_cfg only when assign is required. Minor update to changelog. v13: Moved resctrl_arch_config_cntr() prototype to include/linux/resctrl.h. Changed resctrl_arch_config_cntr() to retun void from int. Updated the kernal doc for the prototype. Updated the code comment. 12: Added the check to reset the architecture-specific state only when assign is requested. Added evt_cfg as the parameter as the user will be passing the event configuration from /info/L3_MON/event_configs/. v11: Moved resctrl_arch_assign_cntr() and resctrl_abmc_config_one_amd() to monitor.c. Added the code to reset the arch state in resctrl_arch_assign_cntr(). Also removed resctrl_arch_reset_rmid() inside IPI as the counters are reset from the callers. Re-wrote commit message. v10: Added call resctrl_arch_reset_rmid() to reset the RMID in the domain inside IPI call. SMP and non-SMP call support is not required in resctrl_arch_config_cn= tr with new domain specific assign approach/data structure. Commit message update. v9: Removed the code to reset the architectural state. It will done in another patch. v8: Rename resctrl_arch_assign_cntr to resctrl_arch_config_cntr. v7: Separated arch and fs functions. This patch only has arch implementatio= n. Added struct rdt_resource to the interface resctrl_arch_assign_cntr. Rename rdtgroup_abmc_cfg() to resctrl_abmc_config_one_amd(). v6: Removed mbm_cntr_alloc() from this patch to keep fs and arch code separate. Added code to update the counter assignment at domain level. v5: Few name changes to match cntr_id. Changed the function names to rdtgroup_assign_cntr resctr_arch_assign_cntr More comments on commit log. Added function summary. v4: Commit message update. User bitmap APIs where applicable. Changed the interfaces considering MPAM(arm). Added domain specific assignment. v3: Removed the static from the prototype of rdtgroup_assign_abmc. The function is not called directly from user anymore. These changes are related to global assignment interface. v2: Minor text changes in commit message. --- arch/x86/kernel/cpu/resctrl/monitor.c | 38 +++++++++++++++++++++++++++ include/linux/resctrl.h | 19 ++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 0ad9c731c13e..6b0ea4b17c7a 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -444,3 +444,41 @@ bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_r= esource *r) { return resctrl_to_arch_res(r)->mbm_cntr_assign_enabled; } + +static void resctrl_abmc_config_one_amd(void *info) +{ + union l3_qos_abmc_cfg *abmc_cfg =3D info; + + wrmsrl(MSR_IA32_L3_QOS_ABMC_CFG, abmc_cfg->full); +} + +/* + * Send an IPI to the domain to assign the counter to RMID, event pair. + */ +void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domai= n *d, + enum resctrl_event_id evtid, u32 rmid, u32 closid, + u32 cntr_id, bool assign) +{ + struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + union l3_qos_abmc_cfg abmc_cfg =3D { 0 }; + struct arch_mbm_state *am; + + abmc_cfg.split.cfg_en =3D 1; + abmc_cfg.split.cntr_en =3D assign ? 1 : 0; + abmc_cfg.split.cntr_id =3D cntr_id; + abmc_cfg.split.bw_src =3D rmid; + if (assign) + abmc_cfg.split.bw_type =3D resctrl_get_mon_evt_cfg(evtid); + + smp_call_function_any(&d->hdr.cpu_mask, resctrl_abmc_config_one_amd, &abm= c_cfg, 1); + + /* + * The hardware counter is reset (because cfg_en =3D=3D 1) so there is no + * need to record initial non-zero counts. + */ + if (assign) { + am =3D get_arch_mbm_state(hw_dom, rmid, evtid); + if (am) + memset(am, 0, sizeof(*am)); + } +} diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index a58dd40b7246..1539d1faa1a1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -594,6 +594,25 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *= r, struct rdt_mon_domain * */ void resctrl_arch_reset_all_ctrls(struct rdt_resource *r); =20 +/** + * resctrl_arch_config_cntr() - Configure the counter with its new RMID + * and event details. + * @r: Resource structure. + * @d: The domain in which the counter ID is to be configured. + * @evtid: Monitoring event type (e.g., QOS_L3_MBM_TOTAL_EVENT_ID + * or QOS_L3_MBM_LOCAL_EVENT_ID). + * @rmid: RMID. + * @closid: CLOSID. + * @cntr_id: Counter ID to configure. + * @assign: True to assign the counter, false to unassign + * the counter. + * + * This can be called from any CPU. + */ +void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_mon_domai= n *d, + enum resctrl_event_id evtid, u32 rmid, u32 closid, + u32 cntr_id, bool assign); + extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; =20 --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2087.outbound.protection.outlook.com [40.107.236.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2835273D9D; Fri, 13 Jun 2025 21:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848884; cv=fail; b=gFQCTvPsSpGkDpISJbdzJT/HYtiVq8AMR/WWFGg/cnE4NLVQocWjZ+oaneLo5au7Wss/I12AinyyZr4cfUDWq/fDlygzALKijagmbHawHpNJy1DJ7x5f4Y2ZDgxFo9WZ9KrshFAhNzbeosSLvEkyJZLPAS+bS4Sf5IiBweK372w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848884; c=relaxed/simple; bh=CFZZ4Y+8y9Mcy7qyY1/na5fg+RZlOVl3ebT+KDT05iI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IXkWY44P1t3+dvH7w471IkMW33Z5yzoeUjRMN+M2Q7rsnnonAXvOUHVQFZmVl8KsGP8Iyk+sS4ITGQIceRU98V/3pDorv0kLL5eEwyr4Zp4pNOP8+LFxUfrIY0IsApLpL0YcGwhnj78ldSDAYeuCMCd7Kn1N7ebuaAI1oOvqdg4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ld8bm178; arc=fail smtp.client-ip=40.107.236.87 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) header.d=amd.com header.i=@amd.com header.b="ld8bm178" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AUsntiNDogxfuumL5MZqNdarV7wVI5BPLk7JkJgREAKaM02BbBxH+AvGNcjsLyWzJm/PAIuxrKNuu7Ps1Pamthlh3u5Ceo2cbjb74VE5PyLXa2E+PahS5ctfmw9lP/HI7U9FNI/+uMchcNWVOXCYcPke4MDiAehD+BjhGWjdACpLjqs3Xo5YHtqOxNzZjLSzSqotgssgpQffyrdW98uWqjRJyu0Fp3jHYhELcIEr79zjiZkyH9vJ6l+ORX5IOTBvueCKTYlj5UYO9oldLNtozFKftz2aMKmRaumisO+fVi2xDvNONj0466rAobrD7EqrODHCufJgEfd1poybhH07jg== 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=QXYD/H8mcF6+k5rhW9/p4qVdw+xoTCeG5UTEQ7KLbS0=; b=V8zpqhnat3GyLIv53k8rUSAlmh/l0Cj9rO1OA4QMSRAiA4PxPaxmVUFXFOV82Lj7pGhgUKQT/OG8MahvbNh45qbeDnm6ya8L7s6GqY3i90skwRGnUHPa2euPU5fSmPmf6EkzAH61qUoNWcyn/g8bVfpp3wzpRSRuD1/1BUie7+u9ggCzLTJlE5fMn97eVKK+gZ3UVriHZ4wvggA0fV4qhSootszknf9t27SFpN6nAlsKU68fsaYtX8WgBr8ErdvPhxaqzlO/6jsQOLjSswzqtN+LCd3kgn7IHDGCnGF8A5PzOy7CyfvQJ4jxwaO6Rsr7Q4FAlgsOy+cv8/IbZ4g4Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=QXYD/H8mcF6+k5rhW9/p4qVdw+xoTCeG5UTEQ7KLbS0=; b=ld8bm178nbl9BVUlxTzz9tcMtbRpwnreCGhMzIOg2VCBKivYWatFdlQ9RXHDolmKPm6f1RoVt1m+VO38BeUh2SDVxiOT3V17NslL9ZLrq8zBzWqlvT8oFjGZa/B9QasQWRsH92QqIpqIU+NKGBHiaoRiYTB8YfOc6Gc/+a2lTUQ= Received: from DM6PR05CA0058.namprd05.prod.outlook.com (2603:10b6:5:335::27) by DS0PR12MB8320.namprd12.prod.outlook.com (2603:10b6:8:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.18; Fri, 13 Jun 2025 21:07:55 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335::4) by DM6PR05CA0058.outlook.office365.com (2603:10b6:5:335::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:07:55 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:07:55 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:07:53 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 18/32] fs/resctrl: Add the functionality to assign MBM events Date: Fri, 13 Jun 2025 16:05:02 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|DS0PR12MB8320:EE_ X-MS-Office365-Filtering-Correlation-Id: 6559eaef-62cc-4102-e651-08ddaabe5e22 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?u516bxvRaVg8lcZJ1wL28QEDmlHwVgYpkyMW6bqKC0ryrG48Yj64qIRaq2aQ?= =?us-ascii?Q?f2XLnD4OteG0zdLG7IvmwNj1CRsxB1/w6SxpWBQJGjEOFBkoxZpJP7kHb9f3?= =?us-ascii?Q?IQlgAd+MnxRisMWw/eb72UOlFXdt1Q8cimy3o/81tvHtaNY00x88iFS32vXZ?= =?us-ascii?Q?ronh7nUrzwy7t8uqbATtuQ18sHQium31oOPkzlq6xIVTECUztcnOMEqxuLl0?= =?us-ascii?Q?I/kih+aYYj3EH79pyymIi3YjXxhgj4x4CIwgFqGscnTfAczu3/HvHkZe4645?= =?us-ascii?Q?7F1gGmKbLXE1kNukYl0oZ1+F3hONrWOtOpCk5UWXwSipluwHTwAapjYETBZh?= =?us-ascii?Q?YtcjnoCYrCpkCoaUWmhff3wvUsnQt7Nd5paSMnUlV+BvmWkm7wlAbFh4QP3C?= =?us-ascii?Q?UsM9WyfmNjGcK5ioDX00tLfkNMu72aZanTuz/O6yf7A5R1JIAX8o0O2iO3Np?= =?us-ascii?Q?xJ5s1mxD0RriaylrJXNH2HMmdKxeqBGtD+F63F7i0OsCd50HOrEFMd9+75Vw?= =?us-ascii?Q?IZJLWYusTieIEYg8QZIHTbJ72T7wPFs/EiP70ALSgscB+ndE5DyMyf4oiiO+?= =?us-ascii?Q?J+F1X9O7Y8uioXHjKjknHFLCWLNdIbcSqoeAGXifhzS7sEW8CBwZZta4W19g?= =?us-ascii?Q?nuaUs7vD4VkheX8Szcj30vtKhO8knsjkK8PM41g14RkB8aLqIebVHpnVoZWN?= =?us-ascii?Q?/343PEXDN85sb5NXDqLNpn3Yy4r+BboBav0ZNgNg3ZK5F2d7y6AvlIfBbC/2?= =?us-ascii?Q?b5d9bkLFTKs2L08/mZo2QZeDrxC/V7aRqmvnqbs1txbIPSlmM2R7EcGSlCzP?= =?us-ascii?Q?7RBrEtnnCwDsc2tis4nq+D7fauIz3Z8fabDuiO9eyUFKX4i7KYkj2kHG3Duw?= =?us-ascii?Q?OJRutHoKKfivEL4tdKRWORh/miL4GOCt/Hwy8p/W+46xr/DL35xnMdeKvOZZ?= =?us-ascii?Q?4QDHPLvgxm4a1SEfNGnluid5b4OIropolbBzNAsPOxcGdrtgBQ4vzYjub1Sj?= =?us-ascii?Q?ohH8B4lck45oCof/5s9KUo9FjySmaaV+vo1pPE47CbbYgA9cru1GA6pSUAVT?= =?us-ascii?Q?0OKcF3pwBjOgchiB22gly3VAiEdJqB7U6rj0nq6Q0c+ZS22+qi+aoMrQVxgP?= =?us-ascii?Q?HluiakLURU3OKwAKWNixNLHIuuk4QQWy3eUn4gpoUj1WGFmivT1gyOssLXGs?= =?us-ascii?Q?cqCgQF4f/8/UYzQLGH5tWyDxBtsAfBSChHFbNiiMgmI3h4qm6Au42uPfsvq/?= =?us-ascii?Q?kZ8Eeqltdnbv2OhmITU+rj4ihKdHLFoMe7tEXcSnj9mf8BMTsVfpSGcrHAMN?= =?us-ascii?Q?JJFEK/0VIcFhauS/7fWMlafAcz7L+1JdaVtujdxvWv4/JUVaxlUgD7gARMVW?= =?us-ascii?Q?Zq+db+R6Q6vJBglB9uNTrOsBUY7E28jIsRpJvT3VxsbQwoITgq4zwrCwPmNV?= =?us-ascii?Q?/WlUGFygnAQ1t+szB3lVJzXcgpsGnhSRRgujtCOgKleh+U4f5GwvsdIj0pDm?= =?us-ascii?Q?j2tqzYtwYA27vM80200wNaHxEHFimsdhvfotLS9G9/4yUcAireGMdhKXo5Mv?= =?us-ascii?Q?0OJHlPrXNb1fTr72szo=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:07:55.5328 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6559eaef-62cc-4102-e651-08ddaabe5e22 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8320 Content-Type: text/plain; charset="utf-8" When supported "mbm_event" mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned. Add the functionality to allocate and assign a counter ID to an RMID, event pair in the domain. If all the counters are in use, kernel will log the error message "Unable to allocate counter in domain" in /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested. Exit on the first failure when assigning counters across all the domains. Signed-off-by: Babu Moger --- v14: Updated the changelog little bit. Updated the code documentation for mbm_cntr_alloc() and mbm_cntr_get(= ). Passed struct mon_evt to resctrl_assign_cntr_event() that way to avoid back and forth calls to get event details. Updated the code documentation about the failure when counters are exh= asted. Changed subject line to fs/resctrl. v13: Updated changelog. Changed resctrl_arch_config_cntr() to return void instead of int. Just passing evtid is to resctrl_alloc_config_cntr() and resctrl_assign_cntr_event(). Event configuration value can be easily obtained from mon_evt list. Introduced new function mbm_get_mon_event() to get event configuration= value. Added prototype descriptions to mbm_cntr_get() and mbm_cntr_alloc(). Resolved conflicts caused by the recent FS/ARCH code restructure. The files monitor.c/rdtgroup.c have been split between FS and ARCH dir= ectories. v12: Fixed typo in the subjest line. Replaced several counters with "num_mbm_cntrs" counters. Changed the check in resctrl_alloc_config_cntr() to reduce the indenta= tion. Fixed the handling error on first failure. Added domain id and event id on failure. Fixed the return error override. Added new parameter event configuration (evt_cfg) to get the event con= figuration from user space. v11: Patch changed again quite a bit. Moved the functions to monitor.c. Renamed rdtgroup_assign_cntr_event() to resctrl_assign_cntr_event(). Refactored the resctrl_assign_cntr_event(). Added functionality to exit on the first error during assignment. Simplified mbm_cntr_free(). Removed the function mbm_cntr_assigned(). Will be using mbm_cntr_get()= to figure out if the counter is assigned or not. Updated commit message and code comments. v10: Patch changed completely. Counters are managed at the domain based on the discussion. https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5A= FgD9cQDCUg@mail.gmail.com/ Reset non-architectural MBM state. Commit message update. v9: Introduced new function resctrl_config_cntr to assign the counter, upda= te the bitmap and reset the architectural state. Taken care of error handling(freeing the counter) when assignment fails. Moved mbm_cntr_assigned_to_domain here as it used in this patch. Minor text changes. v8: Renamed rdtgroup_assign_cntr() to rdtgroup_assign_cntr_event(). Added the code to return the error if rdtgroup_assign_cntr_event fails. Moved definition of MBM_EVENT_ARRAY_INDEX to resctrl/internal.h. Updated typo in the comments. v7: New patch. Moved all the FS code here. Merged rdtgroup_assign_cntr and rdtgroup_alloc_cntr. Adde new #define MBM_EVENT_ARRAY_INDEX. --- fs/resctrl/internal.h | 3 + fs/resctrl/monitor.c | 134 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 71059c2cda16..0767a1c46f26 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -386,6 +386,9 @@ bool closid_allocated(unsigned int closid); =20 int resctrl_find_cleanest_closid(void); =20 +int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domai= n *d, + struct rdtgroup *rdtgrp, struct mon_evt *mevt); + #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 3e1a8239b0d3..38800fe45931 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -950,3 +950,137 @@ void resctrl_mon_resource_exit(void) =20 dom_data_exit(r); } + +/** + * resctrl_config_cntr() - Configure the counter ID for the event, RMID pa= ir in + * the domain. + * + * Assign the counter if @assign is true else unassign the counter. Reset = the + * associated non-architectural state. + */ +static void resctrl_config_cntr(struct rdt_resource *r, struct rdt_mon_dom= ain *d, + enum resctrl_event_id evtid, u32 rmid, u32 closid, + u32 cntr_id, bool assign) +{ + struct mbm_state *m; + + resctrl_arch_config_cntr(r, d, evtid, rmid, closid, cntr_id, assign); + + m =3D get_mbm_state(d, closid, rmid, evtid); + if (m) + memset(m, 0, sizeof(struct mbm_state)); +} + +/** + * mbm_cntr_get() - Return the counter ID for the matching @evtid and @rdt= grp. + * + * Return: + * Valid counter ID on success, or -ENOENT on failure. + */ +static int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d, + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) +{ + int cntr_id; + + if (!resctrl_is_mbm_event(evtid)) + return -ENOENT; + + for (cntr_id =3D 0; cntr_id < r->mon.num_mbm_cntrs; cntr_id++) { + if (d->cntr_cfg[cntr_id].rdtgrp =3D=3D rdtgrp && + d->cntr_cfg[cntr_id].evtid =3D=3D evtid) + return cntr_id; + } + + return -ENOENT; +} + +/** + * mbm_cntr_alloc() - Initilialize and return a new counter ID in the doma= in @d. + * + * Return: + * Valid counter ID on success, or -ENOSPC on failure. + */ +static int mbm_cntr_alloc(struct rdt_resource *r, struct rdt_mon_domain *d, + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) +{ + int cntr_id; + + for (cntr_id =3D 0; cntr_id < r->mon.num_mbm_cntrs; cntr_id++) { + if (!d->cntr_cfg[cntr_id].rdtgrp) { + d->cntr_cfg[cntr_id].rdtgrp =3D rdtgrp; + d->cntr_cfg[cntr_id].evtid =3D evtid; + return cntr_id; + } + } + + return -ENOSPC; +} + +/** + * resctrl_alloc_config_cntr() - Allocate a counter ID and configure it fo= r the + * event pointed to by @mevt and the resctrl group @rdtgrp within the doma= in @d. + * + * Return: + * 0 on success, or a non-zero value on failure. + */ +static int resctrl_alloc_config_cntr(struct rdt_resource *r, struct rdt_mo= n_domain *d, + struct rdtgroup *rdtgrp, struct mon_evt *mevt) +{ + int cntr_id; + + /* No need to allocate a new counter if it is already assigned */ + cntr_id =3D mbm_cntr_get(r, d, rdtgrp, mevt->evtid); + if (cntr_id >=3D 0) + goto cntr_configure; + + cntr_id =3D mbm_cntr_alloc(r, d, rdtgrp, mevt->evtid); + if (cntr_id < 0) { + rdt_last_cmd_printf("Unable to allocate counter in domain %d\n", + d->hdr.id); + return cntr_id; + } + +cntr_configure: + /* + * Skip reconfiguration if the event setup is current; otherwise, + * update and apply the new configuration to the domain. + */ + if (mevt->evt_cfg !=3D d->cntr_cfg[cntr_id].evt_cfg) { + d->cntr_cfg[cntr_id].evt_cfg =3D mevt->evt_cfg; + resctrl_config_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, + rdtgrp->closid, cntr_id, true); + } + + return 0; +} + +/** + * resctrl_assign_cntr_event() - Assign a hardware counter for the event in + * @mevt to the resctrl group @rdtgrp. Assign counters to all domains if @= d is + * NULL; otherwise, assign the counter to the specified domain @d. + * + * If all counters in a domain are already in use, resctrl_alloc_config_cn= tr() + * will fail. The assignment process will abort at the first failure encou= ntered + * during domain traversal, which may result in the event being only parti= ally + * assigned. + * + * Return: + * 0 on success, or a non-zero value on failure. + */ +int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domai= n *d, + struct rdtgroup *rdtgrp, struct mon_evt *mevt) +{ + int ret =3D 0; + + if (!d) { + list_for_each_entry(d, &r->mon_domains, hdr.list) { + ret =3D resctrl_alloc_config_cntr(r, d, rdtgrp, mevt); + if (ret) + return ret; + } + } else { + ret =3D resctrl_alloc_config_cntr(r, d, rdtgrp, mevt); + } + + return ret; +} --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2082.outbound.protection.outlook.com [40.107.220.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 589DF273816; Fri, 13 Jun 2025 21:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848887; cv=fail; b=jFOK96eUoUmqwktpeSL99e/9df1whxq/ci+osqc3FzKPwvSgRRa7ovqA2782k/zX3TrP7V3J392BrmDothT9cnzE51amKTYLkxTH/Jhj6b5yxJwMdP8Fx4RDjJCkK8k7rxHUevqfNVz2DrIAVDlEchrTX017IuBmarzs/lOecFs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848887; c=relaxed/simple; bh=NoCvKmrRbLjHWxz43aN0b8VfM+3yOjZXaqRZSjcZA7M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EHUSzavb8NH7q0OmACVwO+TMPH6hb006QetSa/svL6q/6oyLdqCLRd1Faa1LoZKjCvJKrdus0rEaVvwNWMgUQReHouO7I4XM2xRmwqdpldtwzj1ToEBpILinK80kJzBqxmYddTQPCozrQYmhai7Ts3cjB2KD4j1rpMzUXCEN6YU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=yKyujKK9; arc=fail smtp.client-ip=40.107.220.82 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) header.d=amd.com header.i=@amd.com header.b="yKyujKK9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=r2bDa7DQWAiigesXupJI2z5i1Bwfhpsby0tGinuET6UkNdfGZaq6CRd7tXxizQyt83XgSyBKLM+vRUnfswnxqmHAWPB78fShTcVYeDWouX0WSEcy5kJlPcZBHdFodNr8vMJk6cWXS1zgfYPite2K4CBZe2nRzRy+L3aUAzRhfzvPu8W0IMc48oFnLK7PtgoGnsVkCmFhUoZSeupr9Fxn1w7GzPfaSXngikUTnp9zi2gwIQdodf8lti9LI/p0pxC8emqliApzL9Z8K03EFiQzXuhc8NKInOW0vHmaQcMI1AsXW4562MwBkx5f1ckkJ3/4HX4y4ElzdwDhqfy+DkRDDQ== 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=DwVv5RYmWSy+Uc0Qp7g9Rqt394dhUp3ERCT3KZg4Kks=; b=MuXN58J7KZUtPxXyGEadFuMD29fMjHsct2vGsD6zUVXmZiYzxFlDRcnpCTSrCXrP9GwSE7WsfBHKp6/3pm3TtfXv0oIoSgjzNsolxG7dfeMNsepC5/Qsb/3bZDM7Nq+gJEL8whs5FM4xfAZ7F8nO0MlgsUZiMBB2MiNlenRtJRzDKlBuwiBHUiwSYW5kH8gkvIb/a4ejc7hhuSACvQE9msKZLvCgcBLUSB8IeWfJMaim14K3k0ZTaqw7rbE+axmxTa6EOBrXZiWlQy3kpzGRC5VLDSpASRWndoV5xzIZb0cWsNMIaCr0YVQju160lnP2Vglnx0pbpooUXm0SJNC0VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=DwVv5RYmWSy+Uc0Qp7g9Rqt394dhUp3ERCT3KZg4Kks=; b=yKyujKK9ISGMYDifmROkS3T/16+lH0H6D3MxwiXW862TJ6KG2cILKsp8E7ROQ/8PefBMCtaDxspl699BGfR95RxeJMTR5UO7xhI04WeRLWIpkOGdxqZk2AbvII3wVdz40g6hafJJiQFLjTHsvEx1R13QioY6K6I3MJugBchi0r0= Received: from CYZPR17CA0008.namprd17.prod.outlook.com (2603:10b6:930:8c::17) by DS0PR12MB6608.namprd12.prod.outlook.com (2603:10b6:8:d0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.41; Fri, 13 Jun 2025 21:08:04 +0000 Received: from CY4PEPF0000EDD4.namprd03.prod.outlook.com (2603:10b6:930:8c:cafe::de) by CYZPR17CA0008.outlook.office365.com (2603:10b6:930:8c::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.25 via Frontend Transport; Fri, 13 Jun 2025 21:08:03 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD4.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:03 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:01 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 19/32] fs/resctrl: Add the functionality to unassign MBM events Date: Fri, 13 Jun 2025 16:05:03 -0500 Message-ID: <83d54b00cc873d7d4dec433b7f528da10963d025.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD4:EE_|DS0PR12MB6608:EE_ X-MS-Office365-Filtering-Correlation-Id: 05912bb3-b089-4d61-c1b1-08ddaabe631a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|82310400026|376014|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MW+7KnJKnA5p1gqZ1Myup6lipwHuy+OaG977snnchMEgKVC88j+Any39LNye?= =?us-ascii?Q?S9aWv1tFIaNNKiz8SHArB0+4ms3ZqdUnfSNRqktmpospLJUYSdEpKdum0ZGd?= =?us-ascii?Q?xfhQcjqus/HUyCK3KNKGf3RL0jZ/oaE+y9vJTW25ls/mSYkOgOKLtRH1jaBB?= =?us-ascii?Q?u6gO7wk8uncBt7BXYL4uHMb8y6cO2LRL4PmwAzAF+xW7BgZ3dJ9H2rYEtal0?= =?us-ascii?Q?mo/6+9yAiXBUwdy1d3UD6wuV8g+HC3yEGYOta9p/zCu8Cxeqw+3eYuVg1t0R?= =?us-ascii?Q?W4CFVt8BUIGDKbmWnJ9xgYg3WzgL8PnolbbhEkpUpgoYCezr1fFJ9zeUAlKz?= =?us-ascii?Q?VP9GabQFKx3SGL44mq3o0N+ArxvuSIMXGLrJ3ShvFVv0Uoy4hxYhdv668xcR?= =?us-ascii?Q?jjMMwD1rZ9BaltnBqGiJ9AdOdACfBhr3PUQwAHiy6LTFTSdoJgatdbBNrWyX?= =?us-ascii?Q?QsfJntSnPw/505t01if0sICVn7AY0mjVnGbN+VkfRhhAA4kyTYvgUtXH4LOP?= =?us-ascii?Q?DT4GkfcmN+JK4QTHHeo2Nw3rRYHZ4nnDqH0oi3L/cgPlYxz8ZYAPQMsolqas?= =?us-ascii?Q?Op8pyqeFi5Y+wZ/oaM0U9jxH/mpSTkjqS5H1Q5I16nvueAgFDfn8pVKGexg4?= =?us-ascii?Q?mUT8ObtOstZQ4VW45vQIDOtWAS3+ohclvMbdAyTKFJMAg4yXAORSEBMJ3/IH?= =?us-ascii?Q?ERe8/RX93mFywlADkOOfk4Q0CjCntUpKiKB5kn8Io7Nuuy+uQB1FGFtYhETZ?= =?us-ascii?Q?xqPl2vgaQ2qP0XfPXNCTxpGRVb7xP1gYNHZd7mx5hImiIVNUWh0duMsOz9xB?= =?us-ascii?Q?WdMvHsx6Qb811H9ncdiZQsOx2Wyhu/AqfY/JvYAZEdX3weOLOK4MoaI1Naiv?= =?us-ascii?Q?Z/vV507su+CzbQ3FTgPJ2MMKijHdGcDlanVhzahXsck60yy4exbogzHi0cw8?= =?us-ascii?Q?9MAcXJ2VTT3SVqTIx7UsSnEM0/uuPKjHQc+OQMpGwza0bW4GisMxdCtCFxly?= =?us-ascii?Q?plM55U07K67SnKHX8ZqLryNgfjLjjADz1wLoEipmMXcj/ApCBIH5yAgTydLD?= =?us-ascii?Q?I3TsBnB4EZr/PvvL2a7xvxRNHtia2JYy6NMHFx/3L1DNxIwYCheUjig8Z/ip?= =?us-ascii?Q?BxeFtMdiS6quchHpFwy5qucBU2usShO+xG87bwGro+OKzagvYNJNJMffAXy/?= =?us-ascii?Q?VNYM2SdHLUFkZGSoGW5eJlKo4h3bgat5Jq9eGpashTRpbuEFM4J6PdRO/A9m?= =?us-ascii?Q?w/u8H0LeorNxrwU/wnvH2JBJVT8GrhstFlY4YN4DNNzB+H22xt21MSM/jqzB?= =?us-ascii?Q?XwhUiMwvBmv4VI1VnbSTESmhslgw2iGnZ2M48JepaI7crYaJHs+IdTa4kdst?= =?us-ascii?Q?htUh5hilIt+VdqXPGr4+VCZbNm5rXkzU2g2tPOlkY6q/B7H7tNhz4fcyxJQS?= =?us-ascii?Q?uPfE9V9c+p/aG+VHzuE/yPSmXhLujxNWhRxOZGFYWsoDi5DXdupyaOoxDrhG?= =?us-ascii?Q?Blqih6GTXWMIK7Av6T5kCOTSQFY8ztDKoiC3jNmqdhx7jrbXGtAdTLk1Pw?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(82310400026)(376014)(1800799024)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:03.8568 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05912bb3-b089-4d61-c1b1-08ddaabe631a 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6608 Content-Type: text/plain; charset="utf-8" The "mbm_event" mode offers "num_mbm_cntrs" number of counters that can be assigned to RMID, event pairs and monitor bandwidth usage as long as it is assigned. If all the counters are in use, the kernel logs the error message "Unable to allocate counter in domain" in /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested. To make space for a new assignment, users must unassign an already assigned counter and retry the assignment again. Add the functionality to unassign and free the counters in the domain. Signed-off-by: Babu Moger --- v14: Passing the struct mon_evt to resctrl_free_config_cntr() and removed the need for mbm_get_mon_event() call. Corrected the code documentation for mbm_cntr_free(). Changed resctrl_free_config_cntr() and resctrl_unassign_cntr_event() to return void. Changed subject line to fs/resctrl. Updated the changelog. v13: Moved mbm_cntr_free() to this patch as it is used in here first. Not required to pass evt_cfg to resctrl_unassign_cntr_event(). It is available via mbm_get_mon_event(). Resolved conflicts caused by the recent FS/ARCH code restructure. The monitor.c file has now been split between the FS and ARCH director= ies. v12: Updated the commit text to make bit more clear. Replaced several counters with "num_mbm_cntrs" counters. Fixed typo in the subjest line. Fixed the handling error on first failure. Added domain id and event id on failure. Added new parameter event configuration (evt_cfg) to provide the event= from user space. v11: Moved the functions to monitor.c. Renamed rdtgroup_unassign_cntr_event() to resctrl_unassign_cntr_event(= ). Refactored the resctrl_unassign_cntr_event(). Updated commit message and code comments. v10: Patch changed again. Counters are managed at the domain based on the discussion. https://lore.kernel.org/lkml/CALPaoCj+zWq1vkHVbXYP0znJbe6Ke3PXPWjtri5A= FgD9cQDCUg@mail.gmail.com/ commit message update. v9: Changes related to addition of new function resctrl_config_cntr(). The removed rdtgroup_mbm_cntr_is_assigned() as it was introduced already. Text changes to take care comments. v8: Renamed rdtgroup_mbm_cntr_is_assigned to mbm_cntr_assigned_to_domain Added return error handling in resctrl_arch_config_cntr(). v7: Merged rdtgroup_unassign_cntr and rdtgroup_free_cntr functions. Renamed rdtgroup_mbm_cntr_test() to rdtgroup_mbm_cntr_is_assigned(). Reworded the commit log little bit. v6: Removed mbm_cntr_free from this patch. Added counter test in all the domains and free if it is not assigned to any domains. v5: Few name changes to match cntr_id. Changed the function names to rdtgroup_unassign_cntr More comments on commit log. v4: Added domain specific unassign feature. Few name changes. v3: Removed the static from the prototype of rdtgroup_unassign_abmc. The function is not called directly from user anymore. These changes are related to global assignment interface. v2: No changes. --- fs/resctrl/internal.h | 2 ++ fs/resctrl/monitor.c | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 0767a1c46f26..4496c359ac22 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -388,6 +388,8 @@ int resctrl_find_cleanest_closid(void); =20 int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domai= n *d, struct rdtgroup *rdtgrp, struct mon_evt *mevt); +void resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_do= main *d, + struct rdtgroup *rdtgrp, struct mon_evt *mevt); =20 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 38800fe45931..f2636aea6545 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -1016,6 +1016,14 @@ static int mbm_cntr_alloc(struct rdt_resource *r, st= ruct rdt_mon_domain *d, return -ENOSPC; } =20 +/** + * mbm_cntr_free() - Clear the counter ID configuration details in the dom= ain @d. + */ +static void mbm_cntr_free(struct rdt_mon_domain *d, int cntr_id) +{ + memset(&d->cntr_cfg[cntr_id], 0, sizeof(struct mbm_cntr_cfg)); +} + /** * resctrl_alloc_config_cntr() - Allocate a counter ID and configure it fo= r the * event pointed to by @mevt and the resctrl group @rdtgrp within the doma= in @d. @@ -1084,3 +1092,42 @@ int resctrl_assign_cntr_event(struct rdt_resource *r= , struct rdt_mon_domain *d, =20 return ret; } + +/** + * resctrl_free_config_cntr() - Unassign and reset the counter ID configur= ation + * for the event pointed to by @mevt within the domain @d and resctrl grou= p @rdtgrp. + */ +static void resctrl_free_config_cntr(struct rdt_resource *r, struct rdt_mo= n_domain *d, + struct rdtgroup *rdtgrp, struct mon_evt *mevt) +{ + int cntr_id; + + cntr_id =3D mbm_cntr_get(r, d, rdtgrp, mevt->evtid); + + /* If there is no cntr_id assigned, nothing to do */ + if (cntr_id < 0) + return; + + resctrl_config_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, rdtgrp->closid, + cntr_id, false); + + mbm_cntr_free(d, cntr_id); + + return; +} + +/** + * resctrl_unassign_cntr_event() - Unassign a hardware counter associated = with + * the event structure @mevt from the domain @d and the group @rdtgrp. Una= ssign + * the counters from all the domains if @d is NULL else unassign from @d. + */ +void resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_do= main *d, + struct rdtgroup *rdtgrp, struct mon_evt *mevt) +{ + if (!d) { + list_for_each_entry(d, &r->mon_domains, hdr.list) + resctrl_free_config_cntr(r, d, rdtgrp, mevt); + } else { + resctrl_free_config_cntr(r, d, rdtgrp, mevt); + } +} --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9135271A6D; Fri, 13 Jun 2025 21:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848896; cv=fail; b=FcTirIkHxH8auf7RbvGcHSvPs1B+RMzdgQ7UJADYESCnk5AefMt2TUzx2UOYkN9/8Pfv+EDk6k97EK1I7U54ppxzbVfjKTZ9yHp6SE4g2lpUYO3gBpu9EHpE5X8OcbGYm1vfAW9qEzFNjikyw629QMiAggaYPnrkfDOyyHb9hns= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848896; c=relaxed/simple; bh=bEbPD4HbpkAAXGXsnK8HLzHbmqod0mT+KOgthaslrbE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bcQEOH5kAiAK4JGWr8sIIOxHtCqcpHJ3oXt04hKKTn61o1lFmm7c1B6TbGy+mFlfyA20cguLI8O9eQVyClgeP1k2zIfYf1w34fNmRXbjeEtPmFv/IzvZ1altApM3vyQujNTXZAJ37Vab2kX+p9vekNLPGVq0kFlRsKckJIzP0uA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KY4p14nU; arc=fail smtp.client-ip=40.107.236.40 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) header.d=amd.com header.i=@amd.com header.b="KY4p14nU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bNrkv/Zn6tCaSaVuHw00KAoswRzw1VgkdQsqLEA8xEfRSPTJZ6E5qYH7tRp4qMh9Uf2K9juEQ8OjyDUW9SlPNBE9hil1CkKz6iRUh6P9Ju22M/7qcRvwg/6JQoRKYtNArC6/wHByXpMN4iHLTZJYGqd7Qwz53OrzovHEN5K0KjkorW0cBlFtirVGU3/HKcre0XeRQ+4z0DNvZzdHr9VxScId0f3LoKd7Bjr65WgnUqKJNNrSv+6Pz09GnkTSE3OOGfDBqS+ANQF2j5rxu+F4gLnHLpXhOX4gOkmX/XbyVWG8stYDu76GvH7knLEs7kQ22GUJDhjHoz3ubl8I/9BH3A== 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=XNI8Ek9UAAqS/mxlyZuNiXzPHkNZdAZKtMMVBQ9qLrc=; b=U0lh/qHpy2+cHw7K12eWyHOfM5wrd17igdvkZMeHwyrI7dA9wq/egQYvBDKSO2fRodYiR82ZyYuON4jyIBR3MwDIzx80QoRV6E6YHdU31Wnus95MB7TP7zyZgRBpsJxR0pxkG+zcHApmGX2goGKwoRy6MVTIvfzVHF9wIruH8eieuQR4IADUfHTcmbpNsvrq6lsU9vyVgNzrte7skWSXn5nJc+vqkcZzG6OI4yDCLpl/yuOYaJQh2R4RpwTjCLhpg+/9Wy3Q3kdkUFgCiBKcXpY2B0Jp+EtXjD0XtzafQZrnGhegFXKBWcwk2MxeWl1JqJjF8wbMM8IQT3p1GE6Y7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=XNI8Ek9UAAqS/mxlyZuNiXzPHkNZdAZKtMMVBQ9qLrc=; b=KY4p14nUZJoFXYoBhQ8FqQtfmgLd0pE7zhPjo7HZToxFH/g9vmgVLcwXvpcsjiJ+gtacIAE2HgOGJPAtLxipgTR5L1XLLzrYHBERYx8wMbCwC45Ct84IbX65sJFzUXS+IgM4bR+gl2yBh2LIm04+hllOpQjE8F9CYp41ebz5Fkw= Received: from PH8PR21CA0004.namprd21.prod.outlook.com (2603:10b6:510:2ce::11) by LV3PR12MB9265.namprd12.prod.outlook.com (2603:10b6:408:215::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:08:12 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:2ce:cafe::b2) by PH8PR21CA0004.outlook.office365.com (2603:10b6:510:2ce::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:08:12 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:11 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:09 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 20/32] fs/resctrl: Report 'Unassigned' for MBM events in mbm_event mode Date: Fri, 13 Jun 2025 16:05:04 -0500 Message-ID: <794cd45701dd52f0a7c3ebda305ff980e761ba35.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|LV3PR12MB9265:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f0e1e65-a805-4621-2b72-08ddaabe67e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MY5Eo0kIXwEgWA4+ydst/uKBttOR2B7CJ6H9epk+y90+kj/cPcclrjmhknMm?= =?us-ascii?Q?AJFLsWD77lSifB9enZdNbm9ToPe6kFF4zgZ6nTaqyk5YRdi8DtuW2xXOi+3U?= =?us-ascii?Q?oZl2v0mglQ931VS7mBcApf8VxvDVKe7KFr4Sj9sPH0nGPSa6bltagiHz0iuc?= =?us-ascii?Q?aGyIKskF8a8pJtCUCRl8NOqagztLiBfBsSJv6/Pmu3TSZVDAPEmTBY16ZSLT?= =?us-ascii?Q?vle3Yp1OUpZOJxU2F2XrP+jZuNaJpeVDXwdz4LfVv8lA5uxQFYs1mT83dzCO?= =?us-ascii?Q?tRDHthEo2zhanp4Nil0d8b+BgWCmHxVPHqDyKcNYgyPDDzNGonzQ20FqQ0h5?= =?us-ascii?Q?cQB5ikT+w5qNTUN3eL9awlwgDVIBj1I3w6shvD748nBjU+WPSFwEYe+bmFB6?= =?us-ascii?Q?KX/z3PwRn+0JFe7g3stlD/XQdZ2PRU6oa8Z4MudefYnndgMdZsFaXLUqfI+O?= =?us-ascii?Q?fGKvqDHv/qVmriXNQw9Tc2UrI1eaXFVHtmHd+QM3p7m5my8IhEHD7C2GORbs?= =?us-ascii?Q?mdb1wVLIat5NSVKBMCEx8niGuGVqD+pk7CDHpE8ZGnn50iJWt40bv35jd5Hk?= =?us-ascii?Q?4Xkwzptz3BIqj6vIsL0sUofPfGUPvDE1XW4ZiopFJ+Lzuo9uerQOj3mUpcmS?= =?us-ascii?Q?3GxMNtrugJuriF455C0MoHGm4iCyT3NpjhFRj935M1PbStVAQkVqb7oMbkYi?= =?us-ascii?Q?5Zu62hR/SjkD6CQWl1MwhOOUIyKg3GYv+QOZsxXlj4/DFOkLjGsF9RcYKlxW?= =?us-ascii?Q?NDWPmJ+/YlUT4uk7XzrYoUaGM/wka7ZVtWt4EVKqdb7bVI4aKW7P4tLb/9Mu?= =?us-ascii?Q?Kiu31MaviLY9sUom+vmnORidU0SDPT5lmcJb1r8p7K/YaXOj37ADOOmPrMhK?= =?us-ascii?Q?rYLpRDrku4xYi0jkyxNczoNsEABD/iuBxWPdrp///T1tu+opOeTuCoXvrzoW?= =?us-ascii?Q?huNJDPiFxgujn7hpPoFyIfftejG+PHnhNJZIyNgwrgS9l4mP15D3ECHoFWxA?= =?us-ascii?Q?yrrNx95xl/YNZMp7QzZpGdcoy0F19DKf7y+9TLzBI3otwbSCiF/OzNrZN+VQ?= =?us-ascii?Q?Rs4of1CsqQ2BVlkhX+7LVB7u4otK273yljFio2rnzxEFELpYM1ehi8Vv1scq?= =?us-ascii?Q?Khuu4pprxB3agoh1KKPUx3uI+RsDbpz9OKiwvX/aC8yv7rDbsnq7wdRTYHcJ?= =?us-ascii?Q?RRgq+Wdn6P3BYIrTTWOWCNDOoHYZR+wew7a1OVut+bghS1yjseQMvFbYc1xu?= =?us-ascii?Q?gFE7o4/My6OqjMFpo+AeKd4/ECsSXov3AwGwax+ZnO5DJl+1hEubG85K4nfI?= =?us-ascii?Q?aJci/07beSrd1kxf5WM18z8Lv9ang3w7pZvpQ/8w5XLHp7B+1PwmNrBQYCUT?= =?us-ascii?Q?HCP2aFBGWXfo05XWoN6PzUUFq+VAVY40Bty/ePRu2Gsb/6XqZH257VE2Pk4h?= =?us-ascii?Q?/oA8F8OYCuw5qCqEkjUZGunOmob2G3UDn5qRzmwEzT3CbSxYKbrCOI5df3c+?= =?us-ascii?Q?Z8Y1u2Uq5CoUc5tx5fcRV8OpRr4Ab+McojtM9nBX14PpKoCTJK7+g0LV9w?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:11.8892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f0e1e65-a805-4621-2b72-08ddaabe67e3 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9265 Content-Type: text/plain; charset="utf-8" When "mbm_event" mode is enabled, a hardware counter must be assigned to read the event. Report 'Unassigned' in case the user attempts to read the event without assigning a hardware counter. Export mbm_cntr_get() to allow usage from other functions within fs/resctrl. Signed-off-by: Babu Moger --- v14: Updated the changelog. Added the code comment for "-ENOENT" when counter is read without assi= gnement. Removed the references to resctrl_is_mbm_event(). v13: Minor commitlog and user doc update. Resolved conflicts caused by the recent FS/ARCH code restructure. The monitor.c/rdtgroup.c files have been split between the FS and ARCH= directories. v12: Updated the documentation for more clarity. v11: Domain can be NULL with SNC support so moved the unassign check in rdtgroup_mondata_show(). v10: Moved the code to check the assign state inside mon_event_read(). Fixed few text comments. v9: Used is_mbm_event() to check the event type. Minor user documentation update. v8: Used MBM_EVENT_ARRAY_INDEX to get the index for the MBM event. Documentation update to make the text generic. v7: Moved the documentation under "mon_data". Updated the text little bit. v6: Added more explaination in the resctrl.rst Added checks to detect "Unassigned" before reading RMID. v5: New patch. --- Documentation/filesystems/resctrl.rst | 8 ++++++++ fs/resctrl/ctrlmondata.c | 19 ++++++++++++++++++- fs/resctrl/internal.h | 2 ++ fs/resctrl/monitor.c | 4 ++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index 8a2050098091..18de335e1ff8 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -434,6 +434,14 @@ When monitoring is enabled all MON groups will also co= ntain: for the L3 cache they occupy). These are named "mon_sub_L3_YY" where "YY" is the node number. =20 + The "mbm_event" mode offers "num_mbm_cntrs" number of counters and + allows users to assign counter IDs to mon_hw_id, event pairs enabling + bandwidth monitoring for as long as the counter remains assigned. The + hardware will continue tracking the assigned mon_hw_id until the user + manually unassigns it, ensuring that event data is not reset during this + period. An MBM event returns 'Unassigned' when the event does not have + a hardware counter assigned. + "mon_hw_id": Available only with debug option. The identifier used by hardware for the monitor group. On x86 this is the RMID. diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index ad7ffc6acf13..8a182f506877 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -648,15 +648,32 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) goto out; } d =3D container_of(hdr, struct rdt_mon_domain, hdr); + + /* + * Report 'Unassigned' if "mbm_event" mode is enabled and counter + * is unassigned. + */ + if (resctrl_arch_mbm_cntr_assign_enabled(r) && + resctrl_is_mbm_event(evtid) && + (mbm_cntr_get(r, d, rdtgrp, evtid) < 0)) { + rr.err =3D -ENOENT; + goto checkresult; + } + mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); } =20 checkresult: - + /* + * -ENOENT is a special case, set only when "mbm_event" mode is enabled + * and no counter has been assigned. + */ if (rr.err =3D=3D -EIO) seq_puts(m, "Error\n"); else if (rr.err =3D=3D -EINVAL) seq_puts(m, "Unavailable\n"); + else if (rr.err =3D=3D -ENOENT) + seq_puts(m, "Unassigned\n"); else seq_printf(m, "%llu\n", rr.val); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 4496c359ac22..4a7130018aa1 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -390,6 +390,8 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, s= truct rdt_mon_domain *d, struct rdtgroup *rdtgrp, struct mon_evt *mevt); void resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_do= main *d, struct rdtgroup *rdtgrp, struct mon_evt *mevt); +int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d, + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid); =20 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index f2636aea6545..cf7f6a22ea51 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -977,8 +977,8 @@ static void resctrl_config_cntr(struct rdt_resource *r,= struct rdt_mon_domain *d * Return: * Valid counter ID on success, or -ENOENT on failure. */ -static int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d, - struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) +int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d, + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) { int cntr_id; =20 --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2074.outbound.protection.outlook.com [40.107.243.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81F2D2737EC; Fri, 13 Jun 2025 21:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848906; cv=fail; b=YURo5asaiK8OdX0QaJVhRbrfwFCcvPfYbD8vBjqXWuqugNJL37gfHxZ7ktaVbtj2o6dPEXVJ5HDVsrcxSeS1ky/Vco4d7DWxPJnm8AVdff6uVV8BrDQBtLeOkJpG4WP6TX/SXw56XbjbSSMMOTteHy8oS7KtZoB/rSxig1LJv6c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848906; c=relaxed/simple; bh=6tYfU1Id2XFoUMEezkZ/ZHlsHd1hkxsCKKUmtlXxfac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h4123KbtnDbkYpdv6OdDzXGRShCB6Xm/23IS9PgaYqh1M2lXruIaJwJCucO+OKpioYPNVQx/haNIR7SzvjvVQIQVRz5DQkITa87Qelv47GGde8SrwYbyWJWx3H6g+yQChznVDXAn3lZvTf1ioK2bcxTCsMo2gzN/CJHM7gzKQCk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=m5h7C0BZ; arc=fail smtp.client-ip=40.107.243.74 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) header.d=amd.com header.i=@amd.com header.b="m5h7C0BZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kT4k0MYsZJPXicyBFdyePvM+7+pXunTxHq8Yp+CiA8ERnAfD263GWFuuobjpE8HtAuCPbWmpkfzxJrzcpQVfZwFZ8quoUFe7Gcw+bBMkZ/LYi7UuvsbPXLWMSzOvvQuMhItMiLQtoySDiHulZYRXcfFAu/RZe6M4ifwTSir/Bi9+i2dQfz9BFVPE/LSONo+LwieW1RzouKaa06EAmvmTbss4OtB36B3583GYWnGKeBTW02jKcrkTJYZ8v1Cjqp7MJioTGbGzqCsjtDA91ipd1smi7zrjTpGXKALyTbqd1nEjF+PSYGHrUaQfyhA278xR7rdNMpQPv6iNqddx7SGHfg== 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=LLens14F6NUmFTQA5a2gobwz8Y3vUrFg4TRAzFN/L5c=; b=fRKtZa9NOl3jawsXp5KvCInX5tNSKTQy2T9I/mj5jDTnqmde91sU0LyVOo4ouUnifKJpGhEFowojf1mHTfwBcQOorVXP0gNxMAKwUwS7lu1i9lqgM1BR85ONEpORsIxhFaWnsjtkmWFoc0O91I3xkE3Ij/HAe0g9ZBRGfjFLycPjybrftlNyONGQmXoosko4dweXepnlHAoQBdRTawp8eRPiV0QOe5wiuZ55ZVT502B54hTdedjofqE1Zj9k03gkH6x3AlUSRiycAKMz6JztzLcmTZ6zSaKQ+/jJUrKrFLMhoV2L4XvNTapEovcipXmeTbEjJZMmVD2IHclYuYyLxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=LLens14F6NUmFTQA5a2gobwz8Y3vUrFg4TRAzFN/L5c=; b=m5h7C0BZ0fTZCY3eVpFXiMal+ylN2IQ7cPmDKqtB+R1pu0w1rOjvAFwbIWl4DsAKwxhJYdw7rd98yyZa271Ouzw74ZjZjWUOW5J5VFD3nYgfHrpMfj/qPlMbRYMOnsHdsLvUEio/0clqABfCmN5fH36CkZSAqMW/SbmejgzVOJs= Received: from DM6PR05CA0063.namprd05.prod.outlook.com (2603:10b6:5:335::32) by DM6PR12MB4187.namprd12.prod.outlook.com (2603:10b6:5:212::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.26; Fri, 13 Jun 2025 21:08:20 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335:cafe::40) by DM6PR05CA0063.outlook.office365.com (2603:10b6:5:335::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Fri, 13 Jun 2025 21:08:20 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:19 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:17 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 21/32] fs/resctrl: Pass entire struct rdtgroup rather than passing individual members Date: Fri, 13 Jun 2025 16:05:05 -0500 Message-ID: <84e5cffb2b3f8088f77781babe89b0cab513ed79.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|DM6PR12MB4187:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cd3010c-46b1-448d-098d-08ddaabe6cbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|1800799024|36860700013|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?t2fPt1kQpC0/F9R+8Qa7jy9TIS5uyvNqj8f65N1JULWAD0AZcIxiVEt5+MjZ?= =?us-ascii?Q?ddz7PIjtFvovVntq9jtJqI39TxYJT4sfPy8vzUd8njA1jOkupdjIn5YSm4do?= =?us-ascii?Q?wZqphbzMyDER22JcX7iWeDVhyQtTNcp9Xay9NlwrSAy6yWEFDeZvCO/izgXT?= =?us-ascii?Q?PPKWhoUEo8HfYT70NGjY8j/RQD+HNRF1kthlxKatWA3CRM2GcAz1dBN7e9OL?= =?us-ascii?Q?e2MPSN+QdKTDEGNAaAfeJDzykOwuEqtwJmLyUfAwgsLciucG8v3ytN2hF66S?= =?us-ascii?Q?ggQ8IkqOhLYmAgUTgjGIozTpLUvU8+RBCGoqSQSQlGXo0zVy5pKUYKBS4RDG?= =?us-ascii?Q?r4GqROU54D6uchILtzPrw4/edeJwK8oO0J+9rbds9HdEU6s5WI9M3ysQYZ+K?= =?us-ascii?Q?wpICriJ0SKDkEEBesgonQJtKDPozzxlBBihIb5ZPWEnYXlEE9pw5etYtNxTq?= =?us-ascii?Q?0xPNd2COVZqRyQ4LYsYkON8SQtrYRVwP7Ft1ECY4xpfJ+zb+5GfQd2I9cT5R?= =?us-ascii?Q?FRKgto1r2dg4lSf3XuzLGrrLj+oCkj1tifkIl9uJTRTwmaRf5mJbHxgDy4ok?= =?us-ascii?Q?1k2TCp5W0WurOPCLfPTv+lxtLtL5s/wsCQC+rAR0nvb4A82O44BeOseSugOr?= =?us-ascii?Q?0JnVI481hw9GfFyMggH4Gk5DuAvMt2hOZIJZxbRShcNIZ5Akvaudkx6cUp8l?= =?us-ascii?Q?rPFrVYh18JMOXqX4taWlTZ0O5C8gGWWioiWSQ8PucliJlvBBSX577Wx6CJ/1?= =?us-ascii?Q?SXjnTzilwwhDHY64lrrvkGjINQyFC2UdHbaB986l4E97vpjtqeI4DJQGudmp?= =?us-ascii?Q?V84sty1rGqxWJSCvlBSSjSqyyvNlB9hyLAuhsoAW5OQy9itY5xRVaxrEmumg?= =?us-ascii?Q?4M8NR4OHfMauEk8kDoocRSvf3864BvbxeAwefJgxTFcCYncxZJrP1nGI68lp?= =?us-ascii?Q?96WZ1OreqqfXmCSb5GVgKp+plzcKikdYpz1C878qq+ybnmBaSytknFapAomq?= =?us-ascii?Q?hc5YpgwhieQ4A4D6Zi6DOqBF3McLR7AoOJBBik2TV0bukMF7Y8rasy6pYXma?= =?us-ascii?Q?ycILOOk+fnmaZrpG1dJo8KZXbHZnVcE9rTe59rpReHvmjL5npK6TIfIz/js1?= =?us-ascii?Q?VtLJDwtfxnzSXH20HEH3TEO/Sl7wfAQide/ttThbajtDGB7hrUMkCxzd+DeC?= =?us-ascii?Q?N/f9gd7mhAUAeslIo/N3ycvEBzlY5Wei029/MC17SWyUNWDdmsCV50GfF/2u?= =?us-ascii?Q?2uiJBReFL1+h0TGfWQt4B1Uo0m9W4gvQY7gzQd0/b9WdIoN3+ztgKIR8ofze?= =?us-ascii?Q?7ABKCYc+mMmR24Zr0TdxkmnLWUoyNL16jbYP40QmFK/FVdKRUjY+i1uWqShw?= =?us-ascii?Q?zfwsKOkGmYqLMBLg+7f+mSmGIvcx5WvKcupnU9dlTXqYtZryBUMMxaLG97Dz?= =?us-ascii?Q?sDcuMuyauQZu8PpjbzZVmZgowTo1C5DPKPy+zMqMyI620lPOCGNNr05WOwSU?= =?us-ascii?Q?F5TgOxpO9ymqgo0b7d/TBTIgIHPVwAyzv0ypjyWEkL6JGWFmndg4UHADNg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(1800799024)(36860700013)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:19.9485 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6cd3010c-46b1-448d-098d-08ddaabe6cbb 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4187 Content-Type: text/plain; charset="utf-8" Reading the monitoring data requires RMID, CLOSID, and event ID, among other parameters. These are passed individually, resulting in architecture specific function calls. Passing the pointer to the full rdtgroup structure simplifies access to these parameters. Additionally, when "mbm_event" mode is enabled, a counter ID is required to read the event. The counter ID is obtained through mbm_cntr_get(), which expects a struct rdtgroup pointer. Refactor the code to pass a pointer to struct rdtgroup instead of individual members in preparation for this requirement. Suggested-by: Reinette Chatre Signed-off-by: Babu Moger --- v14: Few text update to commit log. v13: New patch to pass the entire struct rdtgroup to __mon_event_count(), mbm_update(), and related functions. --- fs/resctrl/monitor.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index cf7f6a22ea51..31e08d891db2 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -356,9 +356,11 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_= domain *d, u32 closid, return state ? &state[idx] : NULL; } =20 -static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) +static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) { int cpu =3D smp_processor_id(); + u32 closid =3D rdtgrp->closid; + u32 rmid =3D rdtgrp->mon.rmid; struct rdt_mon_domain *d; struct cacheinfo *ci; struct mbm_state *m; @@ -429,9 +431,11 @@ static int __mon_event_count(u32 closid, u32 rmid, str= uct rmid_read *rr) * __mon_event_count() is compared with the chunks value from the previous * invocation. This must be called once per second to maintain values in M= Bps. */ -static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr) +static void mbm_bw_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) { u64 cur_bw, bytes, cur_bytes; + u32 closid =3D rdtgrp->closid; + u32 rmid =3D rdtgrp->mon.rmid; struct mbm_state *m; =20 m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); @@ -460,7 +464,7 @@ void mon_event_count(void *info) =20 rdtgrp =3D rr->rgrp; =20 - ret =3D __mon_event_count(rdtgrp->closid, rdtgrp->mon.rmid, rr); + ret =3D __mon_event_count(rdtgrp, rr); =20 /* * For Ctrl groups read data from child monitor groups and @@ -471,8 +475,7 @@ void mon_event_count(void *info) =20 if (rdtgrp->type =3D=3D RDTCTRL_GROUP) { list_for_each_entry(entry, head, mon.crdtgrp_list) { - if (__mon_event_count(entry->closid, entry->mon.rmid, - rr) =3D=3D 0) + if (__mon_event_count(entry, rr) =3D=3D 0) ret =3D 0; } } @@ -603,7 +606,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_mon_domain *dom_mbm) } =20 static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_do= main *d, - u32 closid, u32 rmid, enum resctrl_event_id evtid) + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) { struct rmid_read rr =3D {0}; =20 @@ -617,30 +620,30 @@ static void mbm_update_one_event(struct rdt_resource = *r, struct rdt_mon_domain * return; } =20 - __mon_event_count(closid, rmid, &rr); + __mon_event_count(rdtgrp, &rr); =20 /* * If the software controller is enabled, compute the * bandwidth for this event id. */ if (is_mba_sc(NULL)) - mbm_bw_count(closid, rmid, &rr); + mbm_bw_count(rdtgrp, &rr); =20 resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); } =20 static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, - u32 closid, u32 rmid) + struct rdtgroup *rdtgrp) { /* * This is protected from concurrent reads from user as both * the user and overflow handler hold the global mutex. */ if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) - mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID); + mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_TOTAL_EVENT_ID); =20 if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) - mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID); + mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_LOCAL_EVENT_ID); } =20 /* @@ -713,11 +716,11 @@ void mbm_handle_overflow(struct work_struct *work) d =3D container_of(work, struct rdt_mon_domain, mbm_over.work); =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { - mbm_update(r, d, prgrp->closid, prgrp->mon.rmid); + mbm_update(r, d, prgrp); =20 head =3D &prgrp->mon.crdtgrp_list; list_for_each_entry(crgrp, head, mon.crdtgrp_list) - mbm_update(r, d, crgrp->closid, crgrp->mon.rmid); + mbm_update(r, d, crgrp); =20 if (is_mba_sc(NULL)) update_mba_bw(prgrp, d); --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2077.outbound.protection.outlook.com [40.107.244.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A105273D71; Fri, 13 Jun 2025 21:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848914; cv=fail; b=T9ud9Gjh4k9law2oKzeoXbb0USXvWZTp2nkgB5v9UyoS5b+Dazrs+8a/VrKkiBsWvOToFLAle2/oWlIC0mTjdOs3epRLc5UWL+PdKP3Jc7Uw2rik0vOuvM0RoOs2HREIbAn3QjNTjBnJhA2zI+2qdEgxGdE8mAekn9+N94f02AE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848914; c=relaxed/simple; bh=t7FceXhur6eS99OlIHp1Pm/paVSyYm2+GcRsbTB0pK0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a3ztTe2nwlAQElujGQAuaJr/DAuMixTzmnmm+w46TpZ7sIgBu0GrKCNxTveQhHSz+/4c9Yo+M3rat+/+xviMYN7/YuMs0GdNdVypp2z3zdV6XQIzP+7ZDDkbVS6Vq3ov10v8XtaSj+JVJxKgLk2202chWQO56KFEE1pwfOyjlx4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=GQuF0ycc; arc=fail smtp.client-ip=40.107.244.77 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) header.d=amd.com header.i=@amd.com header.b="GQuF0ycc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EDrnBbeOj1+jqI+NOcswgAIbftWHEugk9aBfoxAS3qO38H8PCNIiqNg5Z5row2cFTcu7oztXaf3cBu6YH0Kl8AMoRZw8HR7nBZh0R3frlpLi/hXr0aCFo81o81msjcwNecfs8KQo/dMSMXl+urwZ0Rj8GHcbZSKf4nVjcUfS+eE/4vOjsqqb9PSMVBryKsZNjr5trEE7Qap1e6tFF1NATKZKEmXR8Qlpyy4ABpSsCZLnblmjvlMVz7UiSd8wjePZCK7OpzKR6bX9LpnHCewyemyfLuCKYdoRV/Nz2zXsK4MyPkRXDUPbVA3jV5UIhtIKI5o83myYCY7oc7eO/1bZzA== 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=j3rN78gYqWllDOM/DrGTYIsCavJ8qx4Rx5lQhSIxbuQ=; b=fvtbCAqKtPSAuINuhBC6cf60dcdwi1jAqR7gTyQ7x7gokj1LDv61jzIvy5YsIoN0SkIwL+WikrGT0BSd35vcI5ulqUfZx3UjkuMWxsyBmH+WTMYn3RQPsvaXzSqlGPSbNJ3m8KO6FWgZTPJRMOOawd7VTtIB11TLt4hLsCp4/ddf8bMX2S71woRK1qHgcaMb7HbCcmpDAZlJRti1mUKaSE5VD2np8ME1XuHosATfUhmafMyUM72bIoAccwTxAieykIg99eYdft6kxdVrdQiBf3WGTyQ+7msIXCp3oV95zfyXoFgqJhoLC15RfvMOqDwyqJzPtAeTS2sCOX/n2bTFHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=j3rN78gYqWllDOM/DrGTYIsCavJ8qx4Rx5lQhSIxbuQ=; b=GQuF0yccGhj0073vk1dPn4D0vrj08kLOe2X7O/hIk0ARg/eOczztr+J4B2WlND+JZIe8EQQxDvCeb2bNuAqfBPLVC2CmaYwzVSyMNFrWUyh/y01TJl1cKpy8EEIK+J5ZrN2deh/bRPiEFaNxkI37dJNzqWZeva+9kDZe4+AYPrU= Received: from DM6PR05CA0061.namprd05.prod.outlook.com (2603:10b6:5:335::30) by IA4PR12MB9785.namprd12.prod.outlook.com (2603:10b6:208:55b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.26; Fri, 13 Jun 2025 21:08:27 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335:cafe::80) by DM6PR05CA0061.outlook.office365.com (2603:10b6:5:335::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:08:27 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:27 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:25 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 22/32] x86,fs/resctrl: Add the support for reading ABMC counters Date: Fri, 13 Jun 2025 16:05:06 -0500 Message-ID: <1b6a8a9a076c2893efb456398d266bc50c241ee4.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|IA4PR12MB9785:EE_ X-MS-Office365-Filtering-Correlation-Id: 0847453e-92ab-4c7e-4e28-08ddaabe7134 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|7416014|376014|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DF7Ne9KT2xtE/Pq73Yc/ecO4+stA60ZiacyR1CwUojy1hVvWtat+tSS2VfE/?= =?us-ascii?Q?JYlEvDFz3DsTnEalukbbXRL8rj0mo+2n+GFNoDggN9dmA+loRjGK/zzsm5Qb?= =?us-ascii?Q?uuGGprJP3tsOjMPaOMx9Mw/8sMXKZA0jXXqv/0wDMGnK0rbq6zRP2mtrksE1?= =?us-ascii?Q?QO6AGLNYMqITbThr368g37XB4pP7x42CGV0mgoKdnpAozLH1KxX5/ZKdW8+U?= =?us-ascii?Q?vyF+sm5ZZmbPBjvDEr5RwcEGb3aYalIQbeKYj0KQDQIN0K8igqRBj4nY9wf5?= =?us-ascii?Q?D0/Rv5jPn4iGqP0FqSvKxvOrqIWgauW05dBeUCEMY4oqXFz/06KU+cHKWx22?= =?us-ascii?Q?ojupIpJROwegTjtvraCw7WKIRkFHI/tFMmssAnRRsqmJ5sZeKti9ax+3+xDJ?= =?us-ascii?Q?iyHI8ejcm3t7whoITtvv25SSU366zDgdMWoT2enCFCI7ZIosTfGWC3SJHeeb?= =?us-ascii?Q?2fPMpHyF0NpJDqDzRPadI57CkK8gKwga/f/7CWxI+31Vczolw58BzNXF+DNp?= =?us-ascii?Q?6vATiqHobTRt1NNUTvAsc7F3h7dXgMGnFMJ1bMb3QSLhySefa3BeMw3eTCUQ?= =?us-ascii?Q?8cKU1fN2nSPAaqnekci5EC9W9rRITOSOUkNE8NV7O88d/8iEAmE9HdBzqxsp?= =?us-ascii?Q?+URP/o/38LcUAF1+Hdx6CR0fYwX2E2eovoZMSC8iJ9ktI5ZWWr+HjQQSdMMW?= =?us-ascii?Q?h9TqRXv97UMRzb3ivMMZOXo0f8BIeDrcD0IIWybzjc5j2ZfEcH2PK6ORvnC5?= =?us-ascii?Q?czMDlaQLBn3XttDa7qZxSi/yT35Ihvh7q+gYUHraUrS0SCJZf2YYov6zMqxr?= =?us-ascii?Q?OonqQHzTF8b3aIu5VDiXSxam9kuQLoaEmQoP1p5WFlVECrktgYm8EwR26idn?= =?us-ascii?Q?c1Kpeb+77HJl/e6UNPdrZn+QUFKSgyoiU0NEMSWbELRftjcBktGgrq0/lKfi?= =?us-ascii?Q?DyqO4ruA1MX6vvfL22iEc2WmrlY5nUmO0ujTOQd0aPhhx8GmTJzoRfGvz9fI?= =?us-ascii?Q?/J5OJ/lfUa7sMxjqyuIJa7UWrLSiwTFouMqz5hrBczNZa24kKTmAXWgClTfO?= =?us-ascii?Q?q4uzuKokQWCmmKj/ncrzArjzX35cs0xC9F+atJL2CX1nauUyi+c027sp01+1?= =?us-ascii?Q?lPVxyfDFQwhH83yaGca/FaBV2Wu3K+x5x1iG6JsXCdJpgCrcRnHl/wa/p5uX?= =?us-ascii?Q?Al6Qi3f5oruwunqlERLRYjQsTJVF7c+JNumqmolkIb1pHhXlGva8uXgiPYyT?= =?us-ascii?Q?i6Z2DttdLZF0R3/OhWLmtTVNVg5laSORd1gKdijgFIQ5y5nY45a7pF5VazoO?= =?us-ascii?Q?+x86MQBfg+NBe/ZZzTFfNysFw5jYI0OarK/TWYW5IT06o2/tzyeNQ5pXeMZW?= =?us-ascii?Q?PAyzswAlyEMPhi1ZcShYfxBKUcKF8aEAxNEZHyiXKcCvtW0KvbPhQiq4ZoHI?= =?us-ascii?Q?fp7UxFcv00nflZAHSc9SyK7Y7HE5JUsxhVvmykc/2PvJLa9DCqNOhuPeUKjl?= =?us-ascii?Q?bMmCAlDi17PbbKq9LwBk3Mq7WSpZX2ymRC7ELHfQBEuhXkD0an7VSk3lEg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(7416014)(376014)(921020)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:27.5249 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0847453e-92ab-4c7e-4e28-08ddaabe7134 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR12MB9785 Content-Type: text/plain; charset="utf-8" System software can read resctrl event data for a particular resource by writing the RMID and Event Identifier (EvtID) to the QM_EVTSEL register and then reading the event data from the QM_CTR register. In ABMC mode, the event data of a specific counter ID can be read by setting the following fields in QM_EVTSEL.ExtendedEvtID =3D 1, QM_EVTSEL.EvtID =3D L3CacheABMC (=3D1) and setting [RMID] to the desired counter ID. Reading QM_CTR will then return the contents of the specified counter ID. The E bit will be set if the counter configuration was invalid, or if an invalid counter ID was set in the QM_EVTSEL[RMID] field. Introduce __cntr_id_read_phys() to read event data for a specific counter ID. In ABMC mode, ensure QM_EVTSEL is properly configured by setting the counter ID, Extended Event Identifier, and Event Identifier. QM_EVTSEL Register definition: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Bits Mnemonic Description =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D 63:44 -- Reserved 43:32 RMID Resource Monitoring Identifier 31 ExtEvtID Extended Event Identifier 30:8 -- Reserved 7:0 EvtID Event Identifier =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Link: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/= programmer-references/40332.pdf Signed-off-by: Babu Moger --- v14: Updated the context in changelog. Added text in imperative tone. Added WARN_ON_ONCE() when cntr_id < 0. Improved code documentation in include/linux/resctrl.h. Added the check in mbm_update() to skip overflow handler when counter = is unassigned. v13: Split the patch into 2. First one to handle the passing of rdtgroup st= ructure to few functions( __mon_event_count and mbm_update(). Second one to handle AB= MC counter reading. Added new function __cntr_id_read_phys() to handle ABMC event reading. Updated kernel doc for resctrl_arch_reset_rmid() and resctrl_arch_rmid= _read(). Resolved conflicts caused by the recent FS/ARCH code restructure. The monitor.c file has now been split between the FS and ARCH director= ies. v12: New patch to support extended event mode when ABMC is enabled. --- arch/x86/kernel/cpu/resctrl/internal.h | 6 +++ arch/x86/kernel/cpu/resctrl/monitor.c | 66 ++++++++++++++++++++++---- fs/resctrl/monitor.c | 26 +++++++--- include/linux/resctrl.h | 13 +++-- 4 files changed, 94 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 23c17ce172d3..77a9ce4a8403 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -40,6 +40,12 @@ struct arch_mbm_state { /* Setting bit 0 in L3_QOS_EXT_CFG enables the ABMC feature. */ #define ABMC_ENABLE_BIT 0 =20 +/* + * Qos Event Identifiers. + */ +#define ABMC_EXTENDED_EVT_ID BIT(31) +#define ABMC_EVT_ID BIT(0) + /** * struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs th= at share * a resource for a control function diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 6b0ea4b17c7a..ee0aa741cf6c 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -157,6 +157,41 @@ static int __rmid_read_phys(u32 prmid, enum resctrl_ev= ent_id eventid, u64 *val) return 0; } =20 +static int __cntr_id_read_phys(u32 cntr_id, u64 *val) +{ + u64 msr_val; + + /* + * QM_EVTSEL Register definition: + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + * Bits Mnemonic Description + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + * 63:44 -- Reserved + * 43:32 RMID Resource Monitoring Identifier + * 31 ExtEvtID Extended Event Identifier + * 30:8 -- Reserved + * 7:0 EvtID Event Identifier + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + * The contents of a specific counter can be read by setting the + * following fields in QM_EVTSEL.ExtendedEvtID(=3D1) and + * QM_EVTSEL.EvtID =3D L3CacheABMC (=3D1) and setting [RMID] to the + * desired counter ID. Reading QM_CTR will then return the + * contents of the specified counter. The E bit will be set if the + * counter configuration was invalid, or if an invalid counter ID + * was set in the QM_EVTSEL[RMID] field. + */ + wrmsr(MSR_IA32_QM_EVTSEL, ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID, cntr_id); + rdmsrl(MSR_IA32_QM_CTR, msr_val); + + if (msr_val & RMID_VAL_ERROR) + return -EIO; + if (msr_val & RMID_VAL_UNAVAIL) + return -EINVAL; + + *val =3D msr_val; + return 0; +} + static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain = *hw_dom, u32 rmid, enum resctrl_event_id eventid) @@ -172,7 +207,7 @@ static struct arch_mbm_state *get_arch_mbm_state(struct= rdt_hw_mon_domain *hw_do } =20 void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, - u32 unused, u32 rmid, + u32 unused, u32 rmid, int cntr_id, enum resctrl_event_id eventid) { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); @@ -184,9 +219,16 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, s= truct rdt_mon_domain *d, if (am) { memset(am, 0, sizeof(*am)); =20 - prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); - /* Record any initial, non-zero count value. */ - __rmid_read_phys(prmid, eventid, &am->prev_msr); + if (resctrl_arch_mbm_cntr_assign_enabled(r) && + resctrl_is_mbm_event(eventid)) { + if (WARN_ON_ONCE(cntr_id < 0)) + return; + __cntr_id_read_phys(cntr_id, &am->prev_msr); + } else { + prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); + /* Record any initial, non-zero count value. */ + __rmid_read_phys(prmid, eventid, &am->prev_msr); + } } } =20 @@ -218,8 +260,8 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr= , unsigned int width) } =20 int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, - u32 unused, u32 rmid, enum resctrl_event_id eventid, - u64 *val, void *ignored) + u32 unused, u32 rmid, int cntr_id, + enum resctrl_event_id eventid, u64 *val, void *ignored) { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); @@ -231,8 +273,16 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, str= uct rdt_mon_domain *d, =20 resctrl_arch_rmid_read_context_check(); =20 - prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); - ret =3D __rmid_read_phys(prmid, eventid, &msr_val); + if (resctrl_arch_mbm_cntr_assign_enabled(r) && + resctrl_is_mbm_event(eventid)) { + if (WARN_ON_ONCE(cntr_id < 0)) + return cntr_id; + ret =3D __cntr_id_read_phys(cntr_id, &msr_val); + } else { + prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); + ret =3D __rmid_read_phys(prmid, eventid, &msr_val); + } + if (ret) return ret; =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 31e08d891db2..ef6ef58f180b 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -159,7 +159,11 @@ void __check_limbo(struct rdt_mon_domain *d, bool forc= e_free) break; =20 entry =3D __rmid_entry(idx); - if (resctrl_arch_rmid_read(r, d, entry->closid, entry->rmid, + /* + * cntr_id is not relevant for QOS_L3_OCCUP_EVENT_ID. + * Pass dummy value -1. + */ + if (resctrl_arch_rmid_read(r, d, entry->closid, entry->rmid, -1, QOS_L3_OCCUP_EVENT_ID, &val, arch_mon_ctx)) { rmid_dirty =3D true; @@ -358,6 +362,7 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_d= omain *d, u32 closid, =20 static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) { + int cntr_id =3D mbm_cntr_get(rr->r, rr->d, rdtgrp, rr->evtid); int cpu =3D smp_processor_id(); u32 closid =3D rdtgrp->closid; u32 rmid =3D rdtgrp->mon.rmid; @@ -368,7 +373,7 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, s= truct rmid_read *rr) u64 tval =3D 0; =20 if (rr->first) { - resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid); + resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, cntr_id, rr->evtid); m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); if (m) memset(m, 0, sizeof(struct mbm_state)); @@ -379,7 +384,7 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, s= truct rmid_read *rr) /* Reading a single domain, must be on a CPU in that domain. */ if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) return -EINVAL; - rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, + rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, cntr_id, rr->evtid, &tval, rr->arch_mon_ctx); if (rr->err) return rr->err; @@ -405,7 +410,8 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, s= truct rmid_read *rr) list_for_each_entry(d, &rr->r->mon_domains, hdr.list) { if (d->ci_id !=3D rr->ci_id) continue; - err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, + cntr_id =3D mbm_cntr_get(rr->r, d, rdtgrp, rr->evtid); + err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, cntr_id, rr->evtid, &tval, rr->arch_mon_ctx); if (!err) { rr->val +=3D tval; @@ -638,12 +644,20 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_mon_domain *d, /* * This is protected from concurrent reads from user as both * the user and overflow handler hold the global mutex. + * Skip the update if the counter is unassigned while mbm_event + * mode is enabled. */ - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID) && + (!resctrl_arch_mbm_cntr_assign_enabled(r) || + mbm_cntr_get(r, d, rdtgrp, QOS_L3_MBM_TOTAL_EVENT_ID) >=3D 0)) { mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_TOTAL_EVENT_ID); + } =20 - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID) && + (!resctrl_arch_mbm_cntr_assign_enabled(r) || + mbm_cntr_get(r, d, rdtgrp, QOS_L3_MBM_LOCAL_EVENT_ID) >=3D 0)) { mbm_update_one_event(r, d, rdtgrp, QOS_L3_MBM_LOCAL_EVENT_ID); + } } =20 /* diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 1539d1faa1a1..4b52bac5dbbc 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -507,6 +507,9 @@ void resctrl_offline_cpu(unsigned int cpu); * counter may match traffic of both @closid and @rmid, or @rmid * only. * @rmid: rmid of the counter to read. + * @cntr_id: Counter ID used to read MBM events in mbm_event mode. Only v= alid + * when mbm_event mode is enabled and @eventid is an MBM event. + * Can be negative when invalid. * @eventid: eventid to read, e.g. L3 occupancy. * @val: result of the counter read in bytes. * @arch_mon_ctx: An architecture specific value from @@ -524,8 +527,9 @@ void resctrl_offline_cpu(unsigned int cpu); * 0 on success, or -EIO, -EINVAL etc on error. */ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, - u32 closid, u32 rmid, enum resctrl_event_id eventid, - u64 *val, void *arch_mon_ctx); + u32 closid, u32 rmid, int cntr_id, + enum resctrl_event_id eventid, u64 *val, + void *arch_mon_ctx); =20 /** * resctrl_arch_rmid_read_context_check() - warn about invalid contexts @@ -566,12 +570,15 @@ struct rdt_domain_hdr *resctrl_find_domain(struct lis= t_head *h, int id, * @closid: closid that matches the rmid. Depending on the architecture, t= he * counter may match traffic of both @closid and @rmid, or @rmid only. * @rmid: The rmid whose counter values should be reset. + * @cntr_id: Counter ID used to read MBM events in mbm_event mode. Only va= lid + * when mbm_event mode is enabled and @eventid is an MBM event. Can + * be negative when invalid. * @eventid: The eventid whose counter values should be reset. * * This can be called from any CPU. */ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, - u32 closid, u32 rmid, + u32 closid, u32 rmid, int cntr_id, enum resctrl_event_id eventid); =20 /** --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2065.outbound.protection.outlook.com [40.107.93.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02657272E6E; Fri, 13 Jun 2025 21:08:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848920; cv=fail; b=Xe1q+tjnPhoKaEYM8qPTLZGqblM7dw+gQndaD1n+6QtbPT5l+Aph1X0rqlDgY2JUwzkDJLuetKyu1LQrpe8Ulm+DDYehNfTX5cwufRpAjpf5ASm+fXAU7casK2nnEC1nLi7Mn1Wla8IetB1Ss5Ql3bNV6rYXwoGT2DycRPGdP/o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848920; c=relaxed/simple; bh=L31aCqarey28i9I0CJ0sm9LRpN7Jd9evSz6Oyp/Hu7s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KE0Jyg3O0DL9CRRWvWzDd1tlfrJQNddd1JFpCEfzZC22Z8ZYv8jYaSb7vmG5a4Unu2cBB+RzVwmgfsi0DNRzMEjKLvcO9tekjnPTlnsT0SZChZxgigp6Wweeu79c65JUm/DS9K7wO7pylfxjlmUhfPYPgCOjTKujHMypNHC0zKI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=zsdl1yUT; arc=fail smtp.client-ip=40.107.93.65 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) header.d=amd.com header.i=@amd.com header.b="zsdl1yUT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e1PA3YxpnkjxfCMmeqbA1tg/7YZzhGnWlVrr9pq7ArV/gDR/wXnTFejt5PQYQvoY4y60acDtsH1B9S1+JAEzrIGVXO9Q86TTgQwEnz0VtbloLRJEdFnZClPBgEOaqb1FX+1gR72+ZvOgxKGJCDthVGrsWggXo4h/t9EagYMz4C2wlVUvueoCQviRH7oJhT8yJLXagOWKvaFnbQmmso3n+Zo5l20h7/A+f7FRvRZ7WMXg97TYTC0PSVY8qX4EgfVu66Ctf/lHxU6iprWBitc4eZihXvmjWZzZcqCAjFXOXREinnCuyGHrXY3hXiI7QgytEjB36NUa2H5cllBnK1oMGg== 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=Q6U8LdGvGhXhlsROb4YPBU5C5QiAFKLqBQXF5uQ4Y/0=; b=L9uhX2P5ou4LD8juE8R0S9M2C/GQ9LcwWcTNpO5J4HkIDKfmnBCdPabCJ3Yz2g4a/duO+BgoKPwl9XELDVGPhpWELEQJ1h2SuzuDOOK0SncGn6pmCTV6CSPSkof1+gLYDO/O7iIgIINiq6HTqTuXk2wg4VnDSYKgrVFfmray4lGsJ0PCrbsWWEHvR6jQYpnJKo1QxoIeADVrxOCF/6kfOukJ4lAO8zCfkM3eMfSyAExhsLwOxTpHAEWb3qattPRi8vNeEeQ+a0C5Z7PFtYvGHuHD2WGMOw4qYc40ludLPpuYHSFsNAGSkKLgIH3YqVPtfFsNfofrJitg+i2gSfiGbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=Q6U8LdGvGhXhlsROb4YPBU5C5QiAFKLqBQXF5uQ4Y/0=; b=zsdl1yUTcnxFNoMB3K7gdYCknRQAJ+Huu+ODdDMS4XLf+jVh/Q5imNe3niSW5RyRQPStZpKIUBOBqKLX0pVt7wZRcAtwOGk4JOdLlAokc+1JgNZJ3ntwRiQaIS2gPb8P9JU0BjKLhPVgBVb3Z0dtCEi59IuROnEL3rQpcpiiQUY= Received: from DM6PR05CA0052.namprd05.prod.outlook.com (2603:10b6:5:335::21) by IA1PR12MB6043.namprd12.prod.outlook.com (2603:10b6:208:3d5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.24; Fri, 13 Jun 2025 21:08:35 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:335:cafe::6f) by DM6PR05CA0052.outlook.office365.com (2603:10b6:5:335::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:08:35 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:35 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:33 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 23/32] fs/resctrl: Add definitions for MBM event configuration Date: Fri, 13 Jun 2025 16:05:07 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|IA1PR12MB6043:EE_ X-MS-Office365-Filtering-Correlation-Id: 1cca4e14-b7b0-47c6-8e39-08ddaabe75d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mZSjyJmefS2C4j5R4YCHp3+Ypv2kcAe8U+ecNtr5pnL/XnsUHklOHfE2nThp?= =?us-ascii?Q?zdz0fE8fD7mxgV65WOuNq3L0VY5jFXn5myTvZz5pRyakdaNgfeu9JKwZNbBi?= =?us-ascii?Q?eefyELp7w1Kv5rd+CiiK4QXnLXouJNdRWPZIBYqx8o/XcAMDp6MrucdVh66F?= =?us-ascii?Q?6MP4uj3bKOQq6JHlWl6fD7sD58mHj4PtnodGq/voxigweyExbpllTtOM9t0B?= =?us-ascii?Q?QMTX+1EmSKPHVcffnueejSZxyvMVxxrDD5IwS4UsQfiQFhdOCd4HW6obcuFe?= =?us-ascii?Q?9YgvdIf25axH1J2na4oBzoAF+f7eAyIcKzoojxVsgV6ZEsK1EWScwFFSAbl8?= =?us-ascii?Q?mKAhCAdzTHo3+NWKPCYg0ab5UClehmjdrrqbXYc0iMJT7jaEaWDMpgkVt68O?= =?us-ascii?Q?/oHyGL1ycgYDbfHOAHa3JCfE4cc/+uudglFm0yuBk1fFdEWh+1BnwJFBuTs+?= =?us-ascii?Q?NQYu0/rJb6peAfxTPot1zxdpdeuius+taTC3K4K6712+X9FF44yOqrJiodO/?= =?us-ascii?Q?dEzHQZ9amnXHUGz92CqjhpkoHCeU8NYgBpu49HZqnXZR+40nDe69Z5cu7OIh?= =?us-ascii?Q?x3HuB3u8M7qCfQXc7dvJm2v6eO0aqjff0mVJtBWHIRVqh1iT6WfELTRVob4+?= =?us-ascii?Q?7yvFe1lcr52ucfWSrTSPYhD5m81Qn/bfE+kL0VKP2NT5H4mpArl3V8fymXbI?= =?us-ascii?Q?TyaM2JJ/Tg3Xpu/cLgv0rlW1iNuvrt9L7vXB6YMob2Yb3EVGjwCG1qYmBNrP?= =?us-ascii?Q?6OM83yY6FasWUkhLyxoikVerDclmUPlAwQlxI/awrHAU6nqCcWIpIZH1qITY?= =?us-ascii?Q?0E9leTdp0Oe/tpKXSpP3k6HvYSQtizer6lB9oGgpLEwmE04mmXdlXhg1o1TC?= =?us-ascii?Q?KDjZhOybv+Rj7v6A/Wz5u/pE803cyrM+LC3pZ38DRUFJqqvQNrWhc6qhtOVj?= =?us-ascii?Q?z0bGegwwl7JBTlC/Ndf9O7l/msEDH1Me7e7F94wHbTll2hljxgCdD//63TqN?= =?us-ascii?Q?8NqXgsdp9TCnIYlisZaN4LraVA/xhqQI4ttbyn2+tm5SOJOj7pYPTP1YRLA+?= =?us-ascii?Q?IsTnLo3Sw8qcRF/n29pB6rzUEhYcjn05i/c57IPFPANWe3TT1ACZbF7bfpsx?= =?us-ascii?Q?SalK81Pp2QT59taKLD8cBQPW6k9y+kV8kRiQGPwgisOmQAcnTTuqSeVkEE3e?= =?us-ascii?Q?EM+da96YPpgu74qjbs2SouX+A+52DKaRGtcwHF8Nl71qenFokkgESqLbiyHF?= =?us-ascii?Q?de7ls+BUfALmRq4gdYs1VPSt9gAqYiVVXB3l/fe8KfELuJIAXtx8AXq2c5cu?= =?us-ascii?Q?puQ0mu0YsR3NC5pcNCNZ8CHX1RJRBrhCN4+ufmVZ2fbuGwl36XKLwRFrM1y8?= =?us-ascii?Q?Tma02AYwsknSa1WyPi2asxmjkGrbdGrEk0tabkMkN6cswRkdk/pRebIS2NSI?= =?us-ascii?Q?U7m9JUPAL2IssRpqU/jr49G8Vk4VZHjse3fo+7DD//VeGUih5eTRKS77jgw1?= =?us-ascii?Q?rxUExWAMtaUn0pwAKwIPdyOT0PTiDO9I8WFgZ7u6HQFnU3KRdIRdgmxD5A?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:35.3076 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1cca4e14-b7b0-47c6-8e39-08ddaabe75d8 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6043 Content-Type: text/plain; charset="utf-8" The "mbm_event" mode allows the user to assign a hardware counter ID to an RMID, event pair and monitor the bandwidth as long as it is assigned. Additionally, the user can specify a particular type of memory transactions for the counter to track. By default, each resctrl group supports two MBM events: mbm_total_bytes and mbm_local_bytes. Each event corresponds to an MBM configuration that specifies the memory transactions being tracked by the event. Add definitions for supported memory transactions (e.g., read, write, etc.). Signed-off-by: Babu Moger --- v14: Changed the term memory events to memory transactions to be consistant. Changed the name of the structure to mbm_config_value(from mbm_evt_val= ue). Changed name to memory trasactions where applicable. Changes subject line to fs/resctrl. v13: Updated the changelog. Removed the definitions from resctrl_types.h and moved to internal.h. Removed mbm_assign_config definition. Configurations will be part of mon_evt list. Resolved conflicts caused by the recent FS/ARCH code restructure. The rdtgroup.c file has now been split between the FS and ARCH directo= ries. v12: New patch to support event configurations via new counter_configs method. --- fs/resctrl/internal.h | 11 +++++++++++ fs/resctrl/rdtgroup.c | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 4a7130018aa1..84a136194d9a 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -212,6 +212,17 @@ struct rdtgroup { struct pseudo_lock_region *plr; }; =20 +/** + * struct mbm_config_value - Memory transaction an MBM event can be config= ured with. + * @name: Name of memory transaction (read, write ...). + * @val: The bit used to represent the memory transaction within an + * event's configuration. + */ +struct mbm_config_value { + char name[32]; + u32 val; +}; + /* rdtgroup.flags */ #define RDT_DELETED 1 =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 08bcca9bd8b6..5fb6a9939e23 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -75,6 +75,20 @@ static void rdtgroup_destroy_root(void); =20 struct dentry *debugfs_resctrl; =20 +/* Number of memory transactions that an MBM event can be configured with.= */ +#define NUM_MBM_EVT_VALUES 7 + +/* Decoded values for each type of memory transactions */ +struct mbm_config_value mbm_config_values[NUM_MBM_EVT_VALUES] =3D { + {"local_reads", READS_TO_LOCAL_MEM}, + {"remote_reads", READS_TO_REMOTE_MEM}, + {"local_non_temporal_writes", NON_TEMP_WRITE_TO_LOCAL_MEM}, + {"remote_non_temporal_writes", NON_TEMP_WRITE_TO_REMOTE_MEM}, + {"local_reads_slow_memory", READS_TO_LOCAL_S_MEM}, + {"remote_reads_slow_memory", READS_TO_REMOTE_S_MEM}, + {"dirty_victim_writes_all", DIRTY_VICTIMS_TO_ALL_MEM}, +}; + /* * Memory bandwidth monitoring event to use for the default CTRL_MON group * and each new CTRL_MON group created by the user. Only relevant when --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060.outbound.protection.outlook.com [40.107.93.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53293273D83; Fri, 13 Jun 2025 21:08:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848929; cv=fail; b=PhZNPca/FfveGNjfPe7jK1GopMKLhrIMHWsn8BocBN2fFQU56Q12d7VpiwjqDnfbRXojvh1OAvZHrXgx/ZxPobtVv8G0EVhuyPbtCZNJ+pCyzvQ1xPtU2JsPX28tRohO1/qqVAXTk9bLRsz7OMDTKQ2KUqGpDMGN0KBUdVELGnY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848929; c=relaxed/simple; bh=WvA3TKCNFS+unuzb5KJbiSYQ+U92xT0gtim7LjrjcZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=opRS4yGr+HZnHAAiL7aCaFjDNlCrL6WkBJXRIltHupuWykCkWKN1GAC21yv8r2xiq244KzeHQx2v9sdn6fgBtHxg0oBM2IbNPEWqfQ8Fhu/fF6tXbf/rfWcNxkCcA/AXcuCWbeFKuabD9outZCR0QApECwIetlwN/JSawgJ9LdI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=aLFfeo1B; arc=fail smtp.client-ip=40.107.93.60 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) header.d=amd.com header.i=@amd.com header.b="aLFfeo1B" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ywgsgqg3UkVYkHDqUXUibqW2C63dXCcABxL5sun0mNZCuOgJXNllD+5DTl08kpqx1TY6tO6Pl/E4vG2nrXpmxrY99Y+y1D2mWNZKNHawlItoi+ff6TiV+onEv2Km5oZCw59P+jQ2R5p74AewzADqOCaOFVC2JoUd+ben8Y78Y7i94zshmX8wNYnuMs4I94U5abSgED/uitnlteVRHc3QvXqxGSdsCeh4ruCyoGHh9+sGF1uIaMF3WXWz2+AzIDjrgIAsXQ05N0wi8dUV1cFG4jiude/2nEZey155v65iPxOsRdmKpJ1MemWTDjrNhlU9guP6C+wuKJNfJFz39+ViNA== 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=8vTjq62NH0fKFMgJ2gZOMDOOIUk1H/2KzfnAKvatPng=; b=CLO6E92n/sy+mHFNLkrmBc6wFJvPGxQJBtKKzz6Aa5p9NaYrjv8go2G0CrSmTXVGnxJDgFZf0SvS1y389P0Wx2Bo4JIB61vwZa6fDFXbB3LFwojwTFQFIup7eHEsoRXdr0uFWgrY3pEGjcJd1bR84/LsSATmZskUNhWyRISLQdy+sD9amJBt//9XY+unxtX8XhMK7M+l73AHOofxLp8m+xNXGImiI2WnjbD8dRDyzKr6RTKfXX/GC/pFcfLi75aMpum5h6RW6zdotHrdyybEDttVStijdodUPsNkAde9beivzcZfU+qUp9wp67mPQMqe615TEuLVIc52v01YuV8N1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=8vTjq62NH0fKFMgJ2gZOMDOOIUk1H/2KzfnAKvatPng=; b=aLFfeo1BYe5FgQi8P29TdICF2L+NYWVEp7IKUb+ZAT6kA7Kz41E2Bh6x130+egIM63yaUof5uIp9TigcTL2PQZXAfESA29oRsxr/sy0ggaXh97blGygLuT7xN2rPj2Sp/t4G9B7U8pDc8Gg9oIzN4RyNXHREsIELCxmC+Vvq6FM= Received: from CYZPR17CA0003.namprd17.prod.outlook.com (2603:10b6:930:8c::23) by CY8PR12MB7148.namprd12.prod.outlook.com (2603:10b6:930:5c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.25; Fri, 13 Jun 2025 21:08:44 +0000 Received: from CY4PEPF0000EDD4.namprd03.prod.outlook.com (2603:10b6:930:8c:cafe::51) by CYZPR17CA0003.outlook.office365.com (2603:10b6:930:8c::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.25 via Frontend Transport; Fri, 13 Jun 2025 21:08:44 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD4.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:44 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:41 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 24/32] fs/resctrl: Add event configuration directory under info/L3_MON/ Date: Fri, 13 Jun 2025 16:05:08 -0500 Message-ID: <612428100e6f4529294c3fead6850aaac303d82a.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD4:EE_|CY8PR12MB7148:EE_ X-MS-Office365-Filtering-Correlation-Id: adacf166-b47c-44f2-3d51-08ddaabe7b7a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?S+tNQ5LDs434v2PfGpyJDPKK7LvCxoaAhIEn601U74n6kHaEqT+0p+VuiLjl?= =?us-ascii?Q?btcL0fEGo8sWik5ylyn4DlrCG/r/FBKcKC8tDcIgWEpjmhw+aJJjnsmLZIx+?= =?us-ascii?Q?i1S5aLYNSlHXCXB/yfWzYbyEYMlijP9M9z6c+EuxawJ0geaJK7jhCLwlcDK4?= =?us-ascii?Q?per046XZsLWbiwruMl/9a1vo44epFI94y1IXcycrvimxjPzArdllxZROhZsq?= =?us-ascii?Q?Vh4ab1HOiC/26azSf0ZBOjI34UuB8jGaU1TVO2FXX/MHvBjCXC/PS9dmEzI2?= =?us-ascii?Q?9tbtrnqUKtq8pYkqGQZdz8UbFSBmNGeAttiQVINuD4WoUJjqXk/Z123M6FM8?= =?us-ascii?Q?xkbDhqZTB3kgMi7UiHhWc67TW85iPM+n88g13LHnV4a/HK4FHGi4gRrgNvix?= =?us-ascii?Q?0fDuWMaaDObndqPIpQtVH/pflqbAww6SmWfQ+UCOhY7FtmnvBT96QtFcAZio?= =?us-ascii?Q?aUjo5nyToMveT4y3IKx1vXsSsbnoQBRnymeQ0swtONBpIFpeW8HS0ngQ0kdw?= =?us-ascii?Q?/V9iNW921lTNO8HqJSpHutQ+WgnHKP20uLyuyIyB6K2s2+9pOuk8q1jsCLUh?= =?us-ascii?Q?2XVKvTIOka0K50bPHkTa8LtjQyAztiaKtQeSbfIL3vCy1JKK/7w5aLlMO46F?= =?us-ascii?Q?GBZqIlsO+hvQ8Mi31yh0CfrDXlzkOXfeR656Pht22zN2REn1XdaM203/EPGL?= =?us-ascii?Q?T+l+oIF9zygtvdL4eVM5qoQXiEpzVhaJuIiRZeUf8vOaWDiDJTQQvlQ77R+M?= =?us-ascii?Q?n6H11il/7sfudQtwOA9h3nxqZWB1oBiZZBmc7TkO5LVE5dPO9ZY3vZm3RMYf?= =?us-ascii?Q?DaUFT4R/oc0LbeKhoiL+R89jaVl5D/qb+Ik/x6Bc31qZ6mLzxZ8Aj12RYiPU?= =?us-ascii?Q?mUu4r8uxEj5ZBtEnYLARDV7PnqqrBvjVXUPGgwu3wuEKsug6kIFyVdVaslzb?= =?us-ascii?Q?BzHjrWMhJ9lx9rKYlyV/FjrwWZ+9MJIcCIcNVnz7dGpUB1azBDkrvHfoJMFQ?= =?us-ascii?Q?1LPgFXRz0vjLUy1LZwd33//FZesNtku7KFz1boWNxZH5wVaE5T0TZPif/UF7?= =?us-ascii?Q?1OkRMTUcDBaYPBFEswI0t2CXX8LYGTc90mwvgDQjM+h3scnP0BBYNCkhykc+?= =?us-ascii?Q?jtol2y3Aq+1kbVYTLv6CvgWjPSSPvLkycKRPD/fy68XxK4g1MU10MxLqaQsl?= =?us-ascii?Q?/DY72/LJsMFpPW28eE7a3+L0gYUFdN26O56jW1qHdt/PFGsNeboRoxaUB2GL?= =?us-ascii?Q?HQdomA8RAWm1c93ODqTaBzyn7uUDOJKvQhHoHS6gMG1b7PLq0i5lhusI4y1F?= =?us-ascii?Q?c7cWl79TBajv0xQVq8W4Ijc8eUvm9f1j0m8zwXWlYPMvyjm0eONmdgN5MysH?= =?us-ascii?Q?IfOYIu9XslBR4AtHgo/yobQoBSoquJQYxFyNNLk2gokLjTCFRJnECTCYD0Gc?= =?us-ascii?Q?XRV+eJA8FzboTtC568CFSQkZokNA8FD3yjYIQXdLYzvkV1IMHh629kqPBO0A?= =?us-ascii?Q?TVJ01/44+7rtndFz0zO1hGdp8sd853q51rJYyTI58zYd+Ejcw1p8zYpaWw?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:44.7603 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adacf166-b47c-44f2-3d51-08ddaabe7b7a 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7148 Content-Type: text/plain; charset="utf-8" When assignable counters are supported the /sys/fs/resctrl/info/L3_MON/event_configs directory contains a sub-directory for each MBM event that can be assigned to a counter. The MBM event sub-directory contains a file named "event_filter" that is used to view and modify which memory transactions the MBM event is configured with. Create the /sys/fs/resctrl/info/L3_MON/event_configs directory on resctrl mount and pre-populate it with directories for the two existing MBM events: mbm_total_bytes and mbm_local_bytes. Create the "event_filter" file within each MBM event directory with the needed *show() that displays the memory transactions with which the MBM event is configured. Example: $ mount -t resctrl resctrl /sys/fs/resctrl $ cd /sys/fs/resctrl/ $ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter local_reads, remote_reads, local_non_temporal_writes, remote_non_temporal_writes, local_reads_slow_memory, remote_reads_slow_memory, dirty_victim_writes_all $ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter local_reads, local_non_temporal_writes, local_reads_slow_memory Signed-off-by: Babu Moger --- v14: Updated the changelog with context. Thanks to Reinette. Changed the name of directory to event_configs from counter_config. Updated user doc about the memory transactions supported by assignment. Removed mbm_mode from struct mon_evt. Not required anymore. v13: Updated user doc (resctrl.rst). Changed the name of the function resctrl_mkdir_info_configs to resctrl_mkdir_counter_configs(). Replaced seq_puts() with seq_putc() where applicable. Removed RFTYPE_MON_CONFIG definition. Not required. Changed the name of the flag RFTYPE_CONFIG to RFTYPE_ASSIGN_CONFIG. Reinette suggested RFTYPE_MBM_EVENT_CONFIG but RFTYPE_ASSIGN_CONFIG seemed shorter and pricise. The configuration is created using evt_list. Resolved conflicts caused by the recent FS/ARCH code restructure. The monitor.c/rdtgroup.c files have been split between the FS and ARCH= directories. v12: New patch to hold the MBM event configurations for mbm_cntr_assign mod= e. --- Documentation/filesystems/resctrl.rst | 32 +++++++++++ fs/resctrl/internal.h | 2 + fs/resctrl/monitor.c | 1 + fs/resctrl/rdtgroup.c | 78 +++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index 18de335e1ff8..b1db1a53db2a 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -310,6 +310,38 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs 0=3D30;1=3D30 =20 +"event_configs": + Directory that exists when "mbm_event" mode is supported. Contains + sub-directory for each MBM event that can be assigned to a counter. + + Two MBM events are supported by default: mbm_local_bytes and mbm_total_by= tes. + Each MBM event's sub-directory contains a file named "event_filter" that = is + used to view and modify which memory transactions the MBM event is config= ured + with. + + List of memory transaction types supported: + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + Name Description + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + dirty_victim_writes_all Dirty Victims from the QOS domain to all type= s of memory + remote_reads_slow_memory Reads to slow memory in the non-local NUMA do= main + local_reads_slow_memory Reads to slow memory in the local NUMA domain + remote_non_temporal_writes Non-temporal writes to non-local NUMA domain + local_non_temporal_writes Non-temporal writes to local NUMA domain + remote_reads Reads to memory in the non-local NUMA domain + local_reads Reads to memory in the local NUMA domain + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + + For example:: + + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_f= ilter + local_reads, remote_reads, local_non_temporal_writes, remote_non_tempor= al_writes, + local_reads_slow_memory, remote_reads_slow_memory, dirty_victim_writes_= all + + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_f= ilter + local_reads, local_non_temporal_writes, local_reads_slow_memory + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 84a136194d9a..ed0e3b695ad5 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -248,6 +248,8 @@ struct mbm_config_value { =20 #define RFTYPE_DEBUG BIT(10) =20 +#define RFTYPE_ASSIGN_CONFIG BIT(11) + #define RFTYPE_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL) =20 #define RFTYPE_MON_INFO (RFTYPE_INFO | RFTYPE_MON) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index ef6ef58f180b..09a49029a800 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -956,6 +956,7 @@ int resctrl_mon_resource_init(void) RFTYPE_MON_INFO | RFTYPE_RES_CACHE); resctrl_file_fflags_init("available_mbm_cntrs", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); + resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG); } =20 return 0; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5fb6a9939e23..e2fa5e10c2dd 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1909,6 +1909,25 @@ static int resctrl_available_mbm_cntrs_show(struct k= ernfs_open_file *of, return ret; } =20 +static int event_filter_show(struct kernfs_open_file *of, struct seq_file = *seq, void *v) +{ + struct mon_evt *mevt =3D rdt_kn_parent_priv(of->kn); + bool sep =3D false; + int i; + + for (i =3D 0; i < NUM_MBM_EVT_VALUES; i++) { + if (mevt->evt_cfg & mbm_config_values[i].val) { + if (sep) + seq_putc(seq, ','); + seq_printf(seq, "%s", mbm_config_values[i].name); + sep =3D true; + } + } + seq_putc(seq, '\n'); + + return 0; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -2033,6 +2052,12 @@ static struct rftype res_common_files[] =3D { .seq_show =3D mbm_local_bytes_config_show, .write =3D mbm_local_bytes_config_write, }, + { + .name =3D "event_filter", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D event_filter_show, + }, { .name =3D "mbm_assign_mode", .mode =3D 0444, @@ -2315,6 +2340,53 @@ static int rdtgroup_mkdir_info_resdir(void *priv, ch= ar *name, return ret; } =20 +static int resctrl_mkdir_counter_configs(struct rdt_resource *r, char *nam= e) +{ + struct kernfs_node *l3_mon_kn, *kn_subdir, *kn_subdir2; + struct mon_evt *mevt; + int ret; + + l3_mon_kn =3D kernfs_find_and_get(kn_info, name); + if (!l3_mon_kn) + return -ENOENT; + + kn_subdir =3D kernfs_create_dir(l3_mon_kn, "event_configs", l3_mon_kn->mo= de, NULL); + if (IS_ERR(kn_subdir)) { + kernfs_put(l3_mon_kn); + return PTR_ERR(kn_subdir); + } + + ret =3D rdtgroup_kn_set_ugid(kn_subdir); + if (ret) { + kernfs_put(l3_mon_kn); + return ret; + } + + for (mevt =3D &mon_event_all[0]; mevt < &mon_event_all[QOS_NUM_EVENTS]; m= evt++) { + if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid)) + continue; + + kn_subdir2 =3D kernfs_create_dir(kn_subdir, mevt->name, kn_subdir->mode,= mevt); + if (IS_ERR(kn_subdir2)) { + ret =3D PTR_ERR(kn_subdir2); + goto out_config; + } + + ret =3D rdtgroup_kn_set_ugid(kn_subdir2); + if (ret) + goto out_config; + + ret =3D rdtgroup_add_files(kn_subdir2, RFTYPE_ASSIGN_CONFIG); + if (!ret) + kernfs_activate(kn_subdir); + } + +out_config: + kernfs_put(l3_mon_kn); + + return ret; +} + static unsigned long fflags_from_resource(struct rdt_resource *r) { switch (r->rid) { @@ -2361,6 +2433,12 @@ static int rdtgroup_create_info_dir(struct kernfs_no= de *parent_kn) ret =3D rdtgroup_mkdir_info_resdir(r, name, fflags); if (ret) goto out_destroy; + + if (r->mon.mbm_cntr_assignable) { + ret =3D resctrl_mkdir_counter_configs(r, name); + if (ret) + goto out_destroy; + } } =20 ret =3D rdtgroup_kn_set_ugid(kn_info); --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2081.outbound.protection.outlook.com [40.107.94.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61FDD27380D; Fri, 13 Jun 2025 21:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848941; cv=fail; b=OfA54c3lh4gAfRyDwAwftIpfsrZdhXpYH/DHHWS/xL16VArHnI2LjP5iar8poTt/SLVh1BrLetyUiFV77H33I0DTpwOWt9XCEhpR1dULuYdE5N2BK5wb/aK8Eik3xGqKZuAEVex1glHbxSnzXj9EWwDL8RpiredqlXH6k7SZB4U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848941; c=relaxed/simple; bh=Onvxk7f26RVub/XLUEv4gvotG8WpGrNqRU4+/3Y2a0M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MS7MdafQawpam5FhgO0QlshU0NZfe+dqLMNfsaBDLfrXEno4IHnJpUpskm78LaRgwIsshppvtSlccSFwTP848e+YUdp6C70jkXZaSrPTF4drFSa0SvOIK1S3ykWkd6tbnRMuvzE9wD5VwO85U2qMt3ISG1oUjlSn2L7c5fBJ7mo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=BLztImF5; arc=fail smtp.client-ip=40.107.94.81 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) header.d=amd.com header.i=@amd.com header.b="BLztImF5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u3l4h7p/Qen2iKqrkpPW8lt++lBAqS4C7F3+5ZhMQeq8QBzc3Wy6JHm2Rmd51nT2vhXHdWXKvFMdiZ4eLpPNrXM+HsBuJs5Cpqit0VQ/UtRcH92J9S1G18yvkxpM/AVG7libYRRHUvh1ujA7OU0U3aQyaNQIQhXdYVYnYZrgi2jlbV/pU+h0pOy6g9zOcy3PAQMP6/JxsX7OUa2P1dm5lbbfJqHk9SIIP46wSvIhN98UJZV4qlbH7j5K6VsmmoQjyplIaaErd2cxYViQ053HqC7YaaF+GPJQxOXrp46qALwh0TF2x45ztA8WfRs/lrjsQ343tBpAbNf/kUgYvc1o1w== 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=oNyLC52AeTCBT/3TUcOWmscRgPRuAXlXQmP9jPfQaXU=; b=QN7ht3r8PbfHX3o4BYLSlf4MwUxDv1fnHJSzUftVjVIWa/5hSVZKkaTTjnsmwqa7XMD2ZRJdjZjVeEy0AkRjUGjZ2Ka/NY/f+PZ2GBmhImD+MJFH9F6Bh7T7jEMR+z7SCTFdaA3lv5VKl91oJ1NhjO6T4c0AQGr6jep7iQX1SjqN5GFv2GpdheVb6TEWOl0IE4ASsO9xw8dBDNEwy27EO6VXvYLxn/fUe8zWhveTkrMyGi3s7M0ic0nRTK6uLBKGGd/jANLhry1zO2eBLciqUKGMV8+WRzO853Vv/6UUZZ8/ew+EQF0Tv8OF1+S3tihxTHiGJiaybd4fHwTGsx65Zw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=oNyLC52AeTCBT/3TUcOWmscRgPRuAXlXQmP9jPfQaXU=; b=BLztImF5neFNat54iY/vY2/KGj+0QATGuwyq666Ig4x5NZRey5NJK08HgUyDFhnXmrxJlgTRPclWlNJe2HGXGqFUjO/i61B/3Mi7WAp/hbcGNrIO+wh80Y+jvPXDTadQDlnsEHw6lpQU7DoxRqnQ8/m6DqefrSidrIEa27gxUPU= Received: from PH8PR21CA0020.namprd21.prod.outlook.com (2603:10b6:510:2ce::27) by LV3PR12MB9267.namprd12.prod.outlook.com (2603:10b6:408:211::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.21; Fri, 13 Jun 2025 21:08:56 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:2ce:cafe::65) by PH8PR21CA0020.outlook.office365.com (2603:10b6:510:2ce::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.11 via Frontend Transport; Fri, 13 Jun 2025 21:08:56 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:08:56 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:49 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 25/32] fs/resctrl: Provide interface to update the event configurations Date: Fri, 13 Jun 2025 16:05:09 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|LV3PR12MB9267:EE_ X-MS-Office365-Filtering-Correlation-Id: eb77f6d3-f632-440c-a24d-08ddaabe8279 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|1800799024|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?yOL5opTNijo+Dm7vU3fS1eANTdpYp7ZLnEGMGzdH9Hgy1lMFds0imwVVEfpa?= =?us-ascii?Q?n8ifZphHikUyIxML9oLCtdrL1Puudt3PrZbU0NlCUkjF7dvoz6QSdFWvWWH0?= =?us-ascii?Q?RuhW202dGY57uPWjESY5+oWKyZo8uZr5R/6mclhuJrchZgFojcVnyBesPz8j?= =?us-ascii?Q?DrLzBGMq/hBjwG0dRhifhuT4d8qT7CmOLRGNdKZ/KKreDeWFSn7HBwUoqgoT?= =?us-ascii?Q?YmQncDWUtg+wBczD5TIIUhCygt48k72AiizOs8UiOJ2A0FGnF4MYLB5jyVBV?= =?us-ascii?Q?qZ4Wv0fbAmh5CZ5eRyjvU3e4BMcWpLxi7y1bfhIl67p+o6lGqRh64Tralu3f?= =?us-ascii?Q?npwLYem+WQ87Y/mpMrQpFr1YToZB5xrST9qBHfR4U9gBqy+lVQThwPxPgQmQ?= =?us-ascii?Q?FdYQ39FRm90lasgF/z+TsonR2QBzVXm8XKyxoFcDHn+ObBM7Ns1BO9ZZ6lcE?= =?us-ascii?Q?xopTP1q4DugVCRK1AGI099epyRiTCFOnJYnHycbYDZmxiDZyTf2UyxDPLzXI?= =?us-ascii?Q?6qBqoMsgxnF1RO8vuCGLCdD/hRJ6agpSTNU8ACwQPYCLw6B8ylQtTtdiyywc?= =?us-ascii?Q?7AptDEXV7VpyNucinDOQDMNVcu+09jICtMiZ/elgkK7SbXYN0FJ01WpwABQD?= =?us-ascii?Q?P8UyhX6cwiKHfkU3GC6LuqEApkOn/waogpnXTSHkhxzVM22cxWhvMQjO6TnW?= =?us-ascii?Q?HIqSEzREpUQLWWdvnL8ypAF0gWi2LbomIas9NQzkqaJSzJu94vB4i3FfhNku?= =?us-ascii?Q?e09Pm1seBJoqDBoHFSvoJ9UDneTwISkm+1jumss10defgXoMt4ix7Oi3wlav?= =?us-ascii?Q?tqpinaSco5kwqAgxjcGvxmjdw0xtWh5aMMFNaor8eqtywk9hy+cMcnz4ggCS?= =?us-ascii?Q?10EmHvb6O4ieogYhzWSIkViJtd79FCEncS37xuxZaEk676xD52UjHkkYngs1?= =?us-ascii?Q?Z0fTsOUagK7hgFHzjLk+cvnvsjDzbE2xJOdP3dDF5hsRKX4fsJTFWBUoQCvk?= =?us-ascii?Q?65Xaj9D24mAcPO8y6OHwpk9bf+PAeMGQCBKnHZxSc1v201H3jGQKtxxIWPiv?= =?us-ascii?Q?3J5E0P09LDPUqLSYtCl3eJqwhubKrnCSxa7o96ICTC/1XcGjJUrKcAISK6JS?= =?us-ascii?Q?A//DxFkrgonJciYdkwDCGqKF3C9YqFGZ4fRzd+3o7ak+K9q3MBO3xTb36fp8?= =?us-ascii?Q?mUI6KnBs+EgsJGRZm6uowBOS2niB19/4uknAyBnb0/jMA9aEf1QqvKPN3vsL?= =?us-ascii?Q?1DlOW5AcHaxsDri+/Ada1q3+xUAhX5yL3YjP/h1TQV0B1DGWSvNxH4JSuIPH?= =?us-ascii?Q?Tb1PPPll55rqpeUSnq5bWYH9Ug5AKeIqfCC2YEVgEJgI++EMcIW5HVoLJLUM?= =?us-ascii?Q?l/jFGtXPPOFIcK/TsJzvel3Vo/s0hL6TmjGQbECIN7xGaX8TIEennaBqmLFe?= =?us-ascii?Q?iODD0I6Qx/KX95H4wtL2B5ocsT4Vc2Y3MypXiV2MZ/ZcgP/UpJEn8OoE2CpN?= =?us-ascii?Q?mVttYC6vORI6ctZDB7r9vyoCBMHEPKtrptoEQKb6JfOxpvZKHj1uwFXwpw?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(1800799024)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:08:56.4999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb77f6d3-f632-440c-a24d-08ddaabe8279 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9267 Content-Type: text/plain; charset="utf-8" When assignable counters are supported the users can modify the event configuration by writing to the 'event_filter' interface file. The event configurations for mbm_event mode are located in /sys/fs/resctrl/info/L3_MON/event_configs/. Update the assignments of all groups when the event configuration is modified. Example: $ mount -t resctrl resctrl /sys/fs/resctrl $ cd /sys/fs/resctrl/ $ cat info/L3_MON/event_configs/mbm_local_bytes/event_filter local_reads,local_non_temporal_writes,local_reads_slow_memory $ echo "local_reads,local_non_temporal_writes" > info/L3_MON/event_configs/mbm_total_bytes/event_filter $ cat info/L3_MON/event_configs/mbm_total_bytes/event_filter local_reads,local_non_temporal_writes Signed-off-by: Babu Moger --- v14: Passed struct mon_evt where applicable instead of just the event type. Fixed few text corrections about memory trasaction type. Renamed few functions resctrl_group_assign() -> rdtgroup_assign_cntr() resctrl_update_assign() -> resctrl_assign_cntr_allrdtgrp() Removed few extra bases. v13: Updated changelog for imperative mode. Added function description in the prototype. Updated the user doc resctrl.rst to address few feedback. Resolved conflicts caused by the recent FS/ARCH code restructure. The rdtgroup.c/monitor.c file has now been split between the FS and AR= CH directories. v12: New patch to modify event configurations. --- Documentation/filesystems/resctrl.rst | 12 +++ fs/resctrl/rdtgroup.c | 120 +++++++++++++++++++++++++- 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index b1db1a53db2a..2cd6107ca452 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -342,6 +342,18 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_f= ilter local_reads, local_non_temporal_writes, local_reads_slow_memory =20 + Modify the event configuration by writing to the "event_filter" file with= in the + configuration directory. The read/write event_filter file contains the co= nfiguration + of the event that reflects which memory transactions are counted by it. + + For example:: + + # echo "local_reads, local_non_temporal_writes" > + /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_total_bytes/event_fil= ter + + # cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_total_bytes/event= _filter + local_reads, local_non_temporal_writes + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index e2fa5e10c2dd..fdea608e0796 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1928,6 +1928,123 @@ static int event_filter_show(struct kernfs_open_fil= e *of, struct seq_file *seq, return 0; } =20 +/** + * rdtgroup_assign_cntr - Update the counter assignments for the event in + * a group. + * @r: Resource to which update needs to be done. + * @rdtgrp: Resctrl group. + * @mevt: MBM monitor event. + */ +static int rdtgroup_assign_cntr(struct rdt_resource *r, struct rdtgroup *r= dtgrp, + struct mon_evt *mevt) +{ + struct rdt_mon_domain *d; + int cntr_id; + + list_for_each_entry(d, &r->mon_domains, hdr.list) { + cntr_id =3D mbm_cntr_get(r, d, rdtgrp, mevt->evtid); + if (cntr_id >=3D 0 && d->cntr_cfg[cntr_id].evt_cfg !=3D mevt->evt_cfg) { + d->cntr_cfg[cntr_id].evt_cfg =3D mevt->evt_cfg; + resctrl_arch_config_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, + rdtgrp->closid, cntr_id, true); + } + } + + return 0; +} + +/** + * resctrl_assign_cntr_allrdtgrp - Update the counter assignments for the = event + * for all the groups. + * @r: Resource to which update needs to be done. + * @mevt MBM Monitor event. + */ +static void resctrl_assign_cntr_allrdtgrp(struct rdt_resource *r, struct m= on_evt *mevt) +{ + struct rdtgroup *prgrp, *crgrp; + + /* + * Check all the groups where the event tyoe is assigned and update + * the assignment + */ + list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { + rdtgroup_assign_cntr(r, prgrp, mevt); + + list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list) + rdtgroup_assign_cntr(r, crgrp, mevt); + } +} + +static int resctrl_process_configs(char *tok, u32 *val) +{ + char *evt_str; + u32 temp_val; + bool found; + int i; + +next_config: + if (!tok || tok[0] =3D=3D '\0') + return 0; + + /* Start processing the strings for each memory transaction type */ + evt_str =3D strim(strsep(&tok, ",")); + found =3D false; + for (i =3D 0; i < NUM_MBM_EVT_VALUES; i++) { + if (!strcmp(mbm_config_values[i].name, evt_str)) { + temp_val =3D mbm_config_values[i].val; + found =3D true; + break; + } + } + + if (!found) { + rdt_last_cmd_printf("Invalid memory transaction type %s\n", evt_str); + return -EINVAL; + } + + *val |=3D temp_val; + + goto next_config; +} + +static ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + struct mon_evt *mevt =3D rdt_kn_parent_priv(of->kn); + u32 evt_cfg =3D 0; + int ret =3D 0; + + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') + return -EINVAL; + + buf[nbytes - 1] =3D '\0'; + + cpus_read_lock(); + mutex_lock(&rdtgroup_mutex); + + rdt_last_cmd_clear(); + + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { + rdt_last_cmd_puts("mbm_cntr_assign mode is not enabled\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + ret =3D resctrl_process_configs(buf, &evt_cfg); + if (!ret && mevt->evt_cfg !=3D evt_cfg) { + mevt->evt_cfg =3D evt_cfg; + resctrl_assign_cntr_allrdtgrp(r, mevt); + } + +out_unlock: + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + + return ret ?: nbytes; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -2054,9 +2171,10 @@ static struct rftype res_common_files[] =3D { }, { .name =3D "event_filter", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, .seq_show =3D event_filter_show, + .write =3D event_filter_write, }, { .name =3D "mbm_assign_mode", --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2068.outbound.protection.outlook.com [40.107.244.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F05E273810; Fri, 13 Jun 2025 21:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848945; cv=fail; b=hOPVbBu3XZMjAZLfDmk239H/F/yvHZ2zjNrOUQaEnlOMYDGJ/3YR3LFUK3JN4sO3lWelYJ3ZMuelNNiFHnnuwCGnGjKyrFCmMe7YQ1CxFoChaKqvA09ZlF6orvdXxX9gQ8yUJbt8kT9r5SGNbD+P/0eFKr7lU61Ij5ttie9xcSI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848945; c=relaxed/simple; bh=4bFMNdnQf+6YNkTZeoM5BMqDzhqlKiQonnTCxDaLEQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QLZ0DvkOw86mbwRmSQlaF/7goeTl3J1yWnGBhDiVMDW03GWsgvle0LlD02CgMyuuLiit8JKYbj+9N3HpnBkVeH0+Aj/k26F7c2SJARO+cYb/FGvJpLaK+6ilZ4w3Dv3ARlVSs2fPOKsI7Y/7vz7uHlUfgM7vjqBfFAsG5rgz+Ns= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=XnNByYi8; arc=fail smtp.client-ip=40.107.244.68 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) header.d=amd.com header.i=@amd.com header.b="XnNByYi8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MwoQ6b7igQ58dZ5suH7Jf7Za7rU0Rr7OsEWC1fdmA6eGe0sLKoJl1drtikEgjv1unEVFn5mwWdN040l1aMtc2M5x3c1UZIP8WTMgcaC9+392nx39/nyOYieLUwl/eLiVhq86bmiuRWfdA+WuA9aOb3L5t9SSKd9AnJleH3AXLYN73NZ5Tli9moJB942VykpHbaxE103shPZnQj0r1D63JV6xxsA3o29XrixeM4qtP8NYHiVMcd0h9dwQ2AWegL7TEJzAbaafa9YDwX/0RrkN9betwab5O+h4I6BOGZAxPaoy0FomZM38+40x1KGYuAmopemEXADLiSQlUQid8a8z0g== 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=i0qd+DykOPr3yHTX/yOD+ziS4y8nvw4ixsfA/dt0UgY=; b=Ci0AZ2EswykV3pvNdhogMfRZwGa/yZxWRxGn1mGHihiac9wlGTV9CkR2/q7WzZBw2zSStSzLaWUExMzrS1I7rxgXcghfe+ZsqkhjzvBtZStn7tJdeoOoemB9rYYkSimFyHwAUQ7G+s4YVuS36isF+Rx3xp14tSSQcixCHTikJt7i72qgJh61tHdiXyABEHKueswvJ4BuOJ9zFV283maXmUsVPJP79PwnuJI9WKIthKECPLMH1tokVk3R9Q6Dh11EN0z8t6cJSS0XI2nJU49ngDExBKYLYwIpsJBTBAdK6Wf0JQ7WGueCHovz/+UbjxM5HOP4ECckW3lRFCChFL6tJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=i0qd+DykOPr3yHTX/yOD+ziS4y8nvw4ixsfA/dt0UgY=; b=XnNByYi8KU4MPWv3IeDxKt+n9SSZlyV352xN6x7vy+oJqMAy0Lx86URcnfeRlTPBT6BSIvxI8tqMgHfDfoxhc7PsawmSGHl3KLeuxDp9h5EnAQN111p0a7UNVydLjd6i7F56n50rDgj8sYhoq49O3VM2ivmQCL6P9msrd08FTBA= Received: from PH8PR21CA0003.namprd21.prod.outlook.com (2603:10b6:510:2ce::14) by BN3PR12MB9594.namprd12.prod.outlook.com (2603:10b6:408:2cb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.23; Fri, 13 Jun 2025 21:09:01 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:2ce:cafe::17) by PH8PR21CA0003.outlook.office365.com (2603:10b6:510:2ce::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:09:01 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:00 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:08:57 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 26/32] fs/resctrl: Introduce mbm_assign_on_mkdir to enable assignments on mkdir Date: Fri, 13 Jun 2025 16:05:10 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|BN3PR12MB9594:EE_ X-MS-Office365-Filtering-Correlation-Id: 14f7267c-7a70-400e-ca4a-08ddaabe850f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9DV752GlTr/mzOatJd9ZY2AjJs5gd6PfGKcpMTYFijPPUPzE+1Ch8Th0/mzK?= =?us-ascii?Q?KHtDiaKUqfOX4rDYgfix0GjqC0OMS2qBT6ZmJxSu6HHfUrGVDBk2GjHExjh7?= =?us-ascii?Q?iQMyUoS0vcaZbC6Kp3o1zKv4VlAR5ZSVWYeWYHMAabVem4uQfDJqtNWG4g56?= =?us-ascii?Q?d5tvz9Sm5pwujALBIIKuJucJ5q2+1aG9ECYQq4GBUhJ2q2wzgL8knig2wMhu?= =?us-ascii?Q?z6dJVSVdmbPJS2QwMHI2/+FYIOY2WL1RA3MEZ+eyT76cinmylFerC+bMSeJv?= =?us-ascii?Q?bRArxTWg/Wk9/jcYbzjcnKZLDa1NkYqRvU++YRnKoKF9dHkD4cVFTcfIvuns?= =?us-ascii?Q?8bBAa1xu686zkug8IZyzo/LvGOY9uKjjWqDh535Pu9nOWxgLgxQiGHEkhQri?= =?us-ascii?Q?iYCh9yS0lOSaeOgLeULNKt0OqBBGvUiUcVPDQHWxNvYQLoBEUM9BW6v28Xhe?= =?us-ascii?Q?Sc5KsoD+kJ6DUzMGIcXshrnG2xpnbwn+hHAiAzq40GK0Rwd83B8VQXK5TFgx?= =?us-ascii?Q?fvp64mrHqT7CtN/OWYniQ3vsXB9x9RYFieCw/M+Unl81eFjmQ19MgjSLkXnu?= =?us-ascii?Q?LEsBQKXRuz5zuEq196Wp7NjdgS7Q4RnpzPtyWiHe6hk9z0S4/W9w25rGv1VP?= =?us-ascii?Q?3Uoc+iu6xlkQ0MANb08YUbRHJBzYiu6ulwf2jVzHa0828JD2e2yeqMWc8RZ4?= =?us-ascii?Q?G3SxlzjCW4+t8d532hvvbqqFWc7PVM1MglnAaCZuLfFeCMzed7YhEr6mpA8T?= =?us-ascii?Q?1UAQKZHCo3VssOZC+aM4qiWbrq0k+G0ef1Vrg5NdTqkFOTBFO8SykAysuJZe?= =?us-ascii?Q?zV9g5dUP3ye11Sr276wLFtQBTHvwjkOcySGYNq+2I2DUOcvBdEWL015Vn8xR?= =?us-ascii?Q?DfwA/5td7TsDryofwCrweBOddnw+Lcz9gyBtzmE1+/7+5MD0sSsaqaazx9W6?= =?us-ascii?Q?nw8hB1Ov+4mPN2SqvTaM/BWGSxVp/5bB3OjaDVEV+4702pgWKVbWTC8AdBcO?= =?us-ascii?Q?zJnPne9Dz3o5XIS2kGXcAMVmZVnxBLh1jvM2e4pFyd9VLLElkp8gMrhuC/UO?= =?us-ascii?Q?DqVsJwFvUyyrBK/Uln3nJpzfzTFRnTGSJMcR4knSpJ5JLBIKdYbOEUIy4aMH?= =?us-ascii?Q?r+ngASmuHQANG/tMw9zad6HacTWT1ZMLJFbm9qTfH1u5NJbFQPs/OLc7zYbF?= =?us-ascii?Q?RvA0ftBp0usVGapY2XtVlm8kycB81nkNSYDYIP5Pc7Tazhz1iC81/or2o4FR?= =?us-ascii?Q?ytx1rrLOn54rJ3AdgrJMBkdLy03tPCLxN3jcqm3hyjX7JbiS+7uC/1Cfb9w9?= =?us-ascii?Q?bdEQZdFGmspinKuBEeaUtvzfV/Y+gL3ca5rUXeli/VQ/TRT0I5DZ0QmqeIR9?= =?us-ascii?Q?XLYJYJUGkDFEY+58S5ccpRRwec9IeD4zOA3rAOrCp8igPp9ECeVLKC+QLrV4?= =?us-ascii?Q?joLSk2SekkgtdRDGwdc8fVWRbHJmwyDLpFyKrS03lvag8Kt8SEWsz+DD6tQc?= =?us-ascii?Q?y58vCMhCuImuaVo9xbNnWpPAKJso8YeH/FcEblH2qYX9VA50RTFpVwiVAw?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:00.8391 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14f7267c-7a70-400e-ca4a-08ddaabe850f 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR12MB9594 Content-Type: text/plain; charset="utf-8" The "mbm_event" mode allows users to assign a hardware counter ID to an RMID, event pair and monitor the bandwidth as long as it is assigned. Introduce a user-configurable option that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir. Suggested-by: Peter Newman Signed-off-by: Babu Moger --- v14: Added rdtgroup_mutex in resctrl_mbm_assign_on_mkdir_show(). Updated resctrl.rst for clarity. Fixed squashing of few previous changes. Added more code documentation. v13: Added Suggested-by tag. Resolved conflicts caused by the recent FS/ARCH code restructure. The rdtgroup.c/monitor.c file has now been split between the FS and AR= CH directories. v12: New patch. Added after the discussion on the list. https://lore.kernel.org/lkml/CALPaoCh8siZKjL_3yvOYGL4cF_n_38KpUFgHVGbQ= 86nD+Q2_SA@mail.gmail.com/ --- Documentation/filesystems/resctrl.rst | 16 ++++++++++ fs/resctrl/monitor.c | 2 ++ fs/resctrl/rdtgroup.c | 43 +++++++++++++++++++++++++++ include/linux/resctrl.h | 3 ++ 4 files changed, 64 insertions(+) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index 2cd6107ca452..f94c7c387416 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -354,6 +354,22 @@ with the following files: # cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_total_bytes/event= _filter local_reads, local_non_temporal_writes =20 +"mbm_assign_on_mkdir": + Determines if a counter will automatically be assigned to an RMID, event = pair + when its associated monitor group is created via mkdir. It is enabled by = default + on boot and users can disable by writing to the interface. + + "0": + Auto assignment is disabled. + "1": + Auto assignment is enabled. + + Example:: + + # echo 0 > /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_on_mkdir + 0 + "max_threshold_occupancy": Read/write file provides the largest value (in bytes) at which a previously used LLC_occupancy diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 09a49029a800..1ec2efd50273 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -957,6 +957,8 @@ int resctrl_mon_resource_init(void) resctrl_file_fflags_init("available_mbm_cntrs", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG); + resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO | + RFTYPE_RES_CACHE); } =20 return 0; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index fdea608e0796..bf5fd46bd455 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2045,6 +2045,42 @@ static ssize_t event_filter_write(struct kernfs_open= _file *of, char *buf, return ret ?: nbytes; } =20 +static int resctrl_mbm_assign_on_mkdir_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + + mutex_lock(&rdtgroup_mutex); + rdt_last_cmd_clear(); + + seq_printf(s, "%u\n", r->mon.mbm_assign_on_mkdir); + + mutex_unlock(&rdtgroup_mutex); + + return 0; +} + +static ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *= of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + bool value; + int ret; + + ret =3D kstrtobool(buf, &value); + if (ret) + return ret; + + mutex_lock(&rdtgroup_mutex); + rdt_last_cmd_clear(); + + r->mon.mbm_assign_on_mkdir =3D value; + + mutex_unlock(&rdtgroup_mutex); + + return ret ?: nbytes; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -2054,6 +2090,13 @@ static struct rftype res_common_files[] =3D { .seq_show =3D rdt_last_cmd_status_show, .fflags =3D RFTYPE_TOP_INFO, }, + { + .name =3D "mbm_assign_on_mkdir", + .mode =3D 0644, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D resctrl_mbm_assign_on_mkdir_show, + .write =3D resctrl_mbm_assign_on_mkdir_write, + }, { .name =3D "num_closids", .mode =3D 0444, diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 4b52bac5dbbc..39dd3acff372 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -281,12 +281,15 @@ enum resctrl_schema_fmt { * monitoring events are configured. * @num_mbm_cntrs: Number of assignable counters. * @mbm_cntr_assignable:Is system capable of supporting counter assignment? + * @mbm_assign_on_mkdir:True if counters should automatically be assigned = to MBM + * events of monitor groups created via mkdir. */ struct resctrl_mon { int num_rmid; unsigned int mbm_cfg_mask; int num_mbm_cntrs; bool mbm_cntr_assignable; + bool mbm_assign_on_mkdir; }; =20 /** --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2064.outbound.protection.outlook.com [40.107.220.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 127B42727E7; Fri, 13 Jun 2025 21:09:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848952; cv=fail; b=gl1clhQpopjOV49SI/7bmKWuSb1kHTy1q++nSCoY07MJDGvKow/+2DeYUG24G6Vp/RFJEfCfEXSJwIfD1X/Vf0eFYv3htraGeInVwZcJutIienE2OzVMPxOYQtBMPjc2QxklX9e3Djbug07EORjVNZT049xNw0X5P9u59PEY5+4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848952; c=relaxed/simple; bh=w8w7PSg45AY4bxzhMkUpbwgVIb1aWqQz72jdOgmpY34=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cuzjaZJwJmqZNLQipBUCijsWqjLaal7AIIMM7SiVt6P4mhzT1RNxuiw7APcIt2FhKKidsOlG8lqqRH8ue4KDKvf5eYCSn/HmeVatLHbR4T3h30QVj/WVSIdbgRwx5/qqMBLY6GhcMVbp+WZI8nj21b7CeJfNYhtP+1KK8BLC3sA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=jgowTEpH; arc=fail smtp.client-ip=40.107.220.64 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) header.d=amd.com header.i=@amd.com header.b="jgowTEpH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wawvBHK2SoJKUdngcPD3UsIDKlR8C9+fAxsDga+zhr0bROKZfXpfyf0OovlS8F/Zkj5iU1CbUpFbLkE3J7Rx0Z0yDKlghlfsXzOZyZqKhERzHC9APPDh4Lv7EqQKy3v+PJxsGXoWU2Rnc3FRuEi1xDLjpFMQKLJMhObT08gYbn6lfEYJMztVhVuq/nhaczTvkzoC/JaWHB7aduHnSP60gs989EOKApFl3F8qT6GUQTf1jMp+tqENrpsxtZJUkQ70+DbM/MytdziDZUHNBRltARkqxwnoExUUScRJHUERtnSRMKMFHlk1ibrk4iJp7/XzRsNFTS95pXYUydSi1QAMvw== 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=oRZ/DsQQFoJAX9eqcmsR1Bhsh7kPV8sbSwx2dSGn1hY=; b=v1Yi9r0XUDXUMVKRTTUY2XWLBV467qdDZVNCEzg0Ra1JYJeCQyU2Blvih6+nUC0TKgIkJlu4BW9YnypFL04zoXpe1dWbiCU7pqR2xwwfDvy/E//BteCu+Q4DMYvFa9wWxPthYk5gFjejshQudO7009DRAdA2ULHrTIEWaN2zH8YmIB5o8JBPZElgIwRtiiDYa4jF4tM4ykhgVyGou0DBDXe972nuSMnjA6bNPPnmIlLXqrvToNi1sW3u2ayygDYHCaayU8mj5jWcZSiAtaM9CT4OAJPv/hJ24p46V4wDd9mmqILqAlxPOyfgAQNTQPB1TbgplK6hNbhDM8B7HDwIsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=oRZ/DsQQFoJAX9eqcmsR1Bhsh7kPV8sbSwx2dSGn1hY=; b=jgowTEpHlul92Z99j/j3mOL871lPPaZZpqeVOetFtXPRtrdWjhe2nfCrC3yUr9GsSlAz+Ia/qpA0SgxMIy3DRADI6KSWSVZzeQsrjhFMJoTvTmO2HtoJgjP/kzFLu/HniSj/bCpk7BeOmyD8w8TR6ctSUV6RYWc/svG+yqCYz5k= Received: from CY5PR17CA0060.namprd17.prod.outlook.com (2603:10b6:930:12::27) by DS0PR12MB8020.namprd12.prod.outlook.com (2603:10b6:8:14f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.39; Fri, 13 Jun 2025 21:09:07 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:930:12:cafe::c2) by CY5PR17CA0060.outlook.office365.com (2603:10b6:930:12::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.17 via Frontend Transport; Fri, 13 Jun 2025 21:09:07 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:07 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:09:04 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 27/32] x86,fs/resctrl: Auto assign/unassign counters on mkdir Date: Fri, 13 Jun 2025 16:05:11 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD3:EE_|DS0PR12MB8020:EE_ X-MS-Office365-Filtering-Correlation-Id: 971d126d-4324-4521-9307-08ddaabe88cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BmS1ZIblSFX0XWk0LHB4R+hRxo35Arw0mEIz8cEBCC9hV3zEL28cMWL27gaM?= =?us-ascii?Q?3FPz9x9Y0AlYDyobq3VxExrmuxGKlz3yjqkKzSR54v5jKjBSWV/xox7iwEUE?= =?us-ascii?Q?/WV38D0jSJm4KseA63J8eEXVIj+R+iC59ehzyOcCHoIz3E4Wqb4IkzB19vKP?= =?us-ascii?Q?psf3lVGOKLucrOuLrj/5Ya83Jnvu9yS7e4X5GayY1m8ty1wjuzSZgUrSLsCR?= =?us-ascii?Q?DRgOxYC0QsTRYuTzIMBvtoevMT6SKb/w6G4ob1Jk9s5cSVfE0dd5SkjBORms?= =?us-ascii?Q?FLUiTXIx5LNQyfNniLalmJEZWdcsHm3iAsdBZ5GjUQzCtw5DectRC1lJsKKy?= =?us-ascii?Q?9Z4+geEUnRQAjgIEGPrYzLjiclcq1YQ5nOrZiDXKZa7dAxXCAOKJDCX62OK3?= =?us-ascii?Q?kwi/Uy9N7YWpQscXjAhpCkB4wNt7sOz4QsrAUzLXsH7n5nlbT+NMNlRkrYQ9?= =?us-ascii?Q?OoumqqTvvnc66xz1Bs9gel/jwElVxQJ74ymn9Qg89wQRcVZcNlm7OQtK41xN?= =?us-ascii?Q?ID2FF2rWRlbFiWU9rlO47MMWnOdxOSF0Vx6Maz9IAgU7IU9enXqgZLBHpnn4?= =?us-ascii?Q?V0otPVF4B1ASPijtEVfLx5g+rtu0jptMAcZ9cqrqdNiX0JBZ4hQuZIIyX5Hx?= =?us-ascii?Q?KdLbmIjO3q7o63kcYgmBR+UCr/SNQnISZ73TjBHZUELGFvTMxnjw8e79mZJ3?= =?us-ascii?Q?njHxD2N7lTJL93DIYqdbr69/oNTrbDAKCV+t+f452tXwbmRcNsQZDCxsjM5g?= =?us-ascii?Q?4xVY6q3HVWjsWShWtYQLexpKT0Ox/eJdI5wNG2zcvKFSGM5jaup+zzC+Dugl?= =?us-ascii?Q?b/XdrLI0L4/dMLIYemO+pk6T7y3OWXlECNwpV2LFO3TVor6KoWBSt/RIo03P?= =?us-ascii?Q?Vdl8u/AEKKGLSyryQ9gFmrA+MADK5hxPO4gw6+DZRrjGtxvCUIAmhXh6dq9s?= =?us-ascii?Q?yTNFoKJJFNgC23QWAKZjbpHCVwCr0g/mLWxmGODG6Yuwe3Hrxc/h7CrepmWD?= =?us-ascii?Q?AbrLe79iCiZfm/hI2M8qiZjnX2L6mzxTLVSMmuQ95gqOjGCQ+wA11O8rCTYP?= =?us-ascii?Q?tAXJkvYY1aBvXFj+b+v0LSlJTINYEyw7khN2jzn4mmp4bRl1BFQkHsuvNNVP?= =?us-ascii?Q?2TTFt8YUyoUaNPTDVv2B9oUlJIsEUYqbTB7Ia016YWJACr+D5GCrQ/tVUq2K?= =?us-ascii?Q?jIJVrA9u/yTG6751y0UnKjqc+rpTSoLhC0/PAzekht3pS1aH7sq/aRQ2XEjI?= =?us-ascii?Q?xvOCMKYIXAW8rWPfK56uaoQ1/zz1HE6ukZvxEGgk4haIt2MZezD7UJQuL+nW?= =?us-ascii?Q?Ih1uRjGX8DY7SsW5TQCPyeBdt0XoQKOQlF8KKazKegToAMJPBNoISNPU63Ec?= =?us-ascii?Q?kte1Tt3lym1Ernnv56LKKI7pNVTMUf3W5eYHuBnE5Dt0Kxvr6S1/bg2ZWwNS?= =?us-ascii?Q?kwt/XyfdD9pj5AjUwZmAAHndFeVnYbFpy1YovaIQtsfX2uB5NyGPelySo7hx?= =?us-ascii?Q?ll8QO1+avH716nxdyxXnUnHto2dNegGWsu/tTfrUsDVLmCNCN1hFtSY9FA?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:07.0996 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 971d126d-4324-4521-9307-08ddaabe88cb 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8020 Content-Type: text/plain; charset="utf-8" Resctrl provides a user-configurable option mbm_assign_on_mkdir that determines if a counter will automatically be assigned to an RMID, event pair when its associated monitor group is created via mkdir. Enable mbm_assign_on_mkdir by default and automatically assign or unassign counters when a resctrl group is created or deleted. By default, each group requires two counters: one for the MBM total event and one for the MBM local event. If the counters are exhausted, the kernel will log the error message "Unable to allocate counter in domain" in /sys/fs/resctrl/info/last_cmd_status when a new group is created and the counter assignment will fail. However, the creation of a group should not fail due to assignment failures. Users have the flexibility to modify the assignments at a later time. Signed-off-by: Babu Moger --- v14: Updated the changelog with changed name mbm_event. Update code comments with changed name mbm_event. Changed the code to reflect Tony's struct mon_evt changes. v13: Changes due to calling of resctrl_assign_cntr_event() and resctrl_unas= sign_cntr_event(). It only takes evtid. evt_cfg is not required anymore. Resolved conflicts caused by the recent FS/ARCH code restructure. The monitor.c/rdtgroup.c files have been split between the FS and ARCH= directories. v12: Removed mbm_cntr_reset() as it is not required while removing the grou= p. Update the commit text. Added r->mon_capable check in rdtgroup_assign_cntrs() and rdtgroup_un= assign_cntrs. v11: Moved mbm_cntr_reset() to monitor.c. Added code reset non-architectural state in mbm_cntr_reset(). Added missing rdtgroup_unassign_cntrs() calls on failure path. v10: Assigned the counter before exposing the event files. Moved the call rdtgroup_assign_cntrs() inside mkdir_rdt_prepare_rmid_al= loc(). This is called both CNTR_MON and MON group creation. Call mbm_cntr_reset() when unmounted to clear all the assignments. Taken care of few other feedback comments. v9: Changed rdtgroup_assign_cntrs() and rdtgroup_unassign_cntrs() to return= void. Updated couple of rdtgroup_unassign_cntrs() calls properly. Updated function comments. v8: Renamed rdtgroup_assign_grp to rdtgroup_assign_cntrs. Renamed rdtgroup_unassign_grp to rdtgroup_unassign_cntrs. Fixed the problem with unassigning the child MON groups of CTRL_MON gro= up. v7: Reworded the commit message. Removed the reference of ABMC with mbm_cntr_assign. Renamed the function rdtgroup_assign_cntrs to rdtgroup_assign_grp. v6: Removed the redundant comments on all the calls of rdtgroup_assign_cntrs. Updated the commit message. Dropped printing error message on every call of rdtgroup_assign_cntrs. v5: Removed the code to enable/disable ABMC during the mount. That will be another patch. Added arch callers to get the arch specific data. Renamed fuctions to match the other abmc function. Added code comments for assignment failures. v4: Few name changes based on the upstream discussion. Commit message update. v3: This is a new patch. Patch addresses the upstream comment to enable ABMC feature by default if the feature is available. --- arch/x86/kernel/cpu/resctrl/monitor.c | 1 + fs/resctrl/rdtgroup.c | 71 ++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index ee0aa741cf6c..053f516a8e67 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -429,6 +429,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) r->mon.mbm_cntr_assignable =3D true; cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx); r->mon.num_mbm_cntrs =3D (ebx & GENMASK(15, 0)) + 1; + r->mon.mbm_assign_on_mkdir =3D true; } =20 r->mon_capable =3D true; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index bf5fd46bd455..128a9db339f3 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2945,6 +2945,55 @@ static void schemata_list_destroy(void) } } =20 +/** + * rdtgroup_assign_cntrs() - Assign counters to MBM events. Called when + * a new group is created. + * If "mbm_event" mode is enabled, counters are automatically assigned. + * Each group can accommodate two counters: one for the total event and + * one for the local event. Assignments may fail due to the limited number + * of counters. However, it is not necessary to fail the group creation + * and thus no failure is returned. Users have the option to modify the + * counter assignments after the group has been created. + */ +static void rdtgroup_assign_cntrs(struct rdtgroup *rdtgrp) +{ + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + + if (!r->mon_capable) + return; + + if (resctrl_arch_mbm_cntr_assign_enabled(r) && !r->mon.mbm_assign_on_mkdi= r) + return; + + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) + resctrl_assign_cntr_event(r, NULL, rdtgrp, + &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]); + + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) + resctrl_assign_cntr_event(r, NULL, rdtgrp, + &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]); +} + +/* + * rdtgroup_unassign_cntrs() - Unassign the counters associated with MBM e= vents. + * Called when a group is deleted. + */ +static void rdtgroup_unassign_cntrs(struct rdtgroup *rdtgrp) +{ + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + + if (!r->mon_capable || !resctrl_arch_mbm_cntr_assign_enabled(r)) + return; + + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) + resctrl_unassign_cntr_event(r, NULL, rdtgrp, + &mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID]); + + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) + resctrl_unassign_cntr_event(r, NULL, rdtgrp, + &mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID]); +} + static int rdt_get_tree(struct fs_context *fc) { struct rdt_fs_context *ctx =3D rdt_fc2context(fc); @@ -3001,6 +3050,8 @@ static int rdt_get_tree(struct fs_context *fc) if (ret < 0) goto out_info; =20 + rdtgroup_assign_cntrs(&rdtgroup_default); + ret =3D mkdir_mondata_all(rdtgroup_default.kn, &rdtgroup_default, &kn_mondata); if (ret < 0) @@ -3039,8 +3090,10 @@ static int rdt_get_tree(struct fs_context *fc) if (resctrl_arch_mon_capable()) kernfs_remove(kn_mondata); out_mongrp: - if (resctrl_arch_mon_capable()) + if (resctrl_arch_mon_capable()) { + rdtgroup_unassign_cntrs(&rdtgroup_default); kernfs_remove(kn_mongrp); + } out_info: kernfs_remove(kn_info); out_closid_exit: @@ -3186,6 +3239,7 @@ static void free_all_child_rdtgrp(struct rdtgroup *rd= tgrp) =20 head =3D &rdtgrp->mon.crdtgrp_list; list_for_each_entry_safe(sentry, stmp, head, mon.crdtgrp_list) { + rdtgroup_unassign_cntrs(sentry); free_rmid(sentry->closid, sentry->mon.rmid); list_del(&sentry->mon.crdtgrp_list); =20 @@ -3226,6 +3280,8 @@ static void rmdir_all_sub(void) cpumask_or(&rdtgroup_default.cpu_mask, &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask); =20 + rdtgroup_unassign_cntrs(rdtgrp); + free_rmid(rdtgrp->closid, rdtgrp->mon.rmid); =20 kernfs_remove(rdtgrp->kn); @@ -3310,6 +3366,7 @@ static void resctrl_fs_teardown(void) return; =20 rmdir_all_sub(); + rdtgroup_unassign_cntrs(&rdtgroup_default); mon_put_kn_priv(); rdt_pseudo_lock_release(); rdtgroup_default.mode =3D RDT_MODE_SHAREABLE; @@ -3790,9 +3847,12 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgr= oup *rdtgrp) } rdtgrp->mon.rmid =3D ret; =20 + rdtgroup_assign_cntrs(rdtgrp); + ret =3D mkdir_mondata_all(rdtgrp->kn, rdtgrp, &rdtgrp->mon.mon_data_kn); if (ret) { rdt_last_cmd_puts("kernfs subdir error\n"); + rdtgroup_unassign_cntrs(rdtgrp); free_rmid(rdtgrp->closid, rdtgrp->mon.rmid); return ret; } @@ -3802,8 +3862,10 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgr= oup *rdtgrp) =20 static void mkdir_rdt_prepare_rmid_free(struct rdtgroup *rgrp) { - if (resctrl_arch_mon_capable()) + if (resctrl_arch_mon_capable()) { + rdtgroup_unassign_cntrs(rgrp); free_rmid(rgrp->closid, rgrp->mon.rmid); + } } =20 /* @@ -4079,6 +4141,9 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp= , cpumask_var_t tmpmask) update_closid_rmid(tmpmask, NULL); =20 rdtgrp->flags =3D RDT_DELETED; + + rdtgroup_unassign_cntrs(rdtgrp); + free_rmid(rdtgrp->closid, rdtgrp->mon.rmid); =20 /* @@ -4126,6 +4191,8 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgr= p, cpumask_var_t tmpmask) cpumask_or(tmpmask, tmpmask, &rdtgrp->cpu_mask); update_closid_rmid(tmpmask, NULL); =20 + rdtgroup_unassign_cntrs(rdtgrp); + free_rmid(rdtgrp->closid, rdtgrp->mon.rmid); closid_free(rdtgrp->closid); =20 --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFF0C273D9C; Fri, 13 Jun 2025 21:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848961; cv=fail; b=OTXOjflQ7EI3URCi03fIsXHM3Dasdp4vKHf+GR2ANfMcZKaxsAtENHKJkn0G/HrhgGYfJ/uRQSms2PG7OgqeTJK29scyZyrjlW2KZ9VgKRddBadLGwSatRVhqaXD3bNYpNKOwHOkxKxss4hTxZoK2/VWzna7qc3GAMrhV6cV4Uk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848961; c=relaxed/simple; bh=FRQudJC9NxL//f/JrOgH/HAiBIr08RaHzlVLTAc1D3k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=leZ7v77CK9ryCfiSe1DDTlZk8e943wwamt2286b8aXuCRiPnma8WEoKG0MKUxsvFeK9Mm0alNH6/hehvK88UpMnc62lOQHjq2HuWkTDNv0Ok9layWcQavd57FmH5xUIcSO8b4K50MPYWrGuQAU9A+ARNo5pI9tryYGCRAc6FmKM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ybqf5lTM; arc=fail smtp.client-ip=40.107.93.62 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) header.d=amd.com header.i=@amd.com header.b="ybqf5lTM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vnbxw2OBWF5yp67sACNV1a6vj0AQ3DlqrAOGGjSEE6B4XunGR9+5XfvUUJtMMHrGpmX00tAOn800KMpTLi1hzofIIXhrtMmYBP8OI8qPiAinGVvboH4Y4bMn/OK3P5fPR7iV6woBuXn3PRTLkUiAvkHCyp0CYHBs3wa/tdMxQloXTpe39RcCc0YllVqHSOxMVVAqAhAY0r9X8y+DDVMUgX8tSW7NwWhDcl7BdglprPYA8ZrbOsRsbBklmamzUiOJidisdYUapJGTuDQ9W2skqs8ebfbwwA6FkotTKWBEjHfieMJa8d+CAguMN7Ltx8sbZgNsTlLgZfhJx7h7pnnbbg== 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=irzaO2h2hW+z+KF3z6J/dEetIUxov7ZeLDetAxRqjSo=; b=wfrPEx+AxirNQdA9xOGseRISFtIAC15PaGjONrKG3jB7hUGjPjSKsYyGY/KgdA9hbPunJOXUXWpN0HiXCbkF8bQlz3sfktPOceyYjspMxpWZxkT0QD4O25AcY+gzaWq+zLJ4/KsW1jhOjZyt4q3CIZAaO/e3OK70ky7Q3waxlrZb15ku4Jk3K8wOw9dQVkqBki57KEy6Pro1T34jovC+hDwESjQotHQmoTRR6qkZ9NykKcUJSXcW2Dl6NNPBoy0F79fitpNXXZDPpKZ0G2mxbkHqAAesRwsUUXXrOS9TRNvp8+6aCghjEg42dy7oUKNoq3cHTyIzZsPUc6sDUu5S9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=irzaO2h2hW+z+KF3z6J/dEetIUxov7ZeLDetAxRqjSo=; b=ybqf5lTM5ogh1nbxRhgKy88PdF+EGdwenckdoYvyQ2fiVXenx93iw4UZFsZXxEgpCF2YanTNGsYd5D/yoXXa7QLBelDP2EpmL3gXhoRbsEmgPxPgTVlpW2hPEOjagP1/jK3Lzg/GZNJ+oAXz2Rx+tH+MCgLTeuIxykcuDOJ5rYs= Received: from PH7P222CA0021.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:33a::33) by SJ2PR12MB8977.namprd12.prod.outlook.com (2603:10b6:a03:539::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:09:15 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:510:33a:cafe::a0) by PH7P222CA0021.outlook.office365.com (2603:10b6:510:33a::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:09:15 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:14 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:09:12 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 28/32] fs/resctrl: Introduce mbm_L3_assignments to list assignments in a group Date: Fri, 13 Jun 2025 16:05:12 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|SJ2PR12MB8977:EE_ X-MS-Office365-Filtering-Correlation-Id: 01f5fd76-c15c-4715-793c-08ddaabe8d52 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?iheGwj5XzqH5EJXOwD2Ug7huHhUH7qL6NI2dDxJx2q14vxOc1LIhY6uwtX/E?= =?us-ascii?Q?MWSUSfBQ47arhkLQE0Jsd8xd5FHV6EN/4f0Jig01lmZtKmpG1oNJjK5B6vye?= =?us-ascii?Q?/mBeOKQLeY0uan7kIk2mSah9EHYEnKb5VRAraF2GSKPSWJGoU+YucPgQXGrE?= =?us-ascii?Q?hw5TFSfPCWoQYR/XfKRFWW9XbFW0CeZEft8EyDfyQw97yJ5TFRiGxH5VA2l0?= =?us-ascii?Q?roEMxmbUR9W8vLMUynuYFonQK3jDwPHPkyjRznG6MaJs4w+Bk7PdHoaY3txq?= =?us-ascii?Q?OxNq0UmSBLh/61IxP52c6JzFum0zLaW1bCBeKAMop5eHrF84LZcPv3yixtV0?= =?us-ascii?Q?PWMI2k85UHApvgrjV6E+o1PYZT6u6gA2ea3SlHQZiAqenR+ICivItJ+JKTAf?= =?us-ascii?Q?lud2raNWq3K+cZwBCqokUsKzWT/Vs+dFKsV/0tRh10NY+cV2L/ecUzAPyp4P?= =?us-ascii?Q?ibKaJjMbXZEZNmYrNS9wA2k7oxcXScuagsL3W08TlvAlW7XchSczHXOx1Waz?= =?us-ascii?Q?2o1cP1+Cl3h9eOxEF6eb/B/KxVDWwbo/pG6PvqtW20V76e0opdgVNApIGPGl?= =?us-ascii?Q?t/SUgL/CJSaSSqgZDw4V/x4w/v+hakLQPAl5YjKLlrYGAO1crfc8j3+LEOgS?= =?us-ascii?Q?/69zy2DdSEHLcmXLfGWyP4cKodnRGzqZcBJGLRNP26X+dmBws3EugVg+ojW0?= =?us-ascii?Q?CqAhLl7hJSNq0YVAV16AEXnrlnCc/MMVd2o2pQCBTlEi4Go4Oa0uICtpKcwN?= =?us-ascii?Q?zhrt10nlsrtRuY5HNd6vMhgG7uFFJ7hLiOMXXatklzjUxZugx8qJBEbFgT9c?= =?us-ascii?Q?ZCLa+fikAEf0XAimP1R9kb3G/Rf/znxqj2XE4d8aGLTPcmsJ6rzqUHqHPCOf?= =?us-ascii?Q?k5DIYD9neZfdK3GCmlhI5YIHi+HJaYiBzLzOAg/kkDR/xcC3LNiL8V6HPr3i?= =?us-ascii?Q?9tE1njFalZqPrcVtBvjlvUW22c/Ic3w7l3Dlj3vhnWKWTnIKHLDwZ1aNearM?= =?us-ascii?Q?mXrStams0lHdskTr6JiW1T5+mfIbeV49jb76hnX+AdIR11S22bujilVvKQgO?= =?us-ascii?Q?Ey4IysQR/Xdl2qu7AyfUj0PmVLHh+RI1ZSBgXdpKmaBCxzh8uS/e5YiTe4rl?= =?us-ascii?Q?s3NdUCcHXRTdcQLnEqEpPo4pUSWs5vP2qpApbxj8dmhGr3mzxuHo81NyrUa6?= =?us-ascii?Q?W4UfTI1IoJoO24/qePxkk3UlQtPf/vltFGrDBgfyhI2ewCrlNNKwrH+6YeuN?= =?us-ascii?Q?6Qb5NXD4gp5kgQZ0bxIhs0gHqGjzK90v9IXVzLEUm72g2rr7t1GHEdzpuDVd?= =?us-ascii?Q?cjS+4k+l+uOhlqy00RUp3NRLBy2ZHljdmY0X1S5VFHfuTOAmVZhtnBOeFXG8?= =?us-ascii?Q?ohRw3q8aJzmjyGnT/FMcqfvluEyVBv1bGruXLaJpXra6bEk9/bfFZfJgUCVo?= =?us-ascii?Q?OJDu3FjOqR27fu+tx9lxOYaD5JOVBGzsmkmjKiI1fXjIom1VbgnIFjYIWngw?= =?us-ascii?Q?OkcjCr3eT2svOik=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:14.6933 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 01f5fd76-c15c-4715-793c-08ddaabe8d52 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8977 Content-Type: text/plain; charset="utf-8" Introduce the interface to display the assignment states for resctrl group when "mbm_event" mdoe is enabled. The list is displayed in the following format: :=3D Event: A valid MBM event listed in /sys/fs/resctrl/info/L3_MON/event_configs directory. Domain ID: A valid domain ID. The assignment state can be one of the following: _ : No counter assigned. e : Counter assigned exclusively. Example: To list the assignment states for the default group $ cd /sys/fs/resctrl $ cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=3De;1=3De mbm_local_bytes:0=3De;1=3De Signed-off-by: Babu Moger --- v14: Added missed rdtgroup_kn_lock_live on failure case. Updated the user doc resctrl.rst to clarify counter assignments. Updated the changelog. v13: Changelog update. Few changes in mbm_L3_assignments_show() after moving the event config= to evt_list. Resolved conflicts caused by the recent FS/ARCH code restructure. The rdtgroup.c/monitor.c files have been split between the FS and ARCH= directories. v12: New patch: Assignment interface moved inside the group based the discussion https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=3DkVLBzhfNo0SFqt4kQG= wGSGVUqvr2Dg@mail.gmail.com/#t --- Documentation/filesystems/resctrl.rst | 28 ++++++++++++++ fs/resctrl/monitor.c | 1 + fs/resctrl/rdtgroup.c | 54 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index f94c7c387416..a232a0b1356c 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -516,6 +516,34 @@ When the "mba_MBps" mount option is used all CTRL_MON = groups will also contain: /sys/fs/resctrl/info/L3_MON/mon_features changes the input event. =20 +"mbm_L3_assignments": + Exists when "mbm_event" mode is supported and lists the counter + assignment states for the group. + + The assignment list is displayed in the following format: + + :=3D + + Event: A valid MBM event in the + /sys/fs/resctrl/info/L3_MON/event_configs directory. + + Domain ID: A valid domain ID. + + Assignment states: + + _ : No counter assigned. + + e : Counter assigned exclusively. + + Example: + To display the counter assignment states for the default group. + :: + + # cd /sys/fs/resctrl + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3De;1=3De + mbm_local_bytes:0=3De;1=3De + Resource allocation rules ------------------------- =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 1ec2efd50273..618c94cd1ad8 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -959,6 +959,7 @@ int resctrl_mon_resource_init(void) resctrl_file_fflags_init("event_filter", RFTYPE_ASSIGN_CONFIG); resctrl_file_fflags_init("mbm_assign_on_mkdir", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); + resctrl_file_fflags_init("mbm_L3_assignments", RFTYPE_MON_BASE); } =20 return 0; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 128a9db339f3..18ec65801dbb 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2081,6 +2081,54 @@ static ssize_t resctrl_mbm_assign_on_mkdir_write(str= uct kernfs_open_file *of, return ret ?: nbytes; } =20 +static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq= _file *s, void *v) +{ + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + struct rdt_mon_domain *d; + struct rdtgroup *rdtgrp; + struct mon_evt *mevt; + int ret =3D 0; + bool sep; + + rdtgrp =3D rdtgroup_kn_lock_live(of->kn); + if (!rdtgrp) { + ret =3D -ENOENT; + goto out_assign; + } + + rdt_last_cmd_clear(); + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { + rdt_last_cmd_puts("mbm_event mode is not enabled\n"); + ret =3D -ENOENT; + goto out_assign; + } + + for (mevt =3D &mon_event_all[0]; mevt < &mon_event_all[QOS_NUM_EVENTS]; m= evt++) { + if (!mevt->enabled || !resctrl_is_mbm_event(mevt->evtid)) + continue; + + sep =3D false; + seq_printf(s, "%s:", mevt->name); + list_for_each_entry(d, &r->mon_domains, hdr.list) { + if (sep) + seq_putc(s, ';'); + + if (mbm_cntr_get(r, d, rdtgrp, mevt->evtid) >=3D 0) + seq_printf(s, "%d=3De", d->hdr.id); + else + seq_printf(s, "%d=3D_", d->hdr.id); + + sep =3D true; + } + seq_putc(s, '\n'); + } + +out_assign: + rdtgroup_kn_unlock(of->kn); + + return ret; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -2219,6 +2267,12 @@ static struct rftype res_common_files[] =3D { .seq_show =3D event_filter_show, .write =3D event_filter_write, }, + { + .name =3D "mbm_L3_assignments", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D mbm_L3_assignments_show, + }, { .name =3D "mbm_assign_mode", .mode =3D 0444, --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2043.outbound.protection.outlook.com [40.107.236.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE45927510C; Fri, 13 Jun 2025 21:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848967; cv=fail; b=hVX282VKi2NBn0xlkbB9j1q/mUiqRjlD6HbfKsRr92Sqs1VPZdUqZjpHXPVjC9EcB2WhWQuaZ11i0BkRlc6YCoB6CQPf1Hoj4aSSKXPi2utVnRL0eSpMYoJJT9Lgr8Yq7IkwYXOREWyUaU+mbALsyyfThICEYbuZdqaE+uxZ/o4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848967; c=relaxed/simple; bh=zw7FZaom9Ph8L5nHH3s3hQidmgTfYhKX+FnEPsEFUIM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=to9zQi6s3j2JLm0whJttJqJYjUc4Ts59YTfIBKHmWYlAUEy2g33XJhwrEnJJk1dQv7zz1ucIuW5CgxyWkYC5JxhmSgVWIpNP+HGFD4fQTTzzkTrtu+RJJWwN445Vfff44/ajSvuhF0IAOYS73dgokZv1rbsrOd5oZu6ss8jZK5Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Vcdu3njO; arc=fail smtp.client-ip=40.107.236.43 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) header.d=amd.com header.i=@amd.com header.b="Vcdu3njO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WdCDMplxSJlR0tPqyaEGZoTrvoia+ZFOVxjaxbzXTlsy+aw4P6sreuwDsS95YK3VHwGEwwwueVKfaNq8BtUSUJ9FSU8jwDyyJkLHfKJV3WZF8iBVbJYCOLg59O5IsNn4y9KRreaouikI+xBEjGkBXTbJBHwwdgikqFCp4im0WX+wIiCduknQn35DuibUzy1K5FZmjE+t5nSIPt793Kjm9ZnRnKH4Xtxbrnl0KJIq3cKQrlveQH6l04J+GVtgUr5B0w6/Whs5MZ4h80YuZh5c6ttRE2UplopGhbCmuhCOesnTfHdvsZ2sMx4NzVBpTGJhHU4CdeBI0JCepXg5tbg25Q== 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=vTCi9Q9XdDT5NpRnq2dFHntjIKp/qcvDAJH3epD6EwA=; b=q2Li6Bqfz42TmSr2OgqWFtGV6U/MSwMW6FTxN2pzxzMHj+EWeVD/cReqfirbQP8r08qXSQDEs2ZhfSAHr/mxqWrqiCurk2DvJoess+oCcyU2Ofa4DouZtlly+eh24azKwZQ+nozHI32Jx41iwv/6ZqXB0EsP9SgN8qrlq82Bhn1eUsPTBmlL7tmMlh1oNpYV8dQG53LqFD5QR//trbWEVwYHaZocwbpNAHNOWoObuzZoqhYAg0SZT10zwW7hCA03yX7Dds7dIVAWl95eYEm8QYq+/7egE825Q3YlJydkvvqpBpkwM65WeGTfI8c08ILj7+VxcHCPb9cyGUHAZk1CMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=vTCi9Q9XdDT5NpRnq2dFHntjIKp/qcvDAJH3epD6EwA=; b=Vcdu3njOmL1Dk63D9SyV/Z5E7G8JU7W2lZPRrveKm4Ahcaim4zFwMqo2XaTkiXAOgxCcK8TaADpwe/BTrRP+H+Nm5JTUCWyfKWBQJX6E7ElFU27Cnu346wywH90sfZ+93ObnFnpK2AVN77RPHg3U7xKavGzQfpBbv+57XZreeK8= Received: from DS7PR03CA0235.namprd03.prod.outlook.com (2603:10b6:5:3ba::30) by BL3PR12MB6521.namprd12.prod.outlook.com (2603:10b6:208:3bd::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.20; Fri, 13 Jun 2025 21:09:22 +0000 Received: from CY4PEPF0000EDD6.namprd03.prod.outlook.com (2603:10b6:5:3ba:cafe::1f) by DS7PR03CA0235.outlook.office365.com (2603:10b6:5:3ba::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.24 via Frontend Transport; Fri, 13 Jun 2025 21:09:22 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD6.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:22 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:09:20 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 29/32] fs/resctrl: Introduce the interface to modify assignments in a group Date: Fri, 13 Jun 2025 16:05:13 -0500 Message-ID: <1fa5ee1e36bb599ae33d772e7a3c40fd3a4abe82.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD6:EE_|BL3PR12MB6521:EE_ X-MS-Office365-Filtering-Correlation-Id: 47d8c493-9c3b-4e1a-b7db-08ddaabe91f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?B?UjZJSG1UVHRQRUNSQzluclF0OUNCd3dJYW5hNmsrOW4weDdPRFgwWjZUWWlx?= =?utf-8?B?TWpLTjZMMnozaGxVbG1Jek8wbW9IRlFlczZJZjBCb0w0VlN1WlcySlVGRXNL?= =?utf-8?B?TjlRY01hcEpiVkwxanZtcmRyTG9jQU9wa0Q1THpySDdBRkZKdFFXSDQ3Ymh0?= =?utf-8?B?R1ZyUFVhSVdhV1pheEJXYlZWL0VYalZWcDlUVWJlanVEYW1lSEF1djhwL0sr?= =?utf-8?B?Rmw1N28xK2tGVUlhWXdXR2VlZ2wrbytqaXZ3ODV3N3c3UmNDQWFiUnZGM2pP?= =?utf-8?B?UllxSnpBZkRhM1daTHkvV0Q3U1R3QUhhWTlsRi9wc0FpQUZXMmRsaUR5UlJj?= =?utf-8?B?bXBlV3ExZnJRVERvK3lneXhuelpwYk9NSitYeWpGNXQ0NGU4a3dMZlJHZGpp?= =?utf-8?B?YVV2MzNXMVVhZFhodEU4NG5oK24yak8xaWdFSVkvSEljTmdibm1lNGd5b0R0?= =?utf-8?B?blY1aTdHTkVRcUErKzE0eHkvMGx0ZHZLZ01GWkQ4TGxrcW1OT1JvbW41WE9a?= =?utf-8?B?cnlZMmJwUGdVU1VQZTlWRDM1Rkp1NmhnYk9EVGk0R3lSa0RLNk9VUkRYdlow?= =?utf-8?B?WW85YkZDeVd0ZTFXZDExd3NhbXd6d2xNLy85bkFRM2hNYWVENjdhSlRJeHFV?= =?utf-8?B?aDdJa2tyNnRnMExwa0VtOTFOdE9xb3BmdXVQa2tuZlZaanc2dmJ2WVhXZ0xk?= =?utf-8?B?cFlqbmx3djhCK0h2clFFNVBsZHFqWS9hb29vellDRzZCV01NR2FjYWJlMXBo?= =?utf-8?B?M2lwZ2lmWXFENWVLRnFJb3BtN1QzUFJ2S1orbE0zeGVEb2VXL2Y1K2dZOWll?= =?utf-8?B?VlVDNVc1OXRrZ21kMnFvWnh4NUk0aXlFQzFzNFc3UHpXRUtMck9JMmlsbUVE?= =?utf-8?B?Y2QvdERmV3FzY0NBb2MrOWY1ZXhwUW83Z0tOSlN2U2VCMkxrT1pDdGc4L1o3?= =?utf-8?B?TjBYZHJwNmM0TiswNW8rTXdrZlpjcjd2Z2NzUHpxdEpQclFpVG05TDd1M2Fi?= =?utf-8?B?TTUvUVBTbityeUlkTGNqYkxvRWNjNjQybXkwQW5ldmdzbkpBZjdLVDVuU09v?= =?utf-8?B?ampCNEFaZUNoakh1OHRCcVdOdmUrSmUzNGE3b2ozdVNhMkQxa3VEV0xRYmNP?= =?utf-8?B?T2YxQ0puUlZvam41SjZEL2dBREgrMFJKYnoxejM2c2dObThvbG5hV1RIU3VJ?= =?utf-8?B?RUJyaXVUbFNPTm1TZ1RXRlRqOTdXbzl0WFhrb201S0M4MXNnMnZYQ3pPemJZ?= =?utf-8?B?MENkbXhDeUl3aGE5dDIvUUs2NlJhcjQvVzRneTRBR1p2TnlPamNGbkluVjhh?= =?utf-8?B?VUp0Y3gwOGZnR3BmNmZRZXNlZFBPSXNYVU0zWDVPSldFQ1MvTFZUcWgxVVBV?= =?utf-8?B?bWNneCswRDk2dWFVcWpUZlQzK3FmRk4vSzFpRS9oV0JwNFhaNHY0cGQxdit1?= =?utf-8?B?OG9LU0FVOHZrbnFmaXFRN0xjcDR2ME1qQzZxOUlCdElzelliVVNnTys3dS9P?= =?utf-8?B?QU45aWVxR3lReFJUZExsOGFXNUc5MGRrVHJXamdEL1ZLcXl4aG50NkN3WnI1?= =?utf-8?B?b0RwbTgzc1FyeUg4bkJGanUzay9WR0czYnN1UC91ei85KzFkSUF4MXVhbVVa?= =?utf-8?B?NzN3bkdVdkZBRE1BSFBqTTVXd2RiTUlxREh1SlZhUm8zQmlTTXlEbHZxZUtF?= =?utf-8?B?dnFGTW92UXFPWUNIVjRwRzl4elRGNzNJL01LSjdVVXJzWStHdDd6MHcrZXBB?= =?utf-8?B?MUl0cmNOWnJNbVVqbmxYbUZINng4OTdtQVNBbkFFU3hRQ3ZQbklvWWFkcDdV?= =?utf-8?B?bEJjd29sTDI4cEVFWG9Bekp2TkZMZVg3SGlZQWViUlAvYytOekFkdCs2ZzAz?= =?utf-8?B?LzFUbDdtZEo4NUVrMm1zb25tOVc5RGszQUtxSHVKdnNBQ2xFdXhHaUQyUEFQ?= =?utf-8?B?bkc0RUFsTHpRMjVXNjVMb1NQdmdPMXB5eFN4T2xYVExaRVBGRWN3VWZHNU5I?= =?utf-8?Q?S2qfPxC44PDI6TIzSSiLxHat5qyprk=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:22.4798 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47d8c493-9c3b-4e1a-b7db-08ddaabe91f6 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6521 Introduce the interface to modify assignments within a group when "mbm_event" mode is enabled. The assignment modifications are done in the following format: :=3D Event: A valid MBM event in the /sys/fs/resctrl/info/L3_MON/event_configs directory. Domain ID: A valid domain ID. When writing, '*' applies the changes to all domains. Assignment states: _ : Unassign the counter. e : Assign the counter exclusively. Examples: $ cd /sys/fs/resctrl $ cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=3De;1=3De mbm_local_bytes:0=3De;1=3De To unassign the counter associated with the mbm_total_bytes event on domain 0: $ echo "mbm_total_bytes:0=3D_" > mbm_L3_assignments $ cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=3D_;1=3De mbm_local_bytes:0=3De;1=3De To unassign the counter associated with the mbm_total_bytes event on all the domains: $ echo "mbm_total_bytes:*=3D_" > mbm_L3_assignments $ cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=3D_;1=3D_ mbm_local_bytes:0=3De;1=3De Signed-off-by: Babu Moger --- v14: Fixed the problem reported by Peter. Updated the changelog. Updated the user doc resctrl.rst. Added example section on how to use resctrl with mbm_assign_mode. v13: Few changes in mbm_L3_assignments_write() after moving the event confi= g to evt_list. Resolved conflicts caused by the recent FS/ARCH code restructure. v12: New patch: Assignment interface moved inside the group based the discussion https://lore.kernel.org/lkml/CALPaoCiii0vXOF06mfV=3DkVLBzhfNo0SFqt4kQG= wGSGVUqvr2Dg@mail.gmail.com/#t --- Documentation/filesystems/resctrl.rst | 146 +++++++++++++++++++++++- fs/resctrl/internal.h | 9 ++ fs/resctrl/rdtgroup.c | 157 +++++++++++++++++++++++++- 3 files changed, 310 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index a232a0b1356c..cd82c2966ed7 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -527,7 +527,8 @@ When the "mba_MBps" mount option is used all CTRL_MON g= roups will also contain: Event: A valid MBM event in the /sys/fs/resctrl/info/L3_MON/event_configs directory. =20 - Domain ID: A valid domain ID. + Domain ID: A valid domain ID. When writing, '*' applies the changes + to all domains. =20 Assignment states: =20 @@ -544,6 +545,34 @@ When the "mba_MBps" mount option is used all CTRL_MON = groups will also contain: mbm_total_bytes:0=3De;1=3De mbm_local_bytes:0=3De;1=3De =20 + Assignments can be modified by writing to the interface. + + Example: + To unassign the counter associated with the mbm_total_bytes event on doma= in 0: + :: + + # echo "mbm_total_bytes:0=3D_" > /sys/fs/resctrl/mbm_L3_assignments + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3D_;1=3De + mbm_local_bytes:0=3De;1=3De + + To unassign the counter associated with the mbm_total_bytes event on all = the domains: + :: + + # echo "mbm_total_bytes:*=3D_" > /sys/fs/resctrl/mbm_L3_assignments + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3D_;1=3D_ + mbm_local_bytes:0=3De;1=3De + + To assign the counter associated with the mbm_total_bytes event on all do= mains in + exclusive mode: + :: + + # echo "mbm_total_bytes:*=3De" > /sys/fs/resctrl/mbm_L3_assignments + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3De;1=3De + mbm_local_bytes:0=3De;1=3De + Resource allocation rules ------------------------- =20 @@ -1579,6 +1608,121 @@ View the llc occupancy snapshot:: # cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy 11234000 =20 + +Examples on working with mbm_assign_mode +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +a. Check if MBM assign support is available +:: + + #mount -t resctrl resctrl /sys/fs/resctrl/ + + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [mbm_event] + default + +mbm_event feature is detected and it is enabled. + +b. Check how many assignable counters are supported. +:: + + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs + 0=3D32;1=3D32 + +c. Check how many assignable counters are available for assignment in each= domain. +:: + + # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs + 0=3D30;1=3D30 + +d. To list the default group's assign states: +:: + + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3De;1=3De + mbm_local_bytes:0=3De;1=3De + +e. To unassign the counter associated with the mbm_total_bytes event on d= omain 0: +:: + + # echo "mbm_total_bytes:0=3D_" > /sys/fs/resctrl/mbm_L3_assignments + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3D_;1=3De + mbm_local_bytes:0=3De;1=3De + +f. To unassign the counter associated with the mbm_total_bytes event on al= l domains: +:: + + # echo "mbm_total_bytes:*=3D_" > /sys/fs/resctrl/mbm_L3_assignments + # cat /sys/fs/resctrl/mbm_L3_assignment + mbm_total_bytes:0=3D_;1=3D_ + mbm_local_bytes:0=3De;1=3De + +g. To assign a counter associated with the mbm_total_bytes event on all do= mains i +nexclusive mode: +:: + + # echo "mbm_total_bytes:*=3De" > /sys/fs/resctrl/mbm_L3_assignments + # cat /sys/fs/resctrl/mbm_L3_assignments + mbm_total_bytes:0=3De;1=3De + mbm_local_bytes:0=3De;1=3De + +h. Read the events mbm_total_bytes and mbm_local_bytes of the default grou= p. There is +no change in reading the events with the assignment. If the event is unas= signed when +reading, then the read will come back as "Unassigned". +:: + + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes + 779247936 + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes + 765207488 + +i. Check the default event configurations. +:: + + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_fi= lter + local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_w= rites, + local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all + + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_fi= lter + local_reads,local_non_temporal_writes,local_reads_slow_memory + +j. Change the event configuration for mbm_local_bytes. +:: + + # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory,= remote_reads" > + /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter + + # cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_= filter + local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_= reads + +This will update all (across all domains of all monitor groups) counter as= signments +associated with the mbm_local_bytes event. + +k. Now read the local event again. The first read may come back with "Unav= ailable" +status. The subsequent read of mbm_local_bytes will display only the read = events. +:: + + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes + Unavailable + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes + 314101 + +l. Users have the option to go back to 'default' mbm_assign_mode if requir= ed. This can be +done using the following command. Note that switching the mbm_assign_mode = will reset all +the MBM counters (and thus all MBM events) of all the resctrl groups. +:: + + # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + mbm_event + [default] + +m. Unmount the resctrl +:: + + #umount /sys/fs/resctrl/ + Intel RDT Errata =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index ed0e3b695ad5..14d99c723ea5 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -51,6 +51,15 @@ static inline struct rdt_fs_context *rdt_fc2context(stru= ct fs_context *fc) return container_of(kfc, struct rdt_fs_context, kfc); } =20 +/* + * Assignment types for the monitor modes + */ +enum { + ASSIGN_NONE =3D 0, + ASSIGN_EXCLUSIVE, + ASSIGN_INVALID, +}; + /** * struct mon_evt - Description of a monitor event * @evtid: event id diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 18ec65801dbb..92bb8f3adfae 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2129,6 +2129,160 @@ static int mbm_L3_assignments_show(struct kernfs_op= en_file *of, struct seq_file return ret; } =20 +/** + * mbm_get_mon_event_by_name() - Return the mon_evt entry for the matching + * event name. + */ +static struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r, + char *name) +{ + struct mon_evt *mevt; + + for (mevt =3D &mon_event_all[0]; mevt < &mon_event_all[QOS_NUM_EVENTS]; m= evt++) { + if (mevt->enabled && !strcmp(mevt->name, name)) + return mevt; + } + + return NULL; +} + +static unsigned int resctrl_get_assign_state(char *assign) +{ + if (!assign || strlen(assign) !=3D 1) + return ASSIGN_INVALID; + + switch (*assign) { + case 'e': + return ASSIGN_EXCLUSIVE; + case '_': + return ASSIGN_NONE; + default: + return ASSIGN_INVALID; + } +} + +static int resctrl_process_assign(struct rdt_resource *r, struct rdtgroup = *rdtgrp, + char *event, char *tok) +{ + struct rdt_mon_domain *d; + unsigned long dom_id =3D 0; + char *dom_str, *id_str; + struct mon_evt *mevt; + int assign_state; + char domain[10]; + bool found; + int ret; + + mevt =3D mbm_get_mon_event_by_name(r, event); + if (!mevt) { + rdt_last_cmd_printf("Invalid event %s\n", event); + return -ENOENT; + } + +next: + if (!tok || tok[0] =3D=3D '\0') + return 0; + + /* Start processing the strings for each domain */ + dom_str =3D strim(strsep(&tok, ";")); + + id_str =3D strsep(&dom_str, "=3D"); + + /* Check for domain id '*' which means all domains */ + if (id_str && *id_str =3D=3D '*') { + d =3D NULL; + goto check_state; + } else if (!id_str || kstrtoul(id_str, 10, &dom_id)) { + rdt_last_cmd_puts("Missing domain id\n"); + return -EINVAL; + } + + /* Verify if the dom_id is valid */ + found =3D false; + list_for_each_entry(d, &r->mon_domains, hdr.list) { + if (d->hdr.id =3D=3D dom_id) { + found =3D true; + break; + } + } + + if (!found) { + rdt_last_cmd_printf("Invalid domain id %ld\n", dom_id); + return -EINVAL; + } + +check_state: + assign_state =3D resctrl_get_assign_state(dom_str); + + switch (assign_state) { + case ASSIGN_NONE: + ret =3D resctrl_unassign_cntr_event(r, d, rdtgrp, mevt); + break; + case ASSIGN_EXCLUSIVE: + ret =3D resctrl_assign_cntr_event(r, d, rdtgrp, mevt); + break; + case ASSIGN_INVALID: + ret =3D -EINVAL; + } + + if (ret) + goto out_fail; + + goto next; + +out_fail: + sprintf(domain, d ? "%ld" : "*", dom_id); + + rdt_last_cmd_printf("Assign operation '%s:%s=3D%s' failed\n", event, doma= in, dom_str); + + return ret; +} + +static ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char = *buf, + size_t nbytes, loff_t off) +{ + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + struct rdtgroup *rdtgrp; + char *token, *event; + int ret =3D 0; + + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') + return -EINVAL; + + buf[nbytes - 1] =3D '\0'; + + rdtgrp =3D rdtgroup_kn_lock_live(of->kn); + if (!rdtgrp) { + rdtgroup_kn_unlock(of->kn); + return -ENOENT; + } + rdt_last_cmd_clear(); + + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { + rdt_last_cmd_puts("mbm_event mode is not enabled\n"); + rdtgroup_kn_unlock(of->kn); + return -EINVAL; + } + + while ((token =3D strsep(&buf, "\n")) !=3D NULL) { + /* + * The write command follows the following format: + * =E2=80=9C:=3D=E2=80=9D + * Extract the event name first. + */ + event =3D strsep(&token, ":"); + + ret =3D resctrl_process_assign(r, rdtgrp, event, token); + if (ret) + break; + } + + rdtgroup_kn_unlock(of->kn); + + return ret ?: nbytes; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] =3D { { @@ -2269,9 +2423,10 @@ static struct rftype res_common_files[] =3D { }, { .name =3D "mbm_L3_assignments", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, .seq_show =3D mbm_L3_assignments_show, + .write =3D mbm_L3_assignments_write, }, { .name =3D "mbm_assign_mode", --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2047.outbound.protection.outlook.com [40.107.220.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24EDB272E44; Fri, 13 Jun 2025 21:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848976; cv=fail; b=Gi9XDcDUezUHhYcuzqmtjXuvAyebX8egzDs6t5rbdZ3uGPG2jfRgxlCWn1QFjbkrT0eLbIwS+z0U3JsnFcRh2DIV4gEb8FzJPc+xsJ/8jgXE6uZGZLeulSVCoG1hr4bYL0ga8mwFFn+1MOLeuU1CU08PCMdxzdg9Q8M5Yb5sob4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848976; c=relaxed/simple; bh=utRTbmMjuoseKIyi2mgUgb2CbbO0aZVIVlu38P0Dr9Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LJC1MizmcuKkhW75j8kf7x7IxRYcvmxFDYFn/ibqXGlcseHPcjFbIGAat9cIUmWNruHZI1K778w3PLPmZUY/DKST2zt4xyjdm1950lIL8UDEi2CDp3H9nabK2C/pKJgcM6fIGeefcktHN/VsXbKl8bxAyNvgIPtsAmX/5QTyPhU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=HMNKX3Nr; arc=fail smtp.client-ip=40.107.220.47 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) header.d=amd.com header.i=@amd.com header.b="HMNKX3Nr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=E/STXoYkuTtX6AjvzjzDEINWRZtaCtRXBRmlXUj+twecIAPIJkTJZBHcMTn3e/qpAqSBAffvDdYF3H6djhj97d5oUeCshZF/N7GDlXk166u7+ITOHd0vDOJOOm5nBu6wP8RkbavZ3zJ/hoXoEvxSCfOtLe+KrH1NI5K1ubQs1VuwtcH0jXDr480nloHSJhRYIU9Lsg3zPPvej0/NXM/uQPRLxEWsQkRmXKTyJ0F6HOkbR5tIeG3n/j+uT6bNgAvFiI7Z5EK2X4e8K6izaEXFo7bV2ZATk1MF7O756bmrgjcfeC28sXdypJyrfkH89AaTVWFg+3QQ8IP/icUNZ99LGg== 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=lcTzM5XN3l3Sd7lFf4fpceqrazo3z+vZ2R/RzQSq6C4=; b=LjQKF/HunMbX9v7iSeJwanOSswFD7diUkz2YKj8aBbxw3QYufLv72cOGx732l3ZCd3uOT1ZyVLJJRF2fnTGX0zTfhQVB3aIBz//NcX9KxG6ROMfpVnVCxlKsRkSlyWAZhVS8oFzWnJe4tDi9Nka/+vZz0gWDZic3FnPq1e901WnhDirjaUt6v5kMsJyUD0NIFMVDtL+hySdBLuBiK1zSgLFmGus0Q4Rx1JJPdA46ndVqsRzYzkp/Nd9qCQlg4nc0ADOJwzv79quD9LJWI/mVHqt2puck53cBuEfJIB1kN7FJCYWxXyWkvqfhGfCxgqX9m206MKjUveizdxhFocVMwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=lcTzM5XN3l3Sd7lFf4fpceqrazo3z+vZ2R/RzQSq6C4=; b=HMNKX3Nrpo1yvQWToVOhD01fyPlZ0uu6f8z5UNg6j1Se58fe2jJjrvTO14iQ+YenSaqZET22BZ3695iRMNVqgRJiLh+wLonmHxOFn6Uzo3+v1w9qHAEiQaAxJfz4wWEdZUh9NeBw3DqVDlFEhdaHa/eSMYOxNn9KNcdx+FkDxPA= Received: from DM6PR02CA0103.namprd02.prod.outlook.com (2603:10b6:5:1f4::44) by IA1PR12MB6626.namprd12.prod.outlook.com (2603:10b6:208:3a2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.43; Fri, 13 Jun 2025 21:09:30 +0000 Received: from CY4PEPF0000EDD0.namprd03.prod.outlook.com (2603:10b6:5:1f4:cafe::be) by DM6PR02CA0103.outlook.office365.com (2603:10b6:5:1f4::44) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.31 via Frontend Transport; Fri, 13 Jun 2025 21:09:30 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD0.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:30 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:09:28 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 30/32] fs/resctrl: Hide the BMEC related files when mbm_event mode is enabled Date: Fri, 13 Jun 2025 16:05:14 -0500 Message-ID: <4769751d1de7c4f66b1c7f3c5ea7eeeb49951363.1749848715.git.babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD0:EE_|IA1PR12MB6626:EE_ X-MS-Office365-Filtering-Correlation-Id: e89d6cb4-be5a-403b-9b0a-08ddaabe96b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?B?WURGYm1lM2JKb3UxbjczTTVLTCtqMnRLVzRhT05VS2M5QVIydDh3WUdjOEdI?= =?utf-8?B?c2t3eGUyYXpBN2kxR0pPdEZnbTNhV3VmVUtSaFkrWlZrN2lCaUdUclpRL1k2?= =?utf-8?B?Z2FLQlpBb1hPclY0L3dTY2ZMRXQweEpyYjk1cGdQOXV5ZUNWeFlmU1VlS0lU?= =?utf-8?B?NFI5YWlKb3RvNTN1ZytVcE1aZDltek9oRm5hSVFwd1IyazdSblNWaGV0dDZE?= =?utf-8?B?MldPc2QvRHR4anUrbzBHWUtyNnVleDlWcjJIbnFUMGFWSnlUcHFvWkt4N1VM?= =?utf-8?B?NXBLL1JTUmpTOGhlTXZ2MWszMGhYSnJpeEd1bHRPT3duQjl5bTNYRll4dGsv?= =?utf-8?B?T25wci9sSXpjNTQvSEhEakpUOVJGbW9pSjBxMExpT3Nac0FiU0VualU0SzdC?= =?utf-8?B?am55aTJDeWNmMFFoK2tYS0JuZ1NYMUw0VkpDd3QxRmplVE4vcXRoODZienNz?= =?utf-8?B?N2RRWFNPaGgrai9zN0JKSGVtOVJVdUtLcERvNGV3b0R3WFVqZTBjQmxjMjRi?= =?utf-8?B?Szl4T3lrbjdwWG01aXhEYUVmd0RsZWZEOVFoSVZsa29tM1dJb1JrNmo4K29u?= =?utf-8?B?QjRwL0NHby9aelVQL09tS28zZEM4Ujl0TGcrRDF5MDgycDl1aUg5cUt2a1pR?= =?utf-8?B?ZEJFeDBCTXJlbGRwbW9Ndm5nRVZVdS9oSXBQY3NDRGVFdDF0UnRFK2xnOWp3?= =?utf-8?B?VDBEMFBPaVVhYzRKTUtxUmpCSFZleXl2Zmh4bUlLS2NaUmJyK1k0VG1mMGJw?= =?utf-8?B?cEhKVUZHSFlkNEN3bDZCbUg1elQ5MEJxNFBYSm5zN2pZd2RvcWtjWjBFRmR0?= =?utf-8?B?QnVQUG12dU53QklNLzExbEYyZ05sWHZCS2M4VGRIR1JqRlRJSExhdVRkYVg4?= =?utf-8?B?Qzk0YmR1U0tKRFJQczByc0VVVlh2dWNvbHp5R29tSzYrNVNRNlVMakdFVzg1?= =?utf-8?B?YkVXVmg2OFNXMWxTOVYvMW1HamdoTXBialhHeGFEa1dGZHFTMWM0RkdYNHJP?= =?utf-8?B?bkdoMXkrNDloenBFOEJNekc1OHpneUQzVE1tbGk2YkJTb3FoZ3Q1Smgzb3Yv?= =?utf-8?B?WVBFYTVoTm5UNVBEVWdqNTRsTm81UTFvbk0yM0dxVUkzMHNoTUt1M0FXQ2Zp?= =?utf-8?B?cHFFMmpuNi9WbW9NaGFabmtudSs4ZE14RGlNeVlIdlE3WmpsNWl4NGtRTnRB?= =?utf-8?B?b01aMEROTXVzOTRkT2tiRnVSVkNMMUMyNjV0c0QxVlNaY1ZsQVhwVHRudFUz?= =?utf-8?B?UU9hYVI2M29JTlo4WlpqMm56N2llckFBazkrZkIwQjZjQkJrSlZqOFovTzVX?= =?utf-8?B?RFJtMnhRdGRVQjRRVmRVcXg5YkRsNUZsM3FLMEtIVlVVUGZGaGQraDM2UjM5?= =?utf-8?B?bWhKNEhGTStCNVZrdnZ0VzJQY0tLQzViTStwQ2o1V29oNFkyZDEyVmtiN0hG?= =?utf-8?B?TlE2UGhzSlcycVVUdVVqVzh5a0dTTnVqendSQXh5dEZoNUhOSzhnVjVRVzNj?= =?utf-8?B?OUhCTXZRMERVRWxrMCtJUkhGOGpGR0NkellVTjZuTlJQT1VRSjlTdVg3ZzlL?= =?utf-8?B?TFQwTmdMSXkyVjllb01KdFZQWXNWNXlQOWIzTHZoZXNEeTZ6SUNDY0JXd01F?= =?utf-8?B?eWgvQ2pQYnhTSGErQ2dBVHVZZm1mRU96UUVEdlBERCtXUzlkdDFNYlhYU0Y0?= =?utf-8?B?Y0ZoYzh2Z08zTnk1RW5JRVF2UENlKzZmSFpQY0dMWEd4a2dSRFRocHlvY2c4?= =?utf-8?B?cytNdUk3aUFaNnF0QnRMYmJCWHhLcVMvMGpWdWNLajMxcW5yaG4yUEV0bVJx?= =?utf-8?B?SGFSYUwvNXFxVFVBOSs5MXR2VC9KdThITGsrKzRsRHpZRDlxRzJzUEpyUSth?= =?utf-8?B?SGM2dmtRZDV3SHJpbW5kekdsbFdKRWxNWDh3d3UxOUNkVUI0dFIvRmx6MVdt?= =?utf-8?B?ZVU5RE5WdVFkVmRhRFVnMklWYWc4eE9jbVZEZWwrR0JxZlpFZ2Y4akRmQmpW?= =?utf-8?B?YjJvSERLc2NmbzVCU0NXR2FjZldIT0pqaDlueGZRVHgyZG82RGJ3cmlzU2dK?= =?utf-8?B?ekdrMFZSOE9qUTVQM2wrZzE4ejhZMTUxeTF0dz09?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(376014)(7416014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:30.4319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e89d6cb4-be5a-403b-9b0a-08ddaabe96b3 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6626 BMEC (Bandwidth Monitoring Event Configuration) and mbm_event mode do not work simultaneously. When mbm_event mode is enabled, hide BMEC-related files to avoid confusion and update the mon_features display accordingly. The files /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config and /sys/fs/resctrl/info/L3_MON/mbm_local_bytes_config will not be visible when mbm_event mode is enabled. Suggested-by: Reinette Chatre Signed-off-by: Babu Moger --- v14: Updated the changelog for change in mbm_assign_modes. Added check in rdt_mon_features_show to hide bmec related feature. v13: New patch to hide BMEC related files. --- fs/resctrl/rdtgroup.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 92bb8f3adfae..8c67e0897f25 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1164,7 +1164,8 @@ static int rdt_mon_features_show(struct kernfs_open_f= ile *of, if (mevt->rid !=3D r->rid || !mevt->enabled) continue; seq_printf(seq, "%s\n", mevt->name); - if (mevt->configurable) + if (mevt->configurable && + !resctrl_arch_mbm_cntr_assign_enabled(r)) seq_printf(seq, "%s_config\n", mevt->name); } =20 @@ -1813,6 +1814,38 @@ static ssize_t mbm_local_bytes_config_write(struct k= ernfs_open_file *of, return ret ?: nbytes; } =20 +/** + * resctrl_bmec_files_show() =E2=80=94 Controls the visibility of BMEC-rel= ated resctrl + * files. When @show is true, the files are displayed; when false, the fil= es + * are hidden. + */ +static void resctrl_bmec_files_show(struct rdt_resource *r, bool show) +{ + struct kernfs_node *kn_config, *l3_mon_kn; + char name[32]; + + sprintf(name, "%s_MON", r->name); + l3_mon_kn =3D kernfs_find_and_get(kn_info, name); + if (!l3_mon_kn) + return; + + kn_config =3D kernfs_find_and_get(l3_mon_kn, "mbm_total_bytes_config"); + if (kn_config) { + kernfs_get(kn_config); + kernfs_show(kn_config, show); + kernfs_put(kn_config); + } + + kn_config =3D kernfs_find_and_get(l3_mon_kn, "mbm_local_bytes_config"); + if (kn_config) { + kernfs_get(kn_config); + kernfs_show(kn_config, show); + kernfs_put(kn_config); + } + + kernfs_put(l3_mon_kn); +} + static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, struct seq_file *s, void *v) { @@ -2808,6 +2841,13 @@ static int rdtgroup_create_info_dir(struct kernfs_no= de *parent_kn) ret =3D resctrl_mkdir_counter_configs(r, name); if (ret) goto out_destroy; + + /* + * Hide BMEC related files if mbm_event mode + * is enabled. + */ + if (resctrl_arch_mbm_cntr_assign_enabled(r)) + resctrl_bmec_files_show(r, false); } } =20 --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2076.outbound.protection.outlook.com [40.107.93.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB7A127147F; Fri, 13 Jun 2025 21:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848986; cv=fail; b=gZRPG8+vSElBRDcUwYjx46pnZsGhTwuKhxkRYUMvG4LbCzqEj7KuLLa9SuHLi6r7Jqp5PblxTiSCBn0shnyZDJnLHjgUcZeb2w6khZMFwsHg2No/QSsVPYCiYAK9b0JCieJJO0nGvahmNaUJGw7yLRcnOyRCzCsoq5DwigOJqcU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848986; c=relaxed/simple; bh=nrBkMSeQ4hyt1PJq065LLRj5W7kEqUMIQ1S5AtBQ5IA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dSxszZK0xcAeZIFeuzrG7Jd4g1k96DNv8Y7rCTuRRpqUMNIY4aaaAJTY7G55lUUGD8YmjhMnv1niOX3idmXQG6o3Ib5CZob/x5xsaoMusXce9egNf1gIZhpcSiz1QmpE+BYfRArZ4cPeDvEO44LVW8u2YJ8Q7Dy1gBszX1VthUM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=OFxdh/1d; arc=fail smtp.client-ip=40.107.93.76 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) header.d=amd.com header.i=@amd.com header.b="OFxdh/1d" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sDLadXnUuyuDILvROND5iYozNDIITJhj3gzl4mSLp5MEojf6hxycPpv18HVakx3B9w9Ol76TI0OtB8OtalXoUVtati6Fvudytvyre3USQNCgtMJS4uSiYK/gJ0ROYq1BaVnX88W8Irzv9mydH+YyalcDQWWUVmQbIG1Sv2YdHUM3Yq85RA45bbyvIgpZY5W+9meqiizSVbpJj7hmzWFwDo0cLU2c0w9BLwt6YXIhy+uJWYkM0B5B1NIXZD6yiCwDO1Y+I1wt0GIJbmhxkl6ueDC8UiFWMDIPMI/OMWFn8A0ZSAYgTtGUqcne4j929I/yRvGy3iHkQfPDZ6oib0mEqQ== 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=kz44dNhKh/wmGOH1zi7G3iYeWVetAV8n4l7deteM4rg=; b=bnQfNBEIjJEq4jH2JPSocYqLXPeOnNF8RP2cRvdlS5lglmrAjNB/YoES6rDjkJdEMLtQqJHmEcRZjsaKHK6vDkWsWlvg42El1JrvvT54+5jUoV6LEM2e4QDZ36piyhN3kDAvXYjj9s0v8/WR3pdPTOaMM1VGMYQT+I2WhIpvzAE7LhbDbinmJbpfct9RtGUJrVRXuxhxDWHeVxOVhNQpSobF2LQhkpJ6j7jBErN3LD5gAjay7ZgQdf6mBEOdfz4vBV906PNdn7gmti8DBG06adPjUXWhloYAu9WcxzND40EaNwN48u6BAraJdEBrORoDOAYEWolyYJ5I3Y+Hf7d3hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=kz44dNhKh/wmGOH1zi7G3iYeWVetAV8n4l7deteM4rg=; b=OFxdh/1dR6PaI84RybgJpRHWRTqHOaG4qZe6+pLx9lfmXmbOwBkokz+TXczMmqjAMmaYJPoL86+M61Yoq6Mnevup03VT1eLO8KoeDdeJpgFr2xtCRlaHZdYUd0PcjgxHDN710Kb58+uAJhgzrksyqTBrK3kEx4KgoLXkJMUG9iQ= Received: from CY5PR17CA0033.namprd17.prod.outlook.com (2603:10b6:930:12::8) by MN0PR12MB5980.namprd12.prod.outlook.com (2603:10b6:208:37f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:09:38 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:930:12:cafe::96) by CY5PR17CA0033.outlook.office365.com (2603:10b6:930:12::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.19 via Frontend Transport; Fri, 13 Jun 2025 21:09:38 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:38 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:09:36 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 31/32] fs/resctrl: Introduce the interface to switch between monitor modes Date: Fri, 13 Jun 2025 16:05:15 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD3:EE_|MN0PR12MB5980:EE_ X-MS-Office365-Filtering-Correlation-Id: a483bf21-9580-4c58-47d4-08ddaabe9b66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DVX2jJapq9Hq+qYhfjmsutY6pbVATmkfz3Pzn3cNeppJb7XImX5hBLd96na7?= =?us-ascii?Q?5GB19XjKvaGDSX0pIsydJKGoAbl/7wtljGtOoLI9hft1+txGVjTpzfI4AIaz?= =?us-ascii?Q?Du7bjvXzE8v76TaHxY28jXl1bn9AW8fJPn2RhhV5oVb41HBPIgRshbTACTTG?= =?us-ascii?Q?R1axG32NjXaF+H4315SSiHEtpQQZyRSYEHBIeE1mqpDr0oUb3p0tU5qWHNWT?= =?us-ascii?Q?ia/6b+fbEOTDbUowbNPw+0o0eRYP1tThn6LzTSmqjPBbwfNkfGAgkVP72Z0V?= =?us-ascii?Q?PBzjugI0KQiqNTLQxZtni0Pv6NyISzDXIjzJ2Rl1xrvuhxGyN6TaWg3jwTj/?= =?us-ascii?Q?GBO5UIelJ30smXsJPkHe24SEKrXmPexhb+pri0zzfHBFmmTvnZI+MZ9xTeMm?= =?us-ascii?Q?JepIaH9PEsAcIN834lkHfBP1oqNw8rHIpsrGUkAl8a+gd/s0IHMqz7k5Je3f?= =?us-ascii?Q?2bxF5Bm1bHjYPw9nchDWl/vZ8UkdR2FxehwGJiciCfZxdPq9HzStipA/bKBK?= =?us-ascii?Q?DRyi27DO5Q4B9na1RC2Vu14N9ClQKVSSAOnwa7IRoMFZwoZenkxk4K14zfvQ?= =?us-ascii?Q?VNQLQSrxgHzDTon1v1MTiCOm4FAkkCvKoKtuFpHNh+j1r7nsE2H2T17JdYiB?= =?us-ascii?Q?MnC4nB1hEuuJh7cabh1X7z2HAlLCDuMHPHWO9SYpKxJYtyfpTZqFAmKt88sZ?= =?us-ascii?Q?zImfryn72MYrdQ6z9mUYBYr9QWnCbDaPvVdfLzImiBP6bk+2ZtMIY58lINHN?= =?us-ascii?Q?4fUA3gtgXwQHorzXJ9LOwWbxdFSUftw6FSwk5h8QQsWf1lmom7q0ibzx96F6?= =?us-ascii?Q?/3MeWKPh2rjgLcfvtThD3dEzJYgkdgxsYYyUuMV86ruYODW9w3sY3/4H+eEy?= =?us-ascii?Q?dZwV7RY6oDTqWIlOhWBxD5ZUe1tD78OcJcOZ4RwHNfHuEpmrXk2TgirmGj9Q?= =?us-ascii?Q?mCLZfR5K2D8tgjx/JKRzBLhqt4fFNjqZs11mDO+9YRjHrEVvhCxnB8TK5QyL?= =?us-ascii?Q?+TVyLVin5Q+DDi6O3KQ9mrqaGWVFjmZim0FFzYp8tCO4Kqkor/m04stadwsz?= =?us-ascii?Q?eQTdAOKIq1I3MJsDO03YPmbcB4AhiQ0ojV7FymhtbrXIpfAev/DSJcroZV9c?= =?us-ascii?Q?49QFxZsVNcBfOvftt2zu4P+q/kc5PRVxRrUtJPK/+m0GqtVbXbBWZL3Z1Yk5?= =?us-ascii?Q?SsqvBxS3Z4ZVt6PxKiVZu0JqRtj5nKu5htjn5cqYCt8GcbBtmv3iJxwFobHO?= =?us-ascii?Q?EeIWMJiOAId2f+bd1esDYGHtKW3y3y8SaweKNQ8aqqo1SdQ7N1dIJNlUZfkY?= =?us-ascii?Q?ngACOFWp1Yrzbph9FZ2U2m4nfuGtqrzMLpx0cYlaCKMub3l4sWXrYzlYetvP?= =?us-ascii?Q?EwIEKhos2qKzseY0FlqoPCJPmPjMfw44D75VDBijiAl60lagPvZRbhKfDCpU?= =?us-ascii?Q?DsSGN2qpDIfXWRt+Vm9dY8f3z1LSA31THgjiCYTvxNPE+RiDjSz15jFxdPOG?= =?us-ascii?Q?vLzRvj7f2hC+jhWBMX4oBNz8ANY77lnyDNTH9vKF79jyiBfTpyD7I24HkeQo?= =?us-ascii?Q?dDUDtxv9KlUu6jGlPU4=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:38.3136 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a483bf21-9580-4c58-47d4-08ddaabe9b66 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5980 Content-Type: text/plain; charset="utf-8" Resctrl subsystem can support two monitoring modes, "mbm_event" or "default". In mbm_event mode, monitoring event can only accumulate data while it is backed by a hardware counter. In "default" mode, resctrl assumes there is a hardware counter for each event within every CTRL_MON and MON group. Introduce interface to switch between mbm_event and default modes. Example: To list the MBM monitor modes supported: $ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_event] default To enable the "mbm_event" monitoring mode: $ echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode To enable the "default" monitoring mode: $ echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode MBM event counters are automatically reset as part of changing the mode. Clear both architectural and non-architectural event states to prevent overflow conditions during the next event read. Also clear assignable counter configuration on all the domains. Signed-off-by: Babu Moger --- v14: Updated the changelog to reflect the change in monitor mode naming. Added the call resctrl_bmec_files_show() to enable/disable files related to BMEC. Added resctrl_set_mon_evt_cfg() to reset event configuration values when mode is changes. v13: Resolved the conflicts due to FS/ARCH restructure. Introduced the new resctrl_init_evt_configuration() to initialize the event modes and configuration values. Added the call to resctrl_bmec_files_show() hide/show BMEC related files. v12: Fixed the documentation for a consistency. Introduced mbm_cntr_free_all() and resctrl_reset_rmid_all() to clear counters and non-architectural states when monitor mode is changed. https://lore.kernel.org/lkml/b60b4f72-6245-46db-a126-428fb13b6310@inte= l.com/ v11: Changed the name of the function rdtgroup_mbm_assign_mode_write() to resctrl_mbm_assign_mode_write(). Rewrote the commit message with context. Added few more details in resctrl.rst about mbm_cntr_assign mode. Re-arranged the text in resctrl.rst file. v10: The call mbm_cntr_reset() has been moved to earlier patch. Minor documentation update. v9: Fixed extra spaces in user documentation. Fixed problem changing the mode to mbm_cntr_assign mode when it is not supported. Added extra checks to detect if systems supports it. Used the rdtgroup_cntr_id_init to initialize cntr_id. v8: Reset the internal counters after mbm_cntr_assign mode is changed. Renamed rdtgroup_mbm_cntr_reset() to mbm_cntr_reset() Updated the documentation to make text generic. v7: Changed the interface name to mbm_assign_mode. Removed the references of ABMC. Added the changes to reset global and domain bitmaps. Added the changes to reset rmid. v6: Changed the mode name to mbm_cntr_assign. Moved all the FS related code here. Added changes to reset mbm_cntr_map and resctrl group counters. v5: Change log and mode description text correction. v4: Minor commit text changes. Keep the default to ABMC when supported. Fixed comments to reflect changed interface "mbm_mode". v3: New patch to address the review comments from upstream. --- Documentation/filesystems/resctrl.rst | 23 +++++++- fs/resctrl/internal.h | 2 + fs/resctrl/monitor.c | 27 ++++++++++ fs/resctrl/rdtgroup.c | 78 +++++++++++++++++++++++++-- 4 files changed, 126 insertions(+), 4 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index cd82c2966ed7..7e62c7fdcefa 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -259,7 +259,9 @@ with the following files: =20 "mbm_assign_mode": The supported monitoring modes. The enclosed brackets indicate which mode - is enabled. + is enabled. The MBM events (mbm_total_bytes and/or mbm_local_bytes) assoc= iated + with counters may reset when "mbm_assign_mode" is changed. + :: =20 # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode @@ -279,6 +281,15 @@ with the following files: of counters available is described in the "num_mbm_cntrs" file. Changing = the mode may cause all counters on the resource to reset. =20 + Moving to mbm_event mode require users to assign the counters to the even= ts. + Otherwise, the MBM event counters will return 'Unassigned' when read. + + The mode is beneficial for AMD platforms that support more CTRL_MON + and MON groups than available hardware counters. By default, this + feature is enabled on AMD platforms with the ABMC (Assignable Bandwidth + Monitoring Counters) capability, ensuring counters remain assigned even + when the corresponding RMID is not actively used by any processor. + "default": =20 In default mode, resctrl assumes there is a hardware counter for each @@ -288,6 +299,16 @@ with the following files: result in misleading values or display "Unavailable" if no counter is ass= igned to the event. =20 + * To enable "mbm_event" monitoring mode: + :: + + # echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + + * To enable "default" monitoring mode: + :: + + # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + "num_mbm_cntrs": The maximum number of counter IDs (total of available and assigned counte= rs) in each domain when the system supports mbm_event mode. diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 14d99c723ea5..adc9ff3efdfd 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -414,6 +414,8 @@ void resctrl_unassign_cntr_event(struct rdt_resource *r= , struct rdt_mon_domain * struct rdtgroup *rdtgrp, struct mon_evt *mevt); int mbm_cntr_get(struct rdt_resource *r, struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, enum resctrl_event_id evtid); +void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain = *d); +void mbm_cntr_free_all(struct rdt_resource *r, struct rdt_mon_domain *d); =20 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 618c94cd1ad8..504b869570e6 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -1045,6 +1045,33 @@ static void mbm_cntr_free(struct rdt_mon_domain *d, = int cntr_id) memset(&d->cntr_cfg[cntr_id], 0, sizeof(struct mbm_cntr_cfg)); } =20 +/** + * mbm_cntr_free_all() - Clear all the counter ID configuration details in= the + * domain @d. Called when mbm_assign_mode is changed. + */ +void mbm_cntr_free_all(struct rdt_resource *r, struct rdt_mon_domain *d) +{ + memset(d->cntr_cfg, 0, sizeof(*d->cntr_cfg) * r->mon.num_mbm_cntrs); +} + +/** + * resctrl_reset_rmid_all() - Reset all non-architecture states for all the + * supported RMIDs. + */ +void resctrl_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain = *d) +{ + u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); + enum resctrl_event_id evt; + int idx; + + for_each_mbm_event_id(evt) { + if (!resctrl_is_mon_event_enabled(evt)) + continue; + idx =3D MBM_STATE_IDX(evt); + memset(d->mbm_states[idx], 0, sizeof(struct mbm_state) * idx_limit); + } +} + /** * resctrl_alloc_config_cntr() - Allocate a counter ID and configure it fo= r the * event pointed to by @mevt and the resctrl group @rdtgrp within the doma= in @d. diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 8c67e0897f25..6bb61fcf8673 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1876,6 +1876,77 @@ static int resctrl_mbm_assign_mode_show(struct kernf= s_open_file *of, return 0; } =20 +static ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + struct rdt_mon_domain *d; + int ret =3D 0; + bool enable; + + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') + return -EINVAL; + + buf[nbytes - 1] =3D '\0'; + + cpus_read_lock(); + mutex_lock(&rdtgroup_mutex); + + rdt_last_cmd_clear(); + + if (!strcmp(buf, "default")) { + enable =3D 0; + } else if (!strcmp(buf, "mbm_event")) { + if (r->mon.mbm_cntr_assignable) { + enable =3D 1; + } else { + ret =3D -EINVAL; + rdt_last_cmd_puts("mbm_event mode is not supported\n"); + goto write_exit; + } + } else { + ret =3D -EINVAL; + rdt_last_cmd_puts("Unsupported assign mode\n"); + goto write_exit; + } + + if (enable !=3D resctrl_arch_mbm_cntr_assign_enabled(r)) { + ret =3D resctrl_arch_mbm_cntr_assign_set(r, enable); + if (ret) + goto write_exit; + + /* Update the visibility of BMEC related files */ + resctrl_bmec_files_show(r, !enable); + + /* + * Initialize the default memory transaction values for + * total and local events. + */ + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) + resctrl_set_mon_evt_cfg(QOS_L3_MBM_TOTAL_EVENT_ID, + MAX_EVT_CONFIG_BITS); + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) + resctrl_set_mon_evt_cfg(QOS_L3_MBM_LOCAL_EVENT_ID, + READS_TO_LOCAL_MEM | + READS_TO_LOCAL_S_MEM | + NON_TEMP_WRITE_TO_LOCAL_MEM); + /* + * Reset all the non-achitectural RMID state and assignable counters. + */ + list_for_each_entry(d, &r->mon_domains, hdr.list) { + mbm_cntr_free_all(r, d); + resctrl_reset_rmid_all(r, d); + } + } + +write_exit: + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + + return ret ?: nbytes; +} + static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s, void *v) { @@ -2203,8 +2274,8 @@ static int resctrl_process_assign(struct rdt_resource= *r, struct rdtgroup *rdtgr struct mon_evt *mevt; int assign_state; char domain[10]; + int ret =3D 0; bool found; - int ret; =20 mevt =3D mbm_get_mon_event_by_name(r, event); if (!mevt) { @@ -2249,7 +2320,7 @@ static int resctrl_process_assign(struct rdt_resource= *r, struct rdtgroup *rdtgr =20 switch (assign_state) { case ASSIGN_NONE: - ret =3D resctrl_unassign_cntr_event(r, d, rdtgrp, mevt); + resctrl_unassign_cntr_event(r, d, rdtgrp, mevt); break; case ASSIGN_EXCLUSIVE: ret =3D resctrl_assign_cntr_event(r, d, rdtgrp, mevt); @@ -2463,9 +2534,10 @@ static struct rftype res_common_files[] =3D { }, { .name =3D "mbm_assign_mode", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, .seq_show =3D resctrl_mbm_assign_mode_show, + .write =3D resctrl_mbm_assign_mode_write, .fflags =3D RFTYPE_MON_INFO | RFTYPE_RES_CACHE, }, { --=20 2.34.1 From nobody Fri Oct 10 09:14:56 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2064.outbound.protection.outlook.com [40.107.223.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0835B2741CB; Fri, 13 Jun 2025 21:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848992; cv=fail; b=UW/FOfJjc3S/ZWqzn7QZeAJHpizIAvLKfv0LAj2qxtFWVjpcCb63UwFpoS6EBPmP34Ps8z+JCJYwGlWDXJa/CNSP3Dnr6t7fiHHweEQe3+DsQjcCnmw14/xKiUI3B5AOBj3/QdYFwKHLMII2mMBK/zOaA4g7ik9N1w5a7HVim1M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749848992; c=relaxed/simple; bh=o9TrNhilmmhKv01AG+6GUaAq3fDAsLk0xI5yB4bKl/8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=do3QADjswbFubQbmy7nGwOxnG2Oqm0izd4JZF6kiMD2fj9TV2LNzcicrS8drrwThonDaQgCKhaSoTBmOmgjbQ2AEK8CheyEH4URi4uHvbTPbkfj4wCNMYyGFOIOzdn3OVwDcCuR28e38/wzlNKL2kdKlFpr6NLOQ+j1bwP8tIVo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KQUerUy5; arc=fail smtp.client-ip=40.107.223.64 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) header.d=amd.com header.i=@amd.com header.b="KQUerUy5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xF/M06YOtOGhyDvkAm+OUJ3k+izGvNt6SAAuOCalcnNRQ0mb9oRzCc1EFj7lDg0/t68TSnVjtU3oOrhXoRHOXIEM6BCwGxXtTZ2IgraitE6N5ZXexGiRtD9BJZBiUZZB5AQUgsMwOWkO+F6HsjYmOJRNwhlUcxUFMfMRt8CQpm2Gskt60N9+R1wz8b6qTTG/C/ZRd8C806AdtVUwh2hMVSJFQXh1hZZ00rkVOfQSHbxBSFyTZguI+odaOxGHkuajadp67Bk/xSm/jjnRHVq4Fuq+JRqvuybBBhJOMFFptWLfrXvsvsX3irBp13j5Hw/O5YBUInenOijbQZHZZhTygg== 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=AvBKvX48qdqaObdL6gEBkO8pDRoOzoWjZjBh8RqqvMU=; b=C9beAyqUwqrql0wVVB4W//1CQVStV1bP5dtUNPIDAwSyn7vkNlVVRIGdj+zoucQoi+sPM0POiOh9wbbi7C8rdYNs3hwNnM5h3lp9nvGiTfcLtGGxxLQYPZZeBPoed8obkTIuZBgteJp4RgClKhY7cyMkM9/aIl9+sL4Ub3KZymyksJ0TzioJmSGaLW7cDil3CiAaHdY3Yb62kI22GOBXE3bCTU5XBzYc3rmC4yiLIm+Mv8TKS245AYZ9LcCSZLxEE873OGzmg9RnWTqraqjtq+KV/AB+mQed07ofttwzsCG4FH3Hkp5T6eCfFoua4xHcDOk9kW7RqmbyqTk5SNKNhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net 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=AvBKvX48qdqaObdL6gEBkO8pDRoOzoWjZjBh8RqqvMU=; b=KQUerUy5CJQXZn6Y2BxPiuxIL4FjF+Ba8oO2QUkDus6k/yMCa5v8eje99gFVh48iH93mUg71RT5/kB+0CMRb6URmzh00uVnWAWicmE9uxKL1EMmQkND3dMAmJ2/1fDsHtw6GHIVZ5eq41RzXqu2OLui1mTKDnHVCCZ6zrF3b/2E= Received: from PH8PR21CA0017.namprd21.prod.outlook.com (2603:10b6:510:2ce::17) by DM6PR12MB4283.namprd12.prod.outlook.com (2603:10b6:5:211::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.19; Fri, 13 Jun 2025 21:09:47 +0000 Received: from CY4PEPF0000EDD1.namprd03.prod.outlook.com (2603:10b6:510:2ce:cafe::e6) by PH8PR21CA0017.outlook.office365.com (2603:10b6:510:2ce::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8857.14 via Frontend Transport; Fri, 13 Jun 2025 21:09:47 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD1.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Fri, 13 Jun 2025 21:09:47 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 13 Jun 2025 16:09:44 -0500 From: Babu Moger To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 32/32] x86/resctrl: Configure mbm_event mode if supported Date: Fri, 13 Jun 2025 16:05:16 -0500 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD1:EE_|DM6PR12MB4283:EE_ X-MS-Office365-Filtering-Correlation-Id: 91b1a312-49c9-4fcb-3f4f-08ddaabea0c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?V/dOetoXs2CCADbttw41UKEWrBiuzdSdOqgg1DRJXVwuFIGgU6Oot8pestS+?= =?us-ascii?Q?xPftwALbySYy4Pf/iU4+ZDYdA+yG0vAv7d4lmsUzYfb7rBszoSUzF7lY3Xi7?= =?us-ascii?Q?TJOQjOlOEdO1I476H6n9lXCpr0OPGE4umE+6Iu/sbFyfEGTujarSw7a9M+oV?= =?us-ascii?Q?+8EjooyWufm/4ZztsZ5rdpgLNXneaY7rsPqQx7ztNdDpCnej1R6EcdVI4Tib?= =?us-ascii?Q?m5ZQSWHgPKoHfp951oSNOk5upzBLTkP2qoFePdZ8qBnc10SMwCuRzTuv//LV?= =?us-ascii?Q?TjFbMR/1KvLxZ378iS9KoAH+HYgU6nnicJ8q3RynZEcwIkxKqZG7Dbb4BnL1?= =?us-ascii?Q?7xvOzbXlT0v42phPjOz7KnZeYx758FrVqlkhd05nbQFCodPGxmZ6/vIpzbye?= =?us-ascii?Q?Bg1q7vklFrqUeiah841S/aKjOU3czNGIiWOSn4G4Ey/wpK4q1qQxWtgI7rcn?= =?us-ascii?Q?xA7E1z8GCco7CiVvUBTZZLxM1QCGvQeiBgkW7z6qPEvr/y9OVKDNdeWNjLC6?= =?us-ascii?Q?CRvC22yAJ7tu1rgm1nxCTiYPmZB8vHHZ7LzZCUd3wKNV5dv7pJ05yrf2qKnQ?= =?us-ascii?Q?oQ6iO0ZvuCsw7B+Yi7QpECsZu+ipcQUNq7jNMIpH4OhCpsQ+DHcJu97zqpuZ?= =?us-ascii?Q?k3owbL9lEQS6QDuuXU8w3fzknwcATRE4VjbI8TzxSwhUVtjGkYr0KoPKdSUw?= =?us-ascii?Q?lYX0fgr56NKoSLpj8+ipVu0tDSFkt/orpGso9ibYSuWEG4Sy9+SjvhnAEOz/?= =?us-ascii?Q?DcCj9dT2nFSADlD+mRUrxP2tsOvOvdtt0gEwCQniwdZjZSNu+cqqu6kWYhne?= =?us-ascii?Q?TUYae+tuzm0djz5soDRD/kT6szTc2kqInxPaYatXRGYTYYZ5MU25WX41Z1Mr?= =?us-ascii?Q?nm0sHg7xhby/CTsZdY4TExhhggVkm/1xwSg8wKp/x1dJ9/bN3gue1Mn8Ohj8?= =?us-ascii?Q?wC5wsImQe6DeObirEeQ85mQLUi0NWh4fYBhZED1MISB4RMzNBwfU9M1iylKc?= =?us-ascii?Q?CXPQh3lPyVoSQFtZU6I2nYkPUR9XZzSexcqCwuAP2AiOvwIqQ2lsppSYs+BY?= =?us-ascii?Q?X5BvrCnmiyp1dQQ75y+B8/PaCyRBeFSVYGBAeugTKqeTz0Yh2PHxNEnyYwrH?= =?us-ascii?Q?eMts+JnbNc84HbBIMqvCvNRR6+aOWjpupSu5thpjx7GQW9wg3eJeYArHARpD?= =?us-ascii?Q?h8DylxwT2bruZOONkfyTuL3wPvmeyZiLyFVS4UkPaAH2jQ8pkU38T/o42qEs?= =?us-ascii?Q?kKpkFzhpFzFP6lIR1RvKY1EgGLrWZbG+19iOHHHu0+7Ym8oEHyyytFMInTAm?= =?us-ascii?Q?0I47kuk78AQb0SVHUZKxGOZP7zd0Xqw3rDEXM01HoafTmTauunt01WXbkEuA?= =?us-ascii?Q?/WRQShseLj3IkpmO9rs614IBZdQ4zuXzvmfSA7KU+Id4MzD3YqUY8JkZmoll?= =?us-ascii?Q?eREzKf++yIB3MIds9QygW244CaXZaqMHtKQq0W2mhNV7njZPL3dns0KT60XO?= =?us-ascii?Q?jg5r6CkCBq2pCVSHB5/jjm+Zy2Q3zSaBR14aeLmNVoVhvYkCksIB92+bMA?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2025 21:09:47.3268 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 91b1a312-49c9-4fcb-3f4f-08ddaabea0c5 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4283 Content-Type: text/plain; charset="utf-8" Configure mbm_event mode on AMD platforms. On AMD platforms, it is recommended to use the mbm_event mode, if supported, to prevent the hardware from resetting counters between reads. This can result in misleading values or display "Unavailable" if no counter is assigned to the event. The mbm_event mode, referred to as ABMC (Assignable Bandwidth Monitoring Counters) on AMD, is enabled by default when supported by the system. Update ABMC across all logical processors within the resctrl domain to ensure proper functionality. Signed-off-by: Babu Moger --- v14: Updated the changelog to reflect the change in name of the monitor mode to mbm_event. v13 : Added the call resctrl_init_evt_configuration() to setup the event configuration during init. Resolved conflicts caused by the recent FS/ARCH code restructure. v12: Moved the resctrl_arch_mbm_cntr_assign_set_one to domain_add_cpu_mon(). Updated the commit log. v11: Commit text in imperative tone. Added few more details. Moved resctrl_arch_mbm_cntr_assign_set_one() to monitor.c. v10: Commit text in imperative tone. v9: Minor code change due to merge. Actual code did not change. v8: Renamed resctrl_arch_mbm_cntr_assign_configure to resctrl_arch_mbm_cntr_assign_set_one. Adde r->mon_capable check. Commit message update. v7: Introduced resctrl_arch_mbm_cntr_assign_configure() to configure. Moved the default settings to rdt_get_mon_l3_config(). It should be done before the hotplug handler is called. It cannot be done at rdtgroup_init(). v6: Keeping the default enablement in arch init code for now. This may need some discussion. Renamed resctrl_arch_configure_abmc to resctrl_arch_mbm_cntr_assign_co= nfigure. v5: New patch to enable ABMC by default. --- arch/x86/kernel/cpu/resctrl/core.c | 7 +++++++ arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 1df171d04bea..a8fda1b408c7 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -518,6 +518,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + /* Update the mbm_assign_mode state for the CPU if supported */ + if (r->mon.mbm_cntr_assignable) + resctrl_arch_mbm_cntr_assign_set_one(r); return; } =20 @@ -537,6 +540,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_res= ource *r) d->ci_id =3D ci->id; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 + /* Update the mbm_mbm_assign state for the CPU if supported */ + if (r->mon.mbm_cntr_assignable) + resctrl_arch_mbm_cntr_assign_set_one(r); + arch_mon_domain_online(r, d); =20 if (arch_domain_mbm_alloc(r->mon.num_rmid, hw_dom)) { diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 77a9ce4a8403..f03abae3a2c4 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -216,5 +216,6 @@ bool rdt_cpu_has(int flag); void __init intel_rdt_mbm_apply_quirk(void); =20 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); +void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r); =20 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 053f516a8e67..74282dab7c2b 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -430,6 +430,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx); r->mon.num_mbm_cntrs =3D (ebx & GENMASK(15, 0)) + 1; r->mon.mbm_assign_on_mkdir =3D true; + hw_res->mbm_cntr_assign_enabled =3D true; } =20 r->mon_capable =3D true; @@ -533,3 +534,10 @@ void resctrl_arch_config_cntr(struct rdt_resource *r, = struct rdt_mon_domain *d, memset(am, 0, sizeof(*am)); } } + +void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r) +{ + struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); + + resctrl_abmc_set_one_amd(&hw_res->mbm_cntr_assign_enabled); +} --=20 2.34.1