[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250422084340.457-6-alireza.sanaee@huawei.com>
Date: Tue, 22 Apr 2025 09:43:40 +0100
From: Alireza Sanaee <alireza.sanaee@...wei.com>
To: <devicetree-spec@...r.kernel.org>
CC: <robh@...nel.org>, <mark.rutland@....com>,
<linux-arm-kernel@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
<jonathan.cameron@...wei.com>, <shameerali.kolothum.thodi@...wei.com>,
<linuxarm@...wei.com>
Subject: [PATCH v1 5/5] DT: of_cpu_phandle_to_id to support SMT threads
Enhance the API to support SMT threads, this will allow sharing resources among
multiple SMT threads.
Enabled the sharing of resources, such as L1 Cache and clocks, between SMT
threads. It introduces a fix that uses thread IDs to match each CPU thread in
the register array within the cpu-node. This ensures that the cpu-map or any
driver relying on this API is fine even when SMT threads share resources.
Additionally, I have tested this for CPU based on the discussions in [1], I
adopted the new cpu-map layout, where the first parameter is a phandle and the
second is the local thread index, as shown below:
Used a new variable in CPU node "#cpu-cells", in which I describe the
number of parameters when parsing the phandle with arg to find the local
thread ID. This variable is not mandatory, and is indeed
backward-compatible. The API first look for this particular variable,
if it does not exists, it just assume thread 0, which is the existing approach.
core0 {
thread0 {
cpu = <&cpu0 0>;
};
thread1 {
cpu = <&cpu0 1>;
};
};
[1] https://lore.kernel.org/devicetree-spec/CAL_JsqK1yqRLD9B+G7UUp=D8K++mXHq0Rmv=1i6DL_jXyZwXAw@mail.gmail.com/
Signed-off-by: Alireza Sanaee <alireza.sanaee@...wei.com>
---
drivers/of/cpu.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c
index c2d729999a4e..2df07aea184e 100644
--- a/drivers/of/cpu.c
+++ b/drivers/of/cpu.c
@@ -189,21 +189,26 @@ int of_cpu_phandle_to_id(const struct device_node *node,
const char * prop)
{
bool found = false;
- int cpu, ret;
+ int cpu, ret = -1;
+ uint32_t local_thread, thread_index;
struct device_node *np;
struct of_phandle_args args;
if (!node || !prop)
- return -1;
-
- ret = of_parse_phandle_with_args(node, prop, NULL, 0, &args);
- if (ret < 0)
return ret;
+ ret = of_parse_phandle_with_args(node, prop, "#cpu-cells", 0, &args);
+ if (ret < 0) {
+ ret = of_parse_phandle_with_args(node, prop, NULL, 0, &args);
+ if (ret < 0)
+ return ret;
+ }
+
cpu_np = args.np;
+ thread_index = args.args_count == 1 ? args.args[0] : 0;
for_each_possible_cpu(cpu) {
- np = of_cpu_device_node_get(cpu);
- found = (cpu_np == np);
+ np = of_get_cpu_node(cpu, &local_thread);
+ found = (cpu_np == np) && (local_thread == thread_index);
of_node_put(np);
if (found)
return cpu;
--
2.43.0
Powered by blists - more mailing lists