Skip to content

Commit 30017b6

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Add helpers for system wide mon/alloc capable
resctrl reads rdt_alloc_capable or rdt_mon_capable to determine whether any of the resources support the corresponding features. resctrl also uses the static keys that affect the architecture's context-switch code to determine the same thing. This forces another architecture to have the same static keys. As the static key is enabled based on the capable flag, and none of the filesystem uses of these are in the scheduler path, move the capable flags behind helpers, and use these in the filesystem code instead of the static key. After this change, only the architecture code manages and uses the static keys to ensure __resctrl_sched_in() does not need runtime checks. This avoids multiple architectures having to define the same static keys. Cases where the static key implicitly tested if the resctrl filesystem was mounted all have an explicit check now. Signed-off-by: James Morse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Shaopeng Tan <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Babu Moger <[email protected]> Tested-by: Shaopeng Tan <[email protected]> Tested-by: Peter Newman <[email protected]> Tested-by: Babu Moger <[email protected]> Tested-by: Carl Worth <[email protected]> # arm64 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Borislav Petkov (AMD) <[email protected]>
1 parent 0a2f4d9 commit 30017b6

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

arch/x86/include/asm/resctrl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ struct resctrl_pqr_state {
3838

3939
DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);
4040

41+
extern bool rdt_alloc_capable;
42+
extern bool rdt_mon_capable;
43+
4144
DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
4245
DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
4346
DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
4447

48+
static inline bool resctrl_arch_alloc_capable(void)
49+
{
50+
return rdt_alloc_capable;
51+
}
52+
4553
static inline void resctrl_arch_enable_alloc(void)
4654
{
4755
static_branch_enable_cpuslocked(&rdt_alloc_enable_key);
@@ -54,6 +62,11 @@ static inline void resctrl_arch_disable_alloc(void)
5462
static_branch_dec_cpuslocked(&rdt_enable_key);
5563
}
5664

65+
static inline bool resctrl_arch_mon_capable(void)
66+
{
67+
return rdt_mon_capable;
68+
}
69+
5770
static inline void resctrl_arch_enable_mon(void)
5871
{
5972
static_branch_enable_cpuslocked(&rdt_mon_enable_key);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ struct rmid_read {
137137
void *arch_mon_ctx;
138138
};
139139

140-
extern bool rdt_alloc_capable;
141-
extern bool rdt_mon_capable;
142140
extern unsigned int rdt_mon_features;
143141
extern struct list_head resctrl_schema_all;
144142
extern bool resctrl_mounted;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ void mbm_handle_overflow(struct work_struct *work)
817817
* If the filesystem has been unmounted this work no longer needs to
818818
* run.
819819
*/
820-
if (!resctrl_mounted || !static_branch_likely(&rdt_mon_enable_key))
820+
if (!resctrl_mounted || !resctrl_arch_mon_capable())
821821
goto out_unlock;
822822

823823
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
@@ -854,7 +854,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)
854854
* When a domain comes online there is no guarantee the filesystem is
855855
* mounted. If not, there is no need to catch counter overflow.
856856
*/
857-
if (!resctrl_mounted || !static_branch_likely(&rdt_mon_enable_key))
857+
if (!resctrl_mounted || !resctrl_arch_mon_capable())
858858
return;
859859
cpu = cpumask_any_housekeeping(&dom->cpu_mask);
860860
dom->mbm_work_cpu = cpu;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int rdtgroup_locksetup_user_restrict(struct rdtgroup *rdtgrp)
581581
if (ret)
582582
goto err_cpus;
583583

584-
if (rdt_mon_capable) {
584+
if (resctrl_arch_mon_capable()) {
585585
ret = rdtgroup_kn_mode_restrict(rdtgrp, "mon_groups");
586586
if (ret)
587587
goto err_cpus_list;
@@ -628,7 +628,7 @@ static int rdtgroup_locksetup_user_restore(struct rdtgroup *rdtgrp)
628628
if (ret)
629629
goto err_cpus;
630630

631-
if (rdt_mon_capable) {
631+
if (resctrl_arch_mon_capable()) {
632632
ret = rdtgroup_kn_mode_restore(rdtgrp, "mon_groups", 0777);
633633
if (ret)
634634
goto err_cpus_list;
@@ -776,7 +776,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp)
776776
{
777777
int ret;
778778

779-
if (rdt_mon_capable) {
779+
if (resctrl_arch_mon_capable()) {
780780
ret = alloc_rmid(rdtgrp->closid);
781781
if (ret < 0) {
782782
rdt_last_cmd_puts("Out of RMIDs\n");

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ static int __rdtgroup_move_task(struct task_struct *tsk,
641641

642642
static bool is_closid_match(struct task_struct *t, struct rdtgroup *r)
643643
{
644-
return (rdt_alloc_capable && (r->type == RDTCTRL_GROUP) &&
644+
return (resctrl_arch_alloc_capable() && (r->type == RDTCTRL_GROUP) &&
645645
resctrl_arch_match_closid(t, r->closid));
646646
}
647647

648648
static bool is_rmid_match(struct task_struct *t, struct rdtgroup *r)
649649
{
650-
return (rdt_mon_capable && (r->type == RDTMON_GROUP) &&
650+
return (resctrl_arch_mon_capable() && (r->type == RDTMON_GROUP) &&
651651
resctrl_arch_match_rmid(t, r->mon.parent->closid,
652652
r->mon.rmid));
653653
}
@@ -2632,7 +2632,7 @@ static int rdt_get_tree(struct fs_context *fc)
26322632

26332633
closid_init();
26342634

2635-
if (rdt_mon_capable)
2635+
if (resctrl_arch_mon_capable())
26362636
flags |= RFTYPE_MON;
26372637

26382638
ret = rdtgroup_add_files(rdtgroup_default.kn, flags);
@@ -2645,7 +2645,7 @@ static int rdt_get_tree(struct fs_context *fc)
26452645
if (ret < 0)
26462646
goto out_schemata_free;
26472647

2648-
if (rdt_mon_capable) {
2648+
if (resctrl_arch_mon_capable()) {
26492649
ret = mongroup_create_dir(rdtgroup_default.kn,
26502650
&rdtgroup_default, "mon_groups",
26512651
&kn_mongrp);
@@ -2667,12 +2667,12 @@ static int rdt_get_tree(struct fs_context *fc)
26672667
if (ret < 0)
26682668
goto out_psl;
26692669

2670-
if (rdt_alloc_capable)
2670+
if (resctrl_arch_alloc_capable())
26712671
resctrl_arch_enable_alloc();
2672-
if (rdt_mon_capable)
2672+
if (resctrl_arch_mon_capable())
26732673
resctrl_arch_enable_mon();
26742674

2675-
if (rdt_alloc_capable || rdt_mon_capable)
2675+
if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable())
26762676
resctrl_mounted = true;
26772677

26782678
if (is_mbm_enabled()) {
@@ -2686,10 +2686,10 @@ static int rdt_get_tree(struct fs_context *fc)
26862686
out_psl:
26872687
rdt_pseudo_lock_release();
26882688
out_mondata:
2689-
if (rdt_mon_capable)
2689+
if (resctrl_arch_mon_capable())
26902690
kernfs_remove(kn_mondata);
26912691
out_mongrp:
2692-
if (rdt_mon_capable)
2692+
if (resctrl_arch_mon_capable())
26932693
kernfs_remove(kn_mongrp);
26942694
out_info:
26952695
kernfs_remove(kn_info);
@@ -2944,9 +2944,9 @@ static void rdt_kill_sb(struct super_block *sb)
29442944
rdtgroup_default.mode = RDT_MODE_SHAREABLE;
29452945
schemata_list_destroy();
29462946
rdtgroup_destroy_root();
2947-
if (rdt_alloc_capable)
2947+
if (resctrl_arch_alloc_capable())
29482948
resctrl_arch_disable_alloc();
2949-
if (rdt_mon_capable)
2949+
if (resctrl_arch_mon_capable())
29502950
resctrl_arch_disable_mon();
29512951
resctrl_mounted = false;
29522952
kernfs_kill_sb(sb);
@@ -3326,7 +3326,7 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp)
33263326
{
33273327
int ret;
33283328

3329-
if (!rdt_mon_capable)
3329+
if (!resctrl_arch_mon_capable())
33303330
return 0;
33313331

33323332
ret = alloc_rmid(rdtgrp->closid);
@@ -3348,7 +3348,7 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp)
33483348

33493349
static void mkdir_rdt_prepare_rmid_free(struct rdtgroup *rgrp)
33503350
{
3351-
if (rdt_mon_capable)
3351+
if (resctrl_arch_mon_capable())
33523352
free_rmid(rgrp->closid, rgrp->mon.rmid);
33533353
}
33543354

@@ -3412,7 +3412,7 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
34123412

34133413
if (rtype == RDTCTRL_GROUP) {
34143414
files = RFTYPE_BASE | RFTYPE_CTRL;
3415-
if (rdt_mon_capable)
3415+
if (resctrl_arch_mon_capable())
34163416
files |= RFTYPE_MON;
34173417
} else {
34183418
files = RFTYPE_BASE | RFTYPE_MON;
@@ -3521,7 +3521,7 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
35213521

35223522
list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups);
35233523

3524-
if (rdt_mon_capable) {
3524+
if (resctrl_arch_mon_capable()) {
35253525
/*
35263526
* Create an empty mon_groups directory to hold the subset
35273527
* of tasks and cpus to monitor.
@@ -3576,14 +3576,14 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
35763576
* allocation is supported, add a control and monitoring
35773577
* subdirectory
35783578
*/
3579-
if (rdt_alloc_capable && parent_kn == rdtgroup_default.kn)
3579+
if (resctrl_arch_alloc_capable() && parent_kn == rdtgroup_default.kn)
35803580
return rdtgroup_mkdir_ctrl_mon(parent_kn, name, mode);
35813581

35823582
/*
35833583
* If RDT monitoring is supported and the parent directory is a valid
35843584
* "mon_groups" directory, add a monitoring subdirectory.
35853585
*/
3586-
if (rdt_mon_capable && is_mon_groups(parent_kn, name))
3586+
if (resctrl_arch_mon_capable() && is_mon_groups(parent_kn, name))
35873587
return rdtgroup_mkdir_mon(parent_kn, name, mode);
35883588

35893589
return -EPERM;
@@ -3918,7 +3918,7 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)
39183918
* If resctrl is mounted, remove all the
39193919
* per domain monitor data directories.
39203920
*/
3921-
if (resctrl_mounted && static_branch_unlikely(&rdt_mon_enable_key))
3921+
if (resctrl_mounted && resctrl_arch_mon_capable())
39223922
rmdir_mondata_subdir_allrdtgrp(r, d->id);
39233923

39243924
if (is_mbm_enabled())
@@ -4001,7 +4001,7 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
40014001
* by rdt_get_tree() calling mkdir_mondata_all().
40024002
* If resctrl is mounted, add per domain monitor data directories.
40034003
*/
4004-
if (resctrl_mounted && static_branch_unlikely(&rdt_mon_enable_key))
4004+
if (resctrl_mounted && resctrl_arch_mon_capable())
40054005
mkdir_mondata_subdir_allrdtgrp(r, d);
40064006

40074007
return 0;

0 commit comments

Comments
 (0)