* [PATCH 0/5] Refactoring finding CPU phandles in DT
@ 2025-07-07 15:04 Alireza Sanaee
2025-07-07 15:04 ` [PATCH 1/5] of: add infra for finding CPU id from phandle Alireza Sanaee
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: Alireza Sanaee @ 2025-07-07 15:04 UTC (permalink / raw)
To: mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
This series refactors the way CPU IDs are retrieved from the device
tree.
Usually, there is a for loop that goes over every single CPU that can be
avoided. This also reduces the amount of NULL pointer checks in drivers.
I have abstracted away that loop and introduced a new function
(of_cpu_node_to_id) for this.
This patchset is a subset of [1], where I removed content and patches
relevant to hyper-threaded cores for DT. Based on the discussion, the
code refactor is still useful, hence this patchset.
[1] https://lore.kernel.org/all/20250512080715.82-1-alireza.sanaee@huawei.com/
Alireza Sanaee (5):
of: add infra for finding CPU id from phandle
arch_topology: update CPU map to use the new API
coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id
coresight: Use of_cpu_phandle_to_id for grabbing CPU id
perf/arm-dsu: refactor cpu id retrieval via new API
of_cpu_phandle_to_id
drivers/base/arch_topology.c | 12 ++++----
.../coresight/coresight-cti-platform.c | 15 ++--------
.../hwtracing/coresight/coresight-platform.c | 14 ++-------
drivers/of/cpu.c | 29 +++++++++++++++++++
drivers/perf/arm_dsu_pmu.c | 6 ++--
include/linux/of.h | 9 ++++++
6 files changed, 51 insertions(+), 34 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/5] of: add infra for finding CPU id from phandle
2025-07-07 15:04 [PATCH 0/5] Refactoring finding CPU phandles in DT Alireza Sanaee
@ 2025-07-07 15:04 ` Alireza Sanaee
2025-07-08 8:26 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 2/5] arch_topology: update CPU map to use the new API Alireza Sanaee
` (3 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Alireza Sanaee @ 2025-07-07 15:04 UTC (permalink / raw)
To: mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
Get CPU id from phandle. Many drivers get do this by getting hold of CPU
node first through a phandle and then find the CPU ID using the relevant
function. This commit encapsulates cpu node finding and improves
readability.
The API interface requires two parameters, 1) node, 2) pointer to CPU
node. API sets the pointer to the CPU node and allows the driver to play
with the CPU itself, for logging purposes for instance.
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
drivers/of/cpu.c | 29 +++++++++++++++++++++++++++++
include/linux/of.h | 9 +++++++++
2 files changed, 38 insertions(+)
diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c
index 5214dc3d05ae..fba17994fc20 100644
--- a/drivers/of/cpu.c
+++ b/drivers/of/cpu.c
@@ -173,6 +173,35 @@ int of_cpu_node_to_id(struct device_node *cpu_node)
}
EXPORT_SYMBOL(of_cpu_node_to_id);
+/**
+ * of_cpu_phandle_to_id: Get the logical CPU number for a given device_node
+ *
+ * @node: Pointer to the device_node containing CPU phandle.
+ * @cpu_np: Pointer to the device_node for CPU.
+ * @cpu_idx: The index of the CPU in the list of CPUs.
+ *
+ * Return: The logical CPU number of the given CPU device_node or -ENODEV if
+ * the CPU is not found, or if the node is NULL, it returns -1. On success,
+ * cpu_np will always point to the retrieved CPU device_node with refcount
+ * incremented, use of_node_put() on it when done.
+ */
+int of_cpu_phandle_to_id(const struct device_node *node,
+ struct device_node **cpu_np,
+ uint8_t cpu_idx)
+{
+ if (!node)
+ return -1;
+
+ *cpu_np = of_parse_phandle(node, "cpu", 0);
+ if (!*cpu_np)
+ *cpu_np = of_parse_phandle(node, "cpus", cpu_idx);
+ if (!*cpu_np)
+ return -ENODEV;
+
+ return of_cpu_node_to_id(*cpu_np);
+}
+EXPORT_SYMBOL(of_cpu_phandle_to_id);
+
/**
* of_get_cpu_state_node - Get CPU's idle state node at the given index
*
diff --git a/include/linux/of.h b/include/linux/of.h
index eaf0e2a2b75c..194f1cb0f6c6 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -360,6 +360,8 @@ extern const void *of_get_property(const struct device_node *node,
extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
extern struct device_node *of_cpu_device_node_get(int cpu);
extern int of_cpu_node_to_id(struct device_node *np);
+extern int of_cpu_phandle_to_id(const struct device_node *np,
+ struct device_node **cpu_np, uint8_t cpu_idx);
extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
extern struct device_node *of_get_cpu_state_node(const struct device_node *cpu_node,
int index);
@@ -662,6 +664,13 @@ static inline int of_cpu_node_to_id(struct device_node *np)
return -ENODEV;
}
+static inline int of_cpu_phandle_to_id(const struct device_node *np,
+ struct device_node **cpu_np,
+ uint8_t cpu_idx)
+{
+ return -ENODEV;
+}
+
static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
{
return NULL;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/5] arch_topology: update CPU map to use the new API
2025-07-07 15:04 [PATCH 0/5] Refactoring finding CPU phandles in DT Alireza Sanaee
2025-07-07 15:04 ` [PATCH 1/5] of: add infra for finding CPU id from phandle Alireza Sanaee
@ 2025-07-07 15:04 ` Alireza Sanaee
2025-07-08 6:29 ` Krzysztof Kozlowski
2025-07-08 8:31 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 3/5] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
` (2 subsequent siblings)
4 siblings, 2 replies; 14+ messages in thread
From: Alireza Sanaee @ 2025-07-07 15:04 UTC (permalink / raw)
To: mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
Cleans up the cpu-map generation using the created API.
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
drivers/base/arch_topology.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 3ebe77566788..88970f13f684 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
*/
static int __init get_cpu_for_node(struct device_node *node)
{
+ struct device_node *cpu_node __free(device_node) = NULL;
int cpu;
- struct device_node *cpu_node __free(device_node) =
- of_parse_phandle(node, "cpu", 0);
- if (!cpu_node)
- return -1;
+ cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
- cpu = of_cpu_node_to_id(cpu_node);
if (cpu >= 0)
topology_parse_cpu_capacity(cpu_node, cpu);
- else
+ else if (cpu == -ENODEV)
pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
cpu_node, cpumask_pr_args(cpu_possible_mask));
+ else
+ return -1;
return cpu;
}
+
static int __init parse_core(struct device_node *core, int package_id,
int cluster_id, int core_id)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/5] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id
2025-07-07 15:04 [PATCH 0/5] Refactoring finding CPU phandles in DT Alireza Sanaee
2025-07-07 15:04 ` [PATCH 1/5] of: add infra for finding CPU id from phandle Alireza Sanaee
2025-07-07 15:04 ` [PATCH 2/5] arch_topology: update CPU map to use the new API Alireza Sanaee
@ 2025-07-07 15:04 ` Alireza Sanaee
2025-07-08 8:36 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 4/5] coresight: " Alireza Sanaee
2025-07-07 15:04 ` [PATCH 5/5] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
4 siblings, 1 reply; 14+ messages in thread
From: Alireza Sanaee @ 2025-07-07 15:04 UTC (permalink / raw)
To: mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
Use the newly created API to grab CPU id.
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
.../hwtracing/coresight/coresight-cti-platform.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c
index d0ae10bf6128..cd821e926792 100644
--- a/drivers/hwtracing/coresight/coresight-cti-platform.c
+++ b/drivers/hwtracing/coresight/coresight-cti-platform.c
@@ -41,21 +41,12 @@
*/
static int of_cti_get_cpu_at_node(const struct device_node *node)
{
+ struct device_node *dn = NULL;
int cpu;
- struct device_node *dn;
- if (node == NULL)
- return -1;
-
- dn = of_parse_phandle(node, "cpu", 0);
- /* CTI affinity defaults to no cpu */
- if (!dn)
- return -1;
- cpu = of_cpu_node_to_id(dn);
+ cpu = of_cpu_phandle_to_id(node, &dn, 0);
of_node_put(dn);
-
- /* No Affinity if no cpu nodes are found */
- return (cpu < 0) ? -1 : cpu;
+ return cpu;
}
#else
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/5] coresight: Use of_cpu_phandle_to_id for grabbing CPU id
2025-07-07 15:04 [PATCH 0/5] Refactoring finding CPU phandles in DT Alireza Sanaee
` (2 preceding siblings ...)
2025-07-07 15:04 ` [PATCH 3/5] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
@ 2025-07-07 15:04 ` Alireza Sanaee
2025-07-08 8:37 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 5/5] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
4 siblings, 1 reply; 14+ messages in thread
From: Alireza Sanaee @ 2025-07-07 15:04 UTC (permalink / raw)
To: mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
Use the newly created API to grab CPU id.
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
drivers/hwtracing/coresight/coresight-platform.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 8192ba3279f0..f032fdbe959b 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -167,19 +167,9 @@ of_coresight_get_output_ports_node(const struct device_node *node)
static int of_coresight_get_cpu(struct device *dev)
{
- int cpu;
- struct device_node *dn;
-
- if (!dev->of_node)
- return -ENODEV;
-
- dn = of_parse_phandle(dev->of_node, "cpu", 0);
- if (!dn)
- return -ENODEV;
-
- cpu = of_cpu_node_to_id(dn);
+ struct device_node *dn = NULL;
+ int cpu = of_cpu_phandle_to_id(dev->of_node, &dn, 0);
of_node_put(dn);
-
return cpu;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/5] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id
2025-07-07 15:04 [PATCH 0/5] Refactoring finding CPU phandles in DT Alireza Sanaee
` (3 preceding siblings ...)
2025-07-07 15:04 ` [PATCH 4/5] coresight: " Alireza Sanaee
@ 2025-07-07 15:04 ` Alireza Sanaee
2025-07-08 8:38 ` Jonathan Cameron
4 siblings, 1 reply; 14+ messages in thread
From: Alireza Sanaee @ 2025-07-07 15:04 UTC (permalink / raw)
To: mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
Update arm-dsu to use the new API, where both "cpus" and "cpu"
properties are supported.
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
drivers/perf/arm_dsu_pmu.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
index cb4fb59fe04b..7ef204d39173 100644
--- a/drivers/perf/arm_dsu_pmu.c
+++ b/drivers/perf/arm_dsu_pmu.c
@@ -596,11 +596,9 @@ static int dsu_pmu_dt_get_cpus(struct device *dev, cpumask_t *mask)
n = of_count_phandle_with_args(dev->of_node, "cpus", NULL);
if (n <= 0)
return -ENODEV;
+
for (; i < n; i++) {
- cpu_node = of_parse_phandle(dev->of_node, "cpus", i);
- if (!cpu_node)
- break;
- cpu = of_cpu_node_to_id(cpu_node);
+ cpu = of_cpu_phandle_to_id(dev->of_node, &cpu_node, i);
of_node_put(cpu_node);
/*
* We have to ignore the failures here and continue scanning
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
2025-07-07 15:04 ` [PATCH 2/5] arch_topology: update CPU map to use the new API Alireza Sanaee
@ 2025-07-08 6:29 ` Krzysztof Kozlowski
2025-07-08 8:22 ` Jonathan Cameron
2025-07-08 8:31 ` Jonathan Cameron
1 sibling, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-08 6:29 UTC (permalink / raw)
To: Alireza Sanaee, mark.rutland, robh
Cc: coresight, devicetree, dianders, james.clark, jonathan.cameron,
linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
On 07/07/2025 17:04, Alireza Sanaee wrote:
> Cleans up the cpu-map generation using the created API.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
> drivers/base/arch_topology.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 3ebe77566788..88970f13f684 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
> */
> static int __init get_cpu_for_node(struct device_node *node)
> {
> + struct device_node *cpu_node __free(device_node) = NULL;
That's not a correct style anymore. What's more it is not really
explained anywhere. Follow standard cleanup.h rules (constructor).
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
2025-07-08 6:29 ` Krzysztof Kozlowski
@ 2025-07-08 8:22 ` Jonathan Cameron
2025-07-08 8:26 ` Krzysztof Kozlowski
0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Cameron @ 2025-07-08 8:22 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: mark.rutland, robh, saravanak, devicetree, coresight,
suzuki.poulose, linuxarm, dianders, shameerali.kolothum.thodi,
linux-kernel, linux-perf-users, ruanjinjie, james.clark,
linux-arm-kernel, mike.leach
On Tue, 8 Jul 2025 08:29:43 +0200
Krzysztof Kozlowski <krzk@kernel.org> wrote:
> On 07/07/2025 17:04, Alireza Sanaee wrote:
> > Cleans up the cpu-map generation using the created API.
> >
> > Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> > ---
> > drivers/base/arch_topology.c | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> > index 3ebe77566788..88970f13f684 100644
> > --- a/drivers/base/arch_topology.c
> > +++ b/drivers/base/arch_topology.c
> > @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
> > */
> > static int __init get_cpu_for_node(struct device_node *node)
> > {
> > + struct device_node *cpu_node __free(device_node) = NULL;
>
>
> That's not a correct style anymore. What's more it is not really
> explained anywhere. Follow standard cleanup.h rules (constructor).
There isn't a good solution in this case as the constructor is via
a pointer passed as an argument. I'd just fall back to not using
__free here and instead doing a manual put of the node in the
paths where it is set. That might just be the final successful
return path - I've not checked closely.
>
>
> Best regards,
> Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] of: add infra for finding CPU id from phandle
2025-07-07 15:04 ` [PATCH 1/5] of: add infra for finding CPU id from phandle Alireza Sanaee
@ 2025-07-08 8:26 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2025-07-08 8:26 UTC (permalink / raw)
To: Alireza Sanaee
Cc: mark.rutland, robh, coresight, devicetree, dianders, james.clark,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
On Mon, 7 Jul 2025 16:04:10 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:
> Get CPU id from phandle. Many drivers get do this by getting hold of CPU
> node first through a phandle and then find the CPU ID using the relevant
> function. This commit encapsulates cpu node finding and improves
> readability.
>
> The API interface requires two parameters, 1) node, 2) pointer to CPU
> node. API sets the pointer to the CPU node and allows the driver to play
> with the CPU itself, for logging purposes for instance.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
> drivers/of/cpu.c | 29 +++++++++++++++++++++++++++++
> include/linux/of.h | 9 +++++++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c
> index 5214dc3d05ae..fba17994fc20 100644
> --- a/drivers/of/cpu.c
> +++ b/drivers/of/cpu.c
> @@ -173,6 +173,35 @@ int of_cpu_node_to_id(struct device_node *cpu_node)
> }
> EXPORT_SYMBOL(of_cpu_node_to_id);
>
> +/**
> + * of_cpu_phandle_to_id: Get the logical CPU number for a given device_node
> + *
> + * @node: Pointer to the device_node containing CPU phandle.
> + * @cpu_np: Pointer to the device_node for CPU.
> + * @cpu_idx: The index of the CPU in the list of CPUs.
> + *
> + * Return: The logical CPU number of the given CPU device_node or -ENODEV if
> + * the CPU is not found, or if the node is NULL, it returns -1. On success,
> + * cpu_np will always point to the retrieved CPU device_node with refcount
> + * incremented, use of_node_put() on it when done.
> + */
> +int of_cpu_phandle_to_id(const struct device_node *node,
> + struct device_node **cpu_np,
> + uint8_t cpu_idx)
> +{
> + if (!node)
> + return -1;
> +
> + *cpu_np = of_parse_phandle(node, "cpu", 0);
Gut feeling is that it would be useful to allow a NULL cpu_np
for case where they don't want the cpu device_node, just the ID.
For that you'll need a local variable to hold the device_node
then assign it or put it depending on whether cpu_np != NULL.
Maybe there are no users for that pattern though. If that's the case
then check !node || !cpu_np for that first check.
> + if (!*cpu_np)
> + *cpu_np = of_parse_phandle(node, "cpus", cpu_idx);
> + if (!*cpu_np)
> + return -ENODEV;
> +
> + return of_cpu_node_to_id(*cpu_np);
> +}
> +EXPORT_SYMBOL(of_cpu_phandle_to_id);
> +
> /**
> * of_get_cpu_state_node - Get CPU's idle state node at the given index
> *
> diff --git a/include/linux/of.h b/include/linux/of.h
> index eaf0e2a2b75c..194f1cb0f6c6 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -360,6 +360,8 @@ extern const void *of_get_property(const struct device_node *node,
> extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
> extern struct device_node *of_cpu_device_node_get(int cpu);
> extern int of_cpu_node_to_id(struct device_node *np);
> +extern int of_cpu_phandle_to_id(const struct device_node *np,
> + struct device_node **cpu_np, uint8_t cpu_idx);
> extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
> extern struct device_node *of_get_cpu_state_node(const struct device_node *cpu_node,
> int index);
> @@ -662,6 +664,13 @@ static inline int of_cpu_node_to_id(struct device_node *np)
> return -ENODEV;
> }
>
> +static inline int of_cpu_phandle_to_id(const struct device_node *np,
> + struct device_node **cpu_np,
> + uint8_t cpu_idx)
> +{
> + return -ENODEV;
> +}
> +
> static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
> {
> return NULL;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
2025-07-08 8:22 ` Jonathan Cameron
@ 2025-07-08 8:26 ` Krzysztof Kozlowski
0 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-08 8:26 UTC (permalink / raw)
To: Jonathan Cameron
Cc: mark.rutland, robh, saravanak, devicetree, coresight,
suzuki.poulose, linuxarm, dianders, shameerali.kolothum.thodi,
linux-kernel, linux-perf-users, ruanjinjie, james.clark,
linux-arm-kernel, mike.leach
On 08/07/2025 10:22, Jonathan Cameron wrote:
> On Tue, 8 Jul 2025 08:29:43 +0200
> Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
>> On 07/07/2025 17:04, Alireza Sanaee wrote:
>>> Cleans up the cpu-map generation using the created API.
>>>
>>> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
>>> ---
>>> drivers/base/arch_topology.c | 12 ++++++------
>>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
>>> index 3ebe77566788..88970f13f684 100644
>>> --- a/drivers/base/arch_topology.c
>>> +++ b/drivers/base/arch_topology.c
>>> @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
>>> */
>>> static int __init get_cpu_for_node(struct device_node *node)
>>> {
>>> + struct device_node *cpu_node __free(device_node) = NULL;
>>
>>
>> That's not a correct style anymore. What's more it is not really
>> explained anywhere. Follow standard cleanup.h rules (constructor).
>
> There isn't a good solution in this case as the constructor is via
> a pointer passed as an argument. I'd just fall back to not using
That's even more confusing! There is a destructor here but no
constructor. This is clearly the pattern we people wanted to avoid with
cleanup.h.
> __free here and instead doing a manual put of the node in the
> paths where it is set. That might just be the final successful
Yes.
> return path - I've not checked closely.
Just noticed now:
Patch btw has some more unrelated white space changes... :/
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
2025-07-07 15:04 ` [PATCH 2/5] arch_topology: update CPU map to use the new API Alireza Sanaee
2025-07-08 6:29 ` Krzysztof Kozlowski
@ 2025-07-08 8:31 ` Jonathan Cameron
1 sibling, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2025-07-08 8:31 UTC (permalink / raw)
To: Alireza Sanaee
Cc: mark.rutland, robh, coresight, devicetree, dianders, james.clark,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
On Mon, 7 Jul 2025 16:04:11 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:
> Cleans up the cpu-map generation using the created API.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
> drivers/base/arch_topology.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 3ebe77566788..88970f13f684 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
> */
> static int __init get_cpu_for_node(struct device_node *node)
> {
> + struct device_node *cpu_node __free(device_node) = NULL;
> int cpu;
> - struct device_node *cpu_node __free(device_node) =
> - of_parse_phandle(node, "cpu", 0);
>
> - if (!cpu_node)
> - return -1;
> + cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
>
> - cpu = of_cpu_node_to_id(cpu_node);
Better I think to flip logic to exit early on errors.
So taking previous review into account - something like.
struct device_node *cpu_node = NULL;
int cpu;
cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
if (cpu == -ENODEV) {
pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
cpu_node, cpumask_pr_args(cpu_possible_mask));
return -ENODEV;
} else if (cpu < 0) {
return cpu;
}
topology_parse_cpu_capacity(cpu_node, cpu);
of_node_put(cpu_node);
return cpu;
> if (cpu >= 0)
> topology_parse_cpu_capacity(cpu_node, cpu);
> - else
> + else if (cpu == -ENODEV)
> pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
> cpu_node, cpumask_pr_args(cpu_possible_mask));
> + else
> + return -1;
>
> return cpu;
> }
>
> +
Check all patches before posting for noise like this. It sneaks in as
rebases / refactors happen so you always need to eyeball for it at the end
of development.
> static int __init parse_core(struct device_node *core, int package_id,
> int cluster_id, int core_id)
> {
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/5] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id
2025-07-07 15:04 ` [PATCH 3/5] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
@ 2025-07-08 8:36 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2025-07-08 8:36 UTC (permalink / raw)
To: Alireza Sanaee
Cc: mark.rutland, robh, coresight, devicetree, dianders, james.clark,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
On Mon, 7 Jul 2025 16:04:12 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:
> Use the newly created API to grab CPU id.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
Here is the justification for allowing the node parameter to be null.
> ---
> .../hwtracing/coresight/coresight-cti-platform.c | 15 +++------------
> 1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c
> index d0ae10bf6128..cd821e926792 100644
> --- a/drivers/hwtracing/coresight/coresight-cti-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c
> @@ -41,21 +41,12 @@
> */
> static int of_cti_get_cpu_at_node(const struct device_node *node)
> {
> + struct device_node *dn = NULL;
> int cpu;
> - struct device_node *dn;
>
> - if (node == NULL)
> - return -1;
> -
> - dn = of_parse_phandle(node, "cpu", 0);
> - /* CTI affinity defaults to no cpu */
> - if (!dn)
> - return -1;
> - cpu = of_cpu_node_to_id(dn);
> + cpu = of_cpu_phandle_to_id(node, &dn, 0);
> of_node_put(dn);
With change suggested on patch 1 this becomes
static int of_cti_get_cpu_at_node(const struct device_node *node)
{
int cpu = of_cpu_phandle_to_id(node, NULL, 0);
return (cpu < 0) ? -1 : cpu;
}
> -
> - /* No Affinity if no cpu nodes are found */
> - return (cpu < 0) ? -1 : cpu;
> + return cpu;
This an result in -ENODEV hence juggle above. No idea
why the caller will care but I guess it does or this code
would not be here!
> }
>
> #else
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/5] coresight: Use of_cpu_phandle_to_id for grabbing CPU id
2025-07-07 15:04 ` [PATCH 4/5] coresight: " Alireza Sanaee
@ 2025-07-08 8:37 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2025-07-08 8:37 UTC (permalink / raw)
To: Alireza Sanaee
Cc: mark.rutland, robh, coresight, devicetree, dianders, james.clark,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
On Mon, 7 Jul 2025 16:04:13 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:
> Use the newly created API to grab CPU id.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
> drivers/hwtracing/coresight/coresight-platform.c | 14 ++------------
> 1 file changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index 8192ba3279f0..f032fdbe959b 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -167,19 +167,9 @@ of_coresight_get_output_ports_node(const struct device_node *node)
>
> static int of_coresight_get_cpu(struct device *dev)
> {
> - int cpu;
> - struct device_node *dn;
> -
> - if (!dev->of_node)
> - return -ENODEV;
> -
> - dn = of_parse_phandle(dev->of_node, "cpu", 0);
> - if (!dn)
> - return -ENODEV;
> -
> - cpu = of_cpu_node_to_id(dn);
> + struct device_node *dn = NULL;
> + int cpu = of_cpu_phandle_to_id(dev->of_node, &dn, 0);
> of_node_put(dn);
> -
Again, allowing for NULL parameter gives you simply
return of_cpu_phandle_to_id(dev->of_node, NULL, 0);
> return cpu;
> }
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 5/5] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id
2025-07-07 15:04 ` [PATCH 5/5] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
@ 2025-07-08 8:38 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2025-07-08 8:38 UTC (permalink / raw)
To: Alireza Sanaee
Cc: mark.rutland, robh, coresight, devicetree, dianders, james.clark,
krzk, linux-arm-kernel, linux-kernel, linux-perf-users, linuxarm,
mike.leach, ruanjinjie, saravanak, shameerali.kolothum.thodi,
suzuki.poulose
On Mon, 7 Jul 2025 16:04:14 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:
> Update arm-dsu to use the new API, where both "cpus" and "cpu"
> properties are supported.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
> drivers/perf/arm_dsu_pmu.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
> index cb4fb59fe04b..7ef204d39173 100644
> --- a/drivers/perf/arm_dsu_pmu.c
> +++ b/drivers/perf/arm_dsu_pmu.c
> @@ -596,11 +596,9 @@ static int dsu_pmu_dt_get_cpus(struct device *dev, cpumask_t *mask)
> n = of_count_phandle_with_args(dev->of_node, "cpus", NULL);
> if (n <= 0)
> return -ENODEV;
> +
> for (; i < n; i++) {
> - cpu_node = of_parse_phandle(dev->of_node, "cpus", i);
> - if (!cpu_node)
> - break;
> - cpu = of_cpu_node_to_id(cpu_node);
> + cpu = of_cpu_phandle_to_id(dev->of_node, &cpu_node, i);
Same again.
Does any code actually use the cpu_node?
If not you need a strong justification for ever letting it out of the new
helper.
> of_node_put(cpu_node);
> /*
> * We have to ignore the failures here and continue scanning
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2025-07-08 9:26 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 15:04 [PATCH 0/5] Refactoring finding CPU phandles in DT Alireza Sanaee
2025-07-07 15:04 ` [PATCH 1/5] of: add infra for finding CPU id from phandle Alireza Sanaee
2025-07-08 8:26 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 2/5] arch_topology: update CPU map to use the new API Alireza Sanaee
2025-07-08 6:29 ` Krzysztof Kozlowski
2025-07-08 8:22 ` Jonathan Cameron
2025-07-08 8:26 ` Krzysztof Kozlowski
2025-07-08 8:31 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 3/5] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
2025-07-08 8:36 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 4/5] coresight: " Alireza Sanaee
2025-07-08 8:37 ` Jonathan Cameron
2025-07-07 15:04 ` [PATCH 5/5] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
2025-07-08 8:38 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).