mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/6] Refactoring finding CPU phandles in DT
@ 2025-09-05 16:18 Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 1/6] of: add infra for finding CPU id from phandle Alireza Sanaee
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

This series refactor 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.co

Changes since v3:
    - Rebased to d69eb204c255c35abd9e8cb621484e8074c75eaa

Changes since v2:
    - Addressed Jonathan Cameron's comments.
    - Added reviewed-by tags.
    - Added a new commit where I suggest simplfing the code in
      arch_topology.c to remove the use of cpu_node on failure path.
    - Improve documentation.
    - Caught a bug in patch 1.
    - Commit message fixed for patch 2.

Changes since v1:
    - Rebased on top of the latest mainline.
    - Addressed Krzysztof Kozlowski's comments -- Hopefully :-)
    - Addressed Jonathan Cameron's comments.


Alireza Sanaee (6):
  of: add infra for finding CPU id from phandle
  arch_topology: drop the use of cpu_node in the pr_info
  arch_topology: update CPU map to use of_cpu_phandle_to_id
  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                  | 22 ++++-----
 .../coresight/coresight-cti-platform.c        | 13 +----
 .../hwtracing/coresight/coresight-platform.c  | 15 +-----
 drivers/of/cpu.c                              | 48 +++++++++++++++++++
 drivers/perf/arm_dsu_pmu.c                    |  7 +--
 include/linux/of.h                            |  9 ++++
 6 files changed, 71 insertions(+), 43 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 1/6] of: add infra for finding CPU id from phandle
  2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
@ 2025-09-05 16:18 ` Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 2/6] arch_topology: drop the use of cpu_node in the pr_info Alireza Sanaee
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

Get CPU ID from phandle. Some drivers such as coresight, cti-coresight,
or arm-dsu use this API for finding CPU node in DT. In particular,
drivers do this by getting the CPU device_node through a phandle and
then find the CPU ID using of_cpu_node_to_id(). This commit encapsulates
CPU node finding and improves readability.

The interface takes three parameters, 1) node, 2) pointer to
pointer of CPU node, 3) CPU node index. API sets the pointer to the CPU
node and allows the driver to work with the CPU node, for logging
purposes for instance.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 drivers/of/cpu.c   | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h |  9 +++++++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c
index 5214dc3d05ae..9e0d3ec10bc2 100644
--- a/drivers/of/cpu.c
+++ b/drivers/of/cpu.c
@@ -173,6 +173,54 @@ 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.
+ *
+ * *cpu_np is only set when cpu_np is not NULL.  Use of_node_put() to release
+ * the node reference if cpu_np != NULL and this function succeeds.
+ *
+ * Return: This function has three different possible return situations:
+ *	1) returns -EINVAL if the node is NULL.
+ *	2) returns -ENODEV if the CPU node is not found or of_cpu_node_to_id is
+ *	not successful.
+ *	3) returns the logical CPU number if the CPU node is found.
+ */
+int of_cpu_phandle_to_id(const struct device_node *node,
+			 struct device_node **cpu_np,
+			 uint8_t cpu_idx)
+{
+	struct device_node *local_cpu_node = NULL;
+	int cpu;
+
+	if (!node)
+		return -EINVAL;
+
+	if (cpu_idx == 0)
+		local_cpu_node = of_parse_phandle(node, "cpu", 0);
+	if (!local_cpu_node)
+		local_cpu_node = of_parse_phandle(node, "cpus", cpu_idx);
+	if (!local_cpu_node)
+		return -ENODEV;
+
+	cpu = of_cpu_node_to_id(local_cpu_node);
+	if (cpu < 0) {
+		of_node_put(local_cpu_node);
+		return cpu;
+	}
+
+	if (cpu_np)
+		*cpu_np = local_cpu_node;
+	else
+		of_node_put(local_cpu_node);
+
+	return cpu;
+}
+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 a62154aeda1b..717e55065d99 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -365,6 +365,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);
@@ -680,6 +682,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	[flat|nested] 11+ messages in thread

* [PATCH v4 2/6] arch_topology: drop the use of cpu_node in the pr_info
  2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 1/6] of: add infra for finding CPU id from phandle Alireza Sanaee
@ 2025-09-05 16:18 ` Alireza Sanaee
  2025-11-11 15:00   ` Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 3/6] arch_topology: update CPU map to use of_cpu_phandle_to_id Alireza Sanaee
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

Remove the use of cpu_node in the pr_info(). When of_cpu_node_to_id() fails,
it may set a pointer, cpu_node, and the get_cpu_for_node() function uses that
pointer to log further in the fail scenario.

Also, change the structure to exit early in fail scenarios which will
help enabling code unification that follows in this series.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 drivers/base/arch_topology.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 1037169abb45..6fafd86f608a 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -481,12 +481,13 @@ static int __init get_cpu_for_node(struct device_node *node)
 		return -1;
 
 	cpu = of_cpu_node_to_id(cpu_node);
-	if (cpu >= 0)
-		topology_parse_cpu_capacity(cpu_node, cpu);
-	else
-		pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
-			cpu_node, cpumask_pr_args(cpu_possible_mask));
+	if (cpu < 0) {
+		pr_info("CPU node exist but the possible cpu range is :%*pbl\n",
+			cpumask_pr_args(cpu_possible_mask));
+		return cpu;
+	}
 
+	topology_parse_cpu_capacity(cpu_node, cpu);
 	return cpu;
 }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 3/6] arch_topology: update CPU map to use of_cpu_phandle_to_id
  2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 1/6] of: add infra for finding CPU id from phandle Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 2/6] arch_topology: drop the use of cpu_node in the pr_info Alireza Sanaee
@ 2025-09-05 16:18 ` Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 4/6] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

Refactor get_cpu_for_node to use of_cpu_phandle_to_id instead of
of_cpu_node_to_id.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 drivers/base/arch_topology.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 6fafd86f608a..72bf23cdf469 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -474,20 +474,19 @@ static unsigned int max_smt_thread_num = 1;
 static int __init get_cpu_for_node(struct device_node *node)
 {
 	int cpu;
-	struct device_node *cpu_node __free(device_node) =
-		of_parse_phandle(node, "cpu", 0);
+	struct device_node *cpu_node = NULL;
 
-	if (!cpu_node)
-		return -1;
-
-	cpu = of_cpu_node_to_id(cpu_node);
-	if (cpu < 0) {
+	cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
+	if (cpu == -ENODEV) {
 		pr_info("CPU node exist but the possible cpu range is :%*pbl\n",
 			cpumask_pr_args(cpu_possible_mask));
 		return cpu;
+	} else if (cpu < 0) {
+		return -1;
 	}
 
 	topology_parse_cpu_capacity(cpu_node, cpu);
+	of_node_put(cpu_node);
 	return cpu;
 }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 4/6] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id
  2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
                   ` (2 preceding siblings ...)
  2025-09-05 16:18 ` [PATCH v4 3/6] arch_topology: update CPU map to use of_cpu_phandle_to_id Alireza Sanaee
@ 2025-09-05 16:18 ` Alireza Sanaee
  2025-09-10 16:28   ` Suzuki K Poulose
  2025-09-05 16:18 ` [PATCH v4 5/6] coresight: Use of_cpu_phandle_to_id for grabbing CPU ID Alireza Sanaee
  2025-09-05 16:18 ` [PATCH v4 6/6] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
  5 siblings, 1 reply; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

Use the newly created API (of_cpu_phandle_to_id) to grab CPU ID.

Reviewed-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 .../hwtracing/coresight/coresight-cti-platform.c    | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c
index d0ae10bf6128..2629962dbe3e 100644
--- a/drivers/hwtracing/coresight/coresight-cti-platform.c
+++ b/drivers/hwtracing/coresight/coresight-cti-platform.c
@@ -41,18 +41,7 @@
  */
 static int of_cti_get_cpu_at_node(const struct device_node *node)
 {
-	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);
-	of_node_put(dn);
+	int cpu = of_cpu_phandle_to_id(node, NULL, 0);
 
 	/* No Affinity  if no cpu nodes are found */
 	return (cpu < 0) ? -1 : cpu;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 5/6] coresight: Use of_cpu_phandle_to_id for grabbing CPU ID
  2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
                   ` (3 preceding siblings ...)
  2025-09-05 16:18 ` [PATCH v4 4/6] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
@ 2025-09-05 16:18 ` Alireza Sanaee
  2025-09-10 16:29   ` Suzuki K Poulose
  2025-09-05 16:18 ` [PATCH v4 6/6] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
  5 siblings, 1 reply; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

Use the newly created API (of_cpu_phandle_to_id) to grab CPU ID.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 drivers/hwtracing/coresight/coresight-platform.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 0db64c5f4995..95d46ea08936 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -167,20 +167,7 @@ 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);
-	of_node_put(dn);
-
-	return cpu;
+	return of_cpu_phandle_to_id(dev->of_node, NULL, 0);
 }
 
 /*
-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 6/6] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id
  2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
                   ` (4 preceding siblings ...)
  2025-09-05 16:18 ` [PATCH v4 5/6] coresight: Use of_cpu_phandle_to_id for grabbing CPU ID Alireza Sanaee
@ 2025-09-05 16:18 ` Alireza Sanaee
  2025-09-10 16:29   ` Suzuki K Poulose
  5 siblings, 1 reply; 11+ messages in thread
From: Alireza Sanaee @ 2025-09-05 16:18 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak, suzuki.poulose

Update arm-dsu to use the new API (of_cpu_phandle_to_id).

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 drivers/perf/arm_dsu_pmu.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
index cb4fb59fe04b..8f76bd94349c 100644
--- a/drivers/perf/arm_dsu_pmu.c
+++ b/drivers/perf/arm_dsu_pmu.c
@@ -591,17 +591,12 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev)
 static int dsu_pmu_dt_get_cpus(struct device *dev, cpumask_t *mask)
 {
 	int i = 0, n, cpu;
-	struct device_node *cpu_node;
 
 	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);
-		of_node_put(cpu_node);
+		cpu = of_cpu_phandle_to_id(dev->of_node, NULL, i);
 		/*
 		 * We have to ignore the failures here and continue scanning
 		 * the list to handle cases where the nr_cpus could be capped
-- 
2.43.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 4/6] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id
  2025-09-05 16:18 ` [PATCH v4 4/6] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
@ 2025-09-10 16:28   ` Suzuki K Poulose
  0 siblings, 0 replies; 11+ messages in thread
From: Suzuki K Poulose @ 2025-09-10 16:28 UTC (permalink / raw)
  To: Alireza Sanaee, devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak

On 05/09/2025 17:18, Alireza Sanaee wrote:
> Use the newly created API (of_cpu_phandle_to_id) to grab CPU ID.
> 
> Reviewed-by: Mike Leach <mike.leach@linaro.org>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
>   .../hwtracing/coresight/coresight-cti-platform.c    | 13 +------------
>   1 file changed, 1 insertion(+), 12 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c
> index d0ae10bf6128..2629962dbe3e 100644
> --- a/drivers/hwtracing/coresight/coresight-cti-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c
> @@ -41,18 +41,7 @@
>    */
>   static int of_cti_get_cpu_at_node(const struct device_node *node)
>   {
> -	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);
> -	of_node_put(dn);
> +	int cpu = of_cpu_phandle_to_id(node, NULL, 0);
>   
>   	/* No Affinity  if no cpu nodes are found */
>   	return (cpu < 0) ? -1 : cpu;

Assuming this is going in via DT tree:

Acked-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Suzuki


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 5/6] coresight: Use of_cpu_phandle_to_id for grabbing CPU ID
  2025-09-05 16:18 ` [PATCH v4 5/6] coresight: Use of_cpu_phandle_to_id for grabbing CPU ID Alireza Sanaee
@ 2025-09-10 16:29   ` Suzuki K Poulose
  0 siblings, 0 replies; 11+ messages in thread
From: Suzuki K Poulose @ 2025-09-10 16:29 UTC (permalink / raw)
  To: Alireza Sanaee, devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak

On 05/09/2025 17:18, Alireza Sanaee wrote:
> Use the newly created API (of_cpu_phandle_to_id) to grab CPU ID.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Reviewed-by: Mike Leach <mike.leach@linaro.org>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
>   drivers/hwtracing/coresight/coresight-platform.c | 15 +--------------
>   1 file changed, 1 insertion(+), 14 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index 0db64c5f4995..95d46ea08936 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -167,20 +167,7 @@ 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);
> -	of_node_put(dn);
> -
> -	return cpu;
> +	return of_cpu_phandle_to_id(dev->of_node, NULL, 0);
>   }
>   
>   /*

Acked-by: Suzuki K Poulose <suzuki.poulose@arm.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 6/6] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id
  2025-09-05 16:18 ` [PATCH v4 6/6] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
@ 2025-09-10 16:29   ` Suzuki K Poulose
  0 siblings, 0 replies; 11+ messages in thread
From: Suzuki K Poulose @ 2025-09-10 16:29 UTC (permalink / raw)
  To: Alireza Sanaee, devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, linuxarm, mark.rutland,
	mike.leach, robh, ruanjinjie, saravanak

On 05/09/2025 17:18, Alireza Sanaee wrote:
> Update arm-dsu to use the new API (of_cpu_phandle_to_id).
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
>   drivers/perf/arm_dsu_pmu.c | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
> index cb4fb59fe04b..8f76bd94349c 100644
> --- a/drivers/perf/arm_dsu_pmu.c
> +++ b/drivers/perf/arm_dsu_pmu.c
> @@ -591,17 +591,12 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev)
>   static int dsu_pmu_dt_get_cpus(struct device *dev, cpumask_t *mask)
>   {
>   	int i = 0, n, cpu;
> -	struct device_node *cpu_node;
>   
>   	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);
> -		of_node_put(cpu_node);
> +		cpu = of_cpu_phandle_to_id(dev->of_node, NULL, i);
>   		/*
>   		 * We have to ignore the failures here and continue scanning
>   		 * the list to handle cases where the nr_cpus could be capped

Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 2/6] arch_topology: drop the use of cpu_node in the pr_info
  2025-09-05 16:18 ` [PATCH v4 2/6] arch_topology: drop the use of cpu_node in the pr_info Alireza Sanaee
@ 2025-11-11 15:00   ` Alireza Sanaee
  0 siblings, 0 replies; 11+ messages in thread
From: Alireza Sanaee @ 2025-11-11 15:00 UTC (permalink / raw)
  To: devicetree, linux-kernel
  Cc: coresight, dianders, james.clark, jonathan.cameron, krzk,
	linux-arm-kernel, linux-perf-users, mark.rutland, mike.leach,
	robh, ruanjinjie, saravanak, suzuki.poulose, sudeep.holla

On Fri, 5 Sep 2025 17:18:25 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:

Hi everyone,

+CC Sudeep.

I checked the patchset related to this patch and it still applies.

Just a reminder if case you think it is ready.

Thanks,
Alireza

> Remove the use of cpu_node in the pr_info(). When of_cpu_node_to_id() fails,
> it may set a pointer, cpu_node, and the get_cpu_for_node() function uses that
> pointer to log further in the fail scenario.
> 
> Also, change the structure to exit early in fail scenarios which will
> help enabling code unification that follows in this series.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
>  drivers/base/arch_topology.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 1037169abb45..6fafd86f608a 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -481,12 +481,13 @@ static int __init get_cpu_for_node(struct device_node *node)
>  		return -1;
>  
>  	cpu = of_cpu_node_to_id(cpu_node);
> -	if (cpu >= 0)
> -		topology_parse_cpu_capacity(cpu_node, cpu);
> -	else
> -		pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
> -			cpu_node, cpumask_pr_args(cpu_possible_mask));
> +	if (cpu < 0) {
> +		pr_info("CPU node exist but the possible cpu range is :%*pbl\n",
> +			cpumask_pr_args(cpu_possible_mask));
> +		return cpu;
> +	}
>  
> +	topology_parse_cpu_capacity(cpu_node, cpu);
>  	return cpu;
>  }
>  


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-11-11 15:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-05 16:18 [PATCH v4 0/6] Refactoring finding CPU phandles in DT Alireza Sanaee
2025-09-05 16:18 ` [PATCH v4 1/6] of: add infra for finding CPU id from phandle Alireza Sanaee
2025-09-05 16:18 ` [PATCH v4 2/6] arch_topology: drop the use of cpu_node in the pr_info Alireza Sanaee
2025-11-11 15:00   ` Alireza Sanaee
2025-09-05 16:18 ` [PATCH v4 3/6] arch_topology: update CPU map to use of_cpu_phandle_to_id Alireza Sanaee
2025-09-05 16:18 ` [PATCH v4 4/6] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Alireza Sanaee
2025-09-10 16:28   ` Suzuki K Poulose
2025-09-05 16:18 ` [PATCH v4 5/6] coresight: Use of_cpu_phandle_to_id for grabbing CPU ID Alireza Sanaee
2025-09-10 16:29   ` Suzuki K Poulose
2025-09-05 16:18 ` [PATCH v4 6/6] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Alireza Sanaee
2025-09-10 16:29   ` Suzuki K Poulose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®