[PATCH RFC v3 08/15] arm_mpam: Include all MSC components during domain setup

Shaopeng Tan (Fujitsu) tan.shaopeng at fujitsu.com
Wed Nov 25 22:56:11 PST 2026


Hello Fenghua,

> Iterate all MSC components per CPU when creating and looking up control
> and monitor domains on the controls branch. Key monitor domains by
> component, support MBA mon_capable lookup, and report mon capability
> from any L3 or MBA monitor resource.
> 
> A memory-class MSC keeps control_mode legacy and names its control NODE,
> so the schemata line is MB_NODE in both legacy and native mode. A cache
> MSC keeps the MB line.
> 
> Signed-off-by: Fenghua Yu <fenghuay at nvidia.com>
> ---
>  drivers/resctrl/mpam_resctrl.c | 209 +++++++++++++++++++--------------
>  fs/resctrl/ctrlmondata.c       |   1 +
>  include/linux/resctrl.h        |   3 +
>  3 files changed, 127 insertions(+), 86 deletions(-)
> 
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index 72302f6021d7..ac0c488abe12 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -95,11 +95,27 @@ static bool mpam_class_memory(struct mpam_class *class)
>  
>  bool resctrl_arch_mon_capable(void)
>  {
> -       struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
> -       struct rdt_resource *l3 = &res->resctrl_res;
> +       enum resctrl_event_id eventid;
> +       struct mpam_resctrl_mon *mon;
> +       struct mpam_resctrl_res *res;
> +       struct rdt_resource *r;
> +
> +       for_each_mpam_resctrl_mon(mon, eventid) {
> +               if (!mon->class)
> +                       continue;       // dummy resource
> +
> +               if (mpam_class_memory(mon->class))
> +                       res = &mpam_resctrl_controls[RDT_RESOURCE_MBA];
> +               else
> +                       res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
> +
> +               r = &res->resctrl_res;
> +
> +               if (r->mon_capable)
> +                       return true;
> +       }
>  
> -       /* All monitors are presented as being on the L3 cache */
> -       return l3->mon_capable;
> +       return false;
>  }
>  
>  bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt)
> @@ -1293,8 +1309,18 @@ static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
>                  break;
>          case RDT_RESOURCE_MBA:
>                  r->ctrl_scope = RESCTRL_L3_CACHE;

Do we not need to consider RESCTRL_L3_NODE for the scope here?

> +               /*
> +                * control_mode stays legacy. emulated_by is left empty so
> +                * legacy and native mode expose the same schemata line.
> +                * A memory-class MSC is node-scoped, so that line is
> +                * MB_NODE. A cache MSC keeps the MB line.
> +                */
> +               r->ctrl_mode = RESCTRL_CTRL_MODE_LEGACY;
>                  mpam_ctrl->r_ctrl.type = RESCTRL_CTRL_SCALAR;
> -               mpam_ctrl->r_ctrl.name = RESCTRL_CTRL_NAME_DEF;
> +               if (mpam_class_memory(class))
> +                       mpam_ctrl->r_ctrl.name = RESCTRL_CTRL_NAME_NODE;
> +               else
> +                       mpam_ctrl->r_ctrl.name = RESCTRL_CTRL_NAME_DEF;
>                  INIT_LIST_HEAD_RCU(&mpam_ctrl->r_ctrl.domains);
>                  INIT_LIST_HEAD(&mpam_ctrl->r_ctrl.emulated_by);
>  
> @@ -1731,13 +1757,12 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
>  
>  static struct mpam_resctrl_dom *
>  mpam_resctrl_alloc_ctrl_domain(unsigned int cpu, struct mpam_resctrl_res *res,
> -                              struct resctrl_ctrl *ctrl)
> +                              struct resctrl_ctrl *ctrl,
> +                              struct mpam_component *comp)
>  {
>          int err;
>          struct mpam_resctrl_dom *dom;
>          struct rdt_ctrl_domain *ctrl_d;
> -       struct mpam_class *class = res->class;
> -       struct mpam_component *comp_iter, *ctrl_comp;
>          struct rdt_resource *r = &res->resctrl_res;
>  
>          lockdep_assert_held(&domain_list_lock);
> @@ -1745,28 +1770,17 @@ mpam_resctrl_alloc_ctrl_domain(unsigned int cpu, struct mpam_resctrl_res *res,
>          if (!r->alloc_capable)
>                  return ERR_PTR(-EINVAL);
>  
> -       ctrl_comp = NULL;
> -       guard(srcu)(&mpam_srcu);
> -       list_for_each_entry_srcu(comp_iter, &class->components, class_list,
> -                                srcu_read_lock_held(&mpam_srcu)) {
> -               if (cpumask_test_cpu(cpu, &comp_iter->affinity)) {
> -                       ctrl_comp = comp_iter;
> -                       break;
> -               }
> -       }
> -
> -       /* class has no component for this CPU */
> -       if (WARN_ON_ONCE(!ctrl_comp))
> +       if (WARN_ON_ONCE(!comp))
>                  return ERR_PTR(-EINVAL);
>  
>          dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
>          if (!dom)
>                  return ERR_PTR(-ENOMEM);
>  
> -       dom->ctrl_comp = ctrl_comp;
> +       dom->ctrl_comp = comp;
>  
>          ctrl_d = &dom->resctrl_ctrl_dom;
> -       mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d->hdr);
> +       mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
>          ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
>          err = resctrl_online_ctrl_domain(r, ctrl, ctrl_d);
>          if (err)
> @@ -1784,13 +1798,12 @@ mpam_resctrl_alloc_ctrl_domain(unsigned int cpu, struct mpam_resctrl_res *res,
>  }
>  
>  static struct mpam_resctrl_dom *
> -mpam_resctrl_alloc_mon_domain(unsigned int cpu, struct mpam_resctrl_res *res)
> +mpam_resctrl_alloc_mon_domain(unsigned int cpu, struct mpam_resctrl_res *res,
> +                             struct mpam_component *comp)
>  {
>          int err;
>          struct mpam_resctrl_dom *dom;
>          struct rdt_l3_mon_domain *mon_d;
> -       struct mpam_class *class = res->class;
> -       struct mpam_component *comp_iter, *ctrl_comp;
>          struct rdt_resource *r = &res->resctrl_res;
>          struct mpam_component *any_mon_comp = NULL;
>          struct mpam_resctrl_mon *mon;
> @@ -1801,24 +1814,14 @@ mpam_resctrl_alloc_mon_domain(unsigned int cpu, struct mpam_resctrl_res *res)
>          if (!r->mon_capable)
>                  return ERR_PTR(-EINVAL);
>  
> -       ctrl_comp = NULL;
> -       guard(srcu)(&mpam_srcu);
> -       list_for_each_entry_srcu(comp_iter, &class->components, class_list,
> -                                srcu_read_lock_held(&mpam_srcu)) {
> -               if (cpumask_test_cpu(cpu, &comp_iter->affinity)) {
> -                       ctrl_comp = comp_iter;
> -                       break;
> -               }
> -       }
> -
> -       /* class has no component for this CPU */
> -       if (WARN_ON_ONCE(!ctrl_comp))
> +       if (WARN_ON_ONCE(!comp))
>                  return ERR_PTR(-EINVAL);
>  
>          dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
>          if (!dom)
>                  return ERR_PTR(-ENOMEM);
>  
> +       dom->ctrl_comp = comp;
>  
>          /*
>           * Even if the monitor domain is backed by a different
> @@ -1833,7 +1836,7 @@ mpam_resctrl_alloc_mon_domain(unsigned int cpu, struct mpam_resctrl_res *res)
>                  if (!mon->class)
>                          continue;       // dummy resource
>  
> -               mon_comp = find_component(mon->class, cpu);
> +               mon_comp = comp ? comp : find_component(mon->class, cpu);
>                  dom->mon_comp[eventid] = mon_comp;
>                  if (mon_comp)
>                          any_mon_comp = mon_comp;
> @@ -1870,25 +1873,32 @@ mpam_resctrl_alloc_mon_domain(unsigned int cpu, struct mpam_resctrl_res *res)
>   * for anything that is not a cache.

The comment is outdated and should be updated to reflect these changes.

Best regards,
Shaopeng TAN

>   */
>  static struct mpam_resctrl_dom *
> -mpam_resctrl_get_mon_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
> +mpam_resctrl_get_mon_domain_from_cpu(int cpu, struct mpam_resctrl_res *res,
> +                                    struct mpam_component *comp)
>  {
> -       int cache_id;
>          struct mpam_resctrl_dom *dom;
>          struct rdt_resource *r = &res->resctrl_res;
> +       int id;
>  
>          lockdep_assert_cpus_held();
>  
> -       if (r->rid != RDT_RESOURCE_L3)
> -               return ERR_PTR(-EINVAL);
> +       if (!r->mon_capable || !res->class || !comp)
> +               return NULL;
>  
> -       if (!res->class)
> -               return ERR_PTR(-EINVAL);
> -       cache_id = get_cpu_cacheinfo_id(cpu, 3);
> -       if (cache_id < 0)
> -               return ERR_PTR(-EINVAL);
> +       if (r->rid == RDT_RESOURCE_L3) {
> +               id = get_cpu_cacheinfo_id(cpu, 3);
> +               if (id < 0)
> +                       return NULL;
> +       } else if (r->rid == RDT_RESOURCE_MBA) {
> +               id = comp->comp_id;
> +       } else {
> +               return NULL;
> +       }
>  
> -       list_for_each_entry_rcu(dom, &res->resctrl_res.mon_domains, resctrl_mon_dom.hdr.list) {
> -               if (dom->resctrl_mon_dom.hdr.id == cache_id)
> +       list_for_each_entry_rcu(dom, &r->mon_domains, resctrl_mon_dom.hdr.list) {
> +               if (dom->ctrl_comp != comp)
> +                       continue;
> +               if (dom->resctrl_mon_dom.hdr.id == id)
>                          return dom;
>          }
>  
> @@ -1896,14 +1906,19 @@ mpam_resctrl_get_mon_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
>  }
>  
>  static struct mpam_resctrl_dom *
> -mpam_resctrl_get_ctrl_domain_from_cpu(int cpu, struct resctrl_ctrl *ctrl)
> +mpam_resctrl_get_ctrl_domain_from_cpu(int cpu, struct mpam_resctrl_res *res,
> +                                     struct resctrl_ctrl *ctrl,
> +                                     struct mpam_component *comp)
>  {
>          struct mpam_resctrl_dom *dom;
>  
>          lockdep_assert_cpus_held();
>  
> +       if (!comp)
> +               return NULL;
> +
>          list_for_each_entry_rcu(dom, &ctrl->domains, resctrl_ctrl_dom.hdr.list) {
> -               if (cpumask_test_cpu(cpu, &dom->ctrl_comp->affinity))
> +               if (dom->ctrl_comp == comp)
>                          return dom;
>          }
>  
> @@ -1914,6 +1929,7 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
>  {
>          struct mpam_resctrl_res *res;
>          enum resctrl_res_level rid;
> +       struct mpam_component *comp;
>  
>          guard(mutex)(&domain_list_lock);
>          for_each_mpam_resctrl_control(res, rid) {
> @@ -1924,30 +1940,40 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
>                  if (!res->class)
>                          continue;       // dummy_resource;
>  
> -               if (r->alloc_capable) {
> -                       for_each_resource_ctrl(ctrl, r) {
> -                               dom = mpam_resctrl_get_ctrl_domain_from_cpu(cpu, ctrl);
> -                               if (!dom) {
> -                                       dom = mpam_resctrl_alloc_ctrl_domain(cpu, res, ctrl);
> +               guard(srcu)(&mpam_srcu);
> +               list_for_each_entry_srcu(comp, &res->class->components, class_list,
> +                                        srcu_read_lock_held(&mpam_srcu)) {
> +                       if (!cpumask_test_cpu(cpu, &comp->affinity))
> +                               continue;
> +
> +                       if (r->alloc_capable) {
> +                               for_each_resource_ctrl(ctrl, r) {
> +                                       dom = mpam_resctrl_get_ctrl_domain_from_cpu(cpu, res,
> +                                                                                   ctrl, comp);
> +                                       if (!dom) {
> +                                               dom = mpam_resctrl_alloc_ctrl_domain(cpu, res,
> +                                                                                    ctrl, comp);
> +                                       } else {
> +                                               struct rdt_ctrl_domain *ctrl_d =
> +                                                       &dom->resctrl_ctrl_dom;
> +
> +                                               mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
> +                                       }
>                                          if (IS_ERR(dom))
>                                                  return PTR_ERR(dom);
> +                               }
> +                       }
> +                       if (r->mon_capable) {
> +                               dom = mpam_resctrl_get_mon_domain_from_cpu(cpu, res, comp);
> +                               if (!dom) {
> +                                       dom = mpam_resctrl_alloc_mon_domain(cpu, res, comp);
>                                  } else {
> -                                       struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
> +                                       struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
>  
> -                                       mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
> +                                       mpam_resctrl_online_domain_hdr(cpu, &mon_d->hdr);
>                                  }
> -                       }
> -               }
> -               if (r->mon_capable) {
> -                       dom = mpam_resctrl_get_mon_domain_from_cpu(cpu, res);
> -                       if (!dom) {
> -                               dom = mpam_resctrl_alloc_mon_domain(cpu, res);
>                                  if (IS_ERR(dom))
>                                          return PTR_ERR(dom);
> -                       } else {
> -                               struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
> -
> -                               mpam_resctrl_online_domain_hdr(cpu, &mon_d->hdr);
>                          }
>                  }
>          }
> @@ -1961,6 +1987,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
>  {
>          struct mpam_resctrl_res *res;
>          enum resctrl_res_level rid;
> +       struct mpam_component *comp;
>  
>          resctrl_offline_cpu(cpu);
>  
> @@ -1976,31 +2003,41 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
>                  if (!res->class)
>                          continue;       // dummy resource
>  
> -               if (r->alloc_capable) {
> -                       for_each_resource_ctrl(ctrl, r) {
> -                               dom = mpam_resctrl_get_ctrl_domain_from_cpu(cpu, ctrl);
> +               guard(srcu)(&mpam_srcu);
> +               list_for_each_entry_srcu(comp, &res->class->components, class_list,
> +                                        srcu_read_lock_held(&mpam_srcu)) {
> +                       if (!cpumask_test_cpu(cpu, &comp->affinity))
> +                               continue;
> +
> +                       if (r->alloc_capable) {
> +                               for_each_resource_ctrl(ctrl, r) {
> +                                       dom = mpam_resctrl_get_ctrl_domain_from_cpu(cpu, res,
> +                                                                                   ctrl, comp);
> +                                       if (WARN_ON_ONCE(!dom))
> +                                               continue;
> +                                       ctrl_d = &dom->resctrl_ctrl_dom;
> +                                       dom_empty = mpam_resctrl_offline_domain_hdr(cpu,
> +                                                                                   &ctrl_d->hdr);
> +                                       if (dom_empty) {
> +                                               resctrl_offline_ctrl_domain(&res->resctrl_res, ctrl,
> +                                                                           ctrl_d);
> +                                               kfree(dom);
> +                                       }
> +                               }
> +                       }
> +
> +                       if (r->mon_capable) {
> +                               dom = mpam_resctrl_get_mon_domain_from_cpu(cpu, res, comp);
>                                  if (WARN_ON_ONCE(!dom))
>                                          continue;
> -                               ctrl_d = &dom->resctrl_ctrl_dom;
> -                               dom_empty = mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
> +                               mon_d = &dom->resctrl_mon_dom;
> +                               dom_empty = mpam_resctrl_offline_domain_hdr(cpu, &mon_d->hdr);
>                                  if (dom_empty) {
> -                                       resctrl_offline_ctrl_domain(&res->resctrl_res, ctrl, ctrl_d);
> +                                       resctrl_offline_mon_domain(&res->resctrl_res, &mon_d->hdr);
>                                          kfree(dom);
>                                  }
>                          }
>                  }
> -
> -               if (r->mon_capable) {
> -                       dom = mpam_resctrl_get_mon_domain_from_cpu(cpu, res);
> -                       if (WARN_ON_ONCE(!dom))
> -                               continue;
> -                       mon_d = &dom->resctrl_mon_dom;
> -                       dom_empty = mpam_resctrl_offline_domain_hdr(cpu, &mon_d->hdr);
> -                       if (dom_empty) {
> -                               resctrl_offline_mon_domain(&res->resctrl_res, &mon_d->hdr);
> -                               kfree(dom);
> -                       }
> -               }
>          }
>  }
>  
> diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
> index 4bc7090ad0c7..77a2f2e877a6 100644
> --- a/fs/resctrl/ctrlmondata.c
> +++ b/fs/resctrl/ctrlmondata.c
> @@ -359,6 +359,7 @@ static const char * const resctrl_ctrl_name[] = {
>          [RESCTRL_CTRL_NAME_DEF]         = "",
>          [RESCTRL_CTRL_NAME_MIN]         = "MIN",
>          [RESCTRL_CTRL_NAME_MAX]         = "MAX",
> +       [RESCTRL_CTRL_NAME_NODE]        = "NODE",
>          [RESCTRL_CTRL_NAME_REGION0_MIN]         = "REGION0_MIN",
>          [RESCTRL_CTRL_NAME_REGION0_MAX]         = "REGION0_MAX",
>  };
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 195c0948b26d..3c4675656b51 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
> @@ -398,6 +398,8 @@ struct resctrl_mon {
>   *                             has the same name as the resource.
>   * @RESCTRL_CTRL_NAME_MIN:     "MIN"
>   * @RESCTRL_CTRL_NAME_MAX:     "MAX"
> + * @RESCTRL_CTRL_NAME_NODE:    "NODE". With resource name "MB" the schemata
> + *                             line is "MB_NODE".
>   * @RESCTRL_CTRL_NAME_REGION0_MIN:     "REGION0_MIN"
>   * @RESCTRL_CTRL_NAME_REGION0_MAX:     "REGION0_MAX"
>   */
> @@ -405,6 +407,7 @@ enum resctrl_ctrl_name {
>          RESCTRL_CTRL_NAME_DEF,
>          RESCTRL_CTRL_NAME_MIN,
>          RESCTRL_CTRL_NAME_MAX,
> +       RESCTRL_CTRL_NAME_NODE,
>          RESCTRL_CTRL_NAME_REGION0_MIN,
>          RESCTRL_CTRL_NAME_REGION0_MAX,
>          RESCTRL_CTRL_NAME_LAST = RESCTRL_CTRL_NAME_REGION0_MAX
> --
> 2.53.0



More information about the linux-arm-kernel mailing list