Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1343435rwb; Fri, 23 Sep 2022 11:13:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nBoVTYy+vJsbw2N/L0GV7/6/cegjpRW+gyXvbRqC9F/ZviunyaabOcmvGYN+vd7dE7QlA X-Received: by 2002:a05:6402:3552:b0:451:2037:639e with SMTP id f18-20020a056402355200b004512037639emr9973539edd.136.1663956823585; Fri, 23 Sep 2022 11:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663956823; cv=none; d=google.com; s=arc-20160816; b=OUu7Tc/6pXJvZM7EJ7nk3HFHxKUSHFMZqvEhuCRpZn0XtaFxU91UBsveoOTww51kqe s4129PcO8QSkkqPOBGuLKAApw17BtO44hy7Hmq4neWWa5XaG6lxLV3s7hOemXd66eBxc ujHXV7xtlS3KAGZvda4ErT+FtQWlgCAcjQn4g7igzrnnjxlQQZNsES/uAPj/8nk8u91d mjDUZ98m4tOi4PyftRl0/FpspBkbvOflHDO+/MEI/5g2ygsVfikKa3kL293C2BOLqLR3 O0z0KFz0mStWe3X7OAmVhqoCVg+mMWOmLdoI8zvHHjJNYP9j8rDkh5iMkiOvToDmc36d ygcA== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=aovbly4/A7xUlS7xCzDb0DiWoRe36nGpHkeo2qOdcDw=; b=MXp/5fRMDyAahG1+3QE6mQR0jAiw/EzNbroAyMFJtOhNZAcw9o3NidqZSrbS7SQ38l CDSvj5h9nhzX0u9HcMmkGA3N+/VoWT/YI7CM+rsocg2S8RxEmfI52Lk2uMqDeJF5dgtD lPN+7FZlZ6OFBG4l5Bxdxm06l/NBeVT3LQy3NabX510jX4nu0zQy0tl9eSTeO3NUVK1v 1WCIRvTM4AF2rISWJjfyaTsaekYl3stTuh7MK3O8cfh6a8MYAPfPpORbbHE2cv9nIF7v QA9V1k7198cXLN2CFJ/ZMoiEkHUQC7SrRngd/IUaIQ1zmP7cJPF7Qec+CRHe68M6Rxq6 UQEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aZOwXfSq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv13-20020a17090760cd00b0073d6276b00fsi9351439ejc.704.2022.09.23.11.13.07; Fri, 23 Sep 2022 11:13:43 -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=aZOwXfSq; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S232553AbiIWSCn (ORCPT + 99 others); Fri, 23 Sep 2022 14:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbiIWSCB (ORCPT ); Fri, 23 Sep 2022 14:02:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AACE13C847; Fri, 23 Sep 2022 11:01:52 -0700 (PDT) Date: Fri, 23 Sep 2022 18:01:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663956110; 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: in-reply-to:in-reply-to:references:references; bh=aovbly4/A7xUlS7xCzDb0DiWoRe36nGpHkeo2qOdcDw=; b=aZOwXfSqglQb8M/o9plrl7eISCIvxq8VfDw6AWi7N7hZMEkyedGknGVUWORT7/FcebU23h FldWKWJ38D2qdT5U+nl1imGW2AioKxG9A93g7yv5LO4Ag/waXOA8pSNgKDTqrmGnv1oxsd NKZlXo0ZDDrMOrtEBazQ07dTmeiLs+YL7lI8fnCwWtVH5HwzZrBNkZAANGOtzjnUCu8gF4 m/oD+lcArMt+KjxNUu8fk7UwDdnMvKeGHKM8WSm2h9gKIffXDxhBCkmSveLjAn+UcVv/M9 DduzITrdK/UnzmVgm82wPdmOEzy9u8h0PhJAu/i3p2OMlMsq0NcaoGQTmbYHIA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663956110; 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: in-reply-to:in-reply-to:references:references; bh=aovbly4/A7xUlS7xCzDb0DiWoRe36nGpHkeo2qOdcDw=; b=XJXdpiSWYQ/sEAXgWVqpTdQQgvCyWl2zgmc3jfMxarZQGrroqfrcaa31lJPOPM906eG5R6 1IAiELy3jWaFb+DQ== From: "tip-bot2 for James Morse" 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: Calculate bandwidth from the previous __mon_event_count() chunks Cc: James Morse , Borislav Petkov , Jamie Iles , Shaopeng Tan , Reinette Chatre , Xin Hao , Cristian Marussi , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220902154829.30399-13-james.morse@arm.com> References: <20220902154829.30399-13-james.morse@arm.com> MIME-Version: 1.0 Message-ID: <166395610953.401.969948201916916421.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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 The following commit has been merged into the x86/cache branch of tip: Commit-ID: 30442571ec81fb33f7bd8cea5a14afb10b8f442a Gitweb: https://git.kernel.org/tip/30442571ec81fb33f7bd8cea5a14afb10b8f442a Author: James Morse AuthorDate: Fri, 02 Sep 2022 15:48:20 Committer: Borislav Petkov CommitterDate: Thu, 22 Sep 2022 17:44:57 +02:00 x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks mbm_bw_count() is only called by the mbm_handle_overflow() worker once a second. It reads the hardware register, calculates the bandwidth and updates m->prev_bw_msr which is used to hold the previous hardware register value. Operating directly on hardware register values makes it difficult to make this code architecture independent, so that it can be moved to /fs/, making the mba_sc feature something resctrl supports with no additional support from the architecture. Prior to calling mbm_bw_count(), mbm_update() reads from the same hardware register using __mon_event_count(). Change mbm_bw_count() to use the current chunks value most recently saved by __mon_event_count(). This removes an extra call to __rmid_read(). Instead of using m->prev_msr to calculate the number of chunks seen, use the rr->val that was updated by __mon_event_count(). This removes an extra call to mbm_overflow_count() and get_corrected_mbm_count(). Calculating bandwidth like this means mbm_bw_count() no longer operates on hardware register values directly. Signed-off-by: James Morse Signed-off-by: Borislav Petkov Reviewed-by: Jamie Iles Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Tested-by: Xin Hao Tested-by: Shaopeng Tan Tested-by: Cristian Marussi Link: https://lore.kernel.org/r/20220902154829.30399-13-james.morse@arm.com --- arch/x86/kernel/cpu/resctrl/internal.h | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 3b9e43b..4606209 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -289,7 +289,7 @@ struct rftype { * struct mbm_state - status for each MBM counter in each domain * @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes) * @prev_msr: Value of IA32_QM_CTR for this RMID last time we read it - * @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting + * @prev_bw_chunks: Previous chunks value read for bandwidth calculation * @prev_bw: The most recent bandwidth in MBps * @delta_bw: Difference between the current and previous bandwidth * @delta_comp: Indicates whether to compute the delta_bw @@ -297,7 +297,7 @@ struct rftype { struct mbm_state { u64 chunks; u64 prev_msr; - u64 prev_bw_msr; + u64 prev_bw_chunks; u32 prev_bw; u32 delta_bw; bool delta_comp; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 3e69386..2d81b6c 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -315,7 +315,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) if (rr->first) { memset(m, 0, sizeof(struct mbm_state)); - m->prev_bw_msr = m->prev_msr = tval; + m->prev_msr = tval; return 0; } @@ -329,27 +329,32 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) } /* + * mbm_bw_count() - Update bw count from values previously read by + * __mon_event_count(). + * @rmid: The rmid used to identify the cached mbm_state. + * @rr: The struct rmid_read populated by __mon_event_count(). + * * Supporting function to calculate the memory bandwidth - * and delta bandwidth in MBps. + * and delta bandwidth in MBps. The chunks value previously read by + * __mon_event_count() is compared with the chunks value from the previous + * invocation. This must be called once per second to maintain values in MBps. */ static void mbm_bw_count(u32 rmid, struct rmid_read *rr) { struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r); struct mbm_state *m = &rr->d->mbm_local[rmid]; - u64 tval, cur_bw, chunks; + u64 cur_bw, chunks, cur_chunks; - tval = __rmid_read(rmid, rr->evtid); - if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) - return; + cur_chunks = rr->val; + chunks = cur_chunks - m->prev_bw_chunks; + m->prev_bw_chunks = cur_chunks; - chunks = mbm_overflow_count(m->prev_bw_msr, tval, hw_res->mbm_width); - cur_bw = (get_corrected_mbm_count(rmid, chunks) * hw_res->mon_scale) >> 20; + cur_bw = (chunks * hw_res->mon_scale) >> 20; if (m->delta_comp) m->delta_bw = abs(cur_bw - m->prev_bw); m->delta_comp = false; m->prev_bw = cur_bw; - m->prev_bw_msr = tval; } /* @@ -516,10 +521,12 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid) */ if (is_mbm_total_enabled()) { rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID; + rr.val = 0; __mon_event_count(rmid, &rr); } if (is_mbm_local_enabled()) { rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID; + rr.val = 0; __mon_event_count(rmid, &rr); /*