* [PATCH v4 1/4] cpu: Move CPU hotplug function declarations into their own header
2024-06-10 0:39 [PATCH v4 0/4] Add and use get_cpu_cacheinfo_level() Tony Luck
@ 2024-06-10 0:39 ` Tony Luck
2024-06-10 0:39 ` [PATCH v4 2/4] cpu: Drop "extern" from function declarations in cpuhplock.h Tony Luck
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Tony Luck @ 2024-06-10 0:39 UTC (permalink / raw)
To: Borislav Petkov
Cc: x86, Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman,
Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
linux-kernel, patches, Tony Luck
Avoid upcoming #include hell when <linux/cachinfo.h> wants to use
lockdep_assert_cpus_held() and creates a #include loop that would
break the build for arch/riscv.
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
include/linux/cpu.h | 33 +--------------------------
include/linux/cpuhplock.h | 47 +++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 32 deletions(-)
create mode 100644 include/linux/cpuhplock.h
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 861c3bfc5f17..a8926d0a28cd 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -18,6 +18,7 @@
#include <linux/compiler.h>
#include <linux/cpumask.h>
#include <linux/cpuhotplug.h>
+#include <linux/cpuhplock.h>
#include <linux/cpu_smt.h>
struct device;
@@ -132,38 +133,6 @@ static inline int add_cpu(unsigned int cpu) { return 0;}
#endif /* CONFIG_SMP */
extern const struct bus_type cpu_subsys;
-extern int lockdep_is_cpus_held(void);
-
-#ifdef CONFIG_HOTPLUG_CPU
-extern void cpus_write_lock(void);
-extern void cpus_write_unlock(void);
-extern void cpus_read_lock(void);
-extern void cpus_read_unlock(void);
-extern int cpus_read_trylock(void);
-extern void lockdep_assert_cpus_held(void);
-extern void cpu_hotplug_disable(void);
-extern void cpu_hotplug_enable(void);
-void clear_tasks_mm_cpumask(int cpu);
-int remove_cpu(unsigned int cpu);
-int cpu_device_down(struct device *dev);
-extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
-
-#else /* CONFIG_HOTPLUG_CPU */
-
-static inline void cpus_write_lock(void) { }
-static inline void cpus_write_unlock(void) { }
-static inline void cpus_read_lock(void) { }
-static inline void cpus_read_unlock(void) { }
-static inline int cpus_read_trylock(void) { return true; }
-static inline void lockdep_assert_cpus_held(void) { }
-static inline void cpu_hotplug_disable(void) { }
-static inline void cpu_hotplug_enable(void) { }
-static inline int remove_cpu(unsigned int cpu) { return -EPERM; }
-static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
-#endif /* !CONFIG_HOTPLUG_CPU */
-
-DEFINE_LOCK_GUARD_0(cpus_read_lock, cpus_read_lock(), cpus_read_unlock())
-
#ifdef CONFIG_PM_SLEEP_SMP
extern int freeze_secondary_cpus(int primary);
extern void thaw_secondary_cpus(void);
diff --git a/include/linux/cpuhplock.h b/include/linux/cpuhplock.h
new file mode 100644
index 000000000000..d42d2434dab6
--- /dev/null
+++ b/include/linux/cpuhplock.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * include/linux/cpuhplock.h - cpu hotplug locking
+ *
+ * Locking functions for CPU hot plug.
+ */
+#ifndef _LINUX_CPUHPLOCK_H_
+#define _LINUX_CPUHPLOCK_H_
+
+#include <linux/cleanup.h>
+#include <linux/errno.h>
+
+struct device;
+
+extern int lockdep_is_cpus_held(void);
+
+#ifdef CONFIG_HOTPLUG_CPU
+extern void cpus_write_lock(void);
+extern void cpus_write_unlock(void);
+extern void cpus_read_lock(void);
+extern void cpus_read_unlock(void);
+extern int cpus_read_trylock(void);
+extern void lockdep_assert_cpus_held(void);
+extern void cpu_hotplug_disable(void);
+extern void cpu_hotplug_enable(void);
+void clear_tasks_mm_cpumask(int cpu);
+int remove_cpu(unsigned int cpu);
+int cpu_device_down(struct device *dev);
+extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
+
+#else /* CONFIG_HOTPLUG_CPU */
+
+static inline void cpus_write_lock(void) { }
+static inline void cpus_write_unlock(void) { }
+static inline void cpus_read_lock(void) { }
+static inline void cpus_read_unlock(void) { }
+static inline int cpus_read_trylock(void) { return true; }
+static inline void lockdep_assert_cpus_held(void) { }
+static inline void cpu_hotplug_disable(void) { }
+static inline void cpu_hotplug_enable(void) { }
+static inline int remove_cpu(unsigned int cpu) { return -EPERM; }
+static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
+#endif /* !CONFIG_HOTPLUG_CPU */
+
+DEFINE_LOCK_GUARD_0(cpus_read_lock, cpus_read_lock(), cpus_read_unlock())
+
+#endif /* _LINUX_CPUHPLOCK_H_ */
--
2.45.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 2/4] cpu: Drop "extern" from function declarations in cpuhplock.h
2024-06-10 0:39 [PATCH v4 0/4] Add and use get_cpu_cacheinfo_level() Tony Luck
2024-06-10 0:39 ` [PATCH v4 1/4] cpu: Move CPU hotplug function declarations into their own header Tony Luck
@ 2024-06-10 0:39 ` Tony Luck
2024-06-10 0:39 ` [PATCH v4 3/4] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) Tony Luck
2024-06-10 0:39 ` [PATCH v4 4/4] x86/resctrl: Replace open code cacheinfo searches Tony Luck
3 siblings, 0 replies; 5+ messages in thread
From: Tony Luck @ 2024-06-10 0:39 UTC (permalink / raw)
To: Borislav Petkov
Cc: x86, Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman,
Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
linux-kernel, patches, Tony Luck
This file was created with a direct cut and paste from cpu.h so
kept the legacy declaration style.
But the Linux coding standard for function declarations in header
files is to avoid use of "extern".
Drop "extern" from all function declarations.
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
include/linux/cpuhplock.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/linux/cpuhplock.h b/include/linux/cpuhplock.h
index d42d2434dab6..999f475bea98 100644
--- a/include/linux/cpuhplock.h
+++ b/include/linux/cpuhplock.h
@@ -15,18 +15,18 @@ struct device;
extern int lockdep_is_cpus_held(void);
#ifdef CONFIG_HOTPLUG_CPU
-extern void cpus_write_lock(void);
-extern void cpus_write_unlock(void);
-extern void cpus_read_lock(void);
-extern void cpus_read_unlock(void);
-extern int cpus_read_trylock(void);
-extern void lockdep_assert_cpus_held(void);
-extern void cpu_hotplug_disable(void);
-extern void cpu_hotplug_enable(void);
+void cpus_write_lock(void);
+void cpus_write_unlock(void);
+void cpus_read_lock(void);
+void cpus_read_unlock(void);
+int cpus_read_trylock(void);
+void lockdep_assert_cpus_held(void);
+void cpu_hotplug_disable(void);
+void cpu_hotplug_enable(void);
void clear_tasks_mm_cpumask(int cpu);
int remove_cpu(unsigned int cpu);
int cpu_device_down(struct device *dev);
-extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
+void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
#else /* CONFIG_HOTPLUG_CPU */
--
2.45.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 3/4] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)
2024-06-10 0:39 [PATCH v4 0/4] Add and use get_cpu_cacheinfo_level() Tony Luck
2024-06-10 0:39 ` [PATCH v4 1/4] cpu: Move CPU hotplug function declarations into their own header Tony Luck
2024-06-10 0:39 ` [PATCH v4 2/4] cpu: Drop "extern" from function declarations in cpuhplock.h Tony Luck
@ 2024-06-10 0:39 ` Tony Luck
2024-06-10 0:39 ` [PATCH v4 4/4] x86/resctrl: Replace open code cacheinfo searches Tony Luck
3 siblings, 0 replies; 5+ messages in thread
From: Tony Luck @ 2024-06-10 0:39 UTC (permalink / raw)
To: Borislav Petkov
Cc: x86, Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman,
Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
linux-kernel, patches, Tony Luck
Resctrl code open codes a search for information about a given cache
level in a couple of places (and more are on the way).
Provide a new inline function get_cpu_cacheinfo_level() in
<linux/cacheinfo.h> to do the search and return a pointer to
the cacheinfo structure.
Add lockdep_assert_cpus_held() to enforce the comment that cpuhp
lock must be held.
Simplify the existing get_cpu_cacheinfo_id() by using this new
function to do the search.
Signed-off-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
include/linux/cacheinfo.h | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index 2cb15fe4fe12..3dde175f4108 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -3,6 +3,7 @@
#define _LINUX_CACHEINFO_H
#include <linux/bitops.h>
+#include <linux/cpuhplock.h>
#include <linux/cpumask.h>
#include <linux/smp.h>
@@ -113,23 +114,37 @@ int acpi_get_cache_info(unsigned int cpu,
const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
/*
- * Get the id of the cache associated with @cpu at level @level.
+ * Get the cacheinfo structure for the cache associated with @cpu at
+ * level @level.
* cpuhp lock must be held.
*/
-static inline int get_cpu_cacheinfo_id(int cpu, int level)
+static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, int level)
{
struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
int i;
+ lockdep_assert_cpus_held();
+
for (i = 0; i < ci->num_leaves; i++) {
if (ci->info_list[i].level == level) {
if (ci->info_list[i].attributes & CACHE_ID)
- return ci->info_list[i].id;
- return -1;
+ return &ci->info_list[i];
+ return NULL;
}
}
- return -1;
+ return NULL;
+}
+
+/*
+ * Get the id of the cache associated with @cpu at level @level.
+ * cpuhp lock must be held.
+ */
+static inline int get_cpu_cacheinfo_id(int cpu, int level)
+{
+ struct cacheinfo *ci = get_cpu_cacheinfo_level(cpu, level);
+
+ return ci ? ci->id : -1;
}
#ifdef CONFIG_ARM64
--
2.45.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 4/4] x86/resctrl: Replace open code cacheinfo searches
2024-06-10 0:39 [PATCH v4 0/4] Add and use get_cpu_cacheinfo_level() Tony Luck
` (2 preceding siblings ...)
2024-06-10 0:39 ` [PATCH v4 3/4] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) Tony Luck
@ 2024-06-10 0:39 ` Tony Luck
3 siblings, 0 replies; 5+ messages in thread
From: Tony Luck @ 2024-06-10 0:39 UTC (permalink / raw)
To: Borislav Petkov
Cc: x86, Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman,
Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
linux-kernel, patches, Tony Luck
pseudo_lock_region_init() and rdtgroup_cbm_to_size() open code
a search for details of a particular cache level.
Replace with get_cpu_cacheinfo_level()
Signed-off-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 17 ++++++-----------
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 +++++---------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c
index aacf236dfe3b..1bbfd3c1e300 100644
--- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c
+++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c
@@ -292,9 +292,8 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
*/
static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
{
- struct cpu_cacheinfo *ci;
+ struct cacheinfo *ci;
int ret;
- int i;
/* Pick the first cpu we find that is associated with the cache. */
plr->cpu = cpumask_first(&plr->d->cpu_mask);
@@ -306,15 +305,11 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
goto out_region;
}
- ci = get_cpu_cacheinfo(plr->cpu);
-
- plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm);
-
- for (i = 0; i < ci->num_leaves; i++) {
- if (ci->info_list[i].level == plr->s->res->cache_level) {
- plr->line_size = ci->info_list[i].coherency_line_size;
- return 0;
- }
+ ci = get_cpu_cacheinfo_level(plr->cpu, plr->s->res->cache_level);
+ if (ci) {
+ plr->line_size = ci->coherency_line_size;
+ plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm);
+ return 0;
}
ret = -1;
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 02f213f1c51c..cb68a121dabb 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1450,18 +1450,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
struct rdt_domain *d, unsigned long cbm)
{
- struct cpu_cacheinfo *ci;
unsigned int size = 0;
- int num_b, i;
+ struct cacheinfo *ci;
+ int num_b;
num_b = bitmap_weight(&cbm, r->cache.cbm_len);
- ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask));
- for (i = 0; i < ci->num_leaves; i++) {
- if (ci->info_list[i].level == r->cache_level) {
- size = ci->info_list[i].size / r->cache.cbm_len * num_b;
- break;
- }
- }
+ ci = get_cpu_cacheinfo_level(cpumask_any(&d->cpu_mask), r->cache_level);
+ if (ci)
+ size = ci->size / r->cache.cbm_len * num_b;
return size;
}
--
2.45.0
^ permalink raw reply related [flat|nested] 5+ messages in thread