* [PATCH v2] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs
@ 2025-04-21 19:52 Mike Tipton
2025-04-22 8:50 ` Peng Fan
0 siblings, 1 reply; 3+ messages in thread
From: Mike Tipton @ 2025-04-21 19:52 UTC (permalink / raw)
To: Sudeep Holla, Cristian Marussi, Rafael J . Wysocki, Viresh Kumar
Cc: arm-scmi, linux-arm-kernel, linux-pm, linux-kernel, Peng Fan,
Mike Tipton
Currently, all SCMI devices with performance domains attempt to register
a cpufreq driver, even if their performance domains aren't used to
control the CPUs. The cpufreq framework only supports registering a
single driver, so only the first device will succeed. And if that device
isn't used for the CPUs, then cpufreq will scale the wrong domains.
To avoid this, return early from scmi_cpufreq_probe() if the probing
SCMI device isn't referenced by the CPU device phandles.
This keeps the existing assumption that all CPUs are controlled by a
single SCMI device.
Signed-off-by: Mike Tipton <quic_mdtipton@quicinc.com>
---
Changes in v2:
- Return -ENODEV instead of 0 for irrelevant devices.
- Link to v1: https://lore.kernel.org/all/20250411212941.1275572-1-quic_mdtipton@quicinc.com/
drivers/cpufreq/scmi-cpufreq.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index 944e899eb1be..b558f210c342 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -393,6 +393,32 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
.set_boost = cpufreq_boost_set_sw,
};
+static bool scmi_dev_used_by_cpus(struct device *scmi_dev)
+{
+ struct device_node *scmi_np = scmi_dev->of_node;
+ struct device_node *np;
+ struct device *cpu_dev;
+ int cpu, idx;
+
+ for_each_possible_cpu(cpu) {
+ cpu_dev = get_cpu_device(cpu);
+ if (!cpu_dev)
+ continue;
+
+ np = cpu_dev->of_node;
+
+ if (of_parse_phandle(np, "clocks", 0) == scmi_np)
+ return true;
+
+ idx = of_property_match_string(np, "power-domain-names", "perf");
+
+ if (of_parse_phandle(np, "power-domains", idx) == scmi_np)
+ return true;
+ }
+
+ return false;
+}
+
static int scmi_cpufreq_probe(struct scmi_device *sdev)
{
int ret;
@@ -401,7 +427,7 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
handle = sdev->handle;
- if (!handle)
+ if (!handle || !scmi_dev_used_by_cpus(dev))
return -ENODEV;
scmi_cpufreq_driver.driver_data = sdev;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs
2025-04-21 19:52 [PATCH v2] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs Mike Tipton
@ 2025-04-22 8:50 ` Peng Fan
2025-04-23 0:58 ` Mike Tipton
0 siblings, 1 reply; 3+ messages in thread
From: Peng Fan @ 2025-04-22 8:50 UTC (permalink / raw)
To: Mike Tipton
Cc: Sudeep Holla, Cristian Marussi, Rafael J . Wysocki, Viresh Kumar,
arm-scmi, linux-arm-kernel, linux-pm, linux-kernel
On Mon, Apr 21, 2025 at 12:52:06PM -0700, Mike Tipton wrote:
>Currently, all SCMI devices with performance domains attempt to register
>a cpufreq driver, even if their performance domains aren't used to
>control the CPUs. The cpufreq framework only supports registering a
>single driver, so only the first device will succeed. And if that device
>isn't used for the CPUs, then cpufreq will scale the wrong domains.
>
>To avoid this, return early from scmi_cpufreq_probe() if the probing
>SCMI device isn't referenced by the CPU device phandles.
>
>This keeps the existing assumption that all CPUs are controlled by a
>single SCMI device.
>
>Signed-off-by: Mike Tipton <quic_mdtipton@quicinc.com>
>---
>Changes in v2:
>- Return -ENODEV instead of 0 for irrelevant devices.
>- Link to v1: https://lore.kernel.org/all/20250411212941.1275572-1-quic_mdtipton@quicinc.com/
>
> drivers/cpufreq/scmi-cpufreq.c | 28 +++++++++++++++++++++++++++-
> 1 file changed, 27 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
>index 944e899eb1be..b558f210c342 100644
>--- a/drivers/cpufreq/scmi-cpufreq.c
>+++ b/drivers/cpufreq/scmi-cpufreq.c
>@@ -393,6 +393,32 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
> .set_boost = cpufreq_boost_set_sw,
> };
>
>+static bool scmi_dev_used_by_cpus(struct device *scmi_dev)
>+{
>+ struct device_node *scmi_np = scmi_dev->of_node;
Nitpick: dev_of_node(scmi_dev->of_node) ?
>+ struct device_node *np;
>+ struct device *cpu_dev;
>+ int cpu, idx;
if (!scmi_np)
return false;
>+
>+ for_each_possible_cpu(cpu) {
>+ cpu_dev = get_cpu_device(cpu);
>+ if (!cpu_dev)
>+ continue;
>+
>+ np = cpu_dev->of_node;
dev_of_node(cpu_dev);
>+
>+ if (of_parse_phandle(np, "clocks", 0) == scmi_np)
>+ return true;
>+
>+ idx = of_property_match_string(np, "power-domain-names", "perf");
>+
>+ if (of_parse_phandle(np, "power-domains", idx) == scmi_np)
>+ return true;
>+ }
>+
>+ return false;
>+}
>+
> static int scmi_cpufreq_probe(struct scmi_device *sdev)
> {
> int ret;
>@@ -401,7 +427,7 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
>
> handle = sdev->handle;
>
>- if (!handle)
>+ if (!handle || !scmi_dev_used_by_cpus(dev))
> return -ENODEV;
>
With the minor comments addressed, LGTM:
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Regards,
Peng
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs
2025-04-22 8:50 ` Peng Fan
@ 2025-04-23 0:58 ` Mike Tipton
0 siblings, 0 replies; 3+ messages in thread
From: Mike Tipton @ 2025-04-23 0:58 UTC (permalink / raw)
To: Peng Fan
Cc: Sudeep Holla, Cristian Marussi, Rafael J . Wysocki, Viresh Kumar,
arm-scmi, linux-arm-kernel, linux-pm, linux-kernel
On Tue, Apr 22, 2025 at 04:50:16PM +0800, Peng Fan wrote:
> On Mon, Apr 21, 2025 at 12:52:06PM -0700, Mike Tipton wrote:
> >Currently, all SCMI devices with performance domains attempt to register
> >a cpufreq driver, even if their performance domains aren't used to
> >control the CPUs. The cpufreq framework only supports registering a
> >single driver, so only the first device will succeed. And if that device
> >isn't used for the CPUs, then cpufreq will scale the wrong domains.
> >
> >To avoid this, return early from scmi_cpufreq_probe() if the probing
> >SCMI device isn't referenced by the CPU device phandles.
> >
> >This keeps the existing assumption that all CPUs are controlled by a
> >single SCMI device.
> >
> >Signed-off-by: Mike Tipton <quic_mdtipton@quicinc.com>
> >---
> >Changes in v2:
> >- Return -ENODEV instead of 0 for irrelevant devices.
> >- Link to v1: https://lore.kernel.org/all/20250411212941.1275572-1-quic_mdtipton@quicinc.com/
> >
> > drivers/cpufreq/scmi-cpufreq.c | 28 +++++++++++++++++++++++++++-
> > 1 file changed, 27 insertions(+), 1 deletion(-)
> >
> >diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
> >index 944e899eb1be..b558f210c342 100644
> >--- a/drivers/cpufreq/scmi-cpufreq.c
> >+++ b/drivers/cpufreq/scmi-cpufreq.c
> >@@ -393,6 +393,32 @@ static struct cpufreq_driver scmi_cpufreq_driver = {
> > .set_boost = cpufreq_boost_set_sw,
> > };
> >
> >+static bool scmi_dev_used_by_cpus(struct device *scmi_dev)
> >+{
> >+ struct device_node *scmi_np = scmi_dev->of_node;
>
> Nitpick: dev_of_node(scmi_dev->of_node) ?
>
> >+ struct device_node *np;
> >+ struct device *cpu_dev;
> >+ int cpu, idx;
>
>
> if (!scmi_np)
> return false;
>
> >+
> >+ for_each_possible_cpu(cpu) {
> >+ cpu_dev = get_cpu_device(cpu);
> >+ if (!cpu_dev)
> >+ continue;
> >+
> >+ np = cpu_dev->of_node;
>
> dev_of_node(cpu_dev);
>
> >+
> >+ if (of_parse_phandle(np, "clocks", 0) == scmi_np)
> >+ return true;
> >+
> >+ idx = of_property_match_string(np, "power-domain-names", "perf");
> >+
> >+ if (of_parse_phandle(np, "power-domains", idx) == scmi_np)
> >+ return true;
> >+ }
> >+
> >+ return false;
> >+}
> >+
> > static int scmi_cpufreq_probe(struct scmi_device *sdev)
> > {
> > int ret;
> >@@ -401,7 +427,7 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev)
> >
> > handle = sdev->handle;
> >
> >- if (!handle)
> >+ if (!handle || !scmi_dev_used_by_cpus(dev))
> > return -ENODEV;
> >
>
> With the minor comments addressed, LGTM:
>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>
I'll make these changes. Thanks for the review!
Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-23 1:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-21 19:52 [PATCH v2] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs Mike Tipton
2025-04-22 8:50 ` Peng Fan
2025-04-23 0:58 ` Mike Tipton
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).