Re: [PATCH 05/11] fs/resctrl: Use accurate type for rdt_resource::rid

Luck, Tony
2026-03-03T19:54:28Z

On Tue, Mar 03, 2026 at 11:06:52AM -0800, Reinette Chatre wrote:
> Hi Tony,
> > +int rdt_num_resources = ARRAY_SIZE(rdt_resources_all);
> > +
>
> ... and this proposes to let the *architecture* initialize how many
> resources resctrl fs supports?

Not exactly. The file system is free to support as many resources as
it wants to.

The architecture just provides the largest value that will provide
any useful result from resctrl_arch_get_resource() so that this filesystem macro
works without redundant iterations for unimplemented resources at the high
end of the enum range:

/* Walk all possible resources, with variants for only controls or monitors. */
#define for_each_rdt_resource(_r) \
for ((_r) = resctrl_arch_get_resource(0); \
(_r) && (_r)->rid < rdt_num_resources; \
(_r) = resctrl_arch_get_resource((_r)->rid + 1))

>
> 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?

Yes. Each architecture would have to provide a value. Each architecture
must support the resctrl_arch_get_resource(enum resctrl_res_level l)
function. Regardless of whether this is backed up with an array of
resources, a list, or some other exotic structure this function must
return a valid "struct rdt_resource *" pointer that can be dereferenced
for all values [0 ... RDT_NUM_RESOURCES).

Allowing the architecture to define the upper limit of supported resource
numbers doesn't constrain the file system.

> 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.

Having resctrl fs define the number means that an architecture that uses
an array must pad out that array.

-Tony