Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2314044rwr; Fri, 21 Apr 2023 07:19:21 -0700 (PDT) X-Google-Smtp-Source: AKy350Z8p+g1Jz76ObPRY1gF5rTT3z1Qeo5UkwVB0JfuEIsK7UXiQdeR5H5Bh0+7huXyVcwft7Qi X-Received: by 2002:a05:6a20:8e19:b0:d7:3c1a:6c9a with SMTP id y25-20020a056a208e1900b000d73c1a6c9amr5917664pzj.4.1682086761583; Fri, 21 Apr 2023 07:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086761; cv=none; d=google.com; s=arc-20160816; b=eb5am1siWMgETRvfzMvCFUXdc3AdbjJ4h+iBwzfycN+q6MnKwlGfwmDaC7ntNMAJ1q lk9mL9dPsggsLTwSgmOf60Ec9foundSz8fCAzIoViTiSrUAaBvU19GHiHO9VGJrnGWQt nImqG8CBa0qcjJZiJpo8moY5wgZZcgYjiALHSDPI/v2abl7Nzrqg4cakZY0r87Psp4l6 4/v9/GnD22+bf7CqCqY+W8WGLupeRUSSIyDwo9J07WDl3dfR+ReW6yUEdY24gDTUGx6+ wBSgw1+/U2sKVqPWSnrM14zasLGpg0Ba0dRtYKoO3M14lU8Fpziq6uJs5WdDBbOhZGfW okgg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i62-20020a625441000000b0063b65cea19dsi4380342pfb.62.2023.04.21.07.19.09; Fri, 21 Apr 2023 07:19:21 -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 S232431AbjDUOSs (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:48 -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 Content-Type: text/plain; charset="UTF-8" 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 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(). -- 2.40.0.634.g4ca3ef3211-goog