Skip to content

Commit 3c02153

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Add a helper to avoid reaching into the arch code resource list
Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array. Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct rdt_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct. Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'. resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled. Co-developed-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: Dave Martin <Dave.Martin@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64 Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64 Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lore.kernel.org/r/20250311183715.16445-3-james.morse@arm.com
1 parent a121798 commit 3c02153

6 files changed

Lines changed: 39 additions & 24 deletions

File tree

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void mba_wrmsr_amd(struct msr_param *m);
6262
#define ctrl_domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.ctrl_domains)
6363
#define mon_domain_init(id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.mon_domains)
6464

65-
struct rdt_hw_resource rdt_resources_all[] = {
65+
struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
6666
[RDT_RESOURCE_L3] =
6767
{
6868
.r_resctrl = {
@@ -127,6 +127,14 @@ u32 resctrl_arch_system_num_rmid_idx(void)
127127
return r->num_rmid;
128128
}
129129

130+
struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
131+
{
132+
if (l >= RDT_NUM_RESOURCES)
133+
return NULL;
134+
135+
return &rdt_resources_all[l].r_resctrl;
136+
}
137+
130138
/*
131139
* cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs
132140
* as they do not have CPUID enumeration support for Cache allocation.
@@ -174,7 +182,7 @@ static inline void cache_alloc_hsw_probe(void)
174182
bool is_mba_sc(struct rdt_resource *r)
175183
{
176184
if (!r)
177-
return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.mba_sc;
185+
r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
178186

179187
/*
180188
* The software controller support is only applicable to MBA resource.

arch/x86/kernel/cpu/resctrl/ctrlmondata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
649649
resid = md.u.rid;
650650
domid = md.u.domid;
651651
evtid = md.u.evtid;
652-
r = &rdt_resources_all[resid].r_resctrl;
652+
r = resctrl_arch_get_resource(resid);
653653

654654
if (md.u.sum) {
655655
/*

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,6 @@ extern struct rdtgroup rdtgroup_default;
512512
extern struct dentry *debugfs_resctrl;
513513
extern enum resctrl_event_id mba_mbps_default_event;
514514

515-
enum resctrl_res_level {
516-
RDT_RESOURCE_L3,
517-
RDT_RESOURCE_L2,
518-
RDT_RESOURCE_MBA,
519-
RDT_RESOURCE_SMBA,
520-
521-
/* Must be the last */
522-
RDT_NUM_RESOURCES,
523-
};
524-
525515
static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
526516
{
527517
struct rdt_hw_resource *hw_res = resctrl_to_arch_res(res);

arch/x86/kernel/cpu/resctrl/monitor.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void limbo_release_entry(struct rmid_entry *entry)
365365
*/
366366
void __check_limbo(struct rdt_mon_domain *d, bool force_free)
367367
{
368-
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
368+
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
369369
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
370370
struct rmid_entry *entry;
371371
u32 idx, cur_idx = 1;
@@ -521,7 +521,7 @@ int alloc_rmid(u32 closid)
521521

522522
static void add_rmid_to_limbo(struct rmid_entry *entry)
523523
{
524-
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
524+
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
525525
struct rdt_mon_domain *d;
526526
u32 idx;
527527

@@ -761,7 +761,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
761761
struct rdtgroup *entry;
762762
u32 cur_bw, user_bw;
763763

764-
r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
764+
r_mba = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
765765
evt_id = rgrp->mba_mbps_event;
766766

767767
closid = rgrp->closid;
@@ -925,7 +925,7 @@ void mbm_handle_overflow(struct work_struct *work)
925925
if (!resctrl_mounted || !resctrl_arch_mon_capable())
926926
goto out_unlock;
927927

928-
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
928+
r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
929929
d = container_of(work, struct rdt_mon_domain, mbm_over.work);
930930

931931
list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ static void l2_qos_cfg_update(void *arg)
22562256

22572257
static inline bool is_mba_linear(void)
22582258
{
2259-
return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.delay_linear;
2259+
return resctrl_arch_get_resource(RDT_RESOURCE_MBA)->membw.delay_linear;
22602260
}
22612261

22622262
static int set_cache_qos_cfg(int level, bool enable)
@@ -2346,8 +2346,8 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
23462346
*/
23472347
static bool supports_mba_mbps(void)
23482348
{
2349-
struct rdt_resource *rmbm = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
2350-
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
2349+
struct rdt_resource *rmbm = resctrl_arch_get_resource(RDT_RESOURCE_L3);
2350+
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
23512351

23522352
return (is_mbm_enabled() &&
23532353
r->alloc_capable && is_mba_linear() &&
@@ -2360,7 +2360,7 @@ static bool supports_mba_mbps(void)
23602360
*/
23612361
static int set_mba_sc(bool mba_sc)
23622362
{
2363-
struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
2363+
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
23642364
u32 num_closid = resctrl_arch_get_num_closid(r);
23652365
struct rdt_ctrl_domain *d;
23662366
unsigned long fflags;
@@ -2714,7 +2714,7 @@ static int rdt_get_tree(struct fs_context *fc)
27142714
resctrl_mounted = true;
27152715

27162716
if (is_mbm_enabled()) {
2717-
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
2717+
r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
27182718
list_for_each_entry(dom, &r->mon_domains, hdr.list)
27192719
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
27202720
RESCTRL_PICK_ANY_CPU);
@@ -3951,7 +3951,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
39513951
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
39523952
seq_puts(seq, ",cdpl2");
39533953

3954-
if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
3954+
if (is_mba_sc(resctrl_arch_get_resource(RDT_RESOURCE_MBA)))
39553955
seq_puts(seq, ",mba_MBps");
39563956

39573957
if (resctrl_debug)
@@ -4151,7 +4151,7 @@ static void clear_childcpus(struct rdtgroup *r, unsigned int cpu)
41514151

41524152
void resctrl_offline_cpu(unsigned int cpu)
41534153
{
4154-
struct rdt_resource *l3 = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
4154+
struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
41554155
struct rdt_mon_domain *d;
41564156
struct rdtgroup *rdtgrp;
41574157

include/linux/resctrl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ enum resctrl_conf_type {
3737
CDP_DATA,
3838
};
3939

40+
enum resctrl_res_level {
41+
RDT_RESOURCE_L3,
42+
RDT_RESOURCE_L2,
43+
RDT_RESOURCE_MBA,
44+
RDT_RESOURCE_SMBA,
45+
46+
/* Must be the last */
47+
RDT_NUM_RESOURCES,
48+
};
49+
4050
#define CDP_NUM_TYPES (CDP_DATA + 1)
4151

4252
/*
@@ -226,6 +236,13 @@ struct rdt_resource {
226236
bool cdp_capable;
227237
};
228238

239+
/*
240+
* Get the resource that exists at this level. If the level is not supported
241+
* a dummy/not-capable resource can be returned. Levels >= RDT_NUM_RESOURCES
242+
* will return NULL.
243+
*/
244+
struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
245+
229246
/**
230247
* struct resctrl_schema - configuration abilities of a resource presented to
231248
* user-space

0 commit comments

Comments
 (0)