Hi Babu, On 5/15/25 3:51 PM, Babu Moger wrote: > The mbm_cntr_assign mode offers "num_mbm_cntrs" number of counters that > can be assigned to an RMID, event pair and monitor the bandwidth as long > as it is assigned. If all the counters are in use, the kernel will log 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 | 60 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 62 insertions(+) > > diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h > index ce4fcac91937..64ddc107fcab 100644 > --- a/fs/resctrl/internal.h > +++ b/fs/resctrl/internal.h > @@ -379,6 +379,8 @@ int resctrl_find_cleanest_closid(void); > > int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > struct rdtgroup *rdtgrp, enum resctrl_event_id evtid); > +int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid); > > #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 d76fd0840946..fbc938bd3b23 100644 > --- a/fs/resctrl/monitor.c > +++ b/fs/resctrl/monitor.c > @@ -989,6 +989,14 @@ static int mbm_cntr_alloc(struct rdt_resource *r, struct rdt_mon_domain *d, > return -ENOSPC; > } > > +/* > + * mbm_cntr_free() - Reset cntr_id to zero. "Reset cntr_id to zero"? cntr_id is an index to an array. Please provide accurate and useful descriptions. > + */ > +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)); > +} > + > /* > * mbm_get_mon_event() - Return the mon_evt entry for the matching evtid. > */ > @@ -1068,3 +1076,55 @@ int resctrl_assign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > > return ret; > } > + > +/* > + * Unassign and free the counter if assigned. > + */ > +static int resctrl_free_config_cntr(struct rdt_resource *r, struct rdt_mon_domain *d, > + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) > +{ > + struct mon_evt *mevt; > + int cntr_id; > + > + cntr_id = mbm_cntr_get(r, d, rdtgrp, evtid); > + > + /* If there is no cntr_id assigned, nothing to do */ > + if (cntr_id < 0) > + return 0; > + > + mevt = mbm_get_mon_event(r, evtid); > + if (!mevt) { > + rdt_last_cmd_printf("Invalid event id %d\n", evtid); Similar to previous comment this is in kernel bug territory and could be simplified by passing mon_evt instead. Although this is the unassign portion where evt_cfg seems unnecessary. > + return -EINVAL; > + } > + > + resctrl_config_cntr(r, d, evtid, rdtgrp->mon.rmid, rdtgrp->closid, > + cntr_id, mevt->evt_cfg, false); > + > + mbm_cntr_free(d, cntr_id); > + > + return 0; > +} > + > +/* > + * Unassign a hardware counter associated with @evtid from the domain and > + * the group. Unassign the counters from all the domains if @d is NULL else > + * unassign from @d. > + */ > +int resctrl_unassign_cntr_event(struct rdt_resource *r, struct rdt_mon_domain *d, > + struct rdtgroup *rdtgrp, enum resctrl_event_id evtid) > +{ > + int ret; > + > + if (!d) { > + list_for_each_entry(d, &r->mon_domains, hdr.list) { > + ret = resctrl_free_config_cntr(r, d, rdtgrp, evtid); > + if (ret) > + return ret; > + } > + } else { > + ret = resctrl_free_config_cntr(r, d, rdtgrp, evtid); > + } > + > + return ret; > +} Reinette