Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp813612pxb; Thu, 17 Feb 2022 15:35:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZiGn9YNajYMDlLxib+5hzlCQin/J8ZCkT1fMRIwiVo2rQQ5O0UKmOtMc4dFtTMDFPNzJh X-Received: by 2002:a05:6a00:b84:b0:4e1:b113:d444 with SMTP id g4-20020a056a000b8400b004e1b113d444mr5113143pfj.12.1645140946256; Thu, 17 Feb 2022 15:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645140946; cv=none; d=google.com; s=arc-20160816; b=MzCHtYG0fI/03l4KmuzTLJjt81A2lcjMoz0AK1e96ynG5U0iKZmLyhBOzuWKNLEzBv khEW2tnS0I/rQ86vGWouD9rjOs9bn98tBLr9WYwDv8mDXaZR+8Gc31vvmVNE20HLChJh Vj5x0nMR6TDLPH/XGP20mx+vHL7SZEjx5KT8s9a1SUnTw70UKEytCC7RUqiUqVz4V8Q4 EpcbmrXB8BbAyM2AES5wfzPEmYxO9GSkGGB4tmLGy5EOBqMYqxMVS0KZZXKcu+VJ3X8k grmxcX9nQnYD5iSgxM9UlGTg6q+PdK/ZkyZ+6HIwo/Lqxb05SUFsTg+OnQQBaMYUpxdq NnGA== 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=V7lsh9O0xxIw0ytppzDe8BYDMk75ZC3yGJStjqw6ajA=; b=09kSBs78hJu1ll50BwJ51cqs6hVv94vct+Y2BZKwvSPnSb9MMcUqYCYMTA4LsugcHu g/oyuMXjjRg3hi/M6C6AtZ7xVNugfpyLCnolG8KEoYtDslWyuQOJbueNlT+UVPLEhkLk zEIEW2tpXOn1Ta6ysAr9x44VXofDXuuZvIbODHGNlxSjzRdOxwVhHyCrQ1wzQG87GflG gnM1hrloP0FeCBmp8uAZl8dHxJSXsxPhVqgBVQ6ZK3YZ4L+EEPGPuWUlFIRjAZnuthqv NfDB5QdpMZumHTY0QEwTjeYDjBQBebs0spKpvJzYRBU2ksuN7mx+j+05Ao0m/AkSgjW9 kXIg== 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 l190si9099117pge.591.2022.02.17.15.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 15:35:46 -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 4329E2E59C1; Thu, 17 Feb 2022 15:16:14 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244366AbiBQSYM (ORCPT + 99 others); Thu, 17 Feb 2022 13:24:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244309AbiBQSX7 (ORCPT ); Thu, 17 Feb 2022 13:23:59 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 353B239BA8 for ; Thu, 17 Feb 2022 10:23:44 -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 E7A0715DB; Thu, 17 Feb 2022 10:23:43 -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 B83C43F718; Thu, 17 Feb 2022 10:23:41 -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 17/21] x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read() Date: Thu, 17 Feb 2022 18:21:06 +0000 Message-Id: <20220217182110.7176-18-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 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. 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 e55d1774ce9c..5ab8b448fb7e 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 when 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 277c22f8c976..e04bc97c710d 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 u64 __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 u64 __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