Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4367738rwj; Tue, 20 Dec 2022 09:11:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+mNlBRvQF7Kq8IgaSEI/yhhcvJZrI8790Cw2US3o8RK5Zpm2CPIT9SfgzUmVNql+eWoo2 X-Received: by 2002:a17:90a:be06:b0:219:ecd7:759b with SMTP id a6-20020a17090abe0600b00219ecd7759bmr49882151pjs.10.1671556290376; Tue, 20 Dec 2022 09:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671556290; cv=none; d=google.com; s=arc-20160816; b=Ln75HBGA2SZrykW5JIIhruz62d7MnM2waeQgs/jrjOzBdC4omlh8EmSvoOzXbgTmLc +A61kpVtD/cxkAdvPmcN5jOUd5o32bpfY9gWg7R+r1+32cShe3qQpZ29Ob5dckNAy9Yn jP/yuCHhyUxH8jvhoSziQFnCUvSWsNyVzDuDIZgoYOCmMoiAwXGMm8Rnka8h6nr0Atyj Cb0yxAfa8khsSnSstnVBDuvGe9m59RPJy3Ou4MjvrB6e8+wPFbsCklBbJyy/6AJmqk9W ocZqG8SqbNvNhZO0rbWaMSF/2O7u5tXbg9hoQnKFUmomlDNhwSsImQdq2QCf6hGfEhjB dsRw== 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=Ddxu02Fh985Hkv+dloyjYYVxCvgT54odhdsQPfp8+qk=; b=FdX4xkbCHU6opuGnMgobKx91HS5VahTeGPdDvzR1tf4utYNZBl4PGBrAuEmVK0gscN yBO1+tdfqEMVSJynxTGQ96kIhzEw+vNG5RRtioFRZkkEA5RKB8yfeNCZR2llWOeNvgQb aiHW3oa2GulencrvPGyNpkKRsJGfDZCPJnNVGLlo406EP7ZBNhZBZ8mv1SzA/yDLFnoV gmzSVXylKbAPhDKmqqhPcLzSVVt2r6I99bXYxuxxdXmcEYwFgQdtgzeGuDXt6QNk3bPA Dx1KvxoD2HaodqkAjuJEh7kcZx9PEudtOFDm/CYK1mP+vAmMbCqGykUIJMf1Tz+Sf58I EAJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dtZ2FoIE; 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 mu9-20020a17090b388900b00223770a1235si16395061pjb.138.2022.12.20.09.11.21; Tue, 20 Dec 2022 09:11:30 -0800 (PST) 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=20210112 header.b=dtZ2FoIE; 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 S230506AbiLTQmI (ORCPT + 69 others); Tue, 20 Dec 2022 11:42:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbiLTQly (ORCPT ); Tue, 20 Dec 2022 11:41:54 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 577B76348 for ; Tue, 20 Dec 2022 08:41:53 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3b5da1b3130so147447767b3.5 for ; Tue, 20 Dec 2022 08:41:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ddxu02Fh985Hkv+dloyjYYVxCvgT54odhdsQPfp8+qk=; b=dtZ2FoIE8vSOyMFWa4Ib2Ngomw3+orv/5Y7dkDgPUC3bNOs0ezgSwkeSn3FhzekFi5 +gfuVW12SQftxn7Y2p8SU2QoFzuMboKd9662L8TlqhdYPbal3kndZYKlSL8Lm3Pt48C3 jSk7Qn8qVjZK1npJX+olXvODzx4FFWIouP9vnCTrPUsEO72yhmY3hlujrTOPG4peRewT QtwOu9q8wR161mcr23qO/wVn1d9JMnB1g4Axt95/xCAoIQXYmiad6QEDsW9BZ46N/W72 80kxTHh6SIvmVvEB8CGQXcUU4M4KuQFWz9xUo3FyqMKIraiN9tpfY4N89eA6Illhxt7F fpfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Ddxu02Fh985Hkv+dloyjYYVxCvgT54odhdsQPfp8+qk=; b=fMOevg2Yu3CMPTbktfQbPgaIOG/iVSE3jFDJJnaw1chpyCbiYPJntFOJm82tRz99VP lY1qArxLO4+zJOgOj1KX3U9C0rDtQHqYVbov33cj9bIhbzgnQoq7n3OVjq1SZXp09JyQ PeqpDU4u1xZBVqMaCiG5HUW60g+5dThreiq8w1of11HIdFTyhnoOXjX2R5oCHGFfIgQO aWEvEzPwMQfGfy3G2FGHITcheASEZhNAG193GWVobRmF7cQ6rV/YKp7H0P2aZsxgo+Gc nJO2YAkuUw3t8hLLM75ckbvMG2mUtEJZ9sS9am6cK1m6kog/dxNURRKWj/nJfMMf+8Tw 36EQ== X-Gm-Message-State: AFqh2krD8ogSVz9xi8WK3CnNExzq6rKXy4fLJPj+gzf/DnBTPrG7dkDp biPMKkNXwaaN6n9bSkaLTfUTVxp+V3JLsD+gRw== X-Received: from peternewman10.zrh.corp.google.com ([2a00:79e0:9d:6:8175:5362:6754:c66d]) (user=peternewman job=sendgmr) by 2002:a0d:e24b:0:b0:3d7:28d5:1c6f with SMTP id l72-20020a0de24b000000b003d728d51c6fmr1552006ywe.227.1671554512615; Tue, 20 Dec 2022 08:41:52 -0800 (PST) Date: Tue, 20 Dec 2022 17:41:32 +0100 In-Reply-To: <20221220164132.443083-1-peternewman@google.com> Mime-Version: 1.0 References: <20221220164132.443083-1-peternewman@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221220164132.443083-2-peternewman@google.com> Subject: [PATCH v3 2/2] x86/resctrl: Avoid redundant counter read in __mon_event_count() From: Peter Newman To: reinette.chatre@intel.com, fenghua.yu@intel.com Cc: Babu.Moger@amd.com, bp@alien8.de, dave.hansen@linux.intel.com, eranian@google.com, hpa@zytor.com, james.morse@arm.com, linux-kernel@vger.kernel.org, mingo@redhat.com, quic_jiles@quicinc.com, tan.shaopeng@fujitsu.com, tglx@linutronix.de, x86@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,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 __mon_event_count() does the per-RMID, per-domain work for user-initiated event count reads and the initialization of new monitor groups. In the initialization case, after resctrl_arch_reset_rmid() calls __rmid_read() to record an initial count for a new monitor group, it immediately calls resctrl_arch_rmid_read(). This re-read of the hardware counter is unnecessary and the following computations are ignored by the caller during initialization. Following return from resctrl_arch_reset_rmid(), just clear the mbm_state and return. This involves moving the mbm_state lookup into the rr->first case, as it's not needed for regular event count reads: the QOS_L3_OCCUP_EVENT_ID case was redundant with the accumulating logic at the end of the function. Signed-off-by: Peter Newman Reviewed-by: Reinette Chatre --- v3: - changelog clarifications suggested by Reinette v2: (patch introduced) v2: https://lore.kernel.org/lkml/20221214160856.2164207-2-peternewman@google.com/ --- arch/x86/kernel/cpu/resctrl/monitor.c | 43 ++++++++++++--------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 77538abeb72a..e708df478077 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -366,41 +366,36 @@ void free_rmid(u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } +static struct mbm_state *get_mbm_state(struct rdt_domain *d, u32 rmid, + enum resctrl_event_id evtid) +{ + switch (evtid) { + case QOS_L3_MBM_TOTAL_EVENT_ID: + return &d->mbm_total[rmid]; + case QOS_L3_MBM_LOCAL_EVENT_ID: + return &d->mbm_local[rmid]; + default: + return NULL; + } +} + static int __mon_event_count(u32 rmid, struct rmid_read *rr) { struct mbm_state *m; u64 tval = 0; - if (rr->first) + if (rr->first) { resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid); + m = get_mbm_state(rr->d, rmid, rr->evtid); + if (m) + memset(m, 0, sizeof(struct mbm_state)); + return 0; + } rr->err = resctrl_arch_rmid_read(rr->r, rr->d, rmid, rr->evtid, &tval); if (rr->err) return rr->err; - switch (rr->evtid) { - case QOS_L3_OCCUP_EVENT_ID: - rr->val += tval; - return 0; - case QOS_L3_MBM_TOTAL_EVENT_ID: - m = &rr->d->mbm_total[rmid]; - break; - case QOS_L3_MBM_LOCAL_EVENT_ID: - m = &rr->d->mbm_local[rmid]; - break; - default: - /* - * Code would never reach here because an invalid - * event id would fail in resctrl_arch_rmid_read(). - */ - return -EINVAL; - } - - if (rr->first) { - memset(m, 0, sizeof(struct mbm_state)); - return 0; - } - rr->val += tval; return 0; -- 2.39.0.314.g84b9a713c41-goog