Skip to content

Commit d012b66

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Move the is_mbm_*_enabled() helpers to asm/resctrl.h
The architecture specific parts of resctrl provide helpers like is_mbm_total_enabled() and is_mbm_local_enabled() to hide accesses to the rdt_mon_features bitmap. Exposing a group of helpers between the architecture and filesystem code is preferable to a single unsigned-long like rdt_mon_features. Helpers can be more readable and have a well defined behaviour, while allowing architectures to hide more complex behaviour. Once the filesystem parts of resctrl are moved, these existing helpers can no longer live in internal.h. Move them to include/linux/resctrl.h Once these are exposed to the wider kernel, they should have a 'resctrl_arch_' prefix, to fit the rest of the arch<->fs interface. Move and rename the helpers that touch rdt_mon_features directly. is_mbm_event() and is_mbm_enabled() are only called from rdtgroup.c, so can be moved into that file. Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Tony Luck <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Babu Moger <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Tested-by: Carl Worth <[email protected]> # arm64 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 88464bf commit d012b66

File tree

6 files changed

+56
-55
lines changed

6 files changed

+56
-55
lines changed

arch/x86/include/asm/resctrl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);
4242

4343
extern bool rdt_alloc_capable;
4444
extern bool rdt_mon_capable;
45+
extern unsigned int rdt_mon_features;
4546

4647
DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
4748
DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
@@ -81,6 +82,21 @@ static inline void resctrl_arch_disable_mon(void)
8182
static_branch_dec_cpuslocked(&rdt_enable_key);
8283
}
8384

85+
static inline bool resctrl_arch_is_llc_occupancy_enabled(void)
86+
{
87+
return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
88+
}
89+
90+
static inline bool resctrl_arch_is_mbm_total_enabled(void)
91+
{
92+
return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID));
93+
}
94+
95+
static inline bool resctrl_arch_is_mbm_local_enabled(void)
96+
{
97+
return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID));
98+
}
99+
84100
/*
85101
* __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR
86102
*

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *hw_dom)
453453
{
454454
size_t tsize;
455455

456-
if (is_mbm_total_enabled()) {
456+
if (resctrl_arch_is_mbm_total_enabled()) {
457457
tsize = sizeof(*hw_dom->arch_mbm_total);
458458
hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
459459
if (!hw_dom->arch_mbm_total)
460460
return -ENOMEM;
461461
}
462-
if (is_mbm_local_enabled()) {
462+
if (resctrl_arch_is_mbm_local_enabled()) {
463463
tsize = sizeof(*hw_dom->arch_mbm_local);
464464
hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
465465
if (!hw_dom->arch_mbm_local) {
@@ -908,9 +908,9 @@ static __init bool get_rdt_mon_resources(void)
908908
if (!rdt_mon_features)
909909
return false;
910910

911-
if (is_mbm_local_enabled())
911+
if (resctrl_arch_is_mbm_local_enabled())
912912
mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
913-
else if (is_mbm_total_enabled())
913+
else if (resctrl_arch_is_mbm_total_enabled())
914914
mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
915915

916916
return !rdt_get_mon_l3_config(r);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
559559
rdt_last_cmd_clear();
560560

561561
if (!strcmp(buf, "mbm_local_bytes")) {
562-
if (is_mbm_local_enabled())
562+
if (resctrl_arch_is_mbm_local_enabled())
563563
rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
564564
else
565565
ret = -EINVAL;
566566
} else if (!strcmp(buf, "mbm_total_bytes")) {
567-
if (is_mbm_total_enabled())
567+
if (resctrl_arch_is_mbm_total_enabled())
568568
rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
569569
else
570570
ret = -EINVAL;

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ struct rmid_read {
156156
void *arch_mon_ctx;
157157
};
158158

159-
extern unsigned int rdt_mon_features;
160159
extern struct list_head resctrl_schema_all;
161160
extern bool resctrl_mounted;
162161

@@ -406,32 +405,6 @@ struct msr_param {
406405
u32 high;
407406
};
408407

409-
static inline bool is_llc_occupancy_enabled(void)
410-
{
411-
return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
412-
}
413-
414-
static inline bool is_mbm_total_enabled(void)
415-
{
416-
return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID));
417-
}
418-
419-
static inline bool is_mbm_local_enabled(void)
420-
{
421-
return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID));
422-
}
423-
424-
static inline bool is_mbm_enabled(void)
425-
{
426-
return (is_mbm_total_enabled() || is_mbm_local_enabled());
427-
}
428-
429-
static inline bool is_mbm_event(int e)
430-
{
431-
return (e >= QOS_L3_MBM_TOTAL_EVENT_ID &&
432-
e <= QOS_L3_MBM_LOCAL_EVENT_ID);
433-
}
434-
435408
/**
436409
* struct rdt_hw_resource - arch private attributes of a resctrl resource
437410
* @r_resctrl: Attributes of the resource used directly by resctrl.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *
295295
{
296296
struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
297297

298-
if (is_mbm_total_enabled())
298+
if (resctrl_arch_is_mbm_total_enabled())
299299
memset(hw_dom->arch_mbm_total, 0,
300300
sizeof(*hw_dom->arch_mbm_total) * r->num_rmid);
301301

302-
if (is_mbm_local_enabled())
302+
if (resctrl_arch_is_mbm_local_enabled())
303303
memset(hw_dom->arch_mbm_local, 0,
304304
sizeof(*hw_dom->arch_mbm_local) * r->num_rmid);
305305
}
@@ -569,7 +569,7 @@ void free_rmid(u32 closid, u32 rmid)
569569

570570
entry = __rmid_entry(idx);
571571

572-
if (is_llc_occupancy_enabled())
572+
if (resctrl_arch_is_llc_occupancy_enabled())
573573
add_rmid_to_limbo(entry);
574574
else
575575
list_add_tail(&entry->list, &rmid_free_lru);
@@ -852,10 +852,10 @@ static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
852852
* This is protected from concurrent reads from user as both
853853
* the user and overflow handler hold the global mutex.
854854
*/
855-
if (is_mbm_total_enabled())
855+
if (resctrl_arch_is_mbm_total_enabled())
856856
mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID);
857857

858-
if (is_mbm_local_enabled())
858+
if (resctrl_arch_is_mbm_local_enabled())
859859
mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID);
860860
}
861861

@@ -1085,11 +1085,11 @@ static void l3_mon_evt_init(struct rdt_resource *r)
10851085
{
10861086
INIT_LIST_HEAD(&r->evt_list);
10871087

1088-
if (is_llc_occupancy_enabled())
1088+
if (resctrl_arch_is_llc_occupancy_enabled())
10891089
list_add_tail(&llc_occupancy_event.list, &r->evt_list);
1090-
if (is_mbm_total_enabled())
1090+
if (resctrl_arch_is_mbm_total_enabled())
10911091
list_add_tail(&mbm_total_event.list, &r->evt_list);
1092-
if (is_mbm_local_enabled())
1092+
if (resctrl_arch_is_mbm_local_enabled())
10931093
list_add_tail(&mbm_local_event.list, &r->evt_list);
10941094
}
10951095

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ void rdt_staged_configs_clear(void)
117117
}
118118
}
119119

120+
static bool resctrl_is_mbm_enabled(void)
121+
{
122+
return (resctrl_arch_is_mbm_total_enabled() ||
123+
resctrl_arch_is_mbm_local_enabled());
124+
}
125+
126+
static bool resctrl_is_mbm_event(int e)
127+
{
128+
return (e >= QOS_L3_MBM_TOTAL_EVENT_ID &&
129+
e <= QOS_L3_MBM_LOCAL_EVENT_ID);
130+
}
131+
120132
/*
121133
* Trivial allocator for CLOSIDs. Since h/w only supports a small number,
122134
* we can keep a bitmap of free CLOSIDs in a single integer.
@@ -164,7 +176,7 @@ static int closid_alloc(void)
164176
lockdep_assert_held(&rdtgroup_mutex);
165177

166178
if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
167-
is_llc_occupancy_enabled()) {
179+
resctrl_arch_is_llc_occupancy_enabled()) {
168180
cleanest_closid = resctrl_find_cleanest_closid();
169181
if (cleanest_closid < 0)
170182
return cleanest_closid;
@@ -2378,7 +2390,7 @@ static bool supports_mba_mbps(void)
23782390
struct rdt_resource *rmbm = resctrl_arch_get_resource(RDT_RESOURCE_L3);
23792391
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
23802392

2381-
return (is_mbm_enabled() &&
2393+
return (resctrl_is_mbm_enabled() &&
23822394
r->alloc_capable && is_mba_linear() &&
23832395
r->ctrl_scope == rmbm->mon_scope);
23842396
}
@@ -2756,7 +2768,7 @@ static int rdt_get_tree(struct fs_context *fc)
27562768
if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable())
27572769
resctrl_mounted = true;
27582770

2759-
if (is_mbm_enabled()) {
2771+
if (resctrl_is_mbm_enabled()) {
27602772
r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
27612773
list_for_each_entry(dom, &r->mon_domains, hdr.list)
27622774
mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
@@ -3125,7 +3137,7 @@ static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain *d,
31253137
if (ret)
31263138
return ret;
31273139

3128-
if (!do_sum && is_mbm_event(mevt->evtid))
3140+
if (!do_sum && resctrl_is_mbm_event(mevt->evtid))
31293141
mon_event_read(&rr, r, d, prgrp, &d->hdr.cpu_mask, mevt->evtid, true);
31303142
}
31313143

@@ -4082,9 +4094,9 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d
40824094
if (resctrl_mounted && resctrl_arch_mon_capable())
40834095
rmdir_mondata_subdir_allrdtgrp(r, d);
40844096

4085-
if (is_mbm_enabled())
4097+
if (resctrl_is_mbm_enabled())
40864098
cancel_delayed_work(&d->mbm_over);
4087-
if (is_llc_occupancy_enabled() && has_busy_rmid(d)) {
4099+
if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) {
40884100
/*
40894101
* When a package is going down, forcefully
40904102
* decrement rmid->ebusy. There is no way to know
@@ -4120,20 +4132,20 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domain
41204132
u32 idx_limit = resctrl_arch_system_num_rmid_idx();
41214133
size_t tsize;
41224134

4123-
if (is_llc_occupancy_enabled()) {
4135+
if (resctrl_arch_is_llc_occupancy_enabled()) {
41244136
d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
41254137
if (!d->rmid_busy_llc)
41264138
return -ENOMEM;
41274139
}
4128-
if (is_mbm_total_enabled()) {
4140+
if (resctrl_arch_is_mbm_total_enabled()) {
41294141
tsize = sizeof(*d->mbm_total);
41304142
d->mbm_total = kcalloc(idx_limit, tsize, GFP_KERNEL);
41314143
if (!d->mbm_total) {
41324144
bitmap_free(d->rmid_busy_llc);
41334145
return -ENOMEM;
41344146
}
41354147
}
4136-
if (is_mbm_local_enabled()) {
4148+
if (resctrl_arch_is_mbm_local_enabled()) {
41374149
tsize = sizeof(*d->mbm_local);
41384150
d->mbm_local = kcalloc(idx_limit, tsize, GFP_KERNEL);
41394151
if (!d->mbm_local) {
@@ -4172,13 +4184,13 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)
41724184
if (err)
41734185
goto out_unlock;
41744186

4175-
if (is_mbm_enabled()) {
4187+
if (resctrl_is_mbm_enabled()) {
41764188
INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
41774189
mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL,
41784190
RESCTRL_PICK_ANY_CPU);
41794191
}
41804192

4181-
if (is_llc_occupancy_enabled())
4193+
if (resctrl_arch_is_llc_occupancy_enabled())
41824194
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
41834195

41844196
/*
@@ -4233,12 +4245,12 @@ void resctrl_offline_cpu(unsigned int cpu)
42334245

42344246
d = get_mon_domain_from_cpu(cpu, l3);
42354247
if (d) {
4236-
if (is_mbm_enabled() && cpu == d->mbm_work_cpu) {
4248+
if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
42374249
cancel_delayed_work(&d->mbm_over);
42384250
mbm_setup_overflow_handler(d, 0, cpu);
42394251
}
4240-
if (is_llc_occupancy_enabled() && cpu == d->cqm_work_cpu &&
4241-
has_busy_rmid(d)) {
4252+
if (resctrl_arch_is_llc_occupancy_enabled() &&
4253+
cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
42424254
cancel_delayed_work(&d->cqm_limbo);
42434255
cqm_setup_limbo_handler(d, 0, cpu);
42444256
}

0 commit comments

Comments
 (0)