Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6466135pxv; Thu, 29 Jul 2021 15:40:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziD3RDeVI269EaETW1DDGf2DsMi3qUAG9qSv83SPn2S27XN26sZcyrmrru12ifB90iic/f X-Received: by 2002:a17:906:d147:: with SMTP id br7mr6935480ejb.126.1627598425176; Thu, 29 Jul 2021 15:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627598425; cv=none; d=google.com; s=arc-20160816; b=sDpsqT9BabH3RWsZX4vbQF5GXpl3J/TUR+Vmj1kpZrNsNoUoEwZzsSf/F/Mm6l+Smo dy7gaMYRRpheu36M1iC2J4M2tVRlv42PodRQS/pZTJmJyII2WYxVDsvgpdNwET7/wlu5 JUStiB53nF94f56oQzMP/v6uBXzLjmTuzy9o/7XYad++fv+9Y7YDTxefJyDZrtB1zj9F y9Dejj6AuElt2BXt00sEZ3ZfvsywM3H76i18RrIyjzi7w4cWNxKwbc7bTLyTQPf+/CQr EyDezzZaBETBNQvuz5UGf4VFUHzmQ+qm5gHEMnrvJzfvcheVjlXgtvd3URVkFfjQvWhz sj/Q== 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=3u9kcVaHQ9RJU1E3y8LKDZRzfIqphxAXfexvB0QbBc0=; b=IvjzGkroqRPPWHVHY5HerRe8CoC0jJ23hBk9Z1fMSfIyvb/fsEsbU3p5Bj2MbSE6XG O8i9riFiV9/aMIXLcvB2A3Lwui4juXb6VNC4NW2Y1AMw5vHPME4I0+VndqRnQVw4Ra/n X0RHAPdGNOOzWZ7bwKD7wnA9uYxZbrIvYrgzAQ0r5tDhUItSKq20t/16uTwo/k/EoHId P5E8tSrSbfbFmiyIDOQz6YODRIR8ehvUOHtnwk6cH/jmtT8Kp48ZhvIi8CaN6BKk8X2M t1XSF3utSZsjlTSm/tZJnIaFEx9C6MtoWsjpe+RPLMJott0Bxi1GYFHG5pklMsu4F5Cw tPPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x64si3848955ede.13.2021.07.29.15.40.01; Thu, 29 Jul 2021 15:40:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235366AbhG2WhB (ORCPT + 99 others); Thu, 29 Jul 2021 18:37:01 -0400 Received: from foss.arm.com ([217.140.110.172]:59222 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235347AbhG2Wgz (ORCPT ); Thu, 29 Jul 2021 18:36:55 -0400 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 D133B113E; Thu, 29 Jul 2021 15:36:51 -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 DDA293F70D; Thu, 29 Jul 2021 15:36:49 -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, Jamie Iles , D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com Subject: [PATCH v1 11/20] x86/resctrl: Calculate bandwidth from the total bytes counter Date: Thu, 29 Jul 2021 22:36:01 +0000 Message-Id: <20210729223610.29373-12-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210729223610.29373-1-james.morse@arm.com> References: <20210729223610.29373-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org mbm_bw_count() maintains its own copy of prev_msr to allow it to calculate the bandwidth as the number of chunks counted since the last time mbm_bw_count() was invoked. The prev_msr and chunks values are in a format specific to the architecture. MPAM's monitor scaling can be enabled for some counters and not others. If the value is changed once the bandwidth counter passes some threshold, the prev_msr values need to be converted to the new scale. Having two prev_msr values is a hindrance to moving this logic behind an architecture specific function that returns the counters number of bytes. Change mbm_bw_count() to calculate the total number of bytes the counter has seen in the same way as __mon_event_count(), then calculate the bandwidth from that. prev_bw_msr is replaced by prev_bw_chunks, the chunks value from the last time mbm_bw_count() was invoked. Signed-off-by: James Morse --- arch/x86/kernel/cpu/resctrl/internal.h | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 1b07e49564cf..0a5721e1cc07 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 b178329d3661..af60e154f0ed 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -316,7 +316,7 @@ static int __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_bw_chunks = m->prev_msr = tval; return 0; } @@ -337,20 +337,25 @@ 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 tval, cur_bw, chunks, bw_chunks; tval = __rmid_read(rmid, rr->evtid); if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) return; - 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; + chunks = mbm_overflow_count(m->prev_msr, tval, hw_res->mbm_width); + m->chunks += chunks; + m->prev_msr = tval; + bw_chunks = get_corrected_mbm_count(rmid, m->chunks); + + cur_bw = (bw_chunks - m->prev_bw_chunks) * hw_res->mon_scale; + cur_bw >>= 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; + m->prev_bw_chunks = bw_chunks; } /* -- 2.30.2