| From: Tony Luck <tony.luck@intel.com> |
| Subject: cacheinfo: add function to get cacheinfo for a given (cpu, cachelevel) |
| Date: Fri, 31 May 2024 12:57:18 -0700 |
| |
| Patch series "Add and use get_cpu_cacheinfo_level()". |
| |
| This helper function came up in discussion of the resctrl patches for |
| Sub-NUMA Cluster (SNC) support. Reinette pointed out[1] that there are |
| already two places where it would clean things up by avoiding open coding. |
| The SNC patches will add two additional call sites. |
| |
| So rather than have this jammed up as part of the SNC series, I'm posting |
| it as a simple standalone cleanup. |
| |
| [1] https://lore.kernel.org/all/050c64b3-20b3-4db6-b782-f5124ebaab31@intel.com/ |
| |
| |
| This patch (of 3): |
| |
| 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. |
| |
| Link: https://lkml.kernel.org/r/20240531195720.232561-1-tony.luck@intel.com |
| Link: https://lkml.kernel.org/r/20240531195720.232561-2-tony.luck@intel.com |
| Signed-off-by: Tony Luck <tony.luck@intel.com> |
| Cc: Babu Moger <babu.moger@amd.com> |
| Cc: Borislav Petkov (AMD) <bp@alien8.de> |
| Cc: Dave Martin <Dave.Martin@arm.com> |
| Cc: Drew Fustini <dfustini@baylibre.com> |
| Cc: Fenghua Yu <fenghua.yu@intel.com> |
| Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| Cc: James Morse <james.morse@arm.com> |
| Cc: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> |
| Cc: Peter Newman <peternewman@google.com> |
| Cc: Reinette Chatre <reinette.chatre@intel.com> |
| Cc: Thomas Gleixner <tglx@linutronix.de> |
| Cc: Tony Luck <tony.luck@intel.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| include/linux/cacheinfo.h | 21 ++++++++++++++++----- |
| 1 file changed, 16 insertions(+), 5 deletions(-) |
| |
| --- a/include/linux/cacheinfo.h~cacheinfo-add-function-to-get-cacheinfo-for-a-given-cpu-cachelevel |
| +++ a/include/linux/cacheinfo.h |
| @@ -113,10 +113,10 @@ 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 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 +124,23 @@ static inline int get_cpu_cacheinfo_id(i |
| 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 |
| _ |