linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Sudeep Holla <sudeep.holla@arm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	linux-kernel@vger.kernel.org
Cc: Leo Yan <leo.yan@linaro.org>
Subject: [PATCH v1 2/3] arch_topology: Handle inconsistent binding of CPU raw capacity
Date: Sun, 13 Mar 2022 13:55:11 +0800	[thread overview]
Message-ID: <20220313055512.248571-3-leo.yan@linaro.org> (raw)
In-Reply-To: <20220313055512.248571-1-leo.yan@linaro.org>

There have a corner case is if we use below DT binding:

  cpu0: cpu@0 {
  	compatible = "arm,cortex-a53";
  	device_type = "cpu";
  	reg = <0x0 0x0>;
  	enable-method = "psci";
  };

  cpu1: cpu@1 {
  	compatible = "arm,cortex-a53";
  	device_type = "cpu";
  	reg = <0x0 0x1>;
  	enable-method = "psci";
  	capacity-dmips-mhz = <1024>;
  };

In this case, CPU0 node misses to bind "capacity-dmips-mhz" property,
and CPU1 node binds the property, this means the CPU raw capacity
binding is inconsistent across all CPUs.

This patch introduces an extra flag 'cap_property_miss' to indicate that
any previous CPU nodes miss binding for "capacity-dmips-mhz" property,
and any new CPU node contains the property, it detects the inconsistent
binding, and sets 'cap_parsing_failed' to true and frees raw capacity
array.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 drivers/base/arch_topology.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index b81777ae6425..0687576e880b 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -294,6 +294,7 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
 	struct clk *cpu_clk;
 	int ret;
 	u32 cpu_capacity;
+	static bool cap_property_miss;
 
 	if (cap_parsing_failed)
 		return false;
@@ -301,6 +302,20 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
 	ret = of_property_read_u32(cpu_node, "capacity-dmips-mhz",
 				   &cpu_capacity);
 	if (!ret) {
+		/*
+		 * A previous CPU node misses binding for CPU raw capacity and
+		 * current CPU node finds its property "capacity-dmips-mhz",
+		 * thus the DT binding for "capacity-dmips-mhz" is inconsistent
+		 * across all CPUs.  Set 'cap_parsing_failed' flag and drop the
+		 * CPU raw capacity values.
+		 */
+		if (cap_property_miss) {
+			pr_err("cpu_capacity: binding %pOF raw capacity\n",
+				cpu_node);
+			pr_err("cpu_capacity: partial information: fallback to 1024 for all CPUs\n");
+			goto parsing_failure;
+		}
+
 		if (!raw_capacity) {
 			raw_capacity = kcalloc(num_possible_cpus(),
 					       sizeof(*raw_capacity),
@@ -331,12 +346,18 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
 			pr_err("cpu_capacity: missing %pOF raw capacity\n",
 				cpu_node);
 			pr_err("cpu_capacity: partial information: fallback to 1024 for all CPUs\n");
-			cap_parsing_failed = true;
-			free_raw_capacity();
+			goto parsing_failure;
+		} else {
+			cap_property_miss = true;
 		}
 	}
 
 	return !ret;
+
+parsing_failure:
+	cap_parsing_failed = true;
+	free_raw_capacity();
+	return !ret;
 }
 
 #ifdef CONFIG_CPU_FREQ
-- 
2.25.1


  parent reply	other threads:[~2022-03-13  5:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13  5:55 [PATCH v1 0/3] arch_topology: Correct CPU capacity scaling Leo Yan
2022-03-13  5:55 ` [PATCH v1 1/3] arch_topology: Correct semantics for 'cap_parsing_failed' Leo Yan
2022-03-13  5:55 ` Leo Yan [this message]
2022-03-13  5:55 ` [PATCH v1 3/3] arch_topology: Scale CPU capacity if without CPU raw capacity Leo Yan
2022-03-14 18:10 ` [PATCH v1 0/3] arch_topology: Correct CPU capacity scaling Ionela Voinescu
2022-03-15  3:29   ` Leo Yan
2022-03-15 10:08     ` Sudeep Holla
2022-03-15 14:59       ` Leo Yan
2022-03-15  9:49   ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220313055512.248571-3-leo.yan@linaro.org \
    --to=leo.yan@linaro.org \
    --cc=bryan.odonoghue@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).