Skip to content

Commit 88464bf

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Rewrite and move the for_each_*_rdt_resource() walkers
The for_each_*_rdt_resource() helpers walk the architecture's array of structures, using the resctrl visible part as an iterator. These became over-complex when the structures were split into a filesystem and architecture-specific struct. This approach avoided the need to touch every call site, and was done before there was a helper to retrieve a resource by rid. Once the filesystem parts of resctrl are moved to /fs/, both the arch's resource array, and the definition of those structures is no longer accessible. To support resctrl, each architecture would have to provide equally complex macros. Rewrite the macro to make use of resctrl_arch_get_resource(), and move these to include/linux/resctrl.h so existing x86 arch code continues to use them. Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Tony Luck <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Reviewed-by: Babu Moger <[email protected]> Tested-by: Shaopeng Tan <[email protected]> Tested-by: Peter Newman <[email protected]> Tested-by: Amit Singh Tomar <[email protected]> # arm64 Tested-by: Shanker Donthineni <[email protected]> # arm64 Tested-by: Babu Moger <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4b6bdbf commit 88464bf

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,6 @@ extern struct rdtgroup rdtgroup_default;
475475
extern struct dentry *debugfs_resctrl;
476476
extern enum resctrl_event_id mba_mbps_default_event;
477477

478-
static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
479-
{
480-
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(res);
481-
482-
hw_res++;
483-
return &hw_res->r_resctrl;
484-
}
485-
486478
static inline bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l)
487479
{
488480
return rdt_resources_all[l].cdp_enabled;
@@ -492,27 +484,6 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable);
492484

493485
void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain *d);
494486

495-
/*
496-
* To return the common struct rdt_resource, which is contained in struct
497-
* rdt_hw_resource, walk the resctrl member of struct rdt_hw_resource.
498-
*/
499-
#define for_each_rdt_resource(r) \
500-
for (r = &rdt_resources_all[0].r_resctrl; \
501-
r <= &rdt_resources_all[RDT_NUM_RESOURCES - 1].r_resctrl; \
502-
r = resctrl_inc(r))
503-
504-
#define for_each_capable_rdt_resource(r) \
505-
for_each_rdt_resource(r) \
506-
if (r->alloc_capable || r->mon_capable)
507-
508-
#define for_each_alloc_capable_rdt_resource(r) \
509-
for_each_rdt_resource(r) \
510-
if (r->alloc_capable)
511-
512-
#define for_each_mon_capable_rdt_resource(r) \
513-
for_each_rdt_resource(r) \
514-
if (r->mon_capable)
515-
516487
/* CPUID.(EAX=10H, ECX=ResID=1).EAX */
517488
union cpuid_0x10_1_eax {
518489
struct {

include/linux/resctrl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ int proc_resctrl_show(struct seq_file *m,
2626
/* max value for struct rdt_domain's mbps_val */
2727
#define MBA_MAX_MBPS U32_MAX
2828

29+
/* Walk all possible resources, with variants for only controls or monitors. */
30+
#define for_each_rdt_resource(_r) \
31+
for ((_r) = resctrl_arch_get_resource(0); \
32+
(_r) && (_r)->rid < RDT_NUM_RESOURCES; \
33+
(_r) = resctrl_arch_get_resource((_r)->rid + 1))
34+
35+
#define for_each_capable_rdt_resource(r) \
36+
for_each_rdt_resource((r)) \
37+
if ((r)->alloc_capable || (r)->mon_capable)
38+
39+
#define for_each_alloc_capable_rdt_resource(r) \
40+
for_each_rdt_resource((r)) \
41+
if ((r)->alloc_capable)
42+
43+
#define for_each_mon_capable_rdt_resource(r) \
44+
for_each_rdt_resource((r)) \
45+
if ((r)->mon_capable)
46+
2947
/**
3048
* enum resctrl_conf_type - The type of configuration.
3149
* @CDP_NONE: No prioritisation, both code and data are controlled or monitored.

0 commit comments

Comments
 (0)