Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2133313rwe; Fri, 2 Sep 2022 09:00:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR73F3LmLKhPGrCdiJu9758u4+yvQmjWSm91q/fhG1X961MOALNJ7PhSAvpYlS0VnQdYOGrR X-Received: by 2002:a17:906:3c4a:b0:741:6b91:867e with SMTP id i10-20020a1709063c4a00b007416b91867emr19417888ejg.297.1662134441914; Fri, 02 Sep 2022 09:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662134441; cv=none; d=google.com; s=arc-20160816; b=y76Xj3F4cCdd7NPKF9lUFweyv5rq10TaKrdPFzXiPfQViw7HZ52w4BvAehVsQcQzCj MEPW2iG/Scm+rnMwV+Q+/8vbae7GDeuNt6vUzQqR+VH5wTcAwCGzqQW2W7EV5EbeDZa8 t+xUAzrBZQR6Yw0o96HxIJzrKFaSmC7DUTp3DG9GdEDFAbHx7hEmSkt7ToUBBq9Px0kO sC2l58O/N99wnsM9BiJGm6WBbgN4g9OUtIDx1ohY54RPMvZeSiF3BVwns0ChHZYXqg4m qoy+8rMp+3H9HaBnFr5QKpu6oFJ9YilGdaZRXKjegij+QwLIimrbss8B4LiUUYTrPsou 6q5Q== 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=RRGRY3GcuVAjm5R5XdkWRsioIa/bdJj7lx7jeTz+U/w=; b=Z8MniO9XdDn4fkw3Ts6u0ucNxCeLX4sqdgh29ki1r9LJ7au1A4Xylt01hG9147lO0r s1IZR2Qphlc9Phr3TgKn/INsc4RgPN0ZutKqmjxrazHF5NSFZKsXkLTTxk2iNY2nyL8D 2pcAtwUbA/23RYKTs82s73niLRadGvrK9SLrjiFAw0+BiqX68WThgEEwzkM2zidXwWY2 7Ie92r77MC99O3B18DkvnIZlwjh9gG0x4s2Nweus8lHFADhy3rMeVCzOffseY1ohoKfW CpzPYDH8UrnvgABkG5SE8Sg23o5Mhv3YRO1drjlZpiWLtLehRAa2NSGpQeJ5ZqKB7s6l 3qGQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb38-20020a170907962600b00741991009e4si2160736ejc.560.2022.09.02.09.00.15; Fri, 02 Sep 2022 09:00:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237755AbiIBP5c (ORCPT + 99 others); Fri, 2 Sep 2022 11:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237601AbiIBPzq (ORCPT ); Fri, 2 Sep 2022 11:55:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 04A38CD788 for ; Fri, 2 Sep 2022 08:49:39 -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 EB8301596; Fri, 2 Sep 2022 08:49:44 -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 666F53F766; Fri, 2 Sep 2022 08:49:36 -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 v6 17/21] x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read() Date: Fri, 2 Sep 2022 15:48:25 +0000 Message-Id: <20220902154829.30399-18-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220902154829.30399-1-james.morse@arm.com> References: <20220902154829.30399-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a counter. Currently the function returns the MBM values in chunks directly from hardware. When reading a bandwidth counter, mbm_overflow_count() must be used to correct for any possible overflow. mbm_overflow_count() is architecture specific, its behaviour should be part of resctrl_arch_rmid_read(). Move the mbm_overflow_count() calls into resctrl_arch_rmid_read(). This allows the resctrl filesystems's prev_msr to be removed in favour of the architecture private version. Reviewed-by: Jamie Iles Tested-by: Xin Hao Reviewed-by: Shaopeng Tan Tested-by: Shaopeng Tan Tested-by: Cristian Marussi Reviewed-by: Reinette Chatre Signed-off-by: James Morse --- arch/x86/kernel/cpu/resctrl/internal.h | 2 -- arch/x86/kernel/cpu/resctrl/monitor.c | 35 +++++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 1d2e7bd6305f..8039e8aba7de 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -281,7 +281,6 @@ 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_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 @@ -289,7 +288,6 @@ struct rftype { */ struct mbm_state { u64 chunks; - u64 prev_msr; u64 prev_bw_chunks; u32 prev_bw; u32 delta_bw; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 262141bf4264..862a4462ed60 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -167,9 +167,20 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, memset(am, 0, sizeof(*am)); } +static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width) +{ + u64 shift = 64 - width, chunks; + + chunks = (cur_msr << shift) - (prev_msr << shift); + return chunks >> shift; +} + int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, u32 rmid, enum resctrl_event_id eventid, u64 *val) { + struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); + struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d); + struct arch_mbm_state *am; u64 msr_val; if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask)) @@ -191,7 +202,13 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, if (msr_val & RMID_VAL_UNAVAIL) return -EINVAL; - *val = msr_val; + am = get_arch_mbm_state(hw_dom, rmid, eventid); + if (am) { + *val = mbm_overflow_count(am->prev_msr, msr_val, hw_res->mbm_width); + am->prev_msr = msr_val; + } else { + *val = msr_val; + } return 0; } @@ -322,19 +339,10 @@ void free_rmid(u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } -static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width) -{ - u64 shift = 64 - width, chunks; - - chunks = (cur_msr << shift) - (prev_msr << shift); - return chunks >> shift; -} - static int __mon_event_count(u32 rmid, struct rmid_read *rr) { - struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r); struct mbm_state *m; - u64 chunks, tval = 0; + u64 tval = 0; if (rr->first) resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid); @@ -363,13 +371,10 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr) if (rr->first) { memset(m, 0, sizeof(struct mbm_state)); - m->prev_msr = tval; return 0; } - chunks = mbm_overflow_count(m->prev_msr, tval, hw_res->mbm_width); - m->chunks += chunks; - m->prev_msr = tval; + m->chunks += tval; rr->val += get_corrected_mbm_count(rmid, m->chunks); -- 2.30.2