From patchwork Sat Dec 7 09:21:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 13898220 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 546EFE7717B for ; Sat, 7 Dec 2024 09:11:51 +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-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=S8cg9TB7HYrT8G7AwkENDwenxr/WugLhcIaBY1AqEKM=; b=de8qybWTdDEPRDw3kffYqenYB/ l5BEtGa8VIEuJtf6QF+zyV94QJ3aEJp3pbEZYxf4mE9ZO2QPuGYGk1DrBszesdEhQh2zhLvHuQoLm aq/up5Y17pBUGJoumOFS25f7kJDDLgmfdn5JSHlvlA1/+MHKsrfGgQ9tJ4HlBgqtfvCf6zrwzs57c /eCPr4xxQVLzBV3bVzHVhbN16xJI/eldqOjPu9+H60h1dyEuQVNT1SAPratpTRW+A970aKmny7fXM IleL38fFwhkFRtnT+zY0bNIBL/OaQurtzeE4jnipf1gL2ZTffHN/fhIyRHHfwEgMLPJKLkMZPrUfN 0xcEW0Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJqqh-00000003kxu-0yY1; Sat, 07 Dec 2024 09:11:39 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJqod-00000003kZv-2vQW for linux-arm-kernel@lists.infradead.org; Sat, 07 Dec 2024 09:09:34 +0000 Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Y52Pr63nmz1yrhb; Sat, 7 Dec 2024 17:09:36 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id A4292140120; Sat, 7 Dec 2024 17:09:20 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 7 Dec 2024 17:09:19 +0800 From: Zeng Heng To: , CC: , , , Subject: [RFC PATCH mpam mpam/snapshot/v6.12-rc1 v3 1/5] arm_mpam: Introduce the definitions of intPARTID and reqPARTID Date: Sat, 7 Dec 2024 17:21:32 +0800 Message-ID: <20241207092136.2488426-2-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241207092136.2488426-1-zengheng4@huawei.com> References: <20241207092136.2488426-1-zengheng4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100008.china.huawei.com (7.202.181.222) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241207_010932_033948_091D99FF X-CRM114-Status: GOOD ( 17.03 ) 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 The narrow-partid feature in MPAM allows for a more efficient use of PARTIDs by enabling a many-to-one mapping of reqpartids (requested PARTIDs) to intpartids (internal PARTIDs). This mapping reduces the number of unique PARTIDs needed, thus allowing more tasks or processes to be monitored and managed with the available resources. Regarding intPARTID, MPAM uses it as the unit for control group configuration delivery. MPAM will synchronize the delivered configuration to all reqPARTIDs mapped to the same intPARTIDs. The number of intPARTIDs is indicated by MPAMF_PARTID_NRW_IDR.INTPARTID_MAX if implemented, or directly use the number of PARTID as intpartid_max if narrow-partid feature is not supported. reqPARTIDs can be used to expand the number of monitors, for each control group is no longer simply restricted by the range of PMG. By mapping between intPARTID and reqPARTID, the number of monitors would be greatly expanded and more fine-grained monitoring under a control group will be achieved. As a MPAM driver applicable to general scenarios, it needs to be compatible with systems not supporting narrow-partid and mixed MSCs (some MSCs support narrow-partid and some do not) systems. We determine the number of closids in the following manner: reqPARTID-np -- The number of reqPARTIDs supported by MSCs that support narrow-partid. intPARTID-np -- The number of intPARTIDs supported by MSCs that support narrow partid. PARTID-nnp -- The number of PARTIDs supported by MSCs that do not support narrow partid. n - Indicates the maximum number of control groups l - Represents the total number of reqpartids m - Indicates the number of reqpartids per control group n = min(intPARTID-np, PARTID-nnp) l = min(reqPARTID-np, PARTID-nnp) m = l // n To illustrate how to determine n, l, and m through examples, we can assume a specific example: l3 - Supports the narrow-partid feature, supports 32 intPARTIDs, and supports 256 reqPARTIDs. mata - Does not support the narrow PARTID feature, supports a range of 256 PARTIDs. Then, n = min(intPARTID-l3, PARTID-mata) = min(32, 256) = 32 l = min(reqPARTID-l3, PARTID-mata) = min(256,256) = 256 m = 256 / 32 = 8 After initialization, the driver determines the 'n' parameter returned by resctrl_arch_get_num_closid() and the 'l' parameter returned by get_num_reqpartid(). Signed-off-by: Zeng Heng --- drivers/platform/arm64/mpam/mpam_devices.c | 12 +++++++++++- drivers/platform/arm64/mpam/mpam_internal.h | 2 ++ drivers/platform/arm64/mpam/mpam_resctrl.c | 9 +++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index 9463045c0011..ca621bb132e9 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -67,6 +67,7 @@ static DEFINE_MUTEX(mpam_cpuhp_state_lock); * Generating traffic outside this range will result in screaming interrupts. */ u16 mpam_partid_max; +u16 mpam_intpartid_max; u8 mpam_pmg_max; static bool partid_max_init, partid_max_published; static DEFINE_SPINLOCK(partid_max_lock); @@ -222,10 +223,16 @@ int mpam_register_requestor(u16 partid_max, u8 pmg_max) spin_lock(&partid_max_lock); if (!partid_max_init) { mpam_partid_max = partid_max; + /* + * Update mpam_intpartid_max here, in case the + * system doesn't have narrow-partid feature. + */ + mpam_intpartid_max = partid_max; mpam_pmg_max = pmg_max; partid_max_init = true; } else if (!partid_max_published) { mpam_partid_max = min(mpam_partid_max, partid_max); + mpam_intpartid_max = min(mpam_intpartid_max, partid_max); mpam_pmg_max = min(mpam_pmg_max, pmg_max); } else { /* New requestors can't lower the values */ @@ -984,7 +991,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) u16 partid_max = FIELD_GET(MPAMF_PARTID_NRW_IDR_INTPARTID_MAX, nrwidr); mpam_set_feature(mpam_feat_partid_nrw, props); - msc->partid_max = min(msc->partid_max, partid_max); + msc->intpartid_max = min(msc->partid_max, partid_max); + } else { + msc->intpartid_max = msc->partid_max; } mpam_mon_sel_outer_unlock(msc); @@ -1046,6 +1055,7 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) spin_lock(&partid_max_lock); mpam_partid_max = min(mpam_partid_max, msc->partid_max); + mpam_intpartid_max = min(mpam_intpartid_max, msc->intpartid_max); mpam_pmg_max = min(mpam_pmg_max, msc->pmg_max); spin_unlock(&partid_max_lock); diff --git a/drivers/platform/arm64/mpam/mpam_internal.h b/drivers/platform/arm64/mpam/mpam_internal.h index 5af6ed60272e..5fc9f09b6945 100644 --- a/drivers/platform/arm64/mpam/mpam_internal.h +++ b/drivers/platform/arm64/mpam/mpam_internal.h @@ -86,6 +86,7 @@ struct mpam_msc bool error_irq_requested; bool error_irq_hw_enabled; u16 partid_max; + u16 intpartid_max; u8 pmg_max; unsigned long ris_idxs[128 / BITS_PER_LONG]; u32 ris_max; @@ -466,6 +467,7 @@ static inline void mpam_assert_srcu_read_lock_held(void) /* System wide partid/pmg values */ extern u16 mpam_partid_max; +extern u16 mpam_intpartid_max; extern u8 mpam_pmg_max; /* Scheduled work callback to enable mpam once all MSC have been probed */ diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index 76ddbce0ea9c..ac3d228befcf 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -162,6 +162,11 @@ static bool mpam_resctrl_hide_cdp(enum resctrl_res_level rid) * only the system wide safe value is safe to use. */ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored) +{ + return mpam_intpartid_max + 1; +} + +static u32 get_num_reqpartid(void) { return mpam_partid_max + 1; } @@ -169,9 +174,9 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored) u32 resctrl_arch_system_num_rmid_idx(void) { u8 closid_shift = fls(mpam_pmg_max); - u32 num_partid = resctrl_arch_get_num_closid(NULL); + u32 num_reqpartid = get_num_reqpartid(); - return num_partid << closid_shift; + return num_reqpartid << closid_shift; } u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) From patchwork Sat Dec 7 09:21:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 13898222 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 1DD55E7717B for ; Sat, 7 Dec 2024 09:13:55 +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: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EIicETS8u4s434iN+wMN6ZEKorFAtMH4IqAJLeKjDRc=; b=Bn3Eak9Sk0VQK9YuY24j4wuDcv xUNTrY0wZLz0thLqMqp8p0Q0yOYOTQFeqZroTmD8kESL+IyTR89zRm0NiyoJb4D+bq7RHm/GBKwkJ Fu+ZkGL09fvSC6PzEOYn3ZiGs0O1XdBfYzuiST7gi5pZCpI5OKV99HYbrzhhVm02NcU/UinuLgYOS 7QeDrIxXXc58gmQS0HSIQY0v2EUlub/M5sqPiRAQicMuSOSg8mtxAhubV3CTBM1T8YZjQuoSVeYcT WLJcL+uaNWuIhYpSoLAv52NY+tk0f8hTSVoVEE8zqBTlbrPtX5qikGAQOZHwlbD2q2pk3S5KEbEsV liMqgnBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJqsg-00000003lCe-2PTd; Sat, 07 Dec 2024 09:13:42 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJqod-00000003kZy-466r for linux-arm-kernel@lists.infradead.org; Sat, 07 Dec 2024 09:09:35 +0000 Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Y52LG09pjzgZ7S; Sat, 7 Dec 2024 17:06:30 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 3E274140135; Sat, 7 Dec 2024 17:09:21 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 7 Dec 2024 17:09:20 +0800 From: Zeng Heng To: , CC: , , , Subject: [RFC PATCH mpam mpam/snapshot/v6.12-rc1 v3 2/5] arm_mpam: Read monitor value with new closid/rmid pair Date: Sat, 7 Dec 2024 17:21:33 +0800 Message-ID: <20241207092136.2488426-3-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241207092136.2488426-1-zengheng4@huawei.com> References: <20241207092136.2488426-1-zengheng4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100008.china.huawei.com (7.202.181.222) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241207_010932_339272_E61B56C2 X-CRM114-Status: GOOD ( 16.04 ) 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 The MPAM driver statically assigns all reqPARTIDs to respective intPARTIDs. For the new rmid allocation strategy, it will check if there is an available rmid of any reqPARTID which belongs to the input closid, not just the rmids belonging to the closid. For a mixture of MSCs system, for MSCs that do not support narrow-partid, we use the PARTIDs exceeding the number of closids as reqPARTIDs for expanding the monitoring groups. In order to keep the existing resctrl API interface, the rmid contains both req_idx and PMG information instead of PMG only under the MPAM driver. The req_idx represents the req_idx-th sub-monitoring group under the control group. The new rmid would be like: rmid = (req_idx << shift | pmg). The mapping relationships between each group's closid/rmid and the respective MSCs' intPARTID/reqPARTID/PARTID are illustrated: n - Indicates the total number of intPARTIDs m - Indicates the number of reqPARTIDs per intPARTID P - Partition group (control group) M - Monitoring group Group closid rmid.req_idx (req)PARTID MSCs with narrow-partid MSCs without narrow-partid P1 0 - 0 intPARTID_1 PARTID_1 M1_1 0 0 0 ├── reqPARTID_1_1 ├── PARTID_1_1 M1_2 0 1 0+n ├── reqPARTID_1_2 ├── PARTID_1_2 M1_3 0 2 0+n*2 ├── reqPARTID_1_3 ├── PARTID_1_3 ... ├── ... ├── ... M1_m 0 (m-1) 0+n*(m-1) └── reqPARTID_1_m └── PARTID_1_m P2 1 - 1 intPARTID_2 PARTID_2 M2_1 1 0 1 ├── reqPARTID_2_1 ├── PARTID_2_1 M2_2 1 1 1+n ├── reqPARTID_2_2 ├── PARTID_2_2 M2_3 1 2 1+n*2 ├── reqPARTID_2_3 ├── PARTID_2_3 ... ├── ... ├── ... M2_m 1 (m-1) 1+n*(m-1) └── reqPARTID_2_m └── PARTID_2_m Pn (n-1) - (n-1) intPARTID_n PARTID_n Mn_1 (n-1) 0 (n-1) ├── reqPARTID_n_1 ├── PARTID_n_1 Mn_2 (n-1) 1 (n-1)+n ├── reqPARTID_n_2 ├── PARTID_n_2 Mn_3 (n-1) 2 (n-1)+n*2 ├── reqPARTID_n_3 ├── PARTID_n_3 ... ├── ... ├── ... Mn_m (n-1) (m-1) (n-1)+n*(m-1) = n*m-1 └── reqPARTID_n_m └── PARTID_n_m Based on the example provided, the conversion relationship between closid/rmid and (req)PARTID/PMG is: (req)PARTID = (rmid.req_idx * n) + closid, PMG = rmid.pmg. When the resctrl layer uses the new closid/rmid pair to read or reset the monitoring values, these new conversion functions(closid_rmid2reqpartid() and rmid2pmg()) would be utilized to gain the new (req)PARTID/PMG pair. Since the rmid no longer contains only PMG information, it includes both *req_idx* and *pmg*. Therefore, the conversion between rmid_idx and closid/rmid needs to be adapted accordingly too. Each control group has m (req)PARTIDs, which are used to expand the number of monitoring groups under the control group. Therefore, the number of monitoring groups is no longer limited by the range of MPAM's PMG, which enhances the extensibility of the system's monitoring capabilities. Signed-off-by: Zeng Heng --- drivers/platform/arm64/mpam/mpam_resctrl.c | 64 ++++++++++++++++++---- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index ac3d228befcf..965ff9fd45d3 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -171,6 +171,11 @@ static u32 get_num_reqpartid(void) return mpam_partid_max + 1; } +static u32 get_num_reqpartid_per_closid(void) +{ + return get_num_reqpartid() / resctrl_arch_get_num_closid(NULL); +} + u32 resctrl_arch_system_num_rmid_idx(void) { u8 closid_shift = fls(mpam_pmg_max); @@ -179,24 +184,59 @@ u32 resctrl_arch_system_num_rmid_idx(void) return num_reqpartid << closid_shift; } +/* + * Under MPAM driver, the rmid contains two pieces of information: one is + * req_idx, and the other is pmg. Therefore, + * closid_shift = req_shift + pmg_shift. + */ u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) { - u8 closid_shift = fls(mpam_pmg_max); + u32 rmid_mask; + u8 closid_shift; + u8 pmg_shift = fls(mpam_pmg_max); + u8 req_shift = fls(get_num_reqpartid_per_closid() - 1); + + closid_shift = req_shift + pmg_shift; + rmid_mask = ~(~0 << closid_shift); BUG_ON(closid_shift > 8); - return (closid << closid_shift) | rmid; + return (closid << closid_shift) | (rmid & rmid_mask); } void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid) { - u8 closid_shift = fls(mpam_pmg_max); - u32 pmg_mask = ~(~0 << closid_shift); + u32 rmid_mask; + u8 closid_shift; + u8 pmg_shift = fls(mpam_pmg_max); + u8 req_shift = fls(get_num_reqpartid_per_closid() - 1); + + closid_shift = req_shift + pmg_shift; + rmid_mask = ~(~0 << closid_shift); BUG_ON(closid_shift > 8); - *closid = idx >> closid_shift; - *rmid = idx & pmg_mask; + if (closid) + *closid = idx >> closid_shift; + if (rmid) + *rmid = idx & rmid_mask; +} + +static u32 closid_rmid2reqpartid(u32 closid, u32 rmid) +{ + u8 pmg_shift = fls(mpam_pmg_max); + u32 req_idx = (rmid >> pmg_shift); + u8 intpartid_shift = fls(mpam_intpartid_max); + + return (req_idx << intpartid_shift) | closid; +} + +static u32 rmid2pmg(u32 rmid) +{ + u8 pmg_shift = fls(mpam_pmg_max); + u32 pmg_mask = ~(~0 << pmg_shift); + + return rmid & pmg_mask; } void resctrl_arch_sched_in(struct task_struct *tsk) @@ -397,7 +437,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, cfg.mon = resctrl_arch_rmid_idx_encode(closid, rmid); cfg.match_pmg = true; - cfg.pmg = rmid; + cfg.pmg = rmid2pmg(rmid); cfg.opts = resctrl_evt_config_to_mpam(dom->mbm_local_evt_cfg); if (irqs_disabled()) { @@ -405,7 +445,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, err = -EIO; } else { if (cdp_enabled) { - cfg.partid = closid << 1; + cfg.partid = closid_rmid2reqpartid(closid, rmid) << 1; err = mpam_msmon_read(dom->comp, &cfg, type, val); if (err) return err; @@ -415,7 +455,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, if (!err) *val += cdp_val; } else { - cfg.partid = closid; + cfg.partid = closid_rmid2reqpartid(closid, rmid); err = mpam_msmon_read(dom->comp, &cfg, type, val); } } @@ -434,18 +474,18 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d, cfg.mon = resctrl_arch_rmid_idx_encode(closid, rmid); cfg.match_pmg = true; - cfg.pmg = rmid; + cfg.pmg = rmid2pmg(rmid); dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom); if (cdp_enabled) { - cfg.partid = closid << 1; + cfg.partid = closid_rmid2reqpartid(closid, rmid) << 1; mpam_msmon_reset_mbwu(dom->comp, &cfg); cfg.partid += 1; mpam_msmon_reset_mbwu(dom->comp, &cfg); } else { - cfg.partid = closid; + cfg.partid = closid_rmid2reqpartid(closid, rmid); mpam_msmon_reset_mbwu(dom->comp, &cfg); } } From patchwork Sat Dec 7 09:21:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 13898223 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 08434E7717B for ; Sat, 7 Dec 2024 09:14:54 +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-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=P2E7xqnCjNDMrY4c8PkIGqRI88xAe9s6dstqytTnSo0=; b=KbkRzqO4hH79XQTx3MUldefFNd Afxp0vqi8gV7s698v6QrizHlQa8VQGyYVGbv98f79ehQmEvX3km3Fi4VTAPRtP83+l9XXBvJaiDI0 aaVTxZIYvIFTTen58S2J2TjO/sTl6EyPWHl0s1R/gywhg/4pU/pfjeqBaW3GYUQa2JiTHBJtd4e2z KGOC2nMIqmO8HIIC/Mr1O1K7i8Z2UMJKZxJ9QtiAEIWcNxpwI72f8RzdyuYkjw8fVGEhPfAwkYq7l 8T7zfbVMMBh5IK/s/30HZ6T9DrPI+DLv2fCaVvjKFg603vBYrlT1Q0pt/t0NhX3PwvYOT9gnKyhS7 YxLmyE3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJqtg-00000003lI7-1H1N; Sat, 07 Dec 2024 09:14:44 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJqoe-00000003kZp-3d5D for linux-arm-kernel@lists.infradead.org; Sat, 07 Dec 2024 09:09:35 +0000 Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Y52Md1BL5zRhpr; Sat, 7 Dec 2024 17:07:41 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id D23001800FD; Sat, 7 Dec 2024 17:09:21 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 7 Dec 2024 17:09:21 +0800 From: Zeng Heng To: , CC: , , , Subject: [RFC PATCH mpam mpam/snapshot/v6.12-rc1 v3 3/5] arm_mpam: Set INTERNAL as needed when setting MSC controls Date: Sat, 7 Dec 2024 17:21:34 +0800 Message-ID: <20241207092136.2488426-4-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241207092136.2488426-1-zengheng4@huawei.com> References: <20241207092136.2488426-1-zengheng4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100008.china.huawei.com (7.202.181.222) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241207_010933_228888_3D774E31 X-CRM114-Status: GOOD ( 11.55 ) 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 From: Dave Martin Currently, when an MSC implements PARTID narrowing, MPAMCFG_PART_SEL is left set to the reqPARTID while programming resource controls in an MSC. The MPAM architecture does not guarantee that any particular resource controls will be updated correctly in this scenario. Instead, MPAMCFG_PART_SEL must be written with the corresponding intPARTID and with the INTERNAL bit set before attempting to program resource controls. Only the PARTID->intPARTID mappings can be written without the INTERNAL bit set in MPAMCFG_PART_SEL. Fix it, by rewriting MPAMCFG_PART_SEL appropriately after setting the intPARTID mapping. The MPAMCFG_INTPARTID_INTERNAL flag is not currently accepted as input to the __mpam_part_sel() helper. In the interest of keeping the code clean, break this helper up. Signed-off-by: Dave Martin Signed-off-by: James Morse --- drivers/platform/arm64/mpam/mpam_devices.c | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index ca621bb132e9..781c9146718d 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -205,15 +205,27 @@ static u64 mpam_msc_read_esr(struct mpam_msc *msc) return (esr_high << 32) | esr_low; } +static void __mpam_part_sel_raw(u32 partsel, struct mpam_msc *msc) +{ + lockdep_assert_held(&msc->part_sel_lock); + mpam_write_partsel_reg(msc, PART_SEL, partsel); +} + static void __mpam_part_sel(u8 ris_idx, u16 partid, struct mpam_msc *msc) { - u32 partsel; + u32 partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | + FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, partid); - lockdep_assert_held(&msc->part_sel_lock); + __mpam_part_sel_raw(partsel, msc); +} - partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | - FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, partid); - mpam_write_partsel_reg(msc, PART_SEL, partsel); +static void __mpam_intpart_sel(u8 ris_idx, u16 intpartid, struct mpam_msc *msc) +{ + u32 partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | + FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, intpartid) | + MPAMCFG_PART_SEL_INTERNAL; + + __mpam_part_sel_raw(partsel, msc); } int mpam_register_requestor(u16 partid_max, u8 pmg_max) @@ -1540,9 +1552,11 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, mutex_lock(&msc->part_sel_lock); __mpam_part_sel(ris->ris_idx, partid, msc); - if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) + if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) { mpam_write_partsel_reg(msc, INTPARTID, MPAMCFG_INTPARTID_INTERNAL | partid); + __mpam_intpart_sel(ris->ris_idx, partid, msc); + } if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { if (mpam_has_feature(mpam_feat_cpor_part, cfg)) From patchwork Sat Dec 7 09:21:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 13898219 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 A9B36E7717B for ; Sat, 7 Dec 2024 09:10:50 +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-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iOpl74vZru+3AGb0tJ3rrtNmAzCbq1rZG6QK9a0Sv1Q=; b=mWgVJgO2gjl/350q8kNPXahWsd xZUkPgq1Z2JgtiaQRf1DA/E+X9scTvjuht3Rf9LQUZpTSTa5UZOaPKg2LMZdCZGQwmfyzWePCW8w5 qEadcd3Nc/dYTO8vm5mwu8HAKcZtkTPOYDKOekNz7uUM2I+0P9IoFQwxNCeWwehkZWgy8ZTnxgOa2 VJqNBKNV4OSwpucof9j1Im4qEKJQ+8Db/oFUKekMzLo6wF1Ja3QLYCh7gARIKQKn1RuHEl0AlY0Dq xaKReFghFnnEUl3KS47QxWwQPmuwdlN8aFyH8mZTm7QR/rHj1esGljQ6SdGH5G9C4o0bRwMVUVgdf amAbkOWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJqph-00000003ksI-2YCg; Sat, 07 Dec 2024 09:10:37 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJqod-00000003kZx-1vgR for linux-arm-kernel@lists.infradead.org; Sat, 07 Dec 2024 09:09:33 +0000 Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Y52Ls1vKqz1T6RH; Sat, 7 Dec 2024 17:07:01 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 6F37D1A0188; Sat, 7 Dec 2024 17:09:22 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 7 Dec 2024 17:09:21 +0800 From: Zeng Heng To: , CC: , , , Subject: [RFC PATCH mpam mpam/snapshot/v6.12-rc1 v3 4/5] arm_mpam: Automatically synchronize the configuration of all sub-monitoring groups Date: Sat, 7 Dec 2024 17:21:35 +0800 Message-ID: <20241207092136.2488426-5-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241207092136.2488426-1-zengheng4@huawei.com> References: <20241207092136.2488426-1-zengheng4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100008.china.huawei.com (7.202.181.222) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241207_010931_827943_B9647817 X-CRM114-Status: GOOD ( 13.19 ) 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 After the system expands the narrow-partid feature and statically assigns all (req)PARTIDs to each control group, the following scenarios require configuration synchronization operations: 1. MSCs that support narrow-partid need to establish a mapping between reqPARTID and intPARTID after creating a new monitoring group. 2. MSCs that do not support narrow-partid need to synchronize the configuration of sub-monitoring groups after users update the control group configuration. In __write_config(), we synchronize a control group's configuration to each sub-monitoring group. Signed-off-by: Zeng Heng --- drivers/platform/arm64/mpam/mpam_devices.c | 25 ++++++++++++++++++--- drivers/platform/arm64/mpam/mpam_internal.h | 3 +++ drivers/platform/arm64/mpam/mpam_resctrl.c | 10 ++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index 781c9146718d..91c5849f76e3 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -1544,6 +1544,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, u32 pri_val = 0; u16 cmax = MPAMCFG_CMAX_CMAX; u16 bwa_fract = MPAMCFG_MBW_MAX_MAX; + u16 intpartid = req2intpartid(partid); struct mpam_msc *msc = ris->vmsc->msc; struct mpam_props *rprops = &ris->props; u16 dspri = GENMASK(rprops->dspri_wd, 0); @@ -1554,8 +1555,14 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) { mpam_write_partsel_reg(msc, INTPARTID, - MPAMCFG_INTPARTID_INTERNAL | partid); - __mpam_intpart_sel(ris->ris_idx, partid, msc); + MPAMCFG_INTPARTID_INTERNAL | + intpartid); + + /* Already finish mapping reqPARTID to intPARTID */ + if (partid != intpartid) + goto out; + + __mpam_intpart_sel(ris->ris_idx, intpartid, msc); } if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { @@ -1615,6 +1622,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, mpam_quirk_post_config_change(ris, partid, cfg); +out: mutex_unlock(&msc->part_sel_lock); } @@ -3072,9 +3080,20 @@ struct mpam_write_config_arg { static int __write_config(void *arg) { + int closid_num = resctrl_arch_get_num_closid(NULL); struct mpam_write_config_arg *c = arg; + u32 reqpartid, req_idx; + + WARN_ON(c->partid >= closid_num); - mpam_reprogram_ris_partid(c->ris, c->partid, &c->comp->cfg[c->partid]); + /* Synchronize the configuration to each sub-monitoring group. */ + for (req_idx = 0; req_idx < get_num_reqpartid_per_closid(); + req_idx++) { + reqpartid = req_idx * closid_num + c->partid; + + mpam_reprogram_ris_partid(c->ris, reqpartid, + &c->comp->cfg[c->partid]); + } return 0; } diff --git a/drivers/platform/arm64/mpam/mpam_internal.h b/drivers/platform/arm64/mpam/mpam_internal.h index 5fc9f09b6945..c02365338b21 100644 --- a/drivers/platform/arm64/mpam/mpam_internal.h +++ b/drivers/platform/arm64/mpam/mpam_internal.h @@ -773,4 +773,7 @@ static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { } */ #define MSMON_CAPT_EVNT_NOW BIT(0) +u32 get_num_reqpartid_per_closid(void); +u32 req2intpartid(u32 reqpartid); + #endif /* MPAM_INTERNAL_H */ diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index 965ff9fd45d3..47e3a51b0942 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -171,11 +171,19 @@ static u32 get_num_reqpartid(void) return mpam_partid_max + 1; } -static u32 get_num_reqpartid_per_closid(void) +u32 get_num_reqpartid_per_closid(void) { return get_num_reqpartid() / resctrl_arch_get_num_closid(NULL); } +u32 req2intpartid(u32 reqpartid) +{ + u8 intpartid_shift = fls(mpam_intpartid_max); + u32 intpartid_mask = ~(~0 << intpartid_shift); + + return reqpartid & intpartid_mask; +} + u32 resctrl_arch_system_num_rmid_idx(void) { u8 closid_shift = fls(mpam_pmg_max); From patchwork Sat Dec 7 09:21:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 13898221 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 87612E7717B for ; Sat, 7 Dec 2024 09:12:50 +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-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aMGv0ogzwTzqM1qsPrEMSHmzmUnMDMAlQ/kWd11H0Mw=; b=mN/GFd4XzcR5YyxtMh9y1fMMrj OUYyIQ0v5B0kbh3MWLC90XCcvhyMjh/DTs6b6By5KIzItaLfAPdeky7C+cnjFWvlZPpTlDrpgYgHI XOZDjBCKcT6tsRshmv35sPkj/PfSE7BuAoy0YtVoNg/PsTKhAVauA2G7mFMncdkH6ntff4K8CCqVn S2d5H+rzxkIWrVGlpM+YmWMOP0P7RTuWxNvGj4WVaRx7zpqK/KQTK8kinMjJVgBQWu2/dlk2Jv6H7 8PgeHzryNpxR1R09spQLqLv8dvZy3Modqc8mfELNKyPQHbRPJd3kB4uO7y6Kp7TkiZ8eZ6Y9B6r+z W64mlLnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJqrg-00000003l6L-3nS3; Sat, 07 Dec 2024 09:12:40 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJqoe-00000003kZw-3Old for linux-arm-kernel@lists.infradead.org; Sat, 07 Dec 2024 09:09:34 +0000 Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Y52Ls6H0hz1T6bp; Sat, 7 Dec 2024 17:07:01 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 1113C140136; Sat, 7 Dec 2024 17:09:23 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 7 Dec 2024 17:09:22 +0800 From: Zeng Heng To: , CC: , , , Subject: [RFC PATCH mpam mpam/snapshot/v6.12-rc1 v3 5/5] arm_mpam: Adapting the closid/rmid matching determination functions Date: Sat, 7 Dec 2024 17:21:36 +0800 Message-ID: <20241207092136.2488426-6-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241207092136.2488426-1-zengheng4@huawei.com> References: <20241207092136.2488426-1-zengheng4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemf100008.china.huawei.com (7.202.181.222) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241207_010933_184454_7AD05646 X-CRM114-Status: GOOD ( 12.00 ) 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 According to the previous patches, add the inverse functions for the closid/rmid conversion functions to serve as the conversion functions for reqpartid/pmg. And adapt the matching determination functions resctrl_arch_match_closid() and resctrl_arch_match_rmid() by the inverse functions. For the same reason, when updating the (req)PARTID/PMG pair for a task, the new conversion functions also are used for adaptation. Signed-off-by: Zeng Heng --- arch/arm64/include/asm/mpam.h | 6 ++- drivers/platform/arm64/mpam/mpam_resctrl.c | 63 +++++++++++++++------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h index e5f385767174..9fc095530671 100644 --- a/arch/arm64/include/asm/mpam.h +++ b/arch/arm64/include/asm/mpam.h @@ -93,6 +93,8 @@ static inline u64 mpam_get_regval(struct task_struct *tsk) #endif } +u32 rmid2pmg(u32 rmid); + static inline void resctrl_arch_set_rmid(struct task_struct *tsk, u32 rmid) { #ifdef CONFIG_ARM64_MPAM @@ -100,8 +102,8 @@ static inline void resctrl_arch_set_rmid(struct task_struct *tsk, u32 rmid) regval &= ~MPAM1_EL1_PMG_D; regval &= ~MPAM1_EL1_PMG_I; - regval |= FIELD_PREP(MPAM1_EL1_PMG_D, rmid); - regval |= FIELD_PREP(MPAM1_EL1_PMG_I, rmid); + regval |= FIELD_PREP(MPAM1_EL1_PMG_D, rmid2pmg(rmid)); + regval |= FIELD_PREP(MPAM1_EL1_PMG_I, rmid2pmg(rmid)); WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval); #endif diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index 47e3a51b0942..cb5da3de907a 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -239,7 +239,7 @@ static u32 closid_rmid2reqpartid(u32 closid, u32 rmid) return (req_idx << intpartid_shift) | closid; } -static u32 rmid2pmg(u32 rmid) +u32 rmid2pmg(u32 rmid) { u8 pmg_shift = fls(mpam_pmg_max); u32 pmg_mask = ~(~0 << pmg_shift); @@ -247,6 +247,20 @@ static u32 rmid2pmg(u32 rmid) return rmid & pmg_mask; } +static u32 reqpartid2closid(u32 reqpartid) +{ + return req2intpartid(reqpartid); +} + +static u32 reqpartid_pmg2rmid(u32 reqpartid, u32 pmg) +{ + u8 pmg_shift = fls(mpam_pmg_max); + u8 intpartid_shift = fls(mpam_intpartid_max); + u32 req_idx = (reqpartid >> intpartid_shift); + + return (req_idx << pmg_shift) | pmg; +} + void resctrl_arch_sched_in(struct task_struct *tsk) { lockdep_assert_preemption_disabled(); @@ -256,20 +270,24 @@ void resctrl_arch_sched_in(struct task_struct *tsk) void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid) { - BUG_ON(closid > U16_MAX); - BUG_ON(rmid > U8_MAX); + u32 reqpartid = closid_rmid2reqpartid(closid, rmid); + u32 pmg = rmid2pmg(rmid); + u32 partid_d, partid_i; + + BUG_ON(reqpartid > U16_MAX); + BUG_ON(pmg > U8_MAX); if (!cdp_enabled) { - mpam_set_cpu_defaults(cpu, closid, closid, rmid, rmid); + mpam_set_cpu_defaults(cpu, reqpartid, reqpartid, pmg, pmg); } else { /* * When CDP is enabled, resctrl halves the closid range and we * use odd/even partid for one closid. */ - u32 partid_d = resctrl_get_config_index(closid, CDP_DATA); - u32 partid_i = resctrl_get_config_index(closid, CDP_CODE); + partid_d = resctrl_get_config_index(reqpartid, CDP_DATA); + partid_i = resctrl_get_config_index(reqpartid, CDP_CODE); - mpam_set_cpu_defaults(cpu, partid_d, partid_i, rmid, rmid); + mpam_set_cpu_defaults(cpu, partid_d, partid_i, pmg, pmg); } } @@ -289,41 +307,46 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info) void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { - BUG_ON(closid > U16_MAX); - BUG_ON(rmid > U8_MAX); + u32 reqpartid = closid_rmid2reqpartid(closid, rmid); + u32 pmg = rmid2pmg(rmid); + u32 partid_d, partid_i; + + BUG_ON(reqpartid > U16_MAX); + BUG_ON(pmg > U8_MAX); if (!cdp_enabled) { - mpam_set_task_partid_pmg(tsk, closid, closid, rmid, rmid); + mpam_set_task_partid_pmg(tsk, reqpartid, reqpartid, pmg, pmg); } else { - u32 partid_d = resctrl_get_config_index(closid, CDP_DATA); - u32 partid_i = resctrl_get_config_index(closid, CDP_CODE); + partid_d = resctrl_get_config_index(reqpartid, CDP_DATA); + partid_i = resctrl_get_config_index(reqpartid, CDP_CODE); - mpam_set_task_partid_pmg(tsk, partid_d, partid_i, rmid, rmid); + mpam_set_task_partid_pmg(tsk, partid_d, partid_i, pmg, pmg); } } bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid) { u64 regval = mpam_get_regval(tsk); - u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); + u32 tsk_partid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); if (cdp_enabled) - tsk_closid >>= 1; + tsk_partid >>= 1; - return tsk_closid == closid; + return reqpartid2closid(tsk_partid) == closid; } /* The task's pmg is not unique, the partid must be considered too */ bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { u64 regval = mpam_get_regval(tsk); - u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); - u32 tsk_rmid = FIELD_GET(MPAM1_EL1_PMG_D, regval); + u32 tsk_pmg = FIELD_GET(MPAM1_EL1_PMG_D, regval); + u32 tsk_partid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); if (cdp_enabled) - tsk_closid >>= 1; + tsk_partid >>= 1; - return (tsk_closid == closid) && (tsk_rmid == rmid); + return (reqpartid2closid(tsk_partid) == closid) && + (reqpartid_pmg2rmid(tsk_partid, tsk_pmg) == rmid); } struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)