Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1343333rwb; Fri, 23 Sep 2022 11:13:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4e5IWgrTzF02PZ6xTE6JkI2PYQRzCkqrfRlm5aoqPpJZCNlPNf52Yw5nI8OUkHh8t4kqUT X-Received: by 2002:a17:907:2c67:b0:77d:740a:e9b1 with SMTP id ib7-20020a1709072c6700b0077d740ae9b1mr7908983ejc.614.1663956818069; Fri, 23 Sep 2022 11:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663956818; cv=none; d=google.com; s=arc-20160816; b=C7tYgHHxklKLMDTRau2BWte8K1rhaC8Q+5336DsP552a7W7llSX1T1Wb1IBoRu9IOv t/c+rwpFsYT7XbxAP0TwMgqutGgBd73ehCOaxra+UTXqOHdV9LV7rmpr79Wt4nB/T2LE AAdqSMYDobXGtktyX9htS2X4dTSQdCCRZX3JYGlOsK6VX21qGz5ryO1mMlp5igB2Sr1M 5mwYT57r3yJETaLI/EkgcSwkGDIeffMRFMoFSobgenJzoa06g4SHthK0djMc9a7JuQiG 16MDGbGllLQ2rofP9H7gMNd5IlRKus8/gq/D9HvwtyP5IjBZCazSgqpZST7pHqn/Ctvb fPGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=Li8pAkwglZYyRS/J517vlEY2TKtkkBCB4c1uyllFKWE=; b=EN4XqUeahUVMyBV0dD9qaRhFka/3QUrfzoCgEkz2DzixXuAwMfiT8oWSbYiqZDkt9W rS4MFoqGCwQegCTB5DZt3SCvo3uyNPJ7Lx2qKo6SbzpHZyyV41UzRxfT7u/0RxI/rmDv PPBFG/k0Kmlh8YGtysGYUW2FNawjiNQLMWk8htjrxDOFlpz8xca42J0Sx2a5Vz/nURnM cslnHLRI1KLuxEGW/JpN22f9bChnJVUUzYTNzV1diNimHOIF3ACuxL4YaFZdYk1mANgE bbcVufrv6S5HZSShBXVeSCAMfSWkmsvsflK5W9s+59vXQmjlmS2i9OmJx5bscNk8pBhw DiBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oWJV6Dnm; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bu2-20020a170906a14200b0077a6429787dsi7502559ejb.157.2022.09.23.11.12.49; Fri, 23 Sep 2022 11:13:38 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oWJV6Dnm; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbiIWSCh (ORCPT + 99 others); Fri, 23 Sep 2022 14:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbiIWSCB (ORCPT ); Fri, 23 Sep 2022 14:02:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCB32DF6AB; Fri, 23 Sep 2022 11:01:51 -0700 (PDT) Date: Fri, 23 Sep 2022 18:01:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1663956109; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Li8pAkwglZYyRS/J517vlEY2TKtkkBCB4c1uyllFKWE=; b=oWJV6DnmojLLFC2O0nXPqnFO8JAQnN+vuMxLpKz30BEDbNZVPrJtxILKjCwoR2Pc8brjvp ENt4OSX7pLb5N756QJxq+O52ehgPIoFbfq/9xMUSsoOAJKXBobVT8TgCxREV6vioTv/Gy6 FKBz389uDLRYMUsIS1VkYB9/uz10riWzmUjSLRmt7BzPW3ll4K0YKQ+yV7q49LHGwfiCSt ZH35aEaSLgm1jxv2HXC+Jaru4yBW9n2REZ3vgJKW2m6t2F16PVxOUKR2Rxbw+Qe4rH6bKw BAurigtwwGeJwfoq1V1K3AyEUy/m1lKY0C8F80H5tKTzRKuermbbBchqVilMLg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1663956109; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Li8pAkwglZYyRS/J517vlEY2TKtkkBCB4c1uyllFKWE=; b=G+hBM6JpzF+95Urk5eQdwBuxb/Q+V6U7aaW8GZphDCV91+2vs1+bzXwD9zo3pZIcwHs+ed 1XZGcXxgdpsHT9Dw== From: "tip-bot2 for James Morse" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Add per-rmid arch private storage for overflow and chunks Cc: James Morse , Borislav Petkov , Jamie Iles , Shaopeng Tan , Reinette Chatre , Xin Hao , Cristian Marussi , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220902154829.30399-14-james.morse@arm.com> References: <20220902154829.30399-14-james.morse@arm.com> MIME-Version: 1.0 Message-ID: <166395610853.401.13795446222171166361.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 The following commit has been merged into the x86/cache branch of tip: Commit-ID: 48dbe31a243d5fc7c07b7f03b48e95ec4696b118 Gitweb: https://git.kernel.org/tip/48dbe31a243d5fc7c07b7f03b48e95ec4696b118 Author: James Morse AuthorDate: Fri, 02 Sep 2022 15:48:21 Committer: Borislav Petkov CommitterDate: Thu, 22 Sep 2022 17:46:09 +02:00 x86/resctrl: Add per-rmid arch private storage for overflow and chunks A renamed __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. For bandwidth counters the resctrl filesystem uses this to calculate the number of bytes ever seen. MPAM's scaling of counters can be changed at runtime, reducing the resolution but increasing the range. When this is changed the prev_msr values need to be converted by the architecture code. Add an array for per-rmid private storage. The prev_msr and chunks values will move here to allow resctrl_arch_rmid_read() to always return the number of bytes read by this counter without assistance from the filesystem. The values are moved in later patches when the overflow and correction calls are moved into __rmid_read(). Signed-off-by: James Morse Signed-off-by: Borislav Petkov Reviewed-by: Jamie Iles Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Tested-by: Xin Hao Tested-by: Shaopeng Tan Tested-by: Cristian Marussi Link: https://lore.kernel.org/r/20220902154829.30399-14-james.morse@arm.com --- arch/x86/kernel/cpu/resctrl/core.c | 35 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 14 ++++++++++- 2 files changed, 49 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 90ebb7d..de62b0b 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -413,6 +413,8 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) static void domain_free(struct rdt_hw_domain *hw_dom) { + kfree(hw_dom->arch_mbm_total); + kfree(hw_dom->arch_mbm_local); kfree(hw_dom->ctrl_val); kfree(hw_dom); } @@ -438,6 +440,34 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d) return 0; } +/** + * arch_domain_mbm_alloc() - Allocate arch private storage for the MBM counters + * @num_rmid: The size of the MBM counter array + * @hw_dom: The domain that owns the allocated arrays + */ +static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) +{ + size_t tsize; + + if (is_mbm_total_enabled()) { + tsize = sizeof(*hw_dom->arch_mbm_total); + hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL); + if (!hw_dom->arch_mbm_total) + return -ENOMEM; + } + if (is_mbm_local_enabled()) { + tsize = sizeof(*hw_dom->arch_mbm_local); + hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL); + if (!hw_dom->arch_mbm_local) { + kfree(hw_dom->arch_mbm_total); + hw_dom->arch_mbm_total = NULL; + return -ENOMEM; + } + } + + return 0; +} + /* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -487,6 +517,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) return; } + if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { + domain_free(hw_dom); + return; + } + list_add_tail(&d->list, add_pos); err = resctrl_online_domain(r, d); diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 4606209..4de8e5b 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -304,16 +304,30 @@ struct mbm_state { }; /** + * struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s + * return value. + * @prev_msr: Value of IA32_QM_CTR last time it was read for the RMID used to + * find this struct. + */ +struct arch_mbm_state { + u64 prev_msr; +}; + +/** * struct rdt_hw_domain - Arch private attributes of a set of CPUs that share * a resource * @d_resctrl: Properties exposed to the resctrl file system * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) + * @arch_mbm_total: arch private state for MBM total bandwidth + * @arch_mbm_local: arch private state for MBM local bandwidth * * Members of this structure are accessed via helpers that provide abstraction. */ struct rdt_hw_domain { struct rdt_domain d_resctrl; u32 *ctrl_val; + struct arch_mbm_state *arch_mbm_total; + struct arch_mbm_state *arch_mbm_local; }; static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r)