Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp819186pxb; Thu, 17 Feb 2022 15:44:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFKPOOpd1+1q9cZCSYrU8eBDGve5F9i1bBf4Ff6gxRlKalniast4nHObATPDYpPC9e750k X-Received: by 2002:a63:698a:0:b0:36c:1d0a:2808 with SMTP id e132-20020a63698a000000b0036c1d0a2808mr4247564pgc.567.1645141439848; Thu, 17 Feb 2022 15:43:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645141439; cv=none; d=google.com; s=arc-20160816; b=cgtU66gX4ZuJF4N4n+iLv95aWKve1MAbL7i1L9+z3AmLh0ZngWTrpgcny8hZpwf65b R80CulCHF5beUXmU9oa5RnZFo4psea5mZqWgxzGoHz5YW8GVq+dkxxMCTR3434SoL6O4 6dWPDuRRAps9r3NaIrv1xS4a6JMxolcw+XptgplzcsIU8UrlgS6mnnZavoWVpEVIRCxT AyfXHsHcz9DUeGK8BHajvpDdTyhVdcMLT8C767iOmXZxdGmrr5Rv7r/Iw2nDnsqhorgu dKFn+oxI/t/rLE/z/awYe+SiDQSPM1iK8JTSN6IS8Mu9F43HbOA4BOSLHdUWpsvvs91E aqkQ== 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=ARW6YVx8jmd4V2y1Y1QbCui50mK+gEc0kjy0LG1yLno=; b=liPVTLnGSCez5hyZWTgc+HilRFpDrL4aXM8jQS3HiNtaDlWSdOXBK1v5n7/XHeMLml tKHquJa5bA7hOQUEhBJekjpRt3snJ8PAzPApqP8g3vsoXcgqf5vmeg7zXPPzcl6sIdd/ 3DyWAhqFXPGKatwo+N6LcLD4QqYZW2dzDKcvevJz1yfgYrp303dIjXPjGBfVeFjFIDDC z/sAD6q3kY+vDp7vw0djWTozNm7x8okxec/xHiq9wP4cPg+gmA10IDnajvVOAt5k2MDB YGn5aoAGdHDxvPKnz9Z6NphrAXKPyLv+0yFJ7Z/yiS37YdE9GjtnZAA7fIiwYRFrNa4G TZMw== 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 h18si18670192plf.517.2022.02.17.15.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 15:43:59 -0800 (PST) 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 77CC02FAB43; Thu, 17 Feb 2022 15:21:06 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244338AbiBQSYU (ORCPT + 99 others); Thu, 17 Feb 2022 13:24:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244285AbiBQSXz (ORCPT ); Thu, 17 Feb 2022 13:23:55 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF2F9396A4 for ; Thu, 17 Feb 2022 10:23:29 -0800 (PST) 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 8D8CC15AD; Thu, 17 Feb 2022 10:23:29 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5DDB93F718; Thu, 17 Feb 2022 10:23:27 -0800 (PST) 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, Jamie Iles , D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com Subject: [PATCH v3 12/21] x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks Date: Thu, 17 Feb 2022 18:21:01 +0000 Message-Id: <20220217182110.7176-13-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220217182110.7176-1-james.morse@arm.com> References: <20220217182110.7176-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 a extra calls 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 --- 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 | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 3b9e43ba7590..c50c8911ef59 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 when 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..8ae375e29256 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 oncer 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; } /* @@ -509,6 +514,7 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid) rr.first = false; rr.r = r; rr.d = d; + rr.val = 0; /* * This is protected from concurrent reads from user -- 2.30.2