x86/resctrl: Move alloc/mon static keys into helpers
authorJames Morse <james.morse@arm.com>
Tue, 13 Feb 2024 18:44:31 +0000 (18:44 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Fri, 16 Feb 2024 18:18:32 +0000 (19:18 +0100)
resctrl enables three static keys depending on the features it has enabled.
Another architecture's context switch code may look different, any static keys
that control it should be buried behind helpers.

Move the alloc/mon logic into arch-specific helpers as a preparatory step for
making the rdt_enable_key's status something the arch code decides.

This means other architectures don't have to mirror the static keys.

Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Link: https://lore.kernel.org/r/20240213184438.16675-18-james.morse@arm.com
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
arch/x86/include/asm/resctrl.h
arch/x86/kernel/cpu/resctrl/internal.h
arch/x86/kernel/cpu/resctrl/rdtgroup.c

index 29c4cc34378713d851ae53bf4fb4cf4271ccb8e6..3c9137b6ad4f251bb48fae715f067ccded6016d6 100644 (file)
@@ -42,6 +42,26 @@ DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
 DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
 DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
 
+static inline void resctrl_arch_enable_alloc(void)
+{
+       static_branch_enable_cpuslocked(&rdt_alloc_enable_key);
+}
+
+static inline void resctrl_arch_disable_alloc(void)
+{
+       static_branch_disable_cpuslocked(&rdt_alloc_enable_key);
+}
+
+static inline void resctrl_arch_enable_mon(void)
+{
+       static_branch_enable_cpuslocked(&rdt_mon_enable_key);
+}
+
+static inline void resctrl_arch_disable_mon(void)
+{
+       static_branch_disable_cpuslocked(&rdt_mon_enable_key);
+}
+
 /*
  * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR
  *
index 9bfda6963794359253b6913476a9102bbb77e29e..78580855139dd1b3d3ae55277b4d5037a10aeb72 100644 (file)
@@ -94,9 +94,6 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
        return container_of(kfc, struct rdt_fs_context, kfc);
 }
 
-DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
-DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
-
 /**
  * struct mon_evt - Entry in the event list of a resource
  * @evtid:             event id
@@ -452,8 +449,6 @@ extern struct mutex rdtgroup_mutex;
 
 extern struct rdt_hw_resource rdt_resources_all[];
 extern struct rdtgroup rdtgroup_default;
-DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
-
 extern struct dentry *debugfs_resctrl;
 
 enum resctrl_res_level {
index 857fbbc3c8390357707e4c7a6f568fcc94dd98da..231207f09e040adf2771e0b8ae12fa525fdc4fc9 100644 (file)
@@ -2668,9 +2668,9 @@ static int rdt_get_tree(struct fs_context *fc)
                goto out_psl;
 
        if (rdt_alloc_capable)
-               static_branch_enable_cpuslocked(&rdt_alloc_enable_key);
+               resctrl_arch_enable_alloc();
        if (rdt_mon_capable)
-               static_branch_enable_cpuslocked(&rdt_mon_enable_key);
+               resctrl_arch_enable_mon();
 
        if (rdt_alloc_capable || rdt_mon_capable) {
                static_branch_enable_cpuslocked(&rdt_enable_key);
@@ -2946,8 +2946,8 @@ static void rdt_kill_sb(struct super_block *sb)
        rdtgroup_default.mode = RDT_MODE_SHAREABLE;
        schemata_list_destroy();
        rdtgroup_destroy_root();
-       static_branch_disable_cpuslocked(&rdt_alloc_enable_key);
-       static_branch_disable_cpuslocked(&rdt_mon_enable_key);
+       resctrl_arch_disable_alloc();
+       resctrl_arch_disable_mon();
        static_branch_disable_cpuslocked(&rdt_enable_key);
        resctrl_mounted = false;
        kernfs_kill_sb(sb);