From patchwork Wed Mar 15 23:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 70505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp190757wrt; Wed, 15 Mar 2023 16:59:47 -0700 (PDT) X-Google-Smtp-Source: AK7set/WA32FTJz2BvftZk7T7ax+6/fO9n2ByCL62minhJlk3XB8xVgDN9bJJDMGBVEAW5sfxJ2D X-Received: by 2002:a17:90a:5314:b0:23d:77b3:907d with SMTP id x20-20020a17090a531400b0023d77b3907dmr1659801pjh.22.1678924787471; Wed, 15 Mar 2023 16:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678924787; cv=none; d=google.com; s=arc-20160816; b=vbOJ+987yu/Sm0q36gC5ESypOX2Zi3xmwdpfnWoRVBHYdRTpVDQV5wcfxF8DcIUzvj 64ApnSHCWExB3Pj9P76rAeFohvxeN0m1CPdhMn7I8kq7AWX3riQfdQHvTCE7Red84bNh nWlPXnhJ5cyCbbBfLDhYiNkWQmAuVO2EitXYc2jDIvIXdWHwTjldySWAEX9WPRfxPdp2 F2K8SnQ+aI0I+AADgVSDHWmX7WPwzvhJrvd4iWo3NoUl10YoFpEMNw0VArdx9RuIR+sd 1MOt0DFd9+MlTd3utC4JW10aNhmFnJFX0BRnYs8WknVP7tzQejJ0MPLMoRzmiG3nzRIS P7Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=41dIEGEGewUxp2qWhqXvFItcme40IVFHqdBSwxA8Mg4=; b=0xovA/5dU8Yfay1sgcZZ9awRucBwc2JUNl25g1gN0d/Lhb8hrwpjTZSYigJhuN+4ni XUnrDsQvRVv4IY+djVrsYb8DySlNTMWgUWRx4AOp63bA9IIyFjY8/4fhVy5kFn7yFIYU n91nqkpKvGPd27LRSVpm8Qe01XmITw9FALCR9pFuljLGPUsjbIJwCPC+BlhEzIYPAYva SSFrdG6l2L7c5eJFNzEHbCy4Q9ElgtYTsfWyy4rlZ4c8moRHo95baz8RtqnWDeGc1ph+ XvrJymTlzbiu9INhcTKtx4rITOSGgjH0ZztOqslN40fKUpe1omZqkcwgOraus5GfngXx bR8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oSw0bUcl; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v23-20020a17090a899700b00230cc557396si2840248pjn.73.2023.03.15.16.59.32; Wed, 15 Mar 2023 16:59:47 -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=@linutronix.de header.s=2020 header.b=oSw0bUcl; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232543AbjCOXq2 (ORCPT + 99 others); Wed, 15 Mar 2023 19:46:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232661AbjCOXq0 (ORCPT ); Wed, 15 Mar 2023 19:46:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEA3D15540; Wed, 15 Mar 2023 16:45:57 -0700 (PDT) Date: Wed, 15 Mar 2023 23:36:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1678923379; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=41dIEGEGewUxp2qWhqXvFItcme40IVFHqdBSwxA8Mg4=; b=oSw0bUclzmXJy5ukltY/PYfkqMioLCRNAIYazgnPvBaw9j12Y+xQF4jTq/pohCkIwqTEG9 xme3sssPl7onc30B/+mOF+3BQ4OsLrOUpKswlrsOXDOzCZgpKQDwlc0XOl9OMLtB/7IqE/ FIaAi4b/xSz4mLjCWet8Bs3ZybcmqmI0cQSYkLV4luzYe0Rt03SOau3+59OUqnV1kOTptt HtE6Jayr4o2pQCkflFKfIDLuFUdOACic0w8S/ZhrBVgOpyMhuXMNU0EnipT7yZ+lOjqymz DEyRGm1elovo5W9+4DM2jqe+JMwbqHzL6CTw37cmElf09uRtEEO13g3fnFYRKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1678923379; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=41dIEGEGewUxp2qWhqXvFItcme40IVFHqdBSwxA8Mg4=; b=TXJVi1UZOcZBV50a2x3ao2DTC9q4/7jpIvkBb1a8q6YTiMVvZBLmeITrnXVFxo0kuRWDRJ uYYj8aY2DrJP5XCQ== From: "tip-bot2 for Peter Newman" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Avoid redundant counter read in __mon_event_count() Cc: Peter Newman , Dave Hansen , Reinette Chatre , Babu Moger , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <167892337886.5837.12368110501318980479.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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?1760480237689355470?= X-GMAIL-MSGID: =?utf-8?q?1760480237689355470?= The following commit has been merged into the x86/cache branch of tip: Commit-ID: 322b72e0fd10101f2da8985b31b4af70f184bf79 Gitweb: https://git.kernel.org/tip/322b72e0fd10101f2da8985b31b4af70f184bf79 Author: Peter Newman AuthorDate: Tue, 20 Dec 2022 17:41:32 +01:00 Committer: Dave Hansen CommitterDate: Wed, 15 Mar 2023 15:44:15 -07:00 x86/resctrl: Avoid redundant counter read in __mon_event_count() __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 Signed-off-by: Dave Hansen Reviewed-by: Reinette Chatre Tested-by: Babu Moger Link: https://lore.kernel.org/all/20221220164132.443083-2-peternewman%40google.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 7fe5148..2095241 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -383,41 +383,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;