Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp764828pxb; Tue, 12 Apr 2022 12:51:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVFoDFNd7tlboBZuYOsOARZHgHSH5dajOKwI3pFiJP7TqM2bQHxmnOQ9X2qV1mAKR4wo8K X-Received: by 2002:a63:4d14:0:b0:399:42b9:833c with SMTP id a20-20020a634d14000000b0039942b9833cmr32360568pgb.619.1649793098800; Tue, 12 Apr 2022 12:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649793098; cv=none; d=google.com; s=arc-20160816; b=jKYtyaVQoqGZa1dHejfYPbvhomjQfWsRfthobsgZXtcFNkYDuL9GnF20Hcueq9ltyt CY+PNW8PBB2tutJncBgqor6ZxkvhgxDNxw9gh1RdS6aXmevFTZYkRtPmxukOmjSZX47Q J3DyEuPFFURXqHs32ccMuXAAWhPHRVX5y7Wzjy0nIwKkfwVA45D5/iGqwx19Rv8NYua7 Bp7BeXoP8CCYWiWbHYaIlatzIsBiR7jGxAfm+FrvVaKqXUnqzv8NFuupdQ1m5bj0jJwU 05CjbeQaQpsNqLNPPJ6oyhWy3cKMTnQDqeqech+iRKt6lLuAaWFwSspOalu1+/qdZOnK zNmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=J39jdfPwS9nXr8wU7CBvIYfW3bIy9ZKg46oaOH6jNrg=; b=uQjwp4C/ON/OZvDoGu5ptRzUj8a3sbzdmSDYEYXLgWRe4IEDGgBqL/QTF6H7AaYZqr eaS5s8Zbq1laQ8o2+S3fIboQey6UtKJseDaNfa5LBrujKm8N/Hdnaa7U9/2pn001pf6p MaloCrgMc5qk2GK8rBRcTbWibpGow6PaEb/wgvf+cNnEMqnbiRMWqo9OBQPJR7tzoqT4 N/jybAzMayZtH3WNlzP2ktBs5V298otoAVa97uSK98p6ZQ9jC+ewvBfuRz6fzg92gMhN qTi7k4gCOMRAuv4tv4krVvoyF41IWNvNGkt+mIgVDvuvGWMcJv3a7raQUppW6/GKkiA0 1phA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j37-20020a634a65000000b0039d3228a8c7si3609926pgl.84.2022.04.12.12.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 12:51:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EBCA16D4FB; Tue, 12 Apr 2022 12:47:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353897AbiDLNHI (ORCPT + 99 others); Tue, 12 Apr 2022 09:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356373AbiDLND1 (ORCPT ); Tue, 12 Apr 2022 09:03:27 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 35D3264C6 for ; Tue, 12 Apr 2022 05:45:19 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E613D150C; Tue, 12 Apr 2022 05:45:18 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 94D3A3F70D; Tue, 12 Apr 2022 05:45:16 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, Jamie Iles , Cristian Marussi , Xin Hao , xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com Subject: [PATCH v4 12/21] x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks Date: Tue, 12 Apr 2022 12:44:10 +0000 Message-Id: <20220412124419.30689-13-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220412124419.30689-1-james.morse@arm.com> References: <20220412124419.30689-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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. Reviewed-by: Jamie Iles Tested-by: Xin Hao Reviewed-by: Shaopeng Tan Tested-by: Shaopeng Tan Tested-by: Cristian Marussi Signed-off-by: James Morse --- Changes since v3: * Reset rr.val before each use to avoid over counting. * Fixed typos in kerneldoc. Changes since v2: * Expanded commit message Changes since v1: * This patch was rewritten --- 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 3b9e43ba7590..46062099d69e 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 ac1a2e8998bb..a15f870363b2 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); /* -- 2.30.2