From nobody Wed Nov 27 14:40:28 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2043.outbound.protection.outlook.com [40.107.244.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 A78761E1C31; Wed, 9 Oct 2024 17:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728495782; cv=fail; b=GLq9derXGw2uGfxFDgRfVrOG61yV5I/Zij3D/I6bAPpj6c8xKym0mXnxxptLfXbF8BnVoA4gB8OYBp4wIOD+CWBRnXSCgTglMC6lvZRSXEo5n7paPoHin2HDWTNQUAz8aX1skA3HU5ptzgTbjlwoK2luBeiQ59C6cklK9+22SAg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728495782; c=relaxed/simple; bh=xlq1FmjqHgcjMMoryVpfQnlCL8xGgr+FCAu3OLiy6qU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qh8xdZOXvV1p+gGmTVxzoNh9hfVvsd3ORpmk98m2bvRRkfu2DHzR3PUnfbdiqztRP1i0KzyqcAkoWGDc8z9yegicjqTvhYWNKeMVRxyEp3dmxyj3TWHrMbLsXN0CeIBMdO16+RfsILkqGvGzjswjSeCDc9o4TzDRQBAjDpLIidY= 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=nQxPDdAv; arc=fail smtp.client-ip=40.107.244.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="nQxPDdAv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dMg2Qy5RQVuIYg72f5aVhCwqUqLRWet+s5dumcNBivHnemvTDdId9EVSeLxGyXTPuMX2G1hpXwA8+7kopjjy0Ne/sMPDoSnjjiLMIsATfrraPiwGBTtJisy9Ywi3Huw4PfbP1oH4Lzl0juKIJSAZfkiNynsS4heQ5h/ECp4uFXT+4psTXJ9cU31eb5V+TX1JbTBmyNf4hchkxdFUDlnu3WZ+2Yv9IVFDUme92Hn/Mi/uxfTxJ9bKIrmYxx3IEObdC7buaxfNCFnjC8mc+SFYzTQwn/AZvADfpg9ERakZcqLZ4KYD36+ahQCBqrHygkoJQW5Hfh/0dsgjPMgeqLyA5w== 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=67PxsLWY1X4Jyy+e6y4RSsxsqq08RHlXkJN60Okdyf0=; b=jxbrJMSxLRdWjMG9LdYI5PWjgXmuH+Lh/XM9NftnnrSvDEdk+oxvxhwGHH1I2b4lxJEnKyQe/VdmndhmVngqlX2dyTD81BHF+dDVNGPKegFy3FhXhA3ALnidUUHx98U4vCZXoslZZRsG3/BQjIdB7E8Mm3OArAAH1BCarsZ0thUPfVEqrsY3NGoohmGGUomF0AAfL9nWR4d0b5WFGxcn2KdY/AtjABax2G0fa9xFJLf4aGOWAHM8Mhsk81i5BZ4Y242GwuZ7/jR27aFmO3OyZtAQPGbO2bMRVPOvR8Ygg8lCbJmpDKafcZOOeNN9cqEoBcKW8qCnlWkWpCEkunKYLQ== 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=67PxsLWY1X4Jyy+e6y4RSsxsqq08RHlXkJN60Okdyf0=; b=nQxPDdAvP5WIVAjvM7pwcuJIsVRDOfkz+iiUhU/zudLSfN5yGAsXQ019x5K6yWbRfQzufPManWk4VsyoPf/c6+ADofRBtNrq+uemxWDEys8uZi5eF6NBBH5odWjtl25wpkhgtnZDDErIkLQxSGI6V16jaqXBYcjzSCm3hI6INN8= Received: from SJ0PR13CA0141.namprd13.prod.outlook.com (2603:10b6:a03:2c6::26) by BY5PR12MB4164.namprd12.prod.outlook.com (2603:10b6:a03:207::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Wed, 9 Oct 2024 17:42:51 +0000 Received: from SJ1PEPF00001CE2.namprd05.prod.outlook.com (2603:10b6:a03:2c6:cafe::13) by SJ0PR13CA0141.outlook.office365.com (2603:10b6:a03:2c6::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16 via Frontend Transport; Wed, 9 Oct 2024 17:42:51 +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 SJ1PEPF00001CE2.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8048.13 via Frontend Transport; Wed, 9 Oct 2024 17:42:51 +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; Wed, 9 Oct 2024 12:42:49 -0500 From: Babu Moger To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v8 21/25] x86/resctrl: Introduce the interface to switch between monitor modes Date: Wed, 9 Oct 2024 12:39:46 -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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE2:EE_|BY5PR12MB4164:EE_ X-MS-Office365-Filtering-Correlation-Id: bf438eff-72f9-4e03-5b32-08dce889cc3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?m7wsmiiyAnCkqAI5/cqneY6+k801ype1srbxh0GZajgvLbdifTIAKxz9OWBz?= =?us-ascii?Q?QEOiXJg7eiMkd8f09ucdaHfz7d/3q1YPyTx8QZoVcwPlYfX/ai1ZLhGe4GK3?= =?us-ascii?Q?AFZhNnKg0OgWmhL9L5cyFXkhM2ZYB9/AAxpg5oIkO9F1CFLqPeMeOmrdZ+u/?= =?us-ascii?Q?iDuUKXf/m9+1SLfXWiJvUdNRNb4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onUblqptvSvG7W/3Hg/GYXcg1uRfyCXLX1MUSmn86rEWqIxUddSFALcL?= =?us-ascii?Q?7Mr16Fnv1u6Vu72cWhV77hlkcmKcwCdPIbjzsEOG3927FO3b5lDxJmhJQR1W?= =?us-ascii?Q?o5S9ngDFNT7oglH5ZZ28gGUKtpa3n5Y6OHPyaaVUE6YhREPHDRovVOpd0Q+f?= =?us-ascii?Q?5+DkAZxFW9wB3Xf9+xXeJn0jXoaU3iAfcm2xKbCo13pVc4oJvOPaDcDnXBEm?= =?us-ascii?Q?dpTzN5qoqgLmrZByX02gMvpsEP06b8eOkVtRm/PKMCSpRbQcMKvDvY56x/Jb?= =?us-ascii?Q?nG/NC9I=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)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 17:42:51.2967 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf438eff-72f9-4e03-5b32-08dce889cc3b 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: SJ1PEPF00001CE2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4164 Content-Type: text/plain; charset="utf-8" Introduce interface to switch between mbm_cntr_assign and default modes. $ cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_cntr_assign] default To enable the "mbm_cntr_assign" mode: $ echo "mbm_cntr_assign" > /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 will reset when mbm_assign_mode is changed. Signed-off-by: Babu Moger --- 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/arch/x86/resctrl.rst | 15 ++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 75 +++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/re= sctrl.rst index 99ee9c87952b..d9574078f735 100644 --- a/Documentation/arch/x86/resctrl.rst +++ b/Documentation/arch/x86/resctrl.rst @@ -291,6 +291,21 @@ with the following files: that case reading the mbm_total_bytes and mbm_local_bytes may report 'Unavailable' if there is no counter associated with that group. =20 + * To enable "mbm_cntr_assign" mode: + :: + + # echo "mbm_cntr_assign" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mo= de + + * To enable default monitoring mode: + :: + + # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + + The MBM events (mbm_total_bytes and/or mbm_local_bytes) associated counte= rs + may reset when the mode is changed. Moving to mbm_cntr_assign mode will + require users to assign the counters to the events. Otherwise, the MBM + event counters will return "Unassigned" when read. + "num_mbm_cntrs": The number of monitoring counters available for assignment when the architecture supports mbm_cntr_assign mode. diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index cb2c60c0319e..88eda3cf5c82 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -888,6 +888,78 @@ static int rdtgroup_mbm_assign_mode_show(struct kernfs= _open_file *of, return 0; } =20 +static void mbm_cntr_reset(struct rdt_resource *r) +{ + struct rdtgroup *prgrp, *crgrp; + struct rdt_mon_domain *dom; + + /* + * Hardware counters will reset after switching the monitor mode. + * Reset the architectural state so that reading of hardware + * counter is not considered as an overflow in the next update. + * Also reset the domain counter bitmap. + */ + list_for_each_entry(dom, &r->mon_domains, hdr.list) { + bitmap_zero(dom->mbm_cntr_map, r->mon.num_mbm_cntrs); + resctrl_arch_reset_rmid_all(r, dom); + } + + /* Reset global MBM counter map */ + bitmap_fill(r->mon.mbm_cntr_free_map, r->mon.num_mbm_cntrs); + + /* Reset the cntr_id's for all the monitor groups */ + list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { + prgrp->mon.cntr_id[0] =3D MON_CNTR_UNSET; + prgrp->mon.cntr_id[1] =3D MON_CNTR_UNSET; + list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, + mon.crdtgrp_list) { + crgrp->mon.cntr_id[0] =3D MON_CNTR_UNSET; + crgrp->mon.cntr_id[1] =3D MON_CNTR_UNSET; + } + } +} + +static ssize_t rdtgroup_mbm_assign_mode_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdt_resource *r =3D of->kn->parent->priv; + 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_cntr_assign")) { + enable =3D 1; + } 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) + mbm_cntr_reset(r); + } + +write_exit: + mutex_unlock(&rdtgroup_mutex); + cpus_read_unlock(); + + return ret ?: nbytes; +} + static int rdtgroup_num_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s, void *v) { @@ -2115,9 +2187,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 rdtgroup_mbm_assign_mode_show, + .write =3D rdtgroup_mbm_assign_mode_write, .fflags =3D RFTYPE_MON_INFO, }, { --=20 2.34.1