From patchwork Fri Nov 4 20:00:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 15772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp609595wru; Fri, 4 Nov 2022 13:02:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Wj28xI4x+LBS0BUVogsCz1A6V0xs6fN5olHDaxzlsajznX+pShztoa2qYYrX24mZfq9jH X-Received: by 2002:a17:90a:7d0a:b0:213:ee54:a707 with SMTP id g10-20020a17090a7d0a00b00213ee54a707mr27484535pjl.206.1667592142038; Fri, 04 Nov 2022 13:02:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667592142; cv=pass; d=google.com; s=arc-20160816; b=XNagNuDRDhX7mKU/Qv3vNk4g1K67ZLnZVg+8zaG7S4p1pPwsL2lDbM/+GG+nQ6IW19 bgs3+zGxdh7EIP8N8kFwOUu1KdfrPOeveUkSb7iKbOd8nz588/2aXjWui6VOnoSdG/vU RNRDNMJRG3PV2Oiu11Ebp1pqtMw92EG+SaESkJurKwN0lU6cadBiYuOIGJO9VCYp0Vtb +sVLcYTJr1yxscFK2+FWEwRyZKqetlRqhkHVbp0HClBbji5nVR1yyVGOhSVPtcdT2tp9 UXtForQBNWKIC7k9GBbXrsqtyzcHJP5XeiHR3wNF97j4drKT+Zl5ISn+xWO9emvJAnkp jXTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=4bdApC+C+Pz47I6PY3IaepkhrLN/PquXbV0FTP+h2+o=; b=QaoZ3kiWbhqwpM3Z3vqTYShRsnFhDsL0TkYprNvugtVK8YbxwuiEB/1POLOIWG5q+q ixG06kmcugQPO5Avm88UvIbAJbtYvWx3Q8sCFMsR8ieefgxiRylsijHSGq5lkUU/LJSN zV6VxhCEikgvlYm5z18ppThdrynV3eCFxlOqB1iwgKppP5rtpm4p0/CJV6q1S8iNUduZ O8+j3WkwY16C+zXAQuiNb8Ck5XZ55KCSWNd+UsbPIwuf0CePV126i0F5GKrq0rZKvEBt qvKJYBPSqiPi8c4rMh7iHhetmtGii3qnBRpYkEFrmX3iNUVvnu5flMDEI6QIHQ3CN8oA eL1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=bBAj2uQ5; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn1-20020a17090b38c100b002131bb4043asi5281458pjb.177.2022.11.04.13.02.08; Fri, 04 Nov 2022 13:02:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=bBAj2uQ5; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229713AbiKDUBZ (ORCPT + 99 others); Fri, 4 Nov 2022 16:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbiKDUBD (ORCPT ); Fri, 4 Nov 2022 16:01:03 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2055.outbound.protection.outlook.com [40.107.96.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A144B996; Fri, 4 Nov 2022 13:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FiTT/roqYHQyIZrQkloAOQjG2/c22CxzyVfeJlHHJx31jfETehR1bZts8O7P5M1h+zXM8ec9xQANFKH9ZsvC4z1UZhqyQTynK6v86U3pDV452/v97CJcuPqZOCL3+mzwJzsiuucKUO7qUbeaVWEeTV/4rwiNaMpPxKGbtgMNU1mmhRQAdM19Zde07nnSfQ2ROB1tNoYOIKV9fPvXPTjSaWjfKhH5N++/D+YzKEXc4HhxzG7Mwx0uc9b3a9VtC7v3B17lZJdXV5SK8L+KR29s++awfB3qBqFYOqT1BR72yeVVW40nXcz2f40/1Pp1I3Q2kRnYNdWoVvtwKyJeoB9+5w== 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=4bdApC+C+Pz47I6PY3IaepkhrLN/PquXbV0FTP+h2+o=; b=XaqW4DSwEBFiwPsRY+YwtD5RlR9A3GKbWJpn5nHxgPKEPxCoT2Vj+e3V0u7PM8kGn+BOB6of3Shy6oEv+JoUfIAfmAwREHr8KxKJYRSX7UwChS+CaQYKZ9NCwnp0x4PxXREV0ZkhjGbBzvYPpYqgkKOcAjphcik7ZXMylv9VWgNwR970GMGnW/FnNQaII1vQJ0BtUgqGedbKsSY0NJt2rHfqJ5R7TllOvcoqmMtwapjXJAso3Njup/ZV9zzF/mDslnrT4p2pTccpI+uDZVBrnNwxrrMk2PfyK5/unDegA6XyENw20rtjJlZSKc2xi6QsllEbVMYSeD8g6N5DxuMr7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=quicinc.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none 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=4bdApC+C+Pz47I6PY3IaepkhrLN/PquXbV0FTP+h2+o=; b=bBAj2uQ5+KwErJ8xF5JcoE4dAZ4puYqx6josSkKbqAwW7/50YE1SyW+zDAONMUf74KegReAOEUVc4cU2flqVrykAr8PI0WV1sewpNaCdiGcQdZjHR7jqTBI2DXVjY2agHMl+tTSI3hgx+tm/n/XtDjdqcL+xTrSHn83I4Tsb1fg= Received: from DS7PR03CA0286.namprd03.prod.outlook.com (2603:10b6:5:3ad::21) by MW3PR12MB4489.namprd12.prod.outlook.com (2603:10b6:303:5e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Fri, 4 Nov 2022 20:00:57 +0000 Received: from DM6NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3ad:cafe::17) by DS7PR03CA0286.outlook.office365.com (2603:10b6:5:3ad::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22 via Frontend Transport; Fri, 4 Nov 2022 20:00:57 +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 DM6NAM11FT073.mail.protection.outlook.com (10.13.173.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Fri, 4 Nov 2022 20:00:57 +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.31; Fri, 4 Nov 2022 15:00:55 -0500 Subject: [PATCH v8 08/13] x86/resctrl: Add sysfs interface to read mbm_total_bytes_config From: Babu Moger To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , Date: Fri, 4 Nov 2022 15:00:55 -0500 Message-ID: <166759205510.3281208.11437041392524040365.stgit@bmoger-ubuntu> In-Reply-To: <166759188265.3281208.11769277079826754455.stgit@bmoger-ubuntu> References: <166759188265.3281208.11769277079826754455.stgit@bmoger-ubuntu> User-Agent: StGit/1.1.dev103+g5369f4c MIME-Version: 1.0 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-TrafficTypeDiagnostic: DM6NAM11FT073:EE_|MW3PR12MB4489:EE_ X-MS-Office365-Filtering-Correlation-Id: 9873935e-cdbf-4177-d730-08dabe9f49ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EvffVthzzfomMIfThegbj92TAu/I+9VCLNuBLp09H3y5/Vym4rfmGYD+OfEKJaxQ6iX73GyVAb8zwC5JNbSY9zj/LKeoaqnEl2qJ1oGaQBF4A1jPu+j4aFAwhyia8VQkGXqxWlMENuDKK10O6VRLqagMHMMCD2IiL4D9TRDFqZB49XR055jA8mtGH5Kv3Pu/HXhUzHvw8kz25mONLDQMeIoUNzkxLtHjGob190q3wkhXeNyb8Xvs1csH8n50201833UKQeoxJ70I20OkAhUsX7I4UfHjhzGIwWiTPbGnxZypb0Jifgep6meLYj8czu/6cvbuFRrkhQrVR5+aps5trhtOYlRufJZOdOzXH/yOSgtFpIgPJAu+JpXL6uvfeF+e/6pZjwX/utD2HeePgUzthvwY3XjG/DcweSnwu0adaW0kg5I9c8FeRQriPRKmDZ1lFqVVq6yHHjafZ99jgICkrPru4ib/mD+i5V6SdJtOLi4WcCr13e0mswyKtk5CogdSBZrTjh0dAzdgYiTQzlmhH9wtZ98WkexkGXxswk4HPStkX7yd4tOVKNveOlRgDUigcoDhjx74miq+YxqjgzbzbAQcp42bGsCMaWu9W74Eun5R8JgCuqJKS1s/DYEcMt/zzNl7qk/077DQWfcNxyQmYt/qBwMbdZ6/L7h1TnwExzQTQjzJyWFD5yzJgxghOS0x6XHGOQTcgiBlP3DeE2gnd/i+cxYceEaVl72u94jQjmqn1sdVuk6cCiVT0aUawX5gVGcmfP1Y7OoAywqyWTWtySin4ZYUA2FCRvn7pCbLdh+c7iYWsc5BgjDvl/etnhhGXOt4pnV8WBE098VWX3JEXg== 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:(13230022)(7916004)(4636009)(39860400002)(396003)(376002)(136003)(346002)(451199015)(36840700001)(46966006)(40470700004)(8676002)(47076005)(426003)(2906002)(70586007)(70206006)(4326008)(40480700001)(86362001)(82310400005)(316002)(16576012)(110136005)(83380400001)(82740400003)(36860700001)(356005)(103116003)(81166007)(33716001)(40460700003)(54906003)(5660300002)(7416002)(8936002)(478600001)(41300700001)(9686003)(26005)(16526019)(44832011)(186003)(336012)(71626007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 20:00:57.4941 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9873935e-cdbf-4177-d730-08dabe9f49ef 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: DM6NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4489 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748597098051363303?= X-GMAIL-MSGID: =?utf-8?q?1748597098051363303?= The current event configuration can be viewed by the user by reading the configuration file /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config. The event configuration settings are domain specific and will affect all the CPUs in the domain. Following are the types of events supported: ==== =========================================================== 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_config is set to 0x7f to count all the event types. For example: $cat /sys/fs/resctrl/info/L3_MON/mbm_total_bytes_config 0=0x7f;1=0x7f;2=0x7f;3=0x7f In this case, the event mbm_total_bytes is currently configured with 0x7f on domains 0 to 3. Signed-off-by: Babu Moger --- arch/x86/kernel/cpu/resctrl/internal.h | 28 ++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 1 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 87 ++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 5459b5022760..c74285fd0f6e 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -15,6 +15,7 @@ #define MSR_IA32_MBA_THRTL_BASE 0xd50 #define MSR_IA32_MBA_BW_BASE 0xc0000200 #define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_EVT_CFG_BASE 0xc0000400 #define MSR_IA32_QM_CTR 0x0c8e #define MSR_IA32_QM_EVTSEL 0x0c8d @@ -41,6 +42,32 @@ */ #define MBM_CNTR_WIDTH_OFFSET_MAX (62 - MBM_CNTR_WIDTH_BASE) +/* Reads to Local DRAM Memory */ +#define READS_TO_LOCAL_MEM BIT(0) + +/* Reads to Remote DRAM Memory */ +#define READS_TO_REMOTE_MEM BIT(1) + +/* Non-Temporal Writes to Local Memory */ +#define NON_TEMP_WRITE_TO_LOCAL_MEM BIT(2) + +/* Non-Temporal Writes to Remote Memory */ +#define NON_TEMP_WRITE_TO_REMOTE_MEM BIT(3) + +/* Reads to Local Memory the system identifies as "Slow Memory" */ +#define READS_TO_LOCAL_S_MEM BIT(4) + +/* Reads to Remote Memory the system identifies as "Slow Memory" */ +#define READS_TO_REMOTE_S_MEM BIT(5) + +/* Dirty Victims to All Types of Memory */ +#define DIRTY_VICTIMS_TO_ALL_MEM BIT(6) + +/* Max event bits supported */ +#define MAX_EVT_CONFIG_BITS GENMASK(6, 0) + +/* Max configurable events */ +#define MAX_CONFIG_EVENTS 2 struct rdt_fs_context { struct kernfs_fs_context kfc; @@ -542,5 +569,6 @@ bool has_busy_rmid(struct rdt_resource *r, struct rdt_domain *d); void __check_limbo(struct rdt_domain *d, bool force_free); void rdt_domain_reconfigure_cdp(struct rdt_resource *r); void __init thread_throttle_mode_init(void); +void mbm_config_rftype_init(void); #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 06c2dc980855..a188dacab6c8 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -787,6 +787,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r) if (mon_configurable) { mbm_total_event.configurable = true; mbm_local_event.configurable = true; + mbm_config_rftype_init(); } l3_mon_evt_init(r); diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 8342feb54a7f..dea58b6b4aa4 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1423,6 +1423,78 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, return ret; } +struct mon_config_info { + u32 evtid; + u32 mon_config; +}; + +/** + * mon_event_config_index_get - get the index for the configurable event + * @evtid: event id. + * + * Return: 0 for evtid == QOS_L3_MBM_TOTAL_EVENT_ID + * 1 for evtid == QOS_L3_MBM_LOCAL_EVENT_ID + * > 1 otherwise + */ +static inline unsigned int mon_event_config_index_get(u32 evtid) +{ + return evtid - QOS_L3_MBM_TOTAL_EVENT_ID; +} + +static void mon_event_config_read(void *info) +{ + struct mon_config_info *mon_info = info; + u32 h, index; + + index = mon_event_config_index_get(mon_info->evtid); + if (index >= MAX_CONFIG_EVENTS) { + pr_warn_once("Invalid event id %d\n", mon_info->evtid); + return; + } + rdmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, h); +} + +static void mondata_config_read(struct rdt_domain *d, struct mon_config_info *mon_info) +{ + smp_call_function_any(&d->cpu_mask, mon_event_config_read, mon_info, 1); +} + +static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid) +{ + struct mon_config_info mon_info = {0}; + struct rdt_domain *dom; + bool sep = false; + + mutex_lock(&rdtgroup_mutex); + + list_for_each_entry(dom, &r->domains, list) { + if (sep) + seq_puts(s, ";"); + + mon_info.evtid = evtid; + mondata_config_read(dom, &mon_info); + + seq_printf(s, "%d=0x%02lx", dom->id, + mon_info.mon_config & MAX_EVT_CONFIG_BITS); + sep = true; + } + seq_puts(s, "\n"); + + mutex_unlock(&rdtgroup_mutex); + + return 0; +} + +static int mbm_total_bytes_config_show(struct kernfs_open_file *of, + struct seq_file *seq, void *v) +{ + struct rdt_resource *r = of->kn->parent->priv; + + mbm_config_show(seq, r, QOS_L3_MBM_TOTAL_EVENT_ID); + + return 0; +} + /* rdtgroup information files for one cache resource. */ static struct rftype res_common_files[] = { { @@ -1521,6 +1593,12 @@ static struct rftype res_common_files[] = { .seq_show = max_threshold_occ_show, .fflags = RF_MON_INFO | RFTYPE_RES_CACHE, }, + { + .name = "mbm_total_bytes_config", + .mode = 0444, + .kf_ops = &rdtgroup_kf_single_ops, + .seq_show = mbm_total_bytes_config_show, + }, { .name = "cpus", .mode = 0644, @@ -1627,6 +1705,15 @@ void __init thread_throttle_mode_init(void) rft->fflags = RF_CTRL_INFO | RFTYPE_RES_MB; } +void mbm_config_rftype_init(void) +{ + struct rftype *rft; + + rft = rdtgroup_get_rftype_by_name("mbm_total_bytes_config"); + if (rft) + rft->fflags = RF_MON_INFO | RFTYPE_RES_CACHE; +} + /** * rdtgroup_kn_mode_restrict - Restrict user access to named resctrl file * @r: The resource group with which the file is associated.