From nobody Tue Apr 7 14:05:32 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9A4B21B192 for ; Wed, 25 Feb 2026 20:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052897; cv=none; b=Mxxorn6QGXxNzDxF036k+11ULJhwgBAZYyqJZ16oA+lVdaOiAzKLujsCGiAklk2wxNh/+adw8V8l1xQ+uuhLNT+5GxAgp1eBCVrey7usT7Q8rL2s8DphoGgbMeaRl/epH42Z8cuy6oAwZ9yPAO1H1OEZrkZnsO7oYs9lrU0M2Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052897; c=relaxed/simple; bh=EmoJB2fBA5HwYMQooNq7eqv/lpUXxtcwat/Hy9xd4J4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g248jr39wZ4860M66He5+o1aZyKppjpmx9XFmN7DAtG6Fk5bDsxepSMK7ZkcbirvlOFfDE4Evr/8dRUCN68OHZ8m50/AiwyhtVrLRyfRdhE+SVISaG6b8b69FYz+TKmTpWja4MGaOx0CEc6tPuRhwJB+duj9DcZN1hJJw/ENTFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 F37761650; Wed, 25 Feb 2026 12:54:48 -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 C2D5D3F73B; Wed, 25 Feb 2026 12:54:51 -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, zengheng4@huawei.com Subject: [RFC PATCH v1 1/4] arm_mpam: resctrl: Pre-allocate assignable monitors Date: Wed, 25 Feb 2026 20:54:33 +0000 Message-ID: <20260225205436.3571756-2-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260225205436.3571756-1-ben.horgan@arm.com> References: <20260225205436.3571756-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Morse When there are not enough monitors, MPAM is able to emulate ABMC by making a smaller number of monitors assignable. These monitors still need to be allocated from the driver, and mapped to whichever control/monitor group resctrl wants to use them with. Add a second array to hold the monitor values indexed by resctrl's cntr_id. When CDP is in use, two monitors are needed so the available number of counters halves. Platforms with one monitor will have zero monitors when CDP is in use. Reviewed-by: Jonathan Cameron Signed-off-by: James Morse Signed-off-by: Ben Horgan --- Changes since rfc: Move __free kmalloc -> kcalloc Changes since v2: kcalloc -> kmalloc_array sizeof(*rmid_array) Return error from resctrl_arch_mbm_cntr_assign_set() --- drivers/resctrl/mpam_internal.h | 7 +++ drivers/resctrl/mpam_resctrl.c | 93 +++++++++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_interna= l.h index 195ab821cc52..9c4dc0684f6d 100644 --- a/drivers/resctrl/mpam_internal.h +++ b/drivers/resctrl/mpam_internal.h @@ -417,6 +417,13 @@ struct mpam_resctrl_mon { =20 /* Array of allocated MBWU monitors, indexed by (closid, rmid). */ int *mbwu_idx_to_mon; + + /* + * Array of assigned MBWU monitors, indexed by idx argument. + * When ABMC is not in use, this array can be NULL. Otherwise + * it maps idx to the allocated monitor. + */ + int *assigned_counters; }; =20 static inline int mpam_alloc_csu_mon(struct mpam_class *class) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index afe43034a516..58fd3ee10fd2 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -75,6 +75,12 @@ static DECLARE_WAIT_QUEUE_HEAD(wait_cacheinfo_ready); */ static bool resctrl_enabled; =20 +/* + * L3 local/total may come from different classes - what is the number of = MBWU + * 'on L3'? + */ +static unsigned int l3_num_allocated_mbwu =3D ~0; + /* Whether this num_mbw_mon could result in a free_running system */ static int __mpam_monitors_free_running(u16 num_mbwu_mon) { @@ -83,6 +89,15 @@ static int __mpam_monitors_free_running(u16 num_mbwu_mon) return 0; } =20 +/* + * If l3_num_allocated_mbwu is forced below PARTID * PMG, then the counters + * are not free running, and ABMC's user-interface must be used to assign = them. + */ +static bool mpam_resctrl_abmc_enabled(void) +{ + return l3_num_allocated_mbwu < resctrl_arch_system_num_rmid_idx(); +} + bool resctrl_arch_alloc_capable(void) { struct mpam_resctrl_res *res; @@ -143,7 +158,10 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, str= uct rdt_l3_mon_domain *d, =20 bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r) { - return false; + if (r !=3D &mpam_resctrl_controls[RDT_RESOURCE_L3].resctrl_res) + return false; + + return mpam_resctrl_abmc_enabled(); } =20 int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) @@ -188,9 +206,26 @@ static void resctrl_reset_task_closids(void) read_unlock(&tasklist_lock); } =20 +static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *l3) +{ + l3->mon.num_mbm_cntrs =3D l3_num_allocated_mbwu; + if (cdp_enabled) + l3->mon.num_mbm_cntrs /=3D 2; + + if (l3->mon.num_mbm_cntrs) { + l3->mon.mbm_cntr_assignable =3D mpam_resctrl_abmc_enabled(); + l3->mon.mbm_assign_on_mkdir =3D mpam_resctrl_abmc_enabled(); + } else { + l3->mon.mbm_cntr_assignable =3D false; + l3->mon.mbm_assign_on_mkdir =3D false; + } +} + int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable) { u32 partid_i =3D RESCTRL_RESERVED_CLOSID, partid_d =3D RESCTRL_RESERVED_C= LOSID; + struct mpam_resctrl_res *res =3D &mpam_resctrl_controls[RDT_RESOURCE_L3]; + struct rdt_resource *l3 =3D &res->resctrl_res; int cpu; =20 /* This resctrl hook is only called with enable set to false on error */ @@ -217,6 +252,7 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level= rid, bool enable) WRITE_ONCE(arm64_mpam_global_default, mpam_get_regval(current)); =20 resctrl_reset_task_closids(); + mpam_resctrl_monitor_sync_abmc_vals(l3); =20 for_each_possible_cpu(cpu) mpam_set_cpu_defaults(cpu, partid_d, partid_i, 0, 0); @@ -667,7 +703,10 @@ static bool class_has_usable_mbwu(struct mpam_class *c= lass) return true; } =20 - pr_debug("Insufficient monitors for free-running mode\n"); + if (cprops->num_mbwu_mon) { + pr_debug("monitors usable via ABMC assignment\n"); + return true; + } =20 return false; } @@ -1010,6 +1049,8 @@ static int __alloc_mbwu_mon(struct mpam_class *class,= int *array, array[i] =3D mbwu_mon; } =20 + l3_num_allocated_mbwu =3D min(l3_num_allocated_mbwu, num_mbwu_mon); + return 0; } =20 @@ -1214,9 +1255,46 @@ static int mpam_resctrl_pick_domain_id(int cpu, stru= ct mpam_component *comp) return comp->comp_id; } =20 +/* + * This must run after all event counters have been picked so that any free + * running counters have already been allocated. + */ +static int mpam_resctrl_monitor_init_abmc(struct mpam_resctrl_mon *mon) +{ + struct mpam_resctrl_res *res =3D &mpam_resctrl_controls[RDT_RESOURCE_L3]; + struct rdt_resource *l3 =3D &res->resctrl_res; + struct mpam_class *class =3D mon->class; + u16 num_mbwu_mon; + + if (mon->mbwu_idx_to_mon) { + pr_debug("monitors free running\n"); + return 0; + } + + int *rmid_array __free(kfree) =3D + kmalloc_array(resctrl_arch_system_num_rmid_idx(), sizeof(*rmid_array), G= FP_KERNEL); + + if (!rmid_array) { + pr_debug("Failed to allocate RMID array\n"); + return -ENOMEM; + } + memset(rmid_array, -1, resctrl_arch_system_num_rmid_idx() * sizeof(int)); + + num_mbwu_mon =3D class->props.num_mbwu_mon; + mon->assigned_counters =3D __alloc_mbwu_array(mon->class, num_mbwu_mon); + if (IS_ERR(mon->assigned_counters)) + return PTR_ERR(mon->assigned_counters); + mon->mbwu_idx_to_mon =3D no_free_ptr(rmid_array); + + mpam_resctrl_monitor_sync_abmc_vals(l3); + + return 0; +} + static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon, enum resctrl_event_id type) { + int err =3D 0; struct mpam_resctrl_res *res =3D &mpam_resctrl_controls[RDT_RESOURCE_L3]; struct rdt_resource *l3 =3D &res->resctrl_res; =20 @@ -1259,8 +1337,15 @@ static int mpam_resctrl_monitor_init(struct mpam_res= ctrl_mon *mon, */ l3->mon.num_rmid =3D resctrl_arch_system_num_rmid_idx(); =20 - if (resctrl_enable_mon_event(type, false, 0, NULL)) - l3->mon_capable =3D true; + if (type =3D=3D QOS_L3_MBM_TOTAL_EVENT_ID) + err =3D mpam_resctrl_monitor_init_abmc(mon); + if (err) + return err; + + if (!resctrl_enable_mon_event(type, false, 0, NULL)) + return -EINVAL; + + l3->mon_capable =3D true; =20 return 0; } --=20 2.43.0 From nobody Tue Apr 7 14:05:32 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA8C72949E0 for ; Wed, 25 Feb 2026 20:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052901; cv=none; b=mf4NR3+NQbUyk4UgQSxLryZtGM4VTd5CNmQ5+4WQZ3Q49XqLm7mKvMDjoeHkPKzBv8gtqrJq79al5tjn2+LRERVfNS5KJdU5sWGHt7KZOTvvE3sjcDCizQ9EK0QstFMImVWqN8Vjr8cvEmeBCTaJCBZ9CcdTmU2nS904QPTOnn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052901; c=relaxed/simple; bh=zhMZZs1i94LApS14sfoltW2wqXmvqCFPStaTi5GmC+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h2pS5tgwIfQzyY7jzDeN94EMxB085nncqkN0R9kvkOy3uGzcfBAnZBP47qqZvaHFkriv1WpsYEC4+zKOcWCzr6fmMoVZxmYEfWEKpT8RXsl1+scWTFJDPn+Nj3RuGHE+RbyZ4y1YJpsaHx4ELJuB5/C9XZdY8+AjuRQLLu5VBi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C10481758; Wed, 25 Feb 2026 12:54:52 -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 8DF943F73B; Wed, 25 Feb 2026 12:54:55 -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, zengheng4@huawei.com Subject: [RFC PATCH v1 2/4] arm_mpam: resctrl: Add kunit test for ABMC/CDP interactions Date: Wed, 25 Feb 2026 20:54:34 +0000 Message-ID: <20260225205436.3571756-3-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260225205436.3571756-1-ben.horgan@arm.com> References: <20260225205436.3571756-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Morse ABMC exposes a fun corner case where a platform with one monitor can use ABMC for assignable counters - but not when CDP is enabled. Add some tests. Signed-off-by: James Morse Signed-off-by: Ben Horgan --- drivers/resctrl/test_mpam_resctrl.c | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/resctrl/test_mpam_resctrl.c b/drivers/resctrl/test_mpa= m_resctrl.c index a20da161d965..fd63f7bbb147 100644 --- a/drivers/resctrl/test_mpam_resctrl.c +++ b/drivers/resctrl/test_mpam_resctrl.c @@ -344,6 +344,67 @@ static void test_rmid_idx_encoding(struct kunit *test) mpam_pmg_max =3D orig_mpam_pmg_max; } =20 +static void test_num_assignable_counters(struct kunit *test) +{ + unsigned int orig_l3_num_allocated_mbwu =3D l3_num_allocated_mbwu; + u32 orig_mpam_partid_max =3D mpam_partid_max; + u32 orig_mpam_pmg_max =3D mpam_pmg_max; + bool orig_cdp_enabled =3D cdp_enabled; + struct rdt_resource fake_l3; + + /* Force there to be some PARTID/PMG */ + mpam_partid_max =3D 3; + mpam_pmg_max =3D 1; + + cdp_enabled =3D false; + + /* ABMC off, CDP off */ + l3_num_allocated_mbwu =3D resctrl_arch_system_num_rmid_idx(); + mpam_resctrl_monitor_sync_abmc_vals(&fake_l3); + KUNIT_EXPECT_EQ(test, fake_l3.mon.num_mbm_cntrs, resctrl_arch_system_num_= rmid_idx()); + KUNIT_EXPECT_FALSE(test, fake_l3.mon.mbm_cntr_assignable); + KUNIT_EXPECT_FALSE(test, fake_l3.mon.mbm_assign_on_mkdir); + + /* ABMC on, CDP off */ + l3_num_allocated_mbwu =3D 4; + mpam_resctrl_monitor_sync_abmc_vals(&fake_l3); + KUNIT_EXPECT_EQ(test, fake_l3.mon.num_mbm_cntrs, 4); + KUNIT_EXPECT_TRUE(test, fake_l3.mon.mbm_cntr_assignable); + KUNIT_EXPECT_TRUE(test, fake_l3.mon.mbm_assign_on_mkdir); + + cdp_enabled =3D true; + + /* ABMC off, CDP on */ + l3_num_allocated_mbwu =3D resctrl_arch_system_num_rmid_idx(); + mpam_resctrl_monitor_sync_abmc_vals(&fake_l3); + + /* (value not consumed by resctrl) */ + KUNIT_EXPECT_EQ(test, fake_l3.mon.num_mbm_cntrs, resctrl_arch_system_num_= rmid_idx() / 2); + + KUNIT_EXPECT_FALSE(test, fake_l3.mon.mbm_cntr_assignable); + KUNIT_EXPECT_FALSE(test, fake_l3.mon.mbm_assign_on_mkdir); + + /* ABMC on, CDP on */ + l3_num_allocated_mbwu =3D 4; + mpam_resctrl_monitor_sync_abmc_vals(&fake_l3); + KUNIT_EXPECT_EQ(test, fake_l3.mon.num_mbm_cntrs, 2); + KUNIT_EXPECT_TRUE(test, fake_l3.mon.mbm_cntr_assignable); + KUNIT_EXPECT_TRUE(test, fake_l3.mon.mbm_assign_on_mkdir); + + /* ABMC 'on', CDP on - but not enough counters */ + l3_num_allocated_mbwu =3D 1; + mpam_resctrl_monitor_sync_abmc_vals(&fake_l3); + KUNIT_EXPECT_EQ(test, fake_l3.mon.num_mbm_cntrs, 0); + KUNIT_EXPECT_FALSE(test, fake_l3.mon.mbm_cntr_assignable); + KUNIT_EXPECT_FALSE(test, fake_l3.mon.mbm_assign_on_mkdir); + + /* Restore global variables that were messed with */ + l3_num_allocated_mbwu =3D orig_l3_num_allocated_mbwu; + mpam_partid_max =3D orig_mpam_partid_max; + mpam_pmg_max =3D orig_mpam_pmg_max; + cdp_enabled =3D orig_cdp_enabled; +} + static struct kunit_case mpam_resctrl_test_cases[] =3D { KUNIT_CASE(test_get_mba_granularity), KUNIT_CASE_PARAM(test_mbw_max_to_percent, test_percent_value_gen_params), @@ -353,6 +414,7 @@ static struct kunit_case mpam_resctrl_test_cases[] =3D { KUNIT_CASE_PARAM(test_percent_max_roundtrip_stability, test_all_bwa_wd_gen_params), KUNIT_CASE_PARAM(test_rmid_idx_encoding, test_rmid_idx_gen_params), + KUNIT_CASE(test_num_assignable_counters), {} }; =20 --=20 2.43.0 From nobody Tue Apr 7 14:05:32 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DACA2DC789 for ; Wed, 25 Feb 2026 20:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052904; cv=none; b=DZi12j//U5RhXhUGSqpzQfDm4+GoEgS1UyGFUt2pTphTYMDtR81EE7uAzGZY+4k1AaFHhjWDdagAx3YYj4sOypbrS/+XOYDuRtky0Gu0fXNx7teb6CrERT/IR2YglwF/0c5ks2GbtsF/6W/Hfged+hoV+8aThOJhqY+1XgSRIA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052904; c=relaxed/simple; bh=R/VQJKtd0aTsz68AoAls0zWBd9q2nLJmBp7EFIZ+y8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SFynX7ZprMBJJQz4xWBIpzGrCyVPKwzCikHhyAYD9WBRHAeVfuGSSsKbUR1WM/GOJH1qc+zOeirDPjveju/Its9g1ZVO1SPHYj9y/2oaW7VEuyAmE2Ywynyif6OSPJfOc0xEr3I+I6r+pcJL6+rTVbZkwHWPQAG72cBAL1+ukdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 8C55B15A1; Wed, 25 Feb 2026 12:54:56 -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 58CC73F73B; Wed, 25 Feb 2026 12:54:59 -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, zengheng4@huawei.com Subject: [RFC PATCH v1 3/4] arm_mpam: resctrl: Add resctrl_arch_config_cntr() for ABMC use Date: Wed, 25 Feb 2026 20:54:35 +0000 Message-ID: <20260225205436.3571756-4-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260225205436.3571756-1-ben.horgan@arm.com> References: <20260225205436.3571756-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Morse ABMC has a helper resctrl_arch_config_cntr() for changing the mapping between 'cntr_id' and a CLOSID/RMID pair. Add the helper. For MPAM this is done by updating the mon->mbwu_idx_to_mon[] array, and as usual CDP means it needs doing in three different ways. Reviewed-by: Jonathan Cameron Signed-off-by: James Morse Signed-off-by: Ben Horgan --- drivers/resctrl/mpam_resctrl.c | 43 +++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 58fd3ee10fd2..18528210ba46 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -143,12 +143,6 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, s= truct rdt_l3_mon_domain *d { } =20 -void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_do= main *d, - enum resctrl_event_id evtid, u32 rmid, u32 closid, - u32 cntr_id, bool assign) -{ -} - int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, u32 unused, u32 rmid, int cntr_id, enum resctrl_event_id eventid, u64 *val) @@ -1180,6 +1174,43 @@ static void mpam_resctrl_pick_counters(void) } } =20 +static void __config_cntr(struct mpam_resctrl_mon *mon, u32 cntr_id, + enum resctrl_conf_type cdp_type, u32 closid, u32 rmid, + bool assign) +{ + u32 mbwu_idx, mon_idx =3D resctrl_get_config_index(cntr_id, cdp_type); + + closid =3D resctrl_get_config_index(closid, cdp_type); + mbwu_idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); + WARN_ON_ONCE(mon_idx > l3_num_allocated_mbwu); + + if (assign) + mon->mbwu_idx_to_mon[mbwu_idx] =3D mon->assigned_counters[mon_idx]; + else + mon->mbwu_idx_to_mon[mbwu_idx] =3D -1; +} + +void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_do= main *d, + enum resctrl_event_id evtid, u32 rmid, u32 closid, + u32 cntr_id, bool assign) +{ + struct mpam_resctrl_mon *mon =3D &mpam_resctrl_counters[evtid]; + + if (!mon->mbwu_idx_to_mon || !mon->assigned_counters) { + pr_debug("monitor arrays not allocated\n"); + return; + } + + if (cdp_enabled) { + __config_cntr(mon, cntr_id, CDP_CODE, closid, rmid, assign); + __config_cntr(mon, cntr_id, CDP_DATA, closid, rmid, assign); + } else { + __config_cntr(mon, cntr_id, CDP_NONE, closid, rmid, assign); + } + + resctrl_arch_reset_rmid(r, d, closid, rmid, evtid); +} + static int mpam_resctrl_control_init(struct mpam_resctrl_res *res) { struct mpam_class *class =3D res->class; --=20 2.43.0 From nobody Tue Apr 7 14:05:32 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BB5D27B35F for ; Wed, 25 Feb 2026 20:55:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052908; cv=none; b=R3UjVnH+u+rWo/FM5UG4sLOndzaz+cXNU8k+L9a2IcnFbIFLO5MXoWhqffyQ1RzKTQeAppWPQFK0zLEcAt3To3lvmM1+4rpdJzD+EML26TTCBP9YD/72N1mANBHazzqBFj5DnoD2tKkXwq7ZUtMTbOg4tfKNjc52KmR8oornle0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772052908; c=relaxed/simple; bh=P5CGkcUYxtRe9Fy/nifAutJvfswwdtvxqn1e2KldiAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WQZKs7aRrhJwOa3EMp6SXkDkTBY6nFmNTHo0P4eV5MOWl9SgHYIOzWgw+Xb6u8CZ4ziViERSxBcgaI7h68yH0JlbOs/HVC8bEnTKS+YGrfQCNqALrRFS2Rlv5qs9BfiDRXzCEWhx3KmvsDC6ibRRzYQhvmqI8GB0l1A2tAy4/14= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 5526F175A; Wed, 25 Feb 2026 12:55:00 -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 23F803F73B; Wed, 25 Feb 2026 12:55:03 -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, zengheng4@huawei.com Subject: [RFC PATCH v1 4/4] arm_mpam: resctrl: Add resctrl_arch_cntr_read() & resctrl_arch_reset_cntr() Date: Wed, 25 Feb 2026 20:54:36 +0000 Message-ID: <20260225205436.3571756-5-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260225205436.3571756-1-ben.horgan@arm.com> References: <20260225205436.3571756-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Morse When used in ABMC mode, resctrl uses a different set of helpers to read and reset the counters. Add these. Reviewed-by: Jonathan Cameron Signed-off-by: James Morse Signed-off-by: Ben Horgan --- drivers/resctrl/mpam_resctrl.c | 56 ++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 18528210ba46..6c2542cfb0df 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -137,19 +137,6 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *= r, struct rdt_l3_mon_domai { } =20 -void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, - u32 closid, u32 rmid, int cntr_id, - enum resctrl_event_id eventid) -{ -} - -int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, - u32 unused, u32 rmid, int cntr_id, - enum resctrl_event_id eventid, u64 *val) -{ - return -EOPNOTSUPP; -} - bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r) { if (r !=3D &mpam_resctrl_controls[RDT_RESOURCE_L3].resctrl_res) @@ -544,6 +531,28 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, str= uct rdt_domain_hdr *hdr, closid, rmid, val); } =20 +/* MBWU counters when in ABMC mode */ +int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, + u32 closid, u32 rmid, int mon_idx, + enum resctrl_event_id eventid, u64 *val) +{ + struct mpam_resctrl_mon *mon =3D &mpam_resctrl_counters[eventid]; + struct mpam_resctrl_dom *l3_dom; + struct mpam_component *mon_comp; + + if (!mpam_is_enabled()) + return -EINVAL; + + if (eventid =3D=3D QOS_L3_OCCUP_EVENT_ID || !mon->class) + return -EINVAL; + + l3_dom =3D container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom); + mon_comp =3D l3_dom->mon_comp[eventid]; + + return read_mon_cdp_safe(mon, mon_comp, mpam_feat_msmon_mbwu, mon_idx, + closid, rmid, val); +} + static void __reset_mon(struct mpam_resctrl_mon *mon, struct mpam_componen= t *mon_comp, int mon_idx, enum resctrl_conf_type cdp_type, u32 closid, u32 rmid) @@ -600,6 +609,27 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, s= truct rdt_l3_mon_domain *d reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid); } =20 +/* Reset an assigned counter */ +void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, + u32 closid, u32 rmid, int cntr_id, + enum resctrl_event_id eventid) +{ + struct mpam_resctrl_mon *mon =3D &mpam_resctrl_counters[eventid]; + struct mpam_resctrl_dom *l3_dom; + struct mpam_component *mon_comp; + + if (!mpam_is_enabled()) + return; + + if (eventid =3D=3D QOS_L3_OCCUP_EVENT_ID || !mon->class) + return; + + l3_dom =3D container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom); + mon_comp =3D l3_dom->mon_comp[eventid]; + + reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid); +} + /* * The rmid realloc threshold should be for the smallest cache exposed to * resctrl. --=20 2.43.0