All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: linux-sh@vger.kernel.org
Subject: Re: [PATCH] sh_tmu: compute mult and shift before registration
Date: Mon, 31 May 2010 11:19:51 +0000	[thread overview]
Message-ID: <4C039B57.6010109@aurel32.net> (raw)
In-Reply-To: <1275296994-12005-1-git-send-email-aurelien@aurel32.net>

Magnus Damm a écrit :
> Hey Aurelien,
> 
> Thanks for your patch!
> 
> On Mon, May 31, 2010 at 6:09 PM, Aurelien Jarno <aurelien@aurel32.net> wrote:
>> Since commit 98962465ed9e6ea99c38e0af63fe1dcb5a79dc25 ("nohz: Prevent
>> clocksource wrapping during idle"), the CPU of an R2D board never goes
>> to idle. This commit assumes that mult and shift are assigned before
>> the clocksource is registered. As a consequence the safe maximum sleep
>> time is negative and the CPU never goes into idle.
>>
>> This patch fixes the problem by moving mult and shift initialization
>> from sh_tmu_clocksource_enable() to sh_tmu_register_clocksource().
>>
>> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
>> ---
>>  drivers/clocksource/sh_tmu.c |   14 +++++---------
>>  1 files changed, 5 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
>> index 8e44e14..e9e35aa 100644
>> --- a/drivers/clocksource/sh_tmu.c
>> +++ b/drivers/clocksource/sh_tmu.c
>> @@ -199,16 +199,8 @@ static cycle_t sh_tmu_clocksource_read(struct clocksource *cs)
>>  static int sh_tmu_clocksource_enable(struct clocksource *cs)
>>  {
>>        struct sh_tmu_priv *p = cs_to_sh_tmu(cs);
>> -       int ret;
>> -
>> -       ret = sh_tmu_enable(p);
>> -       if (ret)
>> -               return ret;
>>
>> -       /* TODO: calculate good shift from rate and counter bit width */
>> -       cs->shift = 10;
>> -       cs->mult = clocksource_hz2mult(p->rate, cs->shift);
>> -       return 0;
>> +       return sh_tmu_enable(p);
>>  }
>>
>>  static void sh_tmu_clocksource_disable(struct clocksource *cs)
>> @@ -228,6 +220,10 @@ static int sh_tmu_register_clocksource(struct sh_tmu_priv *p,
>>        cs->disable = sh_tmu_clocksource_disable;
>>        cs->mask = CLOCKSOURCE_MASK(32);
>>        cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
>> +       /* TODO: calculate good shift from rate and counter bit width */
>> +       cs->shift = 10;
>> +       /* channel will be configured at parent clock / 4 */
>> +       cs->mult = clocksource_hz2mult(clk_get_rate(p->clk) / 4, cs->shift);
>>        dev_info(&p->pdev->dev, "used as clock source\n");
>>        clocksource_register(cs);
>>        return 0;
> 
> Hm, are you sure the clock is enabled at this point?
>
> The file include/linux/clk.h says that the clock has to be enabled
> before clk_get_rate() is called.
> 

In practice yes, but as you said it seems that theoretically it is not
guaranteed, so it may break again in the future.

It probably means that if the clock is not already started we have to
start it, call clk_get_rate() and stop it.

That starts to ressemble to my first patch, that started and stoped the
clock before registering it:

diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index 8e44e14..6f0fcfd 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -228,6 +228,8 @@ static int sh_tmu_register_clocksource(struct
sh_tmu_priv *p,
        cs->disable = sh_tmu_clocksource_disable;
        cs->mask = CLOCKSOURCE_MASK(32);
        cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
+       sh_tmu_clocksource_enable(cs);
+       sh_tmu_clocksource_disable(cs);
        dev_info(&p->pdev->dev, "used as clock source\n");
        clocksource_register(cs);
        return 0;


-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

  parent reply	other threads:[~2010-05-31 11:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-31  9:09 [PATCH] sh_tmu: compute mult and shift before registration Aurelien Jarno
2010-05-31 10:50 ` Magnus Damm
2010-05-31 11:19 ` Aurelien Jarno [this message]
2010-05-31 11:36 ` Paul Mundt
2010-05-31 21:45 ` Aurelien Jarno

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=4C039B57.6010109@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=linux-sh@vger.kernel.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.