[PATCH v2 31/45] arm_mpam: resctrl: Add kunit test for ABMC/CDP interactions

Ben Horgan
2025-12-19T18:14:31Z

From: James Morse <james.morse@arm.com>

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 <james.morse@arm.com>
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
---
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_mpam_resctrl.c
index d0615aa7671c..c83d54f21fa0 100644
--- a/drivers/resctrl/test_mpam_resctrl.c
+++ b/drivers/resctrl/test_mpam_resctrl.c
@@ -293,6 +293,67 @@ static void test_percent_to_max_rounding(struct kunit *test)
KUNIT_EXPECT_LE(test, 4 * num_rounded_up, 3 * total);
}

+static void test_num_assignable_counters(struct kunit *test)
+{
+ unsigned int orig_l3_num_allocated_mbwu = l3_num_allocated_mbwu;
+ u32 orig_mpam_partid_max = mpam_partid_max;
+ u32 orig_mpam_pmg_max = mpam_pmg_max;
+ bool orig_cdp_enabled = cdp_enabled;
+ struct rdt_resource fake_l3;
+
+ /* Force there to be some PARTID/PMG */
+ mpam_partid_max = 3;
+ mpam_pmg_max = 1;
+
+ cdp_enabled = false;
+
+ /* ABMC off, CDP off */
+ l3_num_allocated_mbwu = 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 = 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 = true;
+
+ /* ABMC off, CDP on */
+ l3_num_allocated_mbwu = 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 = 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 = 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 = orig_l3_num_allocated_mbwu;
+ mpam_partid_max = orig_mpam_partid_max;
+ mpam_pmg_max = orig_mpam_pmg_max;
+ cdp_enabled = orig_cdp_enabled;
+}
+
static struct kunit_case mpam_resctrl_test_cases[] = {
KUNIT_CASE(test_get_mba_granularity),
KUNIT_CASE_PARAM(test_mbw_max_to_percent, test_percent_value_gen_params),
@@ -301,6 +362,7 @@ static struct kunit_case mpam_resctrl_test_cases[] = {
KUNIT_CASE(test_percent_to_max_rounding),
KUNIT_CASE_PARAM(test_percent_max_roundtrip_stability,
test_all_bwa_wd_gen_params),
+ KUNIT_CASE(test_num_assignable_counters),
{}
};

--
2.43.0