Hi Babu, On 6/13/25 2:05 PM, Babu Moger wrote: > The "mbm_event" mode offers "num_mbm_cntrs" number of counters that can be "The "mbm_event" mode" -> "The "mbm_event" counter assignment mode"? > assigned to RMID, event pairs and monitor bandwidth usage as long as it is > assigned. If all the counters are in use, the kernel logs the error message > "Unable to allocate counter in domain" in > /sys/fs/resctrl/info/last_cmd_status when a new assignment is requested. > > To make space for a new assignment, users must unassign an already > assigned counter and retry the assignment again. > > Add the functionality to unassign and free the counters in the domain. > > Signed-off-by: Babu Moger <babu.moger@xxxxxxx> > --- ... > --- > fs/resctrl/internal.h | 2 ++ > fs/resctrl/monitor.c | 47 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 49 insertions(+) > > diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h > index 0767a1c46f26..4496c359ac22 100644 > --- a/fs/resctrl/internal.h > +++ b/fs/resctrl/internal.h > @@ -388,6 +388,8 @@ int resctrl_find_cleanest_closid(void); > > int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > struct rdtgroup *rdtgrp, struct mon_evt *mevt); > +void resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > + struct rdtgroup *rdtgrp, struct mon_evt *mevt); > > #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK > int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); > diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c > index 38800fe45931..f2636aea6545 100644 > --- a/fs/resctrl/monitor.c > +++ b/fs/resctrl/monitor.c > @@ -1016,6 +1016,14 @@ static int mbm_cntr_alloc(struct rdt_resource *r, struct rdt_mon_domain *d, > return -ENOSPC; > } > > +/** > + * mbm_cntr_free() - Clear the counter ID configuration details in the domain @d. > + */ > +static void mbm_cntr_free(struct rdt_mon_domain *d, int cntr_id) > +{ > + memset(&d->cntr_cfg[cntr_id], 0, sizeof(struct mbm_cntr_cfg)); sizeof(struct mbm_cntr_cfg) -> sizeof(*d->cntr_cfg[0]) > +} > + > /** > * resctrl_alloc_config_cntr() - Allocate a counter ID and configure it for the > * event pointed to by @mevt and the resctrl group @rdtgrp within the domain @d. > @@ -1084,3 +1092,42 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > > return ret; > } > + > +/** > + * resctrl_free_config_cntr() - Unassign and reset the counter ID configuration > + * for the event pointed to by @mevt within the domain @d and resctrl group @rdtgrp. > + */ > +static void resctrl_free_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, > + struct rdtgroup *rdtgrp, struct mon_evt *mevt) > +{ > + int cntr_id; > + > + cntr_id = mbm_cntr_get(r, d, rdtgrp, mevt->evtid); > + > + /* If there is no cntr_id assigned, nothing to do */ > + if (cntr_id < 0) > + return; > + > + resctrl_config_cntr(r, d, mevt->evtid, rdtgrp->mon.rmid, rdtgrp->closid, > + cntr_id, false); > + > + mbm_cntr_free(d, cntr_id); > + > + return; No need for this return. > +} > + > +/** > + * resctrl_unassign_cntr_event() - Unassign a hardware counter associated with > + * the event structure @mevt from the domain @d and the group @rdtgrp. Unassign > + * the counters from all the domains if @d is NULL else unassign from @d. > + */ > +void resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > + struct rdtgroup *rdtgrp, struct mon_evt *mevt) > +{ > + if (!d) { > + list_for_each_entry(d, &r->mon_domains, hdr.list) > + resctrl_free_config_cntr(r, d, rdtgrp, mevt); > + } else { > + resctrl_free_config_cntr(r, d, rdtgrp, mevt); > + } > +} Reinette