* [PATCH v2 1/3] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)
2024-06-05 16:14 [PATCH v2 0/3] Add and use get_cpu_cacheinfo_level() Tony Luck
@ 2024-06-05 16:14 ` Tony Luck
2024-06-06 10:31 ` Borislav Petkov
2024-06-05 16:14 ` [PATCH v2 2/3] x86/resctrl: Replace open code cacheinfo search in pseudo_lock_region_init() Tony Luck
2024-06-05 16:14 ` [PATCH v2 3/3] x86/resctrl: Replace open code cacheinfo search in rdtgroup_cbm_to_size() Tony Luck
2 siblings, 1 reply; 6+ messages in thread
From: Tony Luck @ 2024-06-05 16:14 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.
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 | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index 2cb15fe4fe12..b4d99052d186 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -113,10 +113,11 @@ 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;
@@ -124,12 +125,23 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level)
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] 6+ messages in thread* Re: [PATCH v2 1/3] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)
2024-06-05 16:14 ` [PATCH v2 1/3] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) Tony Luck
@ 2024-06-06 10:31 ` Borislav Petkov
0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2024-06-06 10:31 UTC (permalink / raw)
To: Tony Luck
Cc: x86, Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman,
Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
linux-kernel, patches
On Wed, Jun 05, 2024 at 09:14:25AM -0700, Tony Luck wrote:
> /*
> - * 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;
> @@ -124,12 +125,23 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level)
So:
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;
> +}
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] x86/resctrl: Replace open code cacheinfo search in pseudo_lock_region_init()
2024-06-05 16:14 [PATCH v2 0/3] Add and use get_cpu_cacheinfo_level() Tony Luck
2024-06-05 16:14 ` [PATCH v2 1/3] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) Tony Luck
@ 2024-06-05 16:14 ` Tony Luck
2024-06-05 16:14 ` [PATCH v2 3/3] x86/resctrl: Replace open code cacheinfo search in rdtgroup_cbm_to_size() Tony Luck
2 siblings, 0 replies; 6+ messages in thread
From: Tony Luck @ 2024-06-05 16:14 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
Use get_cpu_cacheinfo_level() instead of open coded search.
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 ++++++-----------
1 file changed, 6 insertions(+), 11 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;
--
2.45.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 3/3] x86/resctrl: Replace open code cacheinfo search in rdtgroup_cbm_to_size()
2024-06-05 16:14 [PATCH v2 0/3] Add and use get_cpu_cacheinfo_level() Tony Luck
2024-06-05 16:14 ` [PATCH v2 1/3] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) Tony Luck
2024-06-05 16:14 ` [PATCH v2 2/3] x86/resctrl: Replace open code cacheinfo search in pseudo_lock_region_init() Tony Luck
@ 2024-06-05 16:14 ` Tony Luck
2024-06-06 12:43 ` Borislav Petkov
2 siblings, 1 reply; 6+ messages in thread
From: Tony Luck @ 2024-06-05 16:14 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
Use get_cpu_cacheinfo_level() instead of open coded search.
Signed-off-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
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] 6+ messages in thread* Re: [PATCH v2 3/3] x86/resctrl: Replace open code cacheinfo search in rdtgroup_cbm_to_size()
2024-06-05 16:14 ` [PATCH v2 3/3] x86/resctrl: Replace open code cacheinfo search in rdtgroup_cbm_to_size() Tony Luck
@ 2024-06-06 12:43 ` Borislav Petkov
0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2024-06-06 12:43 UTC (permalink / raw)
To: Tony Luck
Cc: x86, Fenghua Yu, Reinette Chatre, Maciej Wieczor-Retman,
Peter Newman, James Morse, Babu Moger, Drew Fustini, Dave Martin,
linux-kernel, patches
On Wed, Jun 05, 2024 at 09:14:27AM -0700, Tony Luck wrote:
> Use get_cpu_cacheinfo_level() instead of open coded search.
>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
> ---
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> 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;
> }
> --
Those last two patches can be a single one which replaces open-coded
cacheinfo search in resctrl.
Or is there any particular reason for them to be separate?
Because it is a single logical change...
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 6+ messages in thread