Re: [PATCH v12 09/26] x86/resctrl: Introduce interface to display number of monitoring counters

Moger, Babu
2025-04-14T20:12:46Z

Hi Reinette,

On 4/11/25 16:01, Reinette Chatre wrote:
> Hi Babu,
>
> On 4/3/25 5:18 PM, Babu Moger wrote:
>> The mbm_cntr_assign mode provides an option to the user to assign a
>> counter to an RMID, event pair and monitor the bandwidth as long as
>> the counter is assigned. Number of assignments depend on number of
>> monitoring counters available.
>>
>> Provide the interface to display the number of monitoring counters
>
> An interface can also be a function. To help make this work obvious
> it can be specific:
>
> Create 'num_mbm_cntrs' resctrl file that displays the number of
> monitoring counters supported in each domain. 'num_mbm_cntrs'
> is only visible to user space when the system supports
> mbm_cntr_assign mode.

ok. Sure.

>
>> supported in each domain. The resctrl file 'num_mbm_cntrs' is visible
>> to user space when the system supports mbm_cntr_assign mode.
>>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
> ...
>
>> ---
>> Documentation/arch/x86/resctrl.rst | 11 ++++++++++
>> arch/x86/kernel/cpu/resctrl/monitor.c | 3 +++
>> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++++++++++++++++++++++++++
>> 3 files changed, 44 insertions(+)
>>
>> diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
>> index bb96b44019fe..35d908befdfb 100644
>> --- a/Documentation/arch/x86/resctrl.rst
>> +++ b/Documentation/arch/x86/resctrl.rst
>> @@ -284,6 +284,17 @@ with the following files:
>> misleading values or display "Unavailable" if no counter is assigned
>> to the event.
>>
>> +"num_mbm_cntrs":
>> + The maximum number of monitoring counters (total of available and assigned
>> + counters) in each domain when the system supports mbm_cntr_assign mode.
>> +
>> + For example, on a system with maximum of 32 memory bandwidth monitoring
>> + counters in each of its L3 domains:
>> + ::
>> +
>> + # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
>> + 0=32;1=32
>> +
>> "max_threshold_occupancy":
>> Read/write file provides the largest value (in
>> bytes) at which a previously used LLC_occupancy
>> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c
>> index 6ed7e51d3fdb..028b49878ad0 100644
>> --- a/arch/x86/kernel/cpu/resctrl/monitor.c
>> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c
>> @@ -1234,6 +1234,9 @@ int __init resctrl_mon_resource_init(void)
>> else if (resctrl_arch_is_mbm_total_enabled())
>> mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
>>
>> + if (r->mon.mbm_cntr_assignable)
>> + resctrl_file_fflags_init("num_mbm_cntrs", RFTYPE_MON_INFO);
>
> Missing RFTYPE_RES_CACHE?

Please see my response here.

https://lore.kernel.org/lkml/4fc02936-237d-4060-86af-79efc28a72e5@amd.com/

>
>> +
>> return 0;
>> }
>>
>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> index 626be6becca7..0c9d7a702b93 100644
>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> @@ -912,6 +912,30 @@ static int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of,
>> return 0;
>> }
>>
>> +static int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
>> + struct seq_file *s, void *v)
>> +{
>> + struct rdt_resource *r = of->kn->parent->priv;
>> + struct rdt_mon_domain *dom;
>> + bool sep = false;
>> +
>> + cpus_read_lock();
>> + mutex_lock(&rdtgroup_mutex);
>> +
>> + list_for_each_entry(dom, &r->mon_domains, hdr.list) {
>> + if (sep)
>> + seq_puts(s, ";");
>
> seq_putc() can be used.
>
Sure.

>> +
>> + seq_printf(s, "%d=%d", dom->hdr.id, r->mon.num_mbm_cntrs);
>> + sep = true;
>> + }
>> + seq_puts(s, "\n");
>
> seq_putc() can be used.

Sure.

>
>> +
>> + mutex_unlock(&rdtgroup_mutex);
>> + cpus_read_unlock();
>> + return 0;
>> +}
>> +
>> #ifdef CONFIG_PROC_CPU_RESCTRL
>>
>> /*
>> @@ -1945,6 +1969,12 @@ static struct rftype res_common_files[] = {
>> .seq_show = resctrl_mbm_assign_mode_show,
>> .fflags = RFTYPE_MON_INFO,
>> },
>> + {
>> + .name = "num_mbm_cntrs",
>> + .mode = 0444,
>> + .kf_ops = &rdtgroup_kf_single_ops,
>> + .seq_show = resctrl_num_mbm_cntrs_show,
>> + },
>> {
>> .name = "cpus",
>> .mode = 0644,
>
> Reinette
>

--
Thanks
Babu Moger