Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ACPI / PPTT: Find cache level by cache-id

The MPAM table identifies caches by id. The MPAM driver also wants to know
the cache level to determine if the platform is of the shape that can be
managed via resctrl. Cacheinfo has this information, but only for CPUs that
are online.

Waiting for all CPUs to come online is a problem for platforms where
CPUs are brought online late by user-space.

Add a helper that walks every possible cache, until it finds the one
identified by cache-id, then return the level.

Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>
Tested-by: Fenghua Yu <fenghuay@nvidia.com>
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com>
Tested-by: Gavin Shan <gshan@redhat.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

James Morse and committed by
Catalin Marinas
41a7bb39 cfc085af

+71
+66
drivers/acpi/pptt.c
··· 932 932 entry->length); 933 933 } 934 934 } 935 + 936 + /** 937 + * find_acpi_cache_level_from_id() - Get the level of the specified cache 938 + * @cache_id: The id field of the cache 939 + * 940 + * Determine the level relative to any CPU for the cache identified by 941 + * cache_id. This allows the property to be found even if the CPUs are offline. 942 + * 943 + * The returned level can be used to group caches that are peers. 944 + * 945 + * The PPTT table must be rev 3 or later. 946 + * 947 + * If one CPU's L2 is shared with another CPU as L3, this function will return 948 + * an unpredictable value. 949 + * 950 + * Return: -ENOENT if the PPTT doesn't exist, the revision isn't supported or 951 + * the cache cannot be found. 952 + * Otherwise returns a value which represents the level of the specified cache. 953 + */ 954 + int find_acpi_cache_level_from_id(u32 cache_id) 955 + { 956 + int cpu; 957 + struct acpi_table_header *table; 958 + 959 + table = acpi_get_pptt(); 960 + if (!table) 961 + return -ENOENT; 962 + 963 + if (table->revision < 3) 964 + return -ENOENT; 965 + 966 + for_each_possible_cpu(cpu) { 967 + bool empty; 968 + int level = 1; 969 + u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu); 970 + struct acpi_pptt_cache *cache; 971 + struct acpi_pptt_processor *cpu_node; 972 + 973 + cpu_node = acpi_find_processor_node(table, acpi_cpu_id); 974 + if (!cpu_node) 975 + continue; 976 + 977 + do { 978 + int cache_type[] = {CACHE_TYPE_INST, CACHE_TYPE_DATA, CACHE_TYPE_UNIFIED}; 979 + 980 + empty = true; 981 + for (int i = 0; i < ARRAY_SIZE(cache_type); i++) { 982 + struct acpi_pptt_cache_v1_full *cache_v1; 983 + 984 + cache = acpi_find_cache_node(table, acpi_cpu_id, cache_type[i], 985 + level, &cpu_node); 986 + if (!cache) 987 + continue; 988 + 989 + empty = false; 990 + 991 + cache_v1 = upgrade_pptt_cache(cache); 992 + if (cache_v1 && cache_v1->cache_id == cache_id) 993 + return level; 994 + } 995 + level++; 996 + } while (!empty); 997 + } 998 + 999 + return -ENOENT; 1000 + }
+5
include/linux/acpi.h
··· 1542 1542 int find_acpi_cpu_topology_package(unsigned int cpu); 1543 1543 int find_acpi_cpu_topology_hetero_id(unsigned int cpu); 1544 1544 void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus); 1545 + int find_acpi_cache_level_from_id(u32 cache_id); 1545 1546 #else 1546 1547 static inline int acpi_pptt_cpu_is_thread(unsigned int cpu) 1547 1548 { ··· 1566 1565 } 1567 1566 static inline void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, 1568 1567 cpumask_t *cpus) { } 1568 + static inline int find_acpi_cache_level_from_id(u32 cache_id) 1569 + { 1570 + return -ENOENT; 1571 + } 1569 1572 #endif 1570 1573 1571 1574 void acpi_arch_init(void);