As MPAM's pmg are scoped by partid and RDT's rmid are global the
rescrl mapping to an index needs to differ.
Add some tests for the MPAM rmid mapping.
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
---
drivers/resctrl/test_mpam_resctrl.c | 49 +++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/drivers/resctrl/test_mpam_resctrl.c b/drivers/resctrl/test_mpam_resctrl.c
index b93d6ad87e43..a20da161d965 100644
--- a/drivers/resctrl/test_mpam_resctrl.c
+++ b/drivers/resctrl/test_mpam_resctrl.c
@@ -296,6 +296,54 @@ static void test_percent_to_max_rounding(struct kunit *test)
KUNIT_EXPECT_LE(test, 4 * num_rounded_up, 3 * total);
}
+struct rmid_idx_case {
+ u32 max_partid;
+ u32 max_pmg;
+};
+
+static const struct rmid_idx_case rmid_idx_cases[] = {
+ {0, 0}, {1, 4}, {3, 1}, {5, 9}, {4, 4}, {100, 11}, {0xFFFF, 0xFF},
+};
+
+static void test_rmid_idx_desc(const struct rmid_idx_case *param, char *desc)
+{
+ snprintf(desc, KUNIT_PARAM_DESC_SIZE, "max_partid=%d, max_pmg=%d\n",
+ param->max_partid, param->max_pmg);
+}
+
+KUNIT_ARRAY_PARAM(test_rmid_idx, rmid_idx_cases, test_rmid_idx_desc);
+
+static void test_rmid_idx_encoding(struct kunit *test)
+{
+ u32 orig_mpam_partid_max = mpam_partid_max;
+ u32 orig_mpam_pmg_max = mpam_pmg_max;
+ const struct rmid_idx_case *param = test->param_value;
+ u32 idx, num_idx, count = 0;
+
+ mpam_partid_max = param->max_partid;
+ mpam_pmg_max = param->max_pmg;
+
+ for (u32 partid = 0; partid <= mpam_partid_max; partid++) {
+ for (u32 pmg = 0; pmg <= mpam_pmg_max; pmg++) {
+ u32 partid_out, pmg_out;
+
+ idx = resctrl_arch_rmid_idx_encode(partid, pmg);
+ /* Confirm there are no holes in the rmid idx range */
+ KUNIT_EXPECT_EQ(test, count, idx);
+ count++;
+ resctrl_arch_rmid_idx_decode(idx, &partid_out, &pmg_out);
+ KUNIT_EXPECT_EQ(test, pmg, pmg_out);
+ KUNIT_EXPECT_EQ(test, partid, partid_out);
+ }
+ }
+ num_idx = resctrl_arch_system_num_rmid_idx();
+ KUNIT_EXPECT_EQ(test, idx + 1, num_idx);
+
+ /* Restore global variables that were messed with */
+ mpam_partid_max = orig_mpam_partid_max;
+ mpam_pmg_max = orig_mpam_pmg_max;
+}
+
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),
@@ -304,6 +352,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_PARAM(test_rmid_idx_encoding, test_rmid_idx_gen_params),
{}
};
--
2.43.0