linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Doug Anderson <dianders@chromium.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Russell King <linux@arm.linux.org.uk>,
	Will Deacon <will.deacon@arm.com>,
	John Stultz <john.stultz@linaro.org>,
	David Riley <davidriley@chromium.org>,
	"olof@lixom.net" <olof@lixom.net>,
	Sonny Rao <sonnyrao@chromium.org>,
	Richard Zhao <richard.zhao@linaro.org>,
	Santosh Shilimkar <santosh.shilimkar@ti.com>,
	Shawn Guo <shawn.guo@linaro.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Stephen Warren <swarren@nvidia.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ARM: Don't ever downscale loops_per_jiffy in SMP systems
Date: Thu, 8 May 2014 13:43:29 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.2.11.1405081329010.980@knanqh.ubzr> (raw)
In-Reply-To: <CAD=FV=VtcLOh51LCmafzRMdqtDrwKXCqK6gE6V7OOOUe4gjwbA@mail.gmail.com>

On Thu, 8 May 2014, Doug Anderson wrote:

> Nicolas,
> 
> On Thu, May 8, 2014 at 9:04 AM, Nicolas Pitre <nicolas.pitre@linaro.org> wrote:
> > On Thu, 8 May 2014, Doug Anderson wrote:
> >
> >> 1. Initially CPU1 and CPU2 at 200MHz.  Pretend loops_per_jiffy is 1000.
> >>
> >> 2. CPU1 starts a delay.  It reads global lpj (1000) and sets up its
> >> local registers up for the loop.
> >>
> >> 3. At the same time, CPU2 is transitioning the system to 2000MHz.
> >> Right after CPU1 reads lpj CPU2 stores it as 10000.
> >>
> >> 4. Now CPU1 and CPU2 are running at 2000MHz but CPU1 is only looping
> >> 1000 times.  It will complete too fast.
> >>
> >> ...you could possibly try to account for this in the delay loop code
> >> (being careful to handle all of the corner cases and races).  ...or we
> >> could make the delay loop super conservative and suggest that people
> >> should be using a real timer.
> >
> > I don't see how you can possibly solve this issue without a timer based
> > delay.  Even if you scale the loop count in only one direction, it will
> > still have this problem even though the window for the race would happen
> > much less often.  Yet having a delay which is way longer than expected
> > might cause problems in some cases.
> 
> You could possibly try to do something excessively clever by checking
> the loops per jiffy after the loop was done (and perhaps register for
> cpufreq changes so you know if it changed and then changed back)?  As
> I said, I don't think it's a good use of anyone's time.

Agreed.

> Longer delays aren't very good, but IMHO having some delays of 100 =>
> 1000 is better than having delays of 100 => 75.  The former will cause
> mostly performance problems and the later will cause real correctness
> problems.
> I'm not saying that 100 => 1000 is good, it's just less bad.

There might be some cases where precise timing is needed though.
I thought I came across one such case in the past but I can't remember 
which.

> Specifically even in a timer-based system you can't guarantee that a
> udelay(100) won't end up a udelay(1000) if the kernel finds something
> better to do than to run your code.  I agree that there might be code
> that breaks when a udelay(100) becomes a udelay(1000), but probably
> that code needs to be fixed to be more tolerant anyway.

The timer based udelay implementation does poll the timer, and if exact 
timing is important then you'll certainly turn off IRQs during the 
critical sequence.

[...]
> > SMP with shared clock for DVFS simply doesn't allow pure loop counts to
> > always be accurate.  Trying to fix a broken implementation with
> > something that is still broken to some extent, and maybe more in
> > some cases, doesn't look like much progress to me.
> 
> I totally agree that this doesn't really fix the problem nicely which
> is why I didn't send it initially.
> 
> I will make the argument that this patch makes things less broken
> overall on any systems that actually end up running this code, but if
> you want NAK it then it won't cause me any heartache.  ;)

What I insist on is for this issue to be solved using a stable counter 
such a timer when available.  It _is_ available on one of the target you 
mentioned so that is the solution you should add to your tree.  
Investigating a similar solution for your other target should be 
preferred to hacking the udelay loop. This way you're guaranteed to 
solve this problem fully.


Nicolas

  reply	other threads:[~2014-05-08 17:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 23:23 [PATCH] ARM: Don't ever downscale loops_per_jiffy in SMP systems Doug Anderson
2014-05-08 10:41 ` Viresh Kumar
2014-05-08 15:25   ` Doug Anderson
2014-05-08 16:04     ` Nicolas Pitre
2014-05-08 16:41       ` Doug Anderson
2014-05-08 17:43         ` Nicolas Pitre [this message]
2014-05-08 18:06           ` Doug Anderson
2014-05-08 19:59             ` Nicolas Pitre
2014-05-08 20:55             ` Russell King - ARM Linux
2014-05-09  0:02               ` Doug Anderson
2014-05-09  0:23                 ` Russell King - ARM Linux
2014-05-09  4:41                   ` Doug Anderson
2014-05-08 19:22           ` Russell King - ARM Linux
2014-05-08 20:12             ` Nicolas Pitre
2014-05-08 20:39               ` John Stultz
2014-05-08 20:52               ` Russell King - ARM Linux
2014-05-09  1:37                 ` Nicolas Pitre
2014-05-09  4:43                   ` Doug Anderson
2014-05-09  9:18                   ` [PATCH] ARM: Don't ever downscale loops_per_jiffy in SMP systems# Russell King - ARM Linux
2014-05-09 18:00                     ` Nicolas Pitre
2014-05-09 18:22                       ` Russell King - ARM Linux
2014-05-09 21:05                         ` Nicolas Pitre
2014-05-12 23:51                           ` Doug Anderson
2014-05-13 21:50                             ` Doug Anderson
2014-05-13 22:15                               ` Stephen Warren
2014-05-13 23:15                                 ` Nicolas Pitre
2014-05-13 23:29                                   ` Nicolas Pitre
2014-05-13 23:36                                     ` Russell King - ARM Linux
2014-05-14 21:42                                     ` Doug Anderson
2014-05-15  6:12                               ` Viresh Kumar
2014-05-09  9:25     ` [PATCH] ARM: Don't ever downscale loops_per_jiffy in SMP systems Viresh Kumar

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=alpine.LFD.2.11.1405081329010.980@knanqh.ubzr \
    --to=nicolas.pitre@linaro.org \
    --cc=davidriley@chromium.org \
    --cc=dianders@chromium.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=marc.zyngier@arm.com \
    --cc=olof@lixom.net \
    --cc=paul.gortmaker@windriver.com \
    --cc=richard.zhao@linaro.org \
    --cc=rjw@rjwysocki.net \
    --cc=santosh.shilimkar@ti.com \
    --cc=sboyd@codeaurora.org \
    --cc=shawn.guo@linaro.org \
    --cc=sonnyrao@chromium.org \
    --cc=swarren@nvidia.com \
    --cc=viresh.kumar@linaro.org \
    --cc=will.deacon@arm.com \
    /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).