From: Andreas Mohr <andi@lisas.de>
To: Doug Anderson <dianders@chromium.org>
Cc: Andreas Mohr <andi@lisas.de>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>,
Brian Norris <briannorris@chromium.org>,
Tao Huang <huangtao@rock-chips.com>,
Tony Xie <tony.xie@rock-chips.com>,
"open list:ARM/Rockchip SoC..."
<linux-rockchip@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] timers: Fix usleep_range() in the context of wake_up_process()
Date: Tue, 11 Oct 2016 22:40:03 +0200 [thread overview]
Message-ID: <20161011204003.GA21387@rhlx01.hs-esslingen.de> (raw)
In-Reply-To: <CAD=FV=Ua8c18SGr54ThmVe1oR3bqfCyHxfhL=6z8vJXkMiUedA@mail.gmail.com>
On Tue, Oct 11, 2016 at 01:02:10PM -0700, Doug Anderson wrote:
> Andreas,
>
> On Tue, Oct 11, 2016 at 12:30 PM, Andreas Mohr <andi@lisas.de> wrote:
> > This loop implementation relies on negative kmin (result of ktime_sub())
> > getting internally handled by schedule_hrtimeout_range() as a 0 result.
> > If that ain't the case, then the loop itself will need to handle
> > negative values.
> > OK, scratch that, due to guaranteed-unchanged values of now and end,
> > result of directly subsequent ktime_sub() is guaranteed to
> > not deviate from what ktime_before() figured.
> > However, this is somewhat differing handling of these two APIs.
>
> I read this as: no bug, feel free to ignore.
Heh, yeah ("an alternate style of review" ;).
> I agree that we could try to save some math by making the loop more
> complicated. On the other hand, one could argue that a sufficiently
> good compiler might actually be able to figure some of this stuff out,
> since much of this stuff is just inlined 64-bit math comparisons.
Indeed. "micro-optimization again".
> > BTW, another argument for loop rework might be that
> > the result of ktime_sub() might already be improper
> > (due to being negative!) for
> > subsequent invocation of schedule_hrtimeout_range(),
> > i.e. there's an argument to be made that
> > the loop tail check instead ought to be done as a negative-value check
> > directly prior to schedule_hrtimeout_range() invocation.
> >
> > Hmm, if schedule_hrtimeout_range() can be relied on to
> > internally properly be doing the negative check,
> > then one could simply say that
> > the annoyingly extra calculation via ktime_before() call
> > should simply be removed completely.
> > Which would be a good step since it would centralize protocol behaviour
> > within the inner handling of the helper
> > rather than bloating user-side instruction cache footprint.
>
> Ah, so you're saying just do a "while (true)" after changing the
> behavior of schedule_hrtimeout_range_clock(). If everyone agrees that
> they'd like to see this, I can do it. I'd have to change
> schedule_hrtimeout_range_clock() to check for <= 0 instead of just
> comparing against 0. ...and that would be an API change for
> schedule_hrtimeout_range_clock(), and it seems like that would be yet
> another source of bugs. ...and this is to save an instruction? It
> doesn't seem worth it.
Yup, I just realized that probably what we'd ideally want is
a very thin decorating wrapper (loop handler)
which cares about nothing else other than
eradicating the relevant "feature" of the inner handler
(namely, premature exit),
and otherwise leaves a much as possible to
central inner handler decision-making implementation.
That to me sounds like
the theoretically most precise (since dead simple) handling.
And even if such exceedingly simple handling is dangerous -
in case of failure we would realize it very soon (infinite loop),
and would then know what will need fixing.
I've been reviewing schedule_hrtimeout_range_clock() as well,
and I'm actually puzzled that it checks for zero value only,
and not less-equal zero.
That to me does not seem like a true-to-the-core protocol
to handle the task at hand.
OTOH perhaps less-equal comparison was deemed to be
much more expensive than a zero check,
and thus possibly has been done in inner handlers only.
For the loop code itself,
I'm not sure whether to pursue it -
given the schedule_hrtimeout_range_clock() API change risks you outlined,
and especially given that
optimization is likely to mostly benefit the "repeat" case only,
which likely would be the less relevant non-hotpath case anyway.
Plus, let's not forget the fact that
even hotpath handling *is* an invocation of the entire delay handler,
and then a couple measly opcodes to have the loop exited reliably. So...
Now, at least we have a
Reviewed-by: Andreas Mohr <andim2@users.sf.net>
Oh well, lotsa discussion, some good thoughts,
but no truly revolutionary outcome so far.
However, sometimes the most important thing is
to have had a good educating discussion
(not everything in software circles is about the Get Rich Quick scheme -
you do have to spend some ample time - decades... -
to truly get mental concept things right).
Andreas Mohr
next prev parent reply other threads:[~2016-10-11 20:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-10 21:04 Douglas Anderson
2016-10-10 22:39 ` Doug Anderson
2016-10-11 7:14 ` Thomas Gleixner
2016-10-11 16:33 ` Doug Anderson
2016-10-12 8:56 ` Mark Brown
2016-10-11 18:25 ` Andreas Mohr
2016-10-12 13:11 ` Thomas Gleixner
2016-10-12 17:39 ` Doug Anderson
2016-10-11 20:34 ` Heiko Stuebner
2016-10-11 18:54 ` Brian Norris
2016-10-11 19:30 ` Andreas Mohr
2016-10-11 20:02 ` Doug Anderson
2016-10-11 20:40 ` Andreas Mohr [this message]
2016-10-12 16:03 ` [v2] " Guenter Roeck
2016-10-12 16:27 ` Doug Anderson
2016-10-12 16:53 ` Guenter Roeck
2016-10-18 13:44 ` [PATCH v2] " Daniel Kurtz
2016-10-18 20:29 ` Doug Anderson
2016-10-20 8:57 ` Daniel Kurtz
2016-10-20 9:51 ` Thomas Gleixner
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=20161011204003.GA21387@rhlx01.hs-esslingen.de \
--to=andi@lisas.de \
--cc=briannorris@chromium.org \
--cc=dianders@chromium.org \
--cc=huangtao@rock-chips.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=tglx@linutronix.de \
--cc=tony.xie@rock-chips.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
all inboxes | Powered by JetHome®