Hi Babu, On 7/8/25 3:17 PM, Babu Moger wrote: > Enable the mbm_l3_assignments resctrl file to be used to modify counter > assignments of CTRL_MON and MON groups when the "mbm_event" counter > assignment mode is enabled. > > The assignment modifications are done in the following format: > <Event>:<Domain id>=<Assignment state> > > Event: A valid MBM event in the > /sys/fs/resctrl/info/L3_MON/event_configs directory. > > Domain ID: A valid domain ID. When writing, '*' applies the changes > to all domains. > > Assignment states: > > _ : Unassign the counter. "the counter" -> "a counter" (user cannot control which counter is assigned) > > e : Assign the counter exclusively. "the counter" -> "a counter" > > Examples: > > $ cd /sys/fs/resctrl > $ cat /sys/fs/resctrl/mbm_L3_assignments > mbm_total_bytes:0=e;1=e > mbm_local_bytes:0=e;1=e > > To unassign the counter associated with the mbm_total_bytes event on > domain 0: > > $ echo "mbm_total_bytes:0=_" > mbm_L3_assignments > $ cat /sys/fs/resctrl/mbm_L3_assignments > mbm_total_bytes:0=_;1=e > mbm_local_bytes:0=e;1=e > > To unassign the counter associated with the mbm_total_bytes event on > all the domains: > > $ echo "mbm_total_bytes:*=_" > mbm_L3_assignments > $ cat /sys/fs/resctrl/mbm_L3_assignments > mbm_total_bytes:0=_;1=_ > mbm_local_bytes:0=e;1=e > > Signed-off-by: Babu Moger <babu.moger@xxxxxxx> > --- ... > --- > Documentation/filesystems/resctrl.rst | 146 +++++++++++++++++++++++++- > fs/resctrl/internal.h | 2 + > fs/resctrl/monitor.c | 18 ++++ > fs/resctrl/rdtgroup.c | 123 +++++++++++++++++++++- > 4 files changed, 287 insertions(+), 2 deletions(-) > > diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst > index 4dd1d605d6ad..2b2acb55d8b1 100644 > --- a/Documentation/filesystems/resctrl.rst > +++ b/Documentation/filesystems/resctrl.rst > @@ -527,7 +527,8 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain: > Event: A valid MBM event in the > /sys/fs/resctrl/info/L3_MON/event_configs directory. > > - Domain ID: A valid domain ID. > + Domain ID: A valid domain ID. When writing, '*' applies the changes > + to all the domains. > > Assignment states: > > @@ -544,6 +545,34 @@ When the "mba_MBps" mount option is used all CTRL_MON groups will also contain: > mbm_total_bytes:0=e;1=e > mbm_local_bytes:0=e;1=e > > + Assignments can be modified by writing to the interface. > + > + Example: > + To unassign the counter associated with the mbm_total_bytes event on domain 0: > + :: > + > + # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments > + # cat /sys/fs/resctrl/mbm_L3_assignments > + mbm_total_bytes:0=_;1=e > + mbm_local_bytes:0=e;1=e > + > + To unassign the counter associated with the mbm_total_bytes event on all the domains: > + :: > + > + # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments > + # cat /sys/fs/resctrl/mbm_L3_assignments > + mbm_total_bytes:0=_;1=_ > + mbm_local_bytes:0=e;1=e > + > + To assign the counter associated with the mbm_total_bytes event on all domains in "the counter" -> "a counter" (motivation: user space cannot control which counter is assigned) > + exclusive mode: > + :: > + > + # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments > + # cat /sys/fs/resctrl/mbm_L3_assignments > + mbm_total_bytes:0=e;1=e > + mbm_local_bytes:0=e;1=e > + > Resource allocation rules > ------------------------- > > @@ -1579,6 +1608,121 @@ View the llc occupancy snapshot:: > # cat /sys/fs/resctrl/p1/mon_data/mon_L3_00/llc_occupancy > 11234000 > > + > +Examples on working with mbm_assign_mode > +======================================== > + > +a. Check if MBM counter assignment mode is supported. > +:: > + > + #mount -t resctrl resctrl /sys/fs/resctrl/ "#mount" -> "# mount" (please build htmldocs to confirm everything looks consistent) > + > + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode > + [mbm_event] > + default > + > +The "mbm_event" mode is detected and enabled. > + > +b. Check how many assignable counters are supported. > +:: > + > + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs > + 0=32;1=32 > + > +c. Check how many assignable counters are available for assignment in each domain. > +:: > + > + # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs > + 0=30;1=30 > + > +d. To list the default group's assign states: Please note that these steps are inconsistent. Some end with "." and some end with ":" > +:: > + > + # cat /sys/fs/resctrl/mbm_L3_assignments > + mbm_total_bytes:0=e;1=e > + mbm_local_bytes:0=e;1=e > + > +e. To unassign the counter associated with the mbm_total_bytes event on domain 0: > +:: > + > + # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments > + # cat /sys/fs/resctrl/mbm_L3_assignments > + mbm_total_bytes:0=_;1=e > + mbm_local_bytes:0=e;1=e > + > +f. To unassign the counter associated with the mbm_total_bytes event on all domains: > +:: > + > + # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments > + # cat /sys/fs/resctrl/mbm_L3_assignment > + mbm_total_bytes:0=_;1=_ > + mbm_local_bytes:0=e;1=e > + > +g. To assign a counter associated with the mbm_total_bytes event on all domains in ah ... here "a counter" is used. > +exclusive mode: > +:: > + > + # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments > + # cat /sys/fs/resctrl/mbm_L3_assignments > + mbm_total_bytes:0=e;1=e > + mbm_local_bytes:0=e;1=e > + > +h. Read the events mbm_total_bytes and mbm_local_bytes of the default group. There is > +no change in reading the events with the assignment. If the event is unassigned when > +reading, then the read will come back as "Unassigned". Since returning "Unassigned" can be complicated, the associated description should probably just be done once in the doc. I expect this will be in the "mon_data" section. > +:: > + > + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_total_bytes > + 779247936 > + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes > + 765207488 > + > +i. Check the default event configurations. Drop "default" (there are only these event configurations) > +:: > + > + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_total_bytes/event_filter > + local_reads,remote_reads,local_non_temporal_writes,remote_non_temporal_writes, > + local_reads_slow_memory,remote_reads_slow_memory,dirty_victim_writes_all > + > + # cat /sys/fs/resctrl/info/L3_MON/event_configs/mbm_local_bytes/event_filter > + local_reads,local_non_temporal_writes,local_reads_slow_memory > + > +j. Change the event configuration for mbm_local_bytes. > +:: > + > + # echo "local_reads, local_non_temporal_writes, local_reads_slow_memory, remote_reads" > > + /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter "counter_configs" -> "event_configs" (this was also an issue in previous series, please use grep to ensure all are fixed) > + > + # cat /sys/fs/resctrl/info/L3_MON/counter_configs/mbm_local_bytes/event_filter "counter_configs" -> "event_configs" > + local_reads,local_non_temporal_writes,local_reads_slow_memory,remote_reads > + > +This will update all (across all domains of all monitor groups) counter assignments > +associated with the mbm_local_bytes event. > + > +k. Now read the local event again. The first read may come back with "Unavailable" > +status. The subsequent read of mbm_local_bytes will display the current value. > +:: > + > + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes > + Unavailable > + # cat /sys/fs/resctrl/mon_data/mon_L3_00/mbm_local_bytes > + 314101 > + > +l. Users have the option to go back to 'default' mbm_assign_mode if required. This can be > +done using the following command. Note that switching the mbm_assign_mode may reset all > +the MBM counters (and thus all MBM events) of all the resctrl groups. > +:: > + > + # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode > + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode > + mbm_event > + [default] > + > +m. Unmount the resctrl "Unmount the resctrl" -> "Unmount resctrl" or "Unmount the resctrl filesystem"? > +:: > + > + #umount /sys/fs/resctrl/ "#umount" -> "# umount" > + > Intel RDT Errata > ================ > > diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h > index b42890fd937a..9881674909f2 100644 > --- a/fs/resctrl/internal.h > +++ b/fs/resctrl/internal.h > @@ -403,6 +403,8 @@ bool closid_allocated(unsigned int closid); > > int resctrl_find_cleanest_closid(void); > > +struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r, char *name); > + > int rdtgroup_assign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, > struct mon_evt *mevt); > void rdtgroup_unassign_cntr_event(struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, > diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c > index e30a867c00bb..61419849b257 100644 > --- a/fs/resctrl/monitor.c > +++ b/fs/resctrl/monitor.c > @@ -1220,3 +1220,21 @@ void resctrl_update_cntr_allrdtgrp(struct mon_evt *mevt) > rdtgroup_update_cntr_event(r, crgrp, mevt->evtid); > } > } > + > +/* > + * mbm_get_mon_event_by_name() - Return the mon_evt entry for the matching > + * event name. > + */ > +struct mon_evt *mbm_get_mon_event_by_name(struct rdt_resource *r, char *name) > +{ > + struct mon_evt *mevt; > + > + for_each_mon_event(mevt) { > + if (mevt->rid == r->rid && mevt->enabled && > + resctrl_is_mbm_event(mevt->evtid) && > + !strcmp(mevt->name, name)) > + return mevt; > + } > + > + return NULL; > +} > diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c > index dc108c5db298..b26baca389bb 100644 > --- a/fs/resctrl/rdtgroup.c > +++ b/fs/resctrl/rdtgroup.c > @@ -2071,6 +2071,126 @@ static int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file > return ret; > } > > +static int rdtgroup_modify_assign_state(char *assign, struct rdt_mon_domain *d, Please move to monitor.c > + struct rdtgroup *rdtgrp, struct mon_evt *mevt) > +{ > + int ret = 0; > + > + if (!assign || strlen(assign) != 1) > + return -EINVAL; > + > + switch (*assign) { > + case 'e': > + ret = rdtgroup_assign_cntr_event(d, rdtgrp, mevt); This patch enables the user to assign counters to multiple events in a single write. Looking at this flow: rdtgroup_assign_cntr_event()->rdtgroup_alloc_config_cntr() may thus be called on the same domain but for different events in a single write from user space. I thus think that the error message in rdtgroup_alloc_config_cntr() should not just contain the domain ID, but also the event *name* (not the ID since user space cannot be expect to understand if). considering this it seems that @mevt can be passed through to rdtgroup_alloc_config_cntr() instead of just the event ID to support this? > + break; > + case '_': > + rdtgroup_unassign_cntr_event(d, rdtgrp, mevt); > + break; > + default: > + ret = -EINVAL; Please add a "break". > + } > + > + return ret; > +} > + > +static int resctrl_process_assign(struct rdt_resource *r, struct rdtgroup *rdtgrp, Please move to monitor.c and rename to be more specific. For example, resctrl_parse_mbm_assignment()? Open to ideas. > + char *event, char *tok) > +{ > + struct rdt_mon_domain *d; > + unsigned long dom_id = 0; > + char *dom_str, *id_str; > + struct mon_evt *mevt; > + int ret; > + > + mevt = mbm_get_mon_event_by_name(r, event); > + if (!mevt) { > + rdt_last_cmd_printf("Invalid event %s\n", event); > + return -ENOENT; > + } > + > +next: > + if (!tok || tok[0] == '\0') > + return 0; > + > + /* Start processing the strings for each domain */ > + dom_str = strim(strsep(&tok, ";")); > + > + id_str = strsep(&dom_str, "="); > + > + /* Check for domain id '*' which means all domains */ > + if (id_str && *id_str == '*') { > + ret = rdtgroup_modify_assign_state(dom_str, NULL, rdtgrp, mevt); > + if (ret) > + rdt_last_cmd_printf("Assign operation '%s:*=%s' failed\n", > + event, dom_str); > + return ret; > + } else if (!id_str || kstrtoul(id_str, 10, &dom_id)) { > + rdt_last_cmd_puts("Missing domain id\n"); > + return -EINVAL; > + } > + > + /* Verify if the dom_id is valid */ > + list_for_each_entry(d, &r->mon_domains, hdr.list) { > + if (d->hdr.id == dom_id) { > + ret = rdtgroup_modify_assign_state(dom_str, d, rdtgrp, mevt); > + if (ret) { > + rdt_last_cmd_printf("Assign operation '%s:%ld=%s' failed\n", > + event, dom_id, dom_str); > + return ret; > + } > + goto next; > + } > + } > + > + rdt_last_cmd_printf("Invalid domain id %ld\n", dom_id); > + return -EINVAL; > +} > + Reinette