From nobody Mon Sep 15 08:12:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69FFCC54EBD for ; Fri, 13 Jan 2023 18:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjAMSCd (ORCPT ); Fri, 13 Jan 2023 13:02:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbjAMSBa (ORCPT ); Fri, 13 Jan 2023 13:01:30 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0E9B1E28 for ; Fri, 13 Jan 2023 09:56:00 -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 DF973FEC; Fri, 13 Jan 2023 09:56:41 -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 5464D3F67D; Fri, 13 Jan 2023 09:55:57 -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, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com Subject: [PATCH v2 06/18] x86/resctrl: Allow the allocator to check if a CLOSID can allocate clean RMID Date: Fri, 13 Jan 2023 17:54:47 +0000 Message-Id: <20230113175459.14825-7-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230113175459.14825-1-james.morse@arm.com> References: <20230113175459.14825-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" MPAM's PMG bits extend its PARTID space, meaning the same PMG value can be used for different control groups. This means once a CLOSID is allocated, all its monitoring ids may still be dirty, and held in limbo. Add a helper to allow the CLOSID allocator to check if a CLOSID has dirty RMID values. This behaviour is enabled by a kconfig option selected by the architecture, which avoids a pointless search for x86. Tested-by: Shaopeng Tan Signed-off-by: James Morse --- Changes since v1: * Removed superflous IS_ENABLED(). --- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 31 ++++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 17 ++++++++------ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 013c8fc9fd28..adae6231324f 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -509,6 +509,7 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp= ); void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); int closids_supported(void); +bool resctrl_closid_is_dirty(u32 closid); void closid_free(int closid); int alloc_rmid(u32 closid); void free_rmid(u32 closid, u32 rmid); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 347be3767241..190ac183139e 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -327,6 +327,37 @@ static struct rmid_entry *resctrl_find_free_rmid(u32 c= losid) return ERR_PTR(-ENOSPC); } =20 +/** + * resctrl_closid_is_dirty - Determine if clean RMID can be allocate for t= his + * CLOSID. + * @closid: The CLOSID that is being queried. + * + * MPAM's equivalent of RMID are per-CLOSID, meaning a freshly allocate CL= OSID + * may not be able to allocate clean RMID. To avoid this the allocator will + * only return clean CLOSID. + */ +bool resctrl_closid_is_dirty(u32 closid) +{ + struct rmid_entry *entry; + int i; + + lockdep_assert_held(&rdtgroup_mutex); + + if (!IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) + return false; + + for (i =3D 0; i < resctrl_arch_system_num_rmid_idx(); i++) { + entry =3D &rmid_ptrs[i]; + if (entry->closid !=3D closid) + continue; + + if (entry->busy) + return true; + } + + return false; +} + /* * As of now the RMIDs allocation is the same in each domain. * However we keep track of which packages the RMIDs diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index ac88610a6946..e1f879e13823 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -93,7 +93,7 @@ void rdt_last_cmd_printf(const char *fmt, ...) * - Our choices on how to configure each resource become progressively mo= re * limited as the number of resources grows. */ -static int closid_free_map; +static unsigned long closid_free_map; static int closid_free_map_len; =20 int closids_supported(void) @@ -119,14 +119,17 @@ static void closid_init(void) =20 static int closid_alloc(void) { - u32 closid =3D ffs(closid_free_map); + u32 closid; =20 - if (closid =3D=3D 0) - return -ENOSPC; - closid--; - closid_free_map &=3D ~(1 << closid); + for_each_set_bit(closid, &closid_free_map, closid_free_map_len) { + if (resctrl_closid_is_dirty(closid)) + continue; =20 - return closid; + clear_bit(closid, &closid_free_map); + return closid; + } + + return -ENOSPC; } =20 void closid_free(int closid) --=20 2.30.2