[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7c3d426c-f7f5-4a51-bb59-19005d55f1c5@arm.com>
Date: Wed, 19 Nov 2025 11:09:18 -0600
From: Jeremy Linton <jeremy.linton@....com>
To: Ben Horgan <ben.horgan@....com>, james.morse@....com
Cc: amitsinght@...vell.com, baisheng.gao@...soc.com,
baolin.wang@...ux.alibaba.com, bobo.shaobowang@...wei.com,
carl@...amperecomputing.com, catalin.marinas@....com, dakr@...nel.org,
dave.martin@....com, david@...hat.com, dfustini@...libre.com,
fenghuay@...dia.com, gregkh@...uxfoundation.org, gshan@...hat.com,
guohanjun@...wei.com, jonathan.cameron@...wei.com, kobak@...dia.com,
lcherian@...vell.com, lenb@...nel.org, linux-acpi@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
lpieralisi@...nel.org, peternewman@...gle.com, quic_jiles@...cinc.com,
rafael@...nel.org, robh@...nel.org, rohit.mathew@....com,
scott@...amperecomputing.com, sdonthineni@...dia.com, sudeep.holla@....com,
tan.shaopeng@...itsu.com, will@...nel.org, xhao@...ux.alibaba.com,
reinette.chatre@...el.com, Shaopeng Tan <tan.shaopeng@...fujitsu.com>,
Zeng Heng <zengheng4@...wei.com>
Subject: Re: [PATCH v6 04/34] ACPI / PPTT: Find cache level by cache-id
On 11/19/25 6:22 AM, Ben Horgan wrote:
> From: James Morse <james.morse@....com>
>
> 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.
Per V5:
Reviewed-by: Jeremy Linton <jeremy.linton@....com>>
> Signed-off-by: James Morse <james.morse@....com>
> Signed-off-by: Ben Horgan <ben.horgan@....com>
> Reviewed-by: Gavin Shan <gshan@...hat.com>
> Reviewed-by: Fenghua Yu <fenghuay@...dia.com>
> Reviewed-by: Shaopeng Tan <tan.shaopeng@...fujitsu.com>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@...wei.com>
> Tested-by: Fenghua Yu <fenghuay@...dia.com>
> Tested-by: Shaopeng Tan <tan.shaopeng@...fujitsu.com>
> Tested-by: Carl Worth <carl@...amperecomputing.com>
> Tested-by: Gavin Shan <gshan@...hat.com>
> Tested-by: Zeng Heng <zengheng4@...wei.com>
> Tested-by: Hanjun Guo <guohanjun@...wei.com>
> ---
> Changes since v4:
> Initialise acpi_cpu_id at declaration
> Convert a for loop to do/while (Jonathan)
> Use new version of acpi_pptt_cache_v1_full
>
> Changes since v3:
> Tags dropped due to rework
> Fallout/simplification from adding acpi_pptt_cache_v1_full
> Look for each cache type before incrementing level
> ---
> drivers/acpi/pptt.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
> include/linux/acpi.h | 5 ++++
> 2 files changed, 71 insertions(+)
>
> diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c
> index ef39b176dc00..da49b56a1ef2 100644
> --- a/drivers/acpi/pptt.c
> +++ b/drivers/acpi/pptt.c
> @@ -932,3 +932,69 @@ void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus)
> entry->length);
> }
> }
> +
> +/**
> + * find_acpi_cache_level_from_id() - Get the level of the specified cache
> + * @cache_id: The id field of the cache
> + *
> + * Determine the level relative to any CPU for the cache identified by
> + * cache_id. This allows the property to be found even if the CPUs are offline.
> + *
> + * The returned level can be used to group caches that are peers.
> + *
> + * The PPTT table must be rev 3 or later.
> + *
> + * If one CPU's L2 is shared with another CPU as L3, this function will return
> + * an unpredictable value.
> + *
> + * Return: -ENOENT if the PPTT doesn't exist, the revision isn't supported or
> + * the cache cannot be found.
> + * Otherwise returns a value which represents the level of the specified cache.
> + */
> +int find_acpi_cache_level_from_id(u32 cache_id)
> +{
> + int cpu;
> + struct acpi_table_header *table;
> +
> + table = acpi_get_pptt();
> + if (!table)
> + return -ENOENT;
> +
> + if (table->revision < 3)
> + return -ENOENT;
> +
> + for_each_possible_cpu(cpu) {
> + bool empty;
> + int level = 1;
> + u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
> + struct acpi_pptt_cache *cache;
> + struct acpi_pptt_processor *cpu_node;
> +
> + cpu_node = acpi_find_processor_node(table, acpi_cpu_id);
> + if (!cpu_node)
> + continue;
> +
> + do {
> + int cache_type[] = {CACHE_TYPE_INST, CACHE_TYPE_DATA, CACHE_TYPE_UNIFIED};
> +
> + empty = true;
> + for (int i = 0; i < ARRAY_SIZE(cache_type); i++) {
> + struct acpi_pptt_cache_v1_full *cache_v1;
> +
> + cache = acpi_find_cache_node(table, acpi_cpu_id, cache_type[i],
> + level, &cpu_node);
> + if (!cache)
> + continue;
> +
> + empty = false;
> +
> + cache_v1 = upgrade_pptt_cache(cache);
> + if (cache_v1 && cache_v1->cache_id == cache_id)
> + return level;
> + }
> + level++;
> + } while (!empty);
> + }
> +
> + return -ENOENT;
> +}
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 4752ebd48132..be074bdfd4d1 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -1542,6 +1542,7 @@ int find_acpi_cpu_topology_cluster(unsigned int cpu);
> int find_acpi_cpu_topology_package(unsigned int cpu);
> int find_acpi_cpu_topology_hetero_id(unsigned int cpu);
> void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus);
> +int find_acpi_cache_level_from_id(u32 cache_id);
> #else
> static inline int acpi_pptt_cpu_is_thread(unsigned int cpu)
> {
> @@ -1565,6 +1566,10 @@ static inline int find_acpi_cpu_topology_hetero_id(unsigned int cpu)
> }
> static inline void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id,
> cpumask_t *cpus) { }
> +static inline int find_acpi_cache_level_from_id(u32 cache_id)
> +{
> + return -ENOENT;
> +}
> #endif
>
> void acpi_arch_init(void);
Powered by blists - more mailing lists