From patchwork Fri Apr 21 14:17:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1109578vqo; Fri, 21 Apr 2023 07:27:49 -0700 (PDT) X-Google-Smtp-Source: AKy350azfEj1hci3kpRNq15B2A2y5fs/BMVZphQhtmuJsHfVT/u41lGx1ednzSpLsTj5WzfBpNGw X-Received: by 2002:a17:903:234a:b0:1a6:413c:4a47 with SMTP id c10-20020a170903234a00b001a6413c4a47mr7639835plh.1.1682087268722; Fri, 21 Apr 2023 07:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682087268; cv=none; d=google.com; s=arc-20160816; b=DyoOXVkSAO73+MAdufL3pAsEejzj4yOweoXaaDuElNyLUXzpc+NTmXWWR9S3mwrEMp ByTzJ5rLGl4B0C/8h1uHjI4hiyD1/Ho6uPewxl9Slze9/eLrVgMnjZZJ7X1he3YhTxFN 6Xid9yR0Z4EH+jk3H8FbdMdwyrRaBbV7bu9n3nz82OVGLnyOKNXREEFo4+PvKYwh1msY /alqYISPt8mif39aja9Sivw3KCo7s9tN56+PLpyhUN7YltXTm5uyTJ+rY3GfIW5/oCAh H8OFbEb4AG7lLCPxiVr0+NG/eqoa8bbg+e12G9r+fN8lwV93iji2/zJmIZCnewU68+5X ZTog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=eG+d82X49QK4SbPD8xART0pPpkKrWLwG04cl9OQ+l3E=; b=zra4S4CsnCNFkH8kn6YTWtKVwa44MoJtpkzSWePnmC9hck254XOk1sGbWv9u9a495F thmdpd6BAMN8I7BbXCt7j2bRJdJEjf7RjqVOJy2FdSXBQXY0Lp/0nI1rFvREeyCNiCq1 VAYUMH/8YiJx1lXum6Okxg0uGxgLP+dvxVTYd3Q0NWAFdtU8NDwEpdkJUpVEeC4JEHXI A1RQKhLE3h1JzXJterLHcyGpNfjwAiJSGG1zpiTR3jhYCv2jHFH5OX7MdoS21XnB1fef 7JKS8gpiVmRwRTTFKVa6K1aURQRvmQGxrOmvvwri9avlqhYKOW1joAtZN9KihwLaj63n 97aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Wd+O3j54; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a170902ccd000b001a677821130si4565061ple.13.2023.04.21.07.27.36; Fri, 21 Apr 2023 07:27:48 -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=@google.com header.s=20221208 header.b=Wd+O3j54; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232434AbjDUOSt (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbjDUOSD (ORCPT ); Fri, 21 Apr 2023 10:18:03 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BADA012C99 for ; Fri, 21 Apr 2023 07:18:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9229dd8c62so1210683276.0 for ; Fri, 21 Apr 2023 07:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086682; x=1684678682; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eG+d82X49QK4SbPD8xART0pPpkKrWLwG04cl9OQ+l3E=; b=Wd+O3j54Skqqn0pDaOa4Mjhf66LdJYTTj9EXOkDn/rwzAbg0BNewxKMK2fmMK8iG98 PicL46080hpLDBhfW/fTzkNo0EtVBh5MW6t23IZuu1RN6M338Hjbb0qD9I7z5KZ1n6QO t1cYVANMd85R44HbBJnjZausS2fw39/88Myh/hUlRcAU44GrbT8jfDhuYCOrhyj4MRYK WjHWGraOdx84TsWCjTu5s9cG6f4hnFQ/BeIhldOpzYVeBs4+iwLMdNanU9uFoitxwZAs 4OJ9cE65XStC7x334oAqiaoPQt5KUOL7kSzkZ3ntdiTUox5Fmt7osx4w5LeXwpEmOJoP U8Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086682; x=1684678682; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eG+d82X49QK4SbPD8xART0pPpkKrWLwG04cl9OQ+l3E=; b=goMaArQ54uftf7wReJaPPCCRXb/SbNbBPrFJpRr5vQw6bOu5aQ54ikq0z9ENjUaKGn 6JQixTrRyusHGoSpQRDWphow4I9h8mRCuCpzP7bULppNMfWBBcRZ1Xe9TFzeS9a8UPkp 0sqLqae/lkj1EiwG8atCjDKgPZUeoQT8Z+lrAGkjIRa7UkARrewmInuv83TCniAkBjvl XZYTWIuHf7HWWx1rKmQv9Z+Is9QAeFbT0pM29sIH5BtudXbdZ+x71WcarFfq6Iu56jgR LK5XabO7Urmspv42q09NG4yMZqsA1bCWS4vb5M7AJE3MDUL7xEXUOMk+1thYvSTOU/Ce anTg== X-Gm-Message-State: AAQBX9cdRqPUG6aGayfC0Km0nbbhpIgIgV1l7czEPF6E+f2ftna7WNV0 WYu7gRTfgF0qcNVcjB8TkLowZRxNX1UXt101PQ== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a25:cc93:0:b0:b92:570c:57a1 with SMTP id l141-20020a25cc93000000b00b92570c57a1mr1764698ybf.2.1682086682008; Fri, 21 Apr 2023 07:18:02 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:20 +0200 In-Reply-To: <20230421141723.2405942-1-peternewman@google.com> Mime-Version: 1.0 References: <20230421141723.2405942-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421141723.2405942-7-peternewman@google.com> Subject: [PATCH v1 6/9] x86/resctrl: Create soft RMID version of __mon_event_count() From: Peter Newman To: Fenghua Yu , Reinette Chatre Cc: Babu Moger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Stephane Eranian , James Morse , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Peter Newman X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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?1763796339852862523?= X-GMAIL-MSGID: =?utf-8?q?1763796339852862523?= When RMIDs are soft, __mon_event_count() only needs to report the current byte count in memory and should not touch the hardware RMIDs. Create a parallel version for the soft RMID configuration and update __mon_event_count() to choose between it and the original depending on whether the soft RMID static key is enabled. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/monitor.c | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index bb857eefa3b0..3d54a634471a 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -487,7 +487,30 @@ void resctrl_mbm_flush_cpu(void) __mbm_flush(QOS_L3_MBM_TOTAL_EVENT_ID, r, d); } -static int __mon_event_count(u32 rmid, struct rmid_read *rr) +static int __mon_event_count_soft_rmid(u32 rmid, struct rmid_read *rr) +{ + struct mbm_state *m; + + WARN_ON(!is_mbm_event(rr->evtid)); + m = get_mbm_state(rr->d, rmid, rr->evtid); + if (!m) + /* implies !is_mbm_event(...) */ + return -1; + + rr->val += atomic64_read(&m->soft_rmid_bytes); + + if (rr->first) { + /* + * Discard any bandwidth resulting from the initial HW counter + * reads. + */ + atomic64_set(&m->soft_rmid_bytes, 0); + } + + return 0; +} + +static int __mon_event_count_default(u32 rmid, struct rmid_read *rr) { struct mbm_state *m; u64 tval = 0; @@ -509,6 +532,14 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr) return 0; } +static int __mon_event_count(u32 rmid, struct rmid_read *rr) +{ + if (rdt_mon_soft_rmid) + return __mon_event_count_soft_rmid(rmid, rr); + else + return __mon_event_count_default(rmid, rr); +} + /* * mbm_bw_count() - Update bw count from values previously read by * __mon_event_count().