From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C595BF4BB6C for ; Tue, 24 Feb 2026 17:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZVjcUrsshY335jAS+cTXoVtGVUrUBUxhLdL39wQsdzU=; b=p9LMgquOncNKToXwTGEXZyvXLW 2JxnZs60K5qGxKz9sAM0K/gB0jso2NPPSWDtGkOs7E1wth47hX4IHERmUOwXm2XZgyzT5+1tR+Kf6 ILiI2lj2khwfqX7xAoZJA32OvKLVI9qQJn9EpToB6wo9j8fRyA14jxE6KabmOhSv2oblmuzk68LwM Fp20jiQZ1ZjzSpUIIou/kgZBnZD3JO8+lX8h9wxn9OrlFy8ektU58jvgglXCnFNcwyi2FKOj7952H LMLqtNgDYr0RG+gyh4EuvBLR2yyzrCNdQpyy5k1ryg4HeHMoTzLkELDF139e1bswI2/A/Wfc8itd1 v+sAN0IQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vuwhI-00000002YpR-3XUl; Tue, 24 Feb 2026 17:59:48 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vuwhC-00000002Yf9-35uz for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Feb 2026 17:59:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ZVjcUrsshY335jAS+cTXoVtGVUrUBUxhLdL39wQsdzU=; b=Yvo+A1uMJpIPFGv39UTpdlzTYY KHK6X/0Tx+/8zkie8M8Ws6yI2Lad6E0dnDyJnNZUg6X3qx4H6nswi4+93r56FW9mAHXvAlX2JLZFm ifDK2aAHMylmZhgsaHk05JjUUKghyDUdJPXie4z0EqvSggf1rMhbyC3j+xglGu4lWm/jRtUHCeeAs p/0m1xoq7wZmEXAOTEnmJXZXMaEK0eIWQYUJhxOCRb0+neBpN3KW0Htr9lpIbwISHhaNHtugnBIvn /322hQQk91hoI2AZqHHTi+Ews2FC0HEcGE50G/Hu66ZkNDwwTnccyQHuPzNiztsbBRlRYk65erFCd dJQLxX1A==; Received: from foss.arm.com ([217.140.110.172]) by desiato.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vuwh0-00000007dxj-27GK for linux-arm-kernel@lists.infradead.org; Tue, 24 Feb 2026 17:59:38 +0000 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 94BFC339; Tue, 24 Feb 2026 09:59:22 -0800 (PST) Received: from e134344.cambridge.arm.com (e134344.arm.com [10.1.196.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 01ABA3F59E; Tue, 24 Feb 2026 09:59:23 -0800 (PST) From: Ben Horgan To: ben.horgan@arm.com Cc: amitsinght@marvell.com, baisheng.gao@unisoc.com, baolin.wang@linux.alibaba.com, carl@os.amperecomputing.com, dave.martin@arm.com, david@kernel.org, dfustini@baylibre.com, fenghuay@nvidia.com, gshan@redhat.com, james.morse@arm.com, jonathan.cameron@huawei.com, kobak@nvidia.com, lcherian@marvell.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, peternewman@google.com, punit.agrawal@oss.qualcomm.com, quic_jiles@quicinc.com, reinette.chatre@intel.com, rohit.mathew@arm.com, scott@os.amperecomputing.com, sdonthineni@nvidia.com, tan.shaopeng@fujitsu.com, xhao@linux.alibaba.com, catalin.marinas@arm.com, will@kernel.org, corbet@lwn.net, maz@kernel.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, kvmarm@lists.linux.dev, zengheng4@huawei.com, linux-doc@vger.kernel.org, Shaopeng Tan Subject: [PATCH v5 22/41] arm_mpam: resctrl: Add rmid index helpers Date: Tue, 24 Feb 2026 17:57:01 +0000 Message-ID: <20260224175720.2663924-23-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260224175720.2663924-1-ben.horgan@arm.com> References: <20260224175720.2663924-1-ben.horgan@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260224_175931_082160_9829DC82 X-CRM114-Status: UNSURE ( 8.96 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Because MPAM's pmg aren't identical to RDT's rmid, resctrl handles some data structures by index. This allows x86 to map indexes to RMID, and MPAM to map them to partid-and-pmg. Add the helpers to do this. Tested-by: Gavin Shan Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Zeng Heng Reviewed-by: Shaopeng Tan Suggested-by: James Morse Reviewed-by: Jonathan Cameron Signed-off-by: Ben Horgan --- Changes since rfc: Use ~0U instead of ~0 in lhs of left shift Changes since v2: Drop changes signed-off-by as reworked patch Use multiply and add rather than shift to avoid holes --- drivers/resctrl/mpam_resctrl.c | 16 ++++++++++++++++ include/linux/arm_mpam.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index ded18a9d4cd4..48f96d7f9109 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -130,6 +130,22 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored) return mpam_partid_max + 1; } +u32 resctrl_arch_system_num_rmid_idx(void) +{ + return (mpam_pmg_max + 1) * (mpam_partid_max + 1); +} + +u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) +{ + return closid * (mpam_pmg_max + 1) + rmid; +} + +void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid) +{ + *closid = idx / (mpam_pmg_max + 1); + *rmid = idx % (mpam_pmg_max + 1); +} + void resctrl_arch_sched_in(struct task_struct *tsk) { lockdep_assert_preemption_disabled(); diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index d329b1dc148b..7d23c90f077d 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -58,6 +58,9 @@ void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid); void resctrl_arch_sched_in(struct task_struct *tsk); bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid); bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid); +u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid); +void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid); +u32 resctrl_arch_system_num_rmid_idx(void); /** * mpam_register_requestor() - Register a requestor with the MPAM driver -- 2.43.0