[RESENDv2] arm: topology: Consider clock-frequency property from parent /cpus node

Message ID 20221216124157.13270-1-stefan.wiehler@nokia.com
State New
Headers
Series [RESENDv2] arm: topology: Consider clock-frequency property from parent /cpus node |

Commit Message

Stefan Wiehler Dec. 16, 2022, 12:41 p.m. UTC
  If the clock-frequency property is not set in the cpu node but in the
parent /cpus node, the following warning is emitted:

  /cpus/cpu@X missing clock-frequency property

The devicetree specification in section 3.8 however specifies that
"properties that have identical values across cpu nodes may be placed in
the /cpus node instead.  A client program must first examine a specific cpu
node, but if an expected property is not found then it should look at the
parent /cpus node."

Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com>
---
 arch/arm/kernel/topology.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
  

Comments

Russell King (Oracle) Dec. 16, 2022, 12:53 p.m. UTC | #1
Hi,

On Fri, Dec 16, 2022 at 01:41:58PM +0100, Stefan Wiehler wrote:
> +	cn = of_get_cpu_node(cpu, NULL);
> +	if (!cn)
> +		pr_err("missing device node for CPU %d\n", cpu);
> +	cn = of_get_parent(cn);

Doesn't this need to do an of_node_put()?

> +	if (!cn)
> +		pr_err("missing parent node for CPU %d\n", cpu);
> +	common_rate = of_get_property(cn, "clock-frequency", &common_rate_len);

And here too?

Thanks.
  
Stefan Wiehler Jan. 23, 2023, 9:08 a.m. UTC | #2
Hi Russell,

 >> +	cn = of_get_cpu_node(cpu, NULL);
 >> +	if (!cn)
 >> +		pr_err("missing device node for CPU %d\n", cpu);
 >> +	cn = of_get_parent(cn);
 >
 > Doesn't this need to do an of_node_put()?
 >
 >> +	if (!cn)
 >> +		pr_err("missing parent node for CPU %d\n", cpu);
 >> +	common_rate = of_get_property(cn, "clock-frequency", 
&common_rate_len);
 >
 > And here too?

I have sent v2 in the meanwhile where I have refactored this part; 
please review:

https://patchwork.kernel.org/project/linux-arm-kernel/patch/20221221154213.24382-1-stefan.wiehler@nokia.com/

Kind regards,

Stefan Wiehler
  

Patch

diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c
index ef0058de432b..fe03f1426353 100644
--- a/arch/arm/kernel/topology.c
+++ b/arch/arm/kernel/topology.c
@@ -90,10 +90,20 @@  static void __init parse_dt_topology(void)
 	unsigned long max_capacity = 0;
 	unsigned long capacity = 0;
 	int cpu = 0;
+	const __be32 *common_rate;
+	int common_rate_len;
 
 	__cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity),
 				 GFP_NOWAIT);
 
+	cn = of_get_cpu_node(cpu, NULL);
+	if (!cn)
+		pr_err("missing device node for CPU %d\n", cpu);
+	cn = of_get_parent(cn);
+	if (!cn)
+		pr_err("missing parent node for CPU %d\n", cpu);
+	common_rate = of_get_property(cn, "clock-frequency", &common_rate_len);
+
 	for_each_possible_cpu(cpu) {
 		const __be32 *rate;
 		int len;
@@ -121,8 +131,12 @@  static void __init parse_dt_topology(void)
 
 		rate = of_get_property(cn, "clock-frequency", &len);
 		if (!rate || len != 4) {
-			pr_err("%pOF missing clock-frequency property\n", cn);
-			continue;
+			if (common_rate && common_rate_len == 4) {
+				rate = common_rate;
+			} else {
+				pr_err("%pOF missing clock-frequency property\n", cn);
+				continue;
+			}
 		}
 
 		capacity = ((be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency;