Re: [PATCH 05/11] fs/resctrl: Use accurate type for rdt_resource::rid
From: Reinette Chatre
Date: Tue Mar 03 2026 - 14:11:56 EST
Hi Tony,
On 3/3/26 10:20 AM, Luck, Tony wrote:
> On Mon, Mar 02, 2026 at 10:46:11AM -0800, Reinette Chatre wrote:
>
>> - /* Must be the last */
>> - RDT_NUM_RESOURCES,
>> + /* Additions to enum need to update RDT_NUM_RESOURCES. */
>> };
>>
>> +#define RDT_NUM_RESOURCES (RDT_RESOURCE_PERF_PKG + 1)
>
> Alternative approach that doesn't rely on developers reading
> that comment and updating the define.
>
> Replace the RDT_NUM_RESOURCES #define with a variable initialized
> to ARRAY_SIZE(rdt_resources_all).
....
> include/linux/resctrl.h | 11 +++++------
> arch/x86/kernel/cpu/resctrl/core.c | 9 ++++++---
> 2 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 006e57fd7ca5..ef2efa2e4b39 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
The resources resctrl fs supports are defined within this global
resctrl fs header file as:
enum resctrl_res_level {
RDT_RESOURCE_L3,
RDT_RESOURCE_L2,
RDT_RESOURCE_MBA,
RDT_RESOURCE_SMBA,
RDT_RESOURCE_PERF_PKG,
RDT_NUM_RESOURCES,
};
> @@ -27,13 +27,15 @@ int proc_resctrl_show(struct seq_file *m,
>
> #endif
>
> +extern int rdt_num_resources;
> +
....
Architecture code below ...
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
...
> @@ -57,7 +58,7 @@ static void mba_wrmsr_amd(struct msr_param *m);
> #define ctrl_domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.ctrl_domains)
> #define mon_domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.mon_domains)
>
> -struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
> +struct rdt_hw_resource rdt_resources_all[] = {
> [RDT_RESOURCE_L3] =
> {
> .r_resctrl = {
> @@ -110,6 +111,8 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
> },
> };
>
> +int rdt_num_resources = ARRAY_SIZE(rdt_resources_all);
> +
... and this proposes to let the *architecture* initialize how many
resources resctrl fs supports?
This implies that all architectures need to initialize this on behalf of
resctrl fs. resctrl fs does not force an architecture to use an array nor does
it require an architecture to support all resources. What if an architecture
decides to not use an array and does not support all the resources resctrl fs
supports? How should it initialize rdt_num_resources?
I see the number of resources supported by resctrl fs as a resctrl fs property,
not something it should depend on the architecture to initialize.
Reinette