[RFC,3/3] x86/resctrl: Display the RMID and COSID for resctrl groups

Message ID 167278361325.34228.16916982678071203069.stgit@bmoger-ubuntu
State New
Headers
Series x86/resctrl: Miscellaneous resctrl features |

Commit Message

Moger, Babu Jan. 3, 2023, 10:06 p.m. UTC
  When a user creates a control or monitor group, the CLOSID or RMID
are not visible to the user. These are architecturally defined entities.
There is no harm in displaying these in resctrl groups. Sometimes it
can help to debug the issues.

Add CLOSID and RMID to the control/monitor groups display in resctrl
interface.

  $cat /sys/fs/resctrl/clos1/closid
  1
  $cat /sys/fs/resctrl/mon_groups/mon1/rmid
  3

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
 Documentation/x86/resctrl.rst          |   15 ++++++++++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |   46 ++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
  

Comments

Fenghua Yu Jan. 4, 2023, 6:06 a.m. UTC | #1
Hi, Babu,

> When a user creates a control or monitor group, the CLOSID or RMID are not
> visible to the user. These are architecturally defined entities.
> There is no harm in displaying these in resctrl groups. Sometimes it can help to
> debug the issues.
Although "no harm" to show them, it's not useful for generic user either and may
cause confusion sometimes. CLOSID and RMID are supposed to be invisible to
generic users.

Maybe introduce a new resctrl mount option called "debug" and show the files
and maybe other future debug info only in debug mode?

> 
> Add CLOSID and RMID to the control/monitor groups display in resctrl interface.
> 
>   $cat /sys/fs/resctrl/clos1/closid
>   1
>   $cat /sys/fs/resctrl/mon_groups/mon1/rmid
>   3
> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> ---
>  Documentation/x86/resctrl.rst          |   15 ++++++++++
>  arch/x86/kernel/cpu/resctrl/rdtgroup.c |   46
> ++++++++++++++++++++++++++++++++
>  2 files changed, 61 insertions(+)
> 
> diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst
> index f26e16412bcb..8520514bc8b5 100644
> --- a/Documentation/x86/resctrl.rst
> +++ b/Documentation/x86/resctrl.rst
> @@ -231,6 +231,14 @@ All groups contain the following files:
>  	Just like "cpus", only using ranges of CPUs instead of bitmasks.
> 
> 
> +"rmid":
> +	Reading this file shows the resource monitoring id (RMID) for
> +	monitoring the resource utilization. Monitoring is performed by
> +	tagging each core(or thread) or process via a Resource Monitoring
> +	ID (RMID). Kernel assigns a new RMID when a group is created
> +	depending on the available RMIDs. Multiple cores(or threads) or
> +	processes can share a same RMID in a resctrl domain.
> +
>  When control is enabled all CTRL_MON groups will also contain:
> 
>  "schemata":
> @@ -252,6 +260,13 @@ When control is enabled all CTRL_MON groups will
> also contain:
>  	file. On successful pseudo-locked region creation the mode will
>  	automatically change to "pseudo-locked".
> 
> +"closid":
> +	Reading this file shows the Class of Service (CLOS) id which acts
> +	as a resource control tag on which the resources can be throttled.
> +	Kernel assigns a new CLOSID a control group is created depending
> +	on the available CLOSIDs. Multiple cores(or threads) or processes
> +	can share a same CLOSID in a resctrl domain.
> +
>  When monitoring is enabled all MON groups will also contain:
> 
>  "mon_data":
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index 0d71ed22cfa9..98b4798e5cae 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -769,6 +769,38 @@ static int rdtgroup_tasks_show(struct kernfs_open_file
> *of,
>  	return ret;
>  }
> 
> +static int rdtgroup_closid_show(struct kernfs_open_file *of,
> +				struct seq_file *s, void *v)
> +{
> +	struct rdtgroup *rdtgrp;
> +	int ret = 0;
> +
> +	rdtgrp = rdtgroup_kn_lock_live(of->kn);
> +	if (rdtgrp)
> +		seq_printf(s, "%u\n", rdtgrp->closid);
> +	else
> +		ret = -ENOENT;
> +	rdtgroup_kn_unlock(of->kn);
> +
> +	return ret;
> +}
> +
> +static int rdtgroup_rmid_show(struct kernfs_open_file *of,
> +			      struct seq_file *s, void *v)
> +{
> +	struct rdtgroup *rdtgrp;
> +	int ret = 0;
> +
> +	rdtgrp = rdtgroup_kn_lock_live(of->kn);
> +	if (rdtgrp)
> +		seq_printf(s, "%u\n", rdtgrp->mon.rmid);
> +	else
> +		ret = -ENOENT;
> +	rdtgroup_kn_unlock(of->kn);
> +
> +	return ret;
> +}
> +
>  #ifdef CONFIG_PROC_CPU_RESCTRL
> 
>  /*
> @@ -1593,6 +1625,20 @@ static struct rftype res_common_files[] = {
>  		.seq_show	= rdtgroup_size_show,
>  		.fflags		= RF_CTRL_BASE,
>  	},
> +	{
> +		.name		= "closid",
> +		.mode		= 0444,
> +		.kf_ops		= &rdtgroup_kf_single_ops,
> +		.seq_show	= rdtgroup_closid_show,
> +		.fflags		= RF_CTRL_BASE,
> +	},
> +	{
> +		.name		= "rmid",
> +		.mode		= 0444,
> +		.kf_ops		= &rdtgroup_kf_single_ops,
> +		.seq_show	= rdtgroup_rmid_show,
> +		.fflags		= RFTYPE_BASE,
> +	},
> 
>  };
> 
> 
Thanks.

-Fenghua
  
Stephane Eranian Jan. 4, 2023, 6:45 a.m. UTC | #2
On Tue, Jan 3, 2023 at 10:06 PM Yu, Fenghua <fenghua.yu@intel.com> wrote:
>
> Hi, Babu,
>
> > When a user creates a control or monitor group, the CLOSID or RMID are not
> > visible to the user. These are architecturally defined entities.
> > There is no harm in displaying these in resctrl groups. Sometimes it can help to
> > debug the issues.
> Although "no harm" to show them, it's not useful for generic user either and may
> cause confusion sometimes. CLOSID and RMID are supposed to be invisible to
> generic users.
>
> Maybe introduce a new resctrl mount option called "debug" and show the files
> and maybe other future debug info only in debug mode?
>
On other non-x86 architectures, these have no meaning or no direct mapping.
Take ARM MPAM, it is called PARTID and it does not map to either RMID
or CLOSID, it is combined.
Why would you call this closid/rmid at the user level?
You could instead use a more generic name such as mon_hw_id,
ctrl_hw_id. And on ARM they would be the same.
Just my suggestion.


>
> >
> > Add CLOSID and RMID to the control/monitor groups display in resctrl interface.
> >
> >   $cat /sys/fs/resctrl/clos1/closid
> >   1
> >   $cat /sys/fs/resctrl/mon_groups/mon1/rmid
> >   3
> >
> > Signed-off-by: Babu Moger <babu.moger@amd.com>
> > ---
> >  Documentation/x86/resctrl.rst          |   15 ++++++++++
> >  arch/x86/kernel/cpu/resctrl/rdtgroup.c |   46
> > ++++++++++++++++++++++++++++++++
> >  2 files changed, 61 insertions(+)
> >
> > diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst
> > index f26e16412bcb..8520514bc8b5 100644
> > --- a/Documentation/x86/resctrl.rst
> > +++ b/Documentation/x86/resctrl.rst
> > @@ -231,6 +231,14 @@ All groups contain the following files:
> >       Just like "cpus", only using ranges of CPUs instead of bitmasks.
> >
> >
> > +"rmid":
> > +     Reading this file shows the resource monitoring id (RMID) for
> > +     monitoring the resource utilization. Monitoring is performed by
> > +     tagging each core(or thread) or process via a Resource Monitoring
> > +     ID (RMID). Kernel assigns a new RMID when a group is created
> > +     depending on the available RMIDs. Multiple cores(or threads) or
> > +     processes can share a same RMID in a resctrl domain.
> > +
> >  When control is enabled all CTRL_MON groups will also contain:
> >
> >  "schemata":
> > @@ -252,6 +260,13 @@ When control is enabled all CTRL_MON groups will
> > also contain:
> >       file. On successful pseudo-locked region creation the mode will
> >       automatically change to "pseudo-locked".
> >
> > +"closid":
> > +     Reading this file shows the Class of Service (CLOS) id which acts
> > +     as a resource control tag on which the resources can be throttled.
> > +     Kernel assigns a new CLOSID a control group is created depending
> > +     on the available CLOSIDs. Multiple cores(or threads) or processes
> > +     can share a same CLOSID in a resctrl domain.
> > +
> >  When monitoring is enabled all MON groups will also contain:
> >
> >  "mon_data":
> > diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > index 0d71ed22cfa9..98b4798e5cae 100644
> > --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> > @@ -769,6 +769,38 @@ static int rdtgroup_tasks_show(struct kernfs_open_file
> > *of,
> >       return ret;
> >  }
> >
> > +static int rdtgroup_closid_show(struct kernfs_open_file *of,
> > +                             struct seq_file *s, void *v)
> > +{
> > +     struct rdtgroup *rdtgrp;
> > +     int ret = 0;
> > +
> > +     rdtgrp = rdtgroup_kn_lock_live(of->kn);
> > +     if (rdtgrp)
> > +             seq_printf(s, "%u\n", rdtgrp->closid);
> > +     else
> > +             ret = -ENOENT;
> > +     rdtgroup_kn_unlock(of->kn);
> > +
> > +     return ret;
> > +}
> > +
> > +static int rdtgroup_rmid_show(struct kernfs_open_file *of,
> > +                           struct seq_file *s, void *v)
> > +{
> > +     struct rdtgroup *rdtgrp;
> > +     int ret = 0;
> > +
> > +     rdtgrp = rdtgroup_kn_lock_live(of->kn);
> > +     if (rdtgrp)
> > +             seq_printf(s, "%u\n", rdtgrp->mon.rmid);
> > +     else
> > +             ret = -ENOENT;
> > +     rdtgroup_kn_unlock(of->kn);
> > +
> > +     return ret;
> > +}
> > +
> >  #ifdef CONFIG_PROC_CPU_RESCTRL
> >
> >  /*
> > @@ -1593,6 +1625,20 @@ static struct rftype res_common_files[] = {
> >               .seq_show       = rdtgroup_size_show,
> >               .fflags         = RF_CTRL_BASE,
> >       },
> > +     {
> > +             .name           = "closid",
> > +             .mode           = 0444,
> > +             .kf_ops         = &rdtgroup_kf_single_ops,
> > +             .seq_show       = rdtgroup_closid_show,
> > +             .fflags         = RF_CTRL_BASE,
> > +     },
> > +     {
> > +             .name           = "rmid",
> > +             .mode           = 0444,
> > +             .kf_ops         = &rdtgroup_kf_single_ops,
> > +             .seq_show       = rdtgroup_rmid_show,
> > +             .fflags         = RFTYPE_BASE,
> > +     },
> >
> >  };
> >
> >
> Thanks.
>
> -Fenghua
  
Moger, Babu Jan. 4, 2023, 5:58 p.m. UTC | #3
Hi Fenghua,

On 1/4/23 00:06, Yu, Fenghua wrote:
> Hi, Babu,
>
>> When a user creates a control or monitor group, the CLOSID or RMID are not
>> visible to the user. These are architecturally defined entities.
>> There is no harm in displaying these in resctrl groups. Sometimes it can help to
>> debug the issues.
> Although "no harm" to show them, it's not useful for generic user either and may
> cause confusion sometimes. CLOSID and RMID are supposed to be invisible to
> generic users.
>
> Maybe introduce a new resctrl mount option called "debug" and show the files
> and maybe other future debug info only in debug mode?

Actually, test team feels very strongly about this. Whenever there is some
issue, first question is what is the rmid or closid are you running on? We
normally don't have an answer for that.

In my opinion, adding debug mode just for these two fields seems way overkill.

Thanks

Babu


>
>> Add CLOSID and RMID to the control/monitor groups display in resctrl interface.
>>
>>   $cat /sys/fs/resctrl/clos1/closid
>>   1
>>   $cat /sys/fs/resctrl/mon_groups/mon1/rmid
>>   3
>>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
>>  Documentation/x86/resctrl.rst          |   15 ++++++++++
>>  arch/x86/kernel/cpu/resctrl/rdtgroup.c |   46
>> ++++++++++++++++++++++++++++++++
>>  2 files changed, 61 insertions(+)
>>
>> diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst
>> index f26e16412bcb..8520514bc8b5 100644
>> --- a/Documentation/x86/resctrl.rst
>> +++ b/Documentation/x86/resctrl.rst
>> @@ -231,6 +231,14 @@ All groups contain the following files:
>>  	Just like "cpus", only using ranges of CPUs instead of bitmasks.
>>
>>
>> +"rmid":
>> +	Reading this file shows the resource monitoring id (RMID) for
>> +	monitoring the resource utilization. Monitoring is performed by
>> +	tagging each core(or thread) or process via a Resource Monitoring
>> +	ID (RMID). Kernel assigns a new RMID when a group is created
>> +	depending on the available RMIDs. Multiple cores(or threads) or
>> +	processes can share a same RMID in a resctrl domain.
>> +
>>  When control is enabled all CTRL_MON groups will also contain:
>>
>>  "schemata":
>> @@ -252,6 +260,13 @@ When control is enabled all CTRL_MON groups will
>> also contain:
>>  	file. On successful pseudo-locked region creation the mode will
>>  	automatically change to "pseudo-locked".
>>
>> +"closid":
>> +	Reading this file shows the Class of Service (CLOS) id which acts
>> +	as a resource control tag on which the resources can be throttled.
>> +	Kernel assigns a new CLOSID a control group is created depending
>> +	on the available CLOSIDs. Multiple cores(or threads) or processes
>> +	can share a same CLOSID in a resctrl domain.
>> +
>>  When monitoring is enabled all MON groups will also contain:
>>
>>  "mon_data":
>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> index 0d71ed22cfa9..98b4798e5cae 100644
>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> @@ -769,6 +769,38 @@ static int rdtgroup_tasks_show(struct kernfs_open_file
>> *of,
>>  	return ret;
>>  }
>>
>> +static int rdtgroup_closid_show(struct kernfs_open_file *of,
>> +				struct seq_file *s, void *v)
>> +{
>> +	struct rdtgroup *rdtgrp;
>> +	int ret = 0;
>> +
>> +	rdtgrp = rdtgroup_kn_lock_live(of->kn);
>> +	if (rdtgrp)
>> +		seq_printf(s, "%u\n", rdtgrp->closid);
>> +	else
>> +		ret = -ENOENT;
>> +	rdtgroup_kn_unlock(of->kn);
>> +
>> +	return ret;
>> +}
>> +
>> +static int rdtgroup_rmid_show(struct kernfs_open_file *of,
>> +			      struct seq_file *s, void *v)
>> +{
>> +	struct rdtgroup *rdtgrp;
>> +	int ret = 0;
>> +
>> +	rdtgrp = rdtgroup_kn_lock_live(of->kn);
>> +	if (rdtgrp)
>> +		seq_printf(s, "%u\n", rdtgrp->mon.rmid);
>> +	else
>> +		ret = -ENOENT;
>> +	rdtgroup_kn_unlock(of->kn);
>> +
>> +	return ret;
>> +}
>> +
>>  #ifdef CONFIG_PROC_CPU_RESCTRL
>>
>>  /*
>> @@ -1593,6 +1625,20 @@ static struct rftype res_common_files[] = {
>>  		.seq_show	= rdtgroup_size_show,
>>  		.fflags		= RF_CTRL_BASE,
>>  	},
>> +	{
>> +		.name		= "closid",
>> +		.mode		= 0444,
>> +		.kf_ops		= &rdtgroup_kf_single_ops,
>> +		.seq_show	= rdtgroup_closid_show,
>> +		.fflags		= RF_CTRL_BASE,
>> +	},
>> +	{
>> +		.name		= "rmid",
>> +		.mode		= 0444,
>> +		.kf_ops		= &rdtgroup_kf_single_ops,
>> +		.seq_show	= rdtgroup_rmid_show,
>> +		.fflags		= RFTYPE_BASE,
>> +	},
>>
>>  };
>>
>>
> Thanks.
>
> -Fenghua
  
Moger, Babu Jan. 4, 2023, 6:01 p.m. UTC | #4
Hi Stephane,

On 1/4/23 00:45, Stephane Eranian wrote:
> On Tue, Jan 3, 2023 at 10:06 PM Yu, Fenghua <fenghua.yu@intel.com> wrote:
>> Hi, Babu,
>>
>>> When a user creates a control or monitor group, the CLOSID or RMID are not
>>> visible to the user. These are architecturally defined entities.
>>> There is no harm in displaying these in resctrl groups. Sometimes it can help to
>>> debug the issues.
>> Although "no harm" to show them, it's not useful for generic user either and may
>> cause confusion sometimes. CLOSID and RMID are supposed to be invisible to
>> generic users.
>>
>> Maybe introduce a new resctrl mount option called "debug" and show the files
>> and maybe other future debug info only in debug mode?
>>
> On other non-x86 architectures, these have no meaning or no direct mapping.
> Take ARM MPAM, it is called PARTID and it does not map to either RMID
> or CLOSID, it is combined.
> Why would you call this closid/rmid at the user level?
> You could instead use a more generic name such as mon_hw_id,
> ctrl_hw_id. And on ARM they would be the same.
> Just my suggestion.

Sure. We can change the names to mon_hw_id and ctrl_hw_id.

Thanks

Babu


>
>
>>> Add CLOSID and RMID to the control/monitor groups display in resctrl interface.
>>>
>>>   $cat /sys/fs/resctrl/clos1/closid
>>>   1
>>>   $cat /sys/fs/resctrl/mon_groups/mon1/rmid
>>>   3
>>>
>>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>>> ---
>>>  Documentation/x86/resctrl.rst          |   15 ++++++++++
>>>  arch/x86/kernel/cpu/resctrl/rdtgroup.c |   46
>>> ++++++++++++++++++++++++++++++++
>>>  2 files changed, 61 insertions(+)
>>>
>>> diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst
>>> index f26e16412bcb..8520514bc8b5 100644
>>> --- a/Documentation/x86/resctrl.rst
>>> +++ b/Documentation/x86/resctrl.rst
>>> @@ -231,6 +231,14 @@ All groups contain the following files:
>>>       Just like "cpus", only using ranges of CPUs instead of bitmasks.
>>>
>>>
>>> +"rmid":
>>> +     Reading this file shows the resource monitoring id (RMID) for
>>> +     monitoring the resource utilization. Monitoring is performed by
>>> +     tagging each core(or thread) or process via a Resource Monitoring
>>> +     ID (RMID). Kernel assigns a new RMID when a group is created
>>> +     depending on the available RMIDs. Multiple cores(or threads) or
>>> +     processes can share a same RMID in a resctrl domain.
>>> +
>>>  When control is enabled all CTRL_MON groups will also contain:
>>>
>>>  "schemata":
>>> @@ -252,6 +260,13 @@ When control is enabled all CTRL_MON groups will
>>> also contain:
>>>       file. On successful pseudo-locked region creation the mode will
>>>       automatically change to "pseudo-locked".
>>>
>>> +"closid":
>>> +     Reading this file shows the Class of Service (CLOS) id which acts
>>> +     as a resource control tag on which the resources can be throttled.
>>> +     Kernel assigns a new CLOSID a control group is created depending
>>> +     on the available CLOSIDs. Multiple cores(or threads) or processes
>>> +     can share a same CLOSID in a resctrl domain.
>>> +
>>>  When monitoring is enabled all MON groups will also contain:
>>>
>>>  "mon_data":
>>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>>> b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>>> index 0d71ed22cfa9..98b4798e5cae 100644
>>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>>> @@ -769,6 +769,38 @@ static int rdtgroup_tasks_show(struct kernfs_open_file
>>> *of,
>>>       return ret;
>>>  }
>>>
>>> +static int rdtgroup_closid_show(struct kernfs_open_file *of,
>>> +                             struct seq_file *s, void *v)
>>> +{
>>> +     struct rdtgroup *rdtgrp;
>>> +     int ret = 0;
>>> +
>>> +     rdtgrp = rdtgroup_kn_lock_live(of->kn);
>>> +     if (rdtgrp)
>>> +             seq_printf(s, "%u\n", rdtgrp->closid);
>>> +     else
>>> +             ret = -ENOENT;
>>> +     rdtgroup_kn_unlock(of->kn);
>>> +
>>> +     return ret;
>>> +}
>>> +
>>> +static int rdtgroup_rmid_show(struct kernfs_open_file *of,
>>> +                           struct seq_file *s, void *v)
>>> +{
>>> +     struct rdtgroup *rdtgrp;
>>> +     int ret = 0;
>>> +
>>> +     rdtgrp = rdtgroup_kn_lock_live(of->kn);
>>> +     if (rdtgrp)
>>> +             seq_printf(s, "%u\n", rdtgrp->mon.rmid);
>>> +     else
>>> +             ret = -ENOENT;
>>> +     rdtgroup_kn_unlock(of->kn);
>>> +
>>> +     return ret;
>>> +}
>>> +
>>>  #ifdef CONFIG_PROC_CPU_RESCTRL
>>>
>>>  /*
>>> @@ -1593,6 +1625,20 @@ static struct rftype res_common_files[] = {
>>>               .seq_show       = rdtgroup_size_show,
>>>               .fflags         = RF_CTRL_BASE,
>>>       },
>>> +     {
>>> +             .name           = "closid",
>>> +             .mode           = 0444,
>>> +             .kf_ops         = &rdtgroup_kf_single_ops,
>>> +             .seq_show       = rdtgroup_closid_show,
>>> +             .fflags         = RF_CTRL_BASE,
>>> +     },
>>> +     {
>>> +             .name           = "rmid",
>>> +             .mode           = 0444,
>>> +             .kf_ops         = &rdtgroup_kf_single_ops,
>>> +             .seq_show       = rdtgroup_rmid_show,
>>> +             .fflags         = RFTYPE_BASE,
>>> +     },
>>>
>>>  };
>>>
>>>
>> Thanks.
>>
>> -Fenghua
  
Fenghua Yu Jan. 4, 2023, 11:54 p.m. UTC | #5
Hi, Babu,

> >> When a user creates a control or monitor group, the CLOSID or RMID
> >> are not visible to the user. These are architecturally defined entities.
> >> There is no harm in displaying these in resctrl groups. Sometimes it
> >> can help to debug the issues.
> > Although "no harm" to show them, it's not useful for generic user
> > either and may cause confusion sometimes. CLOSID and RMID are supposed
> > to be invisible to generic users.
> >
> > Maybe introduce a new resctrl mount option called "debug" and show the
> > files and maybe other future debug info only in debug mode?
> 
> Actually, test team feels very strongly about this. Whenever there is some issue,
> first question is what is the rmid or closid are you running on? We normally don't
> have an answer for that.
> 
> In my opinion, adding debug mode just for these two fields seems way overkill.

Yes, they are useful for "test team" (quoted from your statement) and developers.
Not for end users.

A debug mode is useful not just for these two files. I'm working on another resctrl
project where much more complex hardware info needs to be dumped for debug purpose
only. It's obvious not to show it in generic use. It's more obvious to just show the info file in
debug mode in my case.

I think these CLOSID and RMID files and future debug files belong to a new debug mode.
It would be better to introduce the debug mode now rather than later so that it can be extended
easily in the future.

Maybe we can enable debug mode in a separate debug mode patch:
1. Add RFTYPE_DEBUG as a new file type. Files with this flag are for debug purpose and only be visible in\
    debug mode.
2. Add RFTYPE_INVISIBLE as a new file type. Files with this flag will be invisible/not be added in resctrl fs.
3. Add mount parameter "debug" so that ctx->debug=true if mount -o debug is given.
4. If ctx->debug is true, in rdt_enable_ctx(), go through RFTYPE_DEBUG files in res_common_files[] and mark
    fflags with RFTYPE_INVISIBLE.
5. In rdtgroup_add_file(), if (rft->fflags & RFTYPE_INVISIBLE) return. So the debug files will be visible only
    in debug mode.

With the debug mode patch in place, it's simple to extend to any debug files:
In your case, update this patch by just adding RFTYPE_DEBUG in fflags. Then the debug mode will work
for this patch automatically.
In my case or any future debug files, we just simply add RFTYPE_DEBUG in fflags and the debug mode will
work automatically.

Does it make sense?

Thanks.

-Fenghua
  
Moger, Babu Jan. 5, 2023, 3:48 p.m. UTC | #6
Hi Fenghua,

On 1/4/23 17:54, Yu, Fenghua wrote:
> Hi, Babu,
>
>>>> When a user creates a control or monitor group, the CLOSID or RMID
>>>> are not visible to the user. These are architecturally defined entities.
>>>> There is no harm in displaying these in resctrl groups. Sometimes it
>>>> can help to debug the issues.
>>> Although "no harm" to show them, it's not useful for generic user
>>> either and may cause confusion sometimes. CLOSID and RMID are supposed
>>> to be invisible to generic users.
>>>
>>> Maybe introduce a new resctrl mount option called "debug" and show the
>>> files and maybe other future debug info only in debug mode?
>> Actually, test team feels very strongly about this. Whenever there is some issue,
>> first question is what is the rmid or closid are you running on? We normally don't
>> have an answer for that.
>>
>> In my opinion, adding debug mode just for these two fields seems way overkill.
> Yes, they are useful for "test team" (quoted from your statement) and developers.
> Not for end users.
>
> A debug mode is useful not just for these two files. I'm working on another resctrl
> project where much more complex hardware info needs to be dumped for debug purpose
> only. It's obvious not to show it in generic use. It's more obvious to just show the info file in
> debug mode in my case.
>
> I think these CLOSID and RMID files and future debug files belong to a new debug mode.
> It would be better to introduce the debug mode now rather than later so that it can be extended
> easily in the future.
>
> Maybe we can enable debug mode in a separate debug mode patch:
> 1. Add RFTYPE_DEBUG as a new file type. Files with this flag are for debug purpose and only be visible in\
>     debug mode.
> 2. Add RFTYPE_INVISIBLE as a new file type. Files with this flag will be invisible/not be added in resctrl fs.
> 3. Add mount parameter "debug" so that ctx->debug=true if mount -o debug is given.
> 4. If ctx->debug is true, in rdt_enable_ctx(), go through RFTYPE_DEBUG files in res_common_files[] and mark
>     fflags with RFTYPE_INVISIBLE.
> 5. In rdtgroup_add_file(), if (rft->fflags & RFTYPE_INVISIBLE) return. So the debug files will be visible only
>     in debug mode.
>
> With the debug mode patch in place, it's simple to extend to any debug files:
> In your case, update this patch by just adding RFTYPE_DEBUG in fflags. Then the debug mode will work
> for this patch automatically.
> In my case or any future debug files, we just simply add RFTYPE_DEBUG in fflags and the debug mode will
> work automatically.
>
> Does it make sense?

Yes. Sure. The debug mode needs to be resctrl mount option. I will take a
look at this further to see what can be done.

Thanks

Babu
  

Patch

diff --git a/Documentation/x86/resctrl.rst b/Documentation/x86/resctrl.rst
index f26e16412bcb..8520514bc8b5 100644
--- a/Documentation/x86/resctrl.rst
+++ b/Documentation/x86/resctrl.rst
@@ -231,6 +231,14 @@  All groups contain the following files:
 	Just like "cpus", only using ranges of CPUs instead of bitmasks.
 
 
+"rmid":
+	Reading this file shows the resource monitoring id (RMID) for
+	monitoring the resource utilization. Monitoring is performed by
+	tagging each core(or thread) or process via a Resource Monitoring
+	ID (RMID). Kernel assigns a new RMID when a group is created
+	depending on the available RMIDs. Multiple cores(or threads) or
+	processes can share a same RMID in a resctrl domain.
+
 When control is enabled all CTRL_MON groups will also contain:
 
 "schemata":
@@ -252,6 +260,13 @@  When control is enabled all CTRL_MON groups will also contain:
 	file. On successful pseudo-locked region creation the mode will
 	automatically change to "pseudo-locked".
 
+"closid":
+	Reading this file shows the Class of Service (CLOS) id which acts
+	as a resource control tag on which the resources can be throttled.
+	Kernel assigns a new CLOSID a control group is created depending
+	on the available CLOSIDs. Multiple cores(or threads) or processes
+	can share a same CLOSID in a resctrl domain.
+
 When monitoring is enabled all MON groups will also contain:
 
 "mon_data":
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 0d71ed22cfa9..98b4798e5cae 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -769,6 +769,38 @@  static int rdtgroup_tasks_show(struct kernfs_open_file *of,
 	return ret;
 }
 
+static int rdtgroup_closid_show(struct kernfs_open_file *of,
+				struct seq_file *s, void *v)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (rdtgrp)
+		seq_printf(s, "%u\n", rdtgrp->closid);
+	else
+		ret = -ENOENT;
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
+static int rdtgroup_rmid_show(struct kernfs_open_file *of,
+			      struct seq_file *s, void *v)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (rdtgrp)
+		seq_printf(s, "%u\n", rdtgrp->mon.rmid);
+	else
+		ret = -ENOENT;
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
 #ifdef CONFIG_PROC_CPU_RESCTRL
 
 /*
@@ -1593,6 +1625,20 @@  static struct rftype res_common_files[] = {
 		.seq_show	= rdtgroup_size_show,
 		.fflags		= RF_CTRL_BASE,
 	},
+	{
+		.name		= "closid",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= rdtgroup_closid_show,
+		.fflags		= RF_CTRL_BASE,
+	},
+	{
+		.name		= "rmid",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= rdtgroup_rmid_show,
+		.fflags		= RFTYPE_BASE,
+	},
 
 };