public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: Viresh Kumar <viresh.kumar@linaro.org>, rjw@rjwysocki.net
Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, arvind.chauhan@arm.com,
	swarren@nvidia.com, dianders@chromium.org,
	linux@arm.linux.org.uk, nicolas.pitre@linaro.org,
	thomas.abraham@linaro.org, pdeschrijver@nvidia.com
Subject: Re: [PATCH V4 3/3] cpufreq: Tegra: implement intermediate frequency callbacks
Date: Thu, 29 May 2014 11:40:19 -0600	[thread overview]
Message-ID: <53877103.8070604@wwwdotorg.org> (raw)
In-Reply-To: <dc2702973028425e3ded689a6da227658fb914c4.1400662383.git.viresh.kumar@linaro.org>

On 05/21/2014 02:59 AM, Viresh Kumar wrote:
> Tegra had always been switching to intermediate frequency (pll_p_clk) since
> ever. CPUFreq core has better support for handling notifications for these
> frequencies and so we can adapt Tegra's driver to it.
> 
> Also do a WARN() if clk_set_parent() fails while moving back to pll_x as we
> should have atleast restored to earlier frequency on error.

This patch breaks Tegra. The reason is below.

> diff --git a/drivers/cpufreq/tegra-cpufreq.c b/drivers/cpufreq/tegra-cpufreq.c

> -static int tegra_cpu_clk_set_rate(unsigned long rate)
> +static unsigned int
> +tegra_get_intermediate(struct cpufreq_policy *policy, unsigned int index)

(BTW, can we please not put the return type on a separate line; it's
inconsistent with the rest of the code in this file)

> +{
> +	unsigned int ifreq = clk_get_rate(pll_p_clk) / 1000;
> +
> +	/*
> +	 * Don't switch to intermediate freq if:
> +	 * - we are already at it, i.e. policy->cur == ifreq
> +	 * - index corresponds to ifreq
> +	 */
> +	if ((freq_table[index].frequency == ifreq) || (policy->cur == ifreq))
> +		return 0;

If policy->cur == ifreq here, then tegra_target_intermediate() isn't
called by the cpufreq core, so ...

> +static int
> +tegra_target_intermediate(struct cpufreq_policy *policy, unsigned int index)
>  {
>  	int ret;
>  
> 	/*
> 	 * Take an extra reference to the main pll so it doesn't turn
> 	 * off when we move the cpu off of it
> 	 */
> 	clk_prepare_enable(pll_x_clk);

... that reference isn't added...

> @@ -98,10 +96,23 @@ static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
>  	else
>  		clk_set_rate(emc_clk, 100000000);  /* emc 50Mhz */
>  
> -	ret = tegra_cpu_clk_set_rate(rate * 1000);
> +	/* target freq == pll_p */
> +	if (rate * 1000 == clk_get_rate(pll_p_clk)) {
> +		ret = tegra_target_intermediate(policy, index);
> +		goto disable_pll_x;
> +	}

... and this code doesn't call it either, since we could be switching
from the pll_p rate to something faster ...

> +
> +	ret = clk_set_rate(pll_x_clk, rate * 1000);
> +	/* Restore to earlier frequency on error, i.e. pll_x */
>  	if (ret)
> -		pr_err("cpu-tegra: Failed to set cpu frequency to %lu kHz\n",
> -			rate);
> +		pr_err("Failed to change pll_x to %lu\n", rate);
> +
> +	ret = clk_set_parent(cpu_clk, pll_x_clk);
> +	/* This shouldn't fail while changing or restoring */
> +	WARN_ON(ret);
> +
> +disable_pll_x:
> +	clk_disable_unprepare(pll_x_clk);

... so this turns off pll_x even though we're running from it.

It would be simpler if Tegra *always* used an intermediate frequency,
and hence the core *always* called tegra_target_intermediate().
Admittedly, this would result in tegra_target() sometimes (when
switching CPU clock rate to the pll_p rate) doing nothing other than
removing the extra reference on pll_x, but I think that the code would
be simpler to follow and more robust.

  parent reply	other threads:[~2014-05-29 17:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-21  8:59 [PATCH V4 0/3] cpufreq: add support for intermediate (stable) frequencies Viresh Kumar
2014-05-21  8:59 ` [PATCH V4 1/3] cpufreq: handle calls to ->target_index() in separate routine Viresh Kumar
2014-05-26 23:21   ` Rafael J. Wysocki
2014-05-26 23:59     ` Viresh Kumar
2014-05-21  8:59 ` [PATCH V4 2/3] cpufreq: add support for intermediate (stable) frequencies Viresh Kumar
2014-05-22 16:37   ` Stephen Warren
2014-05-23  4:24     ` Viresh Kumar
2014-05-23 15:56       ` Stephen Warren
2014-05-26  4:01         ` Viresh Kumar
2014-05-28 19:40   ` Doug Anderson
2014-05-30  1:19     ` Viresh Kumar
2014-05-21  8:59 ` [PATCH V4 3/3] cpufreq: Tegra: implement intermediate frequency callbacks Viresh Kumar
2014-05-22 16:39   ` Stephen Warren
2014-05-23  4:05     ` Viresh Kumar
2014-05-29 17:42       ` Stephen Warren
2014-06-02 10:01         ` Viresh Kumar
2014-05-29 17:40   ` Stephen Warren [this message]
2014-05-30  1:56     ` Viresh Kumar
2014-05-30 16:26       ` Stephen Warren
2014-06-02 10:06         ` Viresh Kumar
2014-06-02 16:50           ` Stephen Warren

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=53877103.8070604@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=arvind.chauhan@arm.com \
    --cc=dianders@chromium.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=nicolas.pitre@linaro.org \
    --cc=pdeschrijver@nvidia.com \
    --cc=rjw@rjwysocki.net \
    --cc=swarren@nvidia.com \
    --cc=thomas.abraham@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox