
From: James Morse <james.morse@arm.com> hulk inclusion category: feature bugzilla: 34278 CVE: NA ------------------------------------------------- To provide a reasonable threshold for a measure of cache-usage, MPAM would like to keep track of the largest cache it has seen. Provide a helper that takes a cpu and a cache-level, and returns the corresponding leaf. This only works for unified caches. Callers must hold the cpus_read_lock() to prevent the leaf being free()d. Conflicts: include/linux/cacheinfo.h [Wang ShaoBo: fix a little conflicts and validate info_list] Signed-off-by: James Morse <james.morse@arm.com> Link: http://www.linux-arm.org/git?p=linux-jm.git;a=patch;h=c9972f21aa19762dc6acf1... Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com> Reviewed-by: Xiongfeng Wang <wangxiongfeng2@huawei.com> Reviewed-by: Cheng Jian <cj.chengjian@huawei.com> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- include/linux/cacheinfo.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 46b92cd61d0c..6db3f7f8a7d6 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -119,4 +119,39 @@ int acpi_find_last_cache_level(unsigned int cpu); const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf); +/* Get the id of a particular cache on @cpu. cpuhp lock must held. */ +static inline struct cacheinfo *get_cpu_cache_leaf(int cpu, int level) +{ + int i; + struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); + + for (i = 0; i < ci->num_leaves; i++) { + /* + * info_list of this cacheinfo instance + * may not be initialized because sometimes + * free_cache_attributes() may free this + * info_list but not set num_leaves to zero, + * for example when PPTT is not supported. + */ + if (!ci->info_list) + continue; + + if ((ci->info_list[i].type == CACHE_TYPE_UNIFIED) && + (ci->info_list[i].level == level)) { + return &ci->info_list[i]; + } + } + + return NULL; +} + +static inline int get_cpu_cacheinfo_id(int cpu, int level) +{ + struct cacheinfo *leaf = get_cpu_cache_leaf(cpu, level); + + if (leaf && leaf->attributes & CACHE_ID) + return leaf->id; + return -1; +} + #endif /* _LINUX_CACHEINFO_H */ -- 2.25.1