All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: Mike Tipton <quic_mdtipton@quicinc.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>,
	Cristian Marussi <cristian.marussi@arm.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peng Fan <peng.fan@oss.nxp.com>, Peng Fan <peng.fan@nxp.com>
Subject: Re: [PATCH v3] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs
Date: Wed, 7 May 2025 12:59:45 +0100	[thread overview]
Message-ID: <aBtLMYqcnwacGJuy@pluto> (raw)
In-Reply-To: <20250428144728.871404-1-quic_mdtipton@quicinc.com>

On Mon, Apr 28, 2025 at 07:47:28AM -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.
> 

Hi,

bit of lagging behind, my bad.


> 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>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>
> ---
> Changes in v3:
> - Use dev_of_node(dev) instead of dev->of_node.
> - Sanity check scmi_np.
> - Pick up Reviewed-by from Peng.
> - Link to v2: https://lore.kernel.org/all/20250421195206.3736128-1-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 | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
> index 944e899eb1be..b63992de9fc7 100644
> --- a/drivers/cpufreq/scmi-cpufreq.c
> +++ b/drivers/cpufreq/scmi-cpufreq.c
> @@ -393,6 +393,35 @@ 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 = dev_of_node(scmi_dev);
> +	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 = dev_of_node(cpu_dev);
> +
> +		if (of_parse_phandle(np, "clocks", 0) == scmi_np)

Shouldn't this, on Success, be released by an of_node_put() (or, BETTER,
by some OF-related cleanup.h magic...)

> +			return true;
> +
> +		idx = of_property_match_string(np, "power-domain-names", "perf");
> +
> +		if (of_parse_phandle(np, "power-domains", idx) == scmi_np)

Same.

> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>  static int scmi_cpufreq_probe(struct scmi_device *sdev)
>  {
>  	int ret;
> @@ -401,7 +430,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;

Other than the above glitches, LGTM.
(I gave it a go on JUNO and some emulated setup..)

Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Tested-by: Cristian Marussi <cristian.marussi@arm.com>

Thanks,
Cristian

  parent reply	other threads:[~2025-05-07 11:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-28 14:47 [PATCH v3] cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs Mike Tipton
2025-05-06  1:25 ` Mike Tipton
2025-05-06 10:12   ` Sudeep Holla
2025-05-07 11:59 ` Cristian Marussi [this message]
2025-05-07 13:12   ` Sudeep Holla
2025-05-15  3:47     ` Mike Tipton
2025-05-07 13:18   ` Dan Carpenter
2025-05-07 13:27     ` Cristian Marussi

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=aBtLMYqcnwacGJuy@pluto \
    --to=cristian.marussi@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=peng.fan@oss.nxp.com \
    --cc=quic_mdtipton@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=viresh.kumar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.