[RFC PATCH 32/38] arm_mpam: resctrl: Sort the order of the domain lists

James Morse
2025-12-05T22:01:39Z

resctrl documents that the domains appear in numeric order in the
schemata file. This means a little more work is needed when bringing
a domain online.

Add the support for this, using resctrl_find_domain() to find the
point to insert in the list.

Signed-off-by: James Morse <james.morse@arm.com>
---
drivers/resctrl/mpam_resctrl.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index ccdf8db742c9..84ef3c1b4f53 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1547,6 +1547,21 @@ static struct mpam_component *find_component(struct mpam_class *victim, int cpu)
return NULL;
}

+static void mpam_resctrl_domain_insert(struct list_head *list,
+ struct rdt_domain_hdr *new)
+{
+ struct rdt_domain_hdr *err;
+ struct list_head *pos = NULL;
+
+ lockdep_assert_held(&domain_list_lock);
+
+ err = resctrl_find_domain(list, new->id, &pos);
+ if (WARN_ON_ONCE(err))
+ return;
+
+ list_add_tail_rcu(&new->list, pos);
+}
+
static struct mpam_resctrl_dom *
mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
{
@@ -1584,8 +1599,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
ctrl_d = &dom->resctrl_ctrl_dom;
mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, &ctrl_d->hdr);
ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
- /* TODO: this list should be sorted */
- list_add_tail_rcu(&ctrl_d->hdr.list, &r->ctrl_domains);
+ mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
err = resctrl_online_ctrl_domain(r, ctrl_d);
if (err) {
dom = ERR_PTR(err);
@@ -1623,8 +1637,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
mon_d = &dom->resctrl_mon_dom;
mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, &mon_d->hdr);
mon_d->hdr.type = RESCTRL_MON_DOMAIN;
- /* TODO: this list should be sorted */
- list_add_tail_rcu(&mon_d->hdr.list, &r->mon_domains);
+ mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
err = resctrl_online_mon_domain(r, mon_d);
if (err) {
dom = ERR_PTR(err);
--
2.39.5