From nobody Sun Apr 12 04:32:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F88BC00144 for ; Mon, 1 Aug 2022 20:57:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235178AbiHAU51 (ORCPT ); Mon, 1 Aug 2022 16:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235035AbiHAU4n (ORCPT ); Mon, 1 Aug 2022 16:56:43 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2044.outbound.protection.outlook.com [40.107.101.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC68041992; Mon, 1 Aug 2022 13:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QtWW2r455YecChyFFSYHdZpNcL8zwQ3qkHEorychSuHwbwMY1lkXFXTY1/vaTRd43SgLrTIXz61ZJwJa497/CFQ04jgoxnGe/uFAnEVJ26VaQu6r+GCgGI4QlZmYIemvIGptQsO6oNVRi/yl5Ys5RLuu3YHA4BHX8gBpHXqdn/+lnvNAYY1S9eznFWUOdW3z9BfHWnKwULUYFgaE2v5EMUn5w1SRVvx+XoYqgEf38l7V4lUeINazMZgsLIPsb+uPUWO15itfDtV+iWkEBrBXCzpREGim39SdvThgT9P85bmQD89IC4CW+yKa+lrL/Ns2pD//SE+7oZHU7idvC5veOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=H3SDTR/kL4O1R4+mhUqund24vBhQUTOpem5bZn5n4P4=; b=gYNs/2AAmdBRMXpDnsQ38ZX/yN5svwdqikQsTyJplmVsZBxgkM5mmCQd9y/YTuAAUPMKUXrrStOS1PuBvacTnrWS7ZLuGZcFTtnVPykscN7lhEtPPiV1mqv41/wZxjQYrm/YxN8oMxPBIgreES+WvKmm0WAnk5d5xUWMVOKW9zi+My+Te92EuLMUv59LHduFa75xP8EyocXcoFGLV2cFaTjYBnjl/0lVtFCQHhD5G4n83x3GLdptEfz22pIM2ZiC/8I20kDxSmWoL8k/YU+rXaRwKs4+pl6PTWIeW6kf8/7UTp1UfXAI6VfzGa3JrxUTy4BpNdzewew/KHPf/M8fcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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 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=H3SDTR/kL4O1R4+mhUqund24vBhQUTOpem5bZn5n4P4=; b=iO3XUvBW4DfPkLeJ1xQxJGzrivR1J2pe2bzXMRwOriaqk+6hHTnfZt6S1u474rq/lMl7XEAnk5aSGwY6H2iQmdOK3xPbXzLWCITVp1qOT7/3Ko2qr3fOP9s4EMnAfNYIczEYNIta+6k+QbVZPkCGsNAmuzzPc5/YBFoS2NyTbQg= Received: from BN0PR04CA0189.namprd04.prod.outlook.com (2603:10b6:408:e9::14) by DM6PR12MB4498.namprd12.prod.outlook.com (2603:10b6:5:2a2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.6; Mon, 1 Aug 2022 20:56:39 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e9:cafe::ec) by BN0PR04CA0189.outlook.office365.com (2603:10b6:408:e9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.23 via Frontend Transport; Mon, 1 Aug 2022 20:56:39 +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 BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5482.10 via Frontend Transport; Mon, 1 Aug 2022 20:56:39 +0000 Received: from [127.0.1.1] (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.2375.28; Mon, 1 Aug 2022 15:56:37 -0500 Subject: [PATCH v2 09/10] x86/resctrl: Add sysfs interface to write the event configuration From: Babu Moger To: , , , , CC: , , , , , , , Date: Mon, 1 Aug 2022 15:56:37 -0500 Message-ID: <165938739737.724959.9952911763036010551.stgit@bmoger-ubuntu> In-Reply-To: <165938717220.724959.10931629283087443782.stgit@bmoger-ubuntu> References: <165938717220.724959.10931629283087443782.stgit@bmoger-ubuntu> User-Agent: StGit/1.1.dev103+g5369f4c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] 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-Office365-Filtering-Correlation-Id: 7ffeb334-7a19-4946-4376-08da740054b0 X-MS-TrafficTypeDiagnostic: DM6PR12MB4498:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i7kjce+xTpQ6jZ4b4ZCg2Ca0lg7MdyDvVJvdr2yDjmXNCcOSkalqUGT7c65ZVST8d7MluY7SzFnPmrm3dZegTkS3v50KhworCw6IPlmm1v1MhEcp9zUAHmuXGdMapOl35X/zqYthLMi4jnacfYKsNgapLI0MSPp0Ps6QtDEj67R69r1+j3tccrb72eOQMHC945+y0JKQvWfjMIs1Y+XsTQDl4pv4r18o2YH2fG9KatGwNyMPvughpK7Ni4ITNusJJ8VlhBWtJJplBn+COEUJxhDctElz/zoIdwYpV6SVVLm/nplog2PTiCVwM1iLueaoUBp1bzq2iyEm8Cg+81cdZugwnBPH3CmFwNU0CudDuCu5X/esdTubj0UFfWg6dsA9ThfcElOKCVsFgH3TqKJETWi0YptPWTpMj7M9TzmNzL5r5KI7BENLJTaPwbI+JAuSSI82cAsajSRYQsrnBj8JBW83TygQQbJH0SIML+ixnwt48YbHbJesnH48TkaUxgnsXASVcF+fEKeAaEJZEj+uV7ig6M4YfAwTP4DUI1LqB6FVkvzs+QF0JXMUGcqlKzBTDRINUphWJSKJvHF/rIHeHXPTcwNlsesshdLE0BqCCx/xTCD12tWVTqGxperYyMJgzPpPkRLbrnyZpZWKPg1Fr9391PFyY6cARAfkrtv/a93oFXraP5/4sybOiWh9ODXkTnF+tq4VmpcaNAvaGx3bp6l7QDIhK80TQ/rB01m8crpv+cgGuhUsR7Gvo5AG7Wiv+ROuLBrEw3kyLjPXakp7q5K/1broTAxup7oVOZQvg0XtFlMzH9GpOFvnyzE9hEt2QQxUTao4Oat8lM9bSeoRvw2Rd16/uyOEb9zgrfTJetI= 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:(13230016)(4636009)(7916004)(346002)(39860400002)(376002)(136003)(396003)(40470700004)(46966006)(36840700001)(4326008)(478600001)(70206006)(8676002)(70586007)(33716001)(36860700001)(40480700001)(83380400001)(86362001)(110136005)(8936002)(316002)(54906003)(16576012)(9686003)(44832011)(26005)(103116003)(5660300002)(186003)(336012)(47076005)(426003)(2906002)(7416002)(16526019)(41300700001)(356005)(82740400003)(81166007)(82310400005)(40460700003)(71626007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2022 20:56:39.4443 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ffeb334-7a19-4946-4376-08da740054b0 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: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4498 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the sysfs interface to write the event configuration for the MBM configurable events. The event configuration can be changed by writing to the sysfs file for that specific event. Following are the types of events 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 Bits Description 6 Dirty Victims from the QOS domain to all types of memory 5 Reads to slow memory in the non-local NUMA domain 4 Reads to slow memory in the local NUMA domain 3 Non-temporal writes to non-local NUMA domain 2 Non-temporal writes to local NUMA domain 1 Reads to memory in the non-local NUMA domain 0 Reads to memory in the local NUMA domain By default the mbm_total_bytes configuration is set to 0x7f to count all the types of events and mbm_local_bytes configuration is set to 0x15 to count all the local memory events. For example: To change the mbm_total_bytes to count all the reads, run the command. $echo 0x33 > /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_config To change the mbm_local_bytes to count all the slow memory reads, run the command. $echo 0x30 > /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_config Signed-off-by: Babu Moger --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 109 ++++++++++++++++++++++++++++= ++++ 1 file changed, 109 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index e1847d49fa15..83c8780726ff 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -323,9 +323,118 @@ int rdtgroup_mondata_config_show(struct seq_file *m, = void *arg) return ret; } =20 +/* + * This is called via IPI to read the CQM/MBM counters + * in a domain. + */ +void mon_event_config_write(void *info) +{ + union mon_data_bits *md =3D info; + u32 evtid =3D md->u.evtid; + u32 msr_index; + + switch (evtid) { + case QOS_L3_MBM_TOTAL_EVENT_ID: + msr_index =3D 0; + break; + case QOS_L3_MBM_LOCAL_EVENT_ID: + msr_index =3D 1; + break; + default: + return; /* Not expected to come here */ + } + + wrmsr(MSR_IA32_EVT_CFG_BASE + msr_index, md->u.mon_config, 0); +} + +ssize_t rdtgroup_mondata_config_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdt_hw_resource *hw_res; + struct rdtgroup *rdtgrp; + struct rdt_resource *r; + unsigned int mon_config; + cpumask_var_t cpu_mask; + union mon_data_bits md; + struct rdt_domain *d; + u32 resid, domid; + int ret =3D 0, cpu; + + ret =3D kstrtouint(buf, 0, &mon_config); + if (ret) + return ret; + + rdt_last_cmd_clear(); + + /* mon_config cannot be more than the supported set of events */ + if (mon_config > GENMASK(6, 0)) { + rdt_last_cmd_puts("Invalid event configuration\n"); + return -EINVAL; + } + + cpus_read_lock(); + rdtgrp =3D rdtgroup_kn_lock_live(of->kn); + if (!rdtgrp) { + return -ENOENT; + goto e_unlock; + } + + if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL)) { + ret =3D -ENOMEM; + goto e_unlock; + } + + + md.priv =3D of->kn->priv; + resid =3D md.u.rid; + domid =3D md.u.domid; + + hw_res =3D &rdt_resources_all[resid]; + r =3D &hw_res->r_resctrl; + d =3D rdt_find_domain(r, domid, NULL); + if (IS_ERR_OR_NULL(d)) { + ret =3D -ENOENT; + goto e_cpumask; + } + + md.u.mon_config =3D mon_config & 0xFF; + + /* Pick all the CPUs in the domain instance */ + for_each_cpu(cpu, &d->cpu_mask) + cpumask_set_cpu(cpu, cpu_mask); + + cpu =3D get_cpu(); + /* Update MSR_IA32_EVT_CFG_BASE MSR on this cpu if it's in cpu_mask */ + if (cpumask_test_cpu(cpu, cpu_mask)) + mon_event_config_write(&md); + + /* Update MSR_IA32_EVT_CFG_BASE MSR on all other cpus in cpu_mask */ + smp_call_function_many(cpu_mask, mon_event_config_write, &md, 1); + put_cpu(); + + /* + * When an Event Configuration is changed, the bandwidth counters + * for all RMIDs and Events will be cleared, and the U-bit for every + * RMID will be set on the next read to any BwEvent for every RMID. + * Clear the mbm_local and mbm_total counts for all the RMIDs. + */ + memset(d->mbm_local, 0, sizeof(struct mbm_state) * r->num_rmid); + memset(d->mbm_total, 0, sizeof(struct mbm_state) * r->num_rmid); + +e_cpumask: + free_cpumask_var(cpu_mask); + +e_unlock: + rdtgroup_kn_unlock(of->kn); + cpus_read_unlock(); + + return ret ?: nbytes; +} + static const struct kernfs_ops kf_mondata_config_ops =3D { .atomic_write_len =3D PAGE_SIZE, .seq_show =3D rdtgroup_mondata_config_show, + .write =3D rdtgroup_mondata_config_write, }; =20 static bool is_cpu_list(struct kernfs_open_file *of)