From: Imre Deak <imre.deak@intel.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
David Howells <dhowells@redhat.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Dave Jones <davej@redhat.com>,
Lukas Czerner <lczerner@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] wait: fix false timeouts when using wait_event_timeout()
Date: Thu, 02 May 2013 16:56:50 +0300 [thread overview]
Message-ID: <1367503010.24182.29.camel@intelbox> (raw)
In-Reply-To: <20130502125426.GN7800@kernel.dk>
On Thu, 2013-05-02 at 14:54 +0200, Jens Axboe wrote:
> On Thu, May 02 2013, Imre Deak wrote:
> > On Thu, 2013-05-02 at 14:23 +0200, Jens Axboe wrote:
> > > On Thu, May 02 2013, Daniel Vetter wrote:
> > > > On Thu, May 2, 2013 at 12:29 PM, David Howells <dhowells@redhat.com> wrote:
> > > > >> Fix this by returning at least 1 if the condition becomes true. This
> > > > >> semantic is in line with what wait_for_condition_timeout() does; see
> > > > >> commit bb10ed09 - "sched: fix wait_for_completion_timeout() spurious
> > > > >> failure under heavy load".
> > > > >
> > > > > But now you can't distinguish the timer expiring first, if the thread doing
> > > > > the waiting gets delayed sufficiently long for the event to happen.
> > > >
> > > > That can already happen, e.g.
> > > >
> > > > 1. wakeup happens and condition is true.
> > > > 2. we compute remaining jiffies > 0
> > > > -> preempt
> > > > 3. now wait_for_event_timeout returns.
> > > >
> > > > Only difference is that the delay/preempt happens in between 1. and
> > > > 2., and then suddenly the wake up didn't happen in time (with the
> > > > current return code semantics).
> > > >
> > > > So imo the current behaviour is simply a bug and will miss timely
> > > > wakeups in some cases.
> > > >
> > > > The other way round, namely wait_for_event_timeout taking longer than
> > > > the timeout is expected (and part of the interface for every timeout
> > > > function). So all current callers already need to be able to cope with
> > > > random preemption/delays pushing the total time before the call to
> > > > wait_for_event and checking the return value over the timeout, even
> > > > when condition was signalled in time.
> > > >
> > > > If there's any case which relies on accurate timeout detection that
> > > > simply won't work with wait_for_event (they need an nmi or a hw
> > > > timestamp counter or something similar).
> > >
> > > I seriously doubt that anyone is depending on any sort of accuracy on
> > > the return. 1 jiffy is not going to make or break anything - in fact,
> > > jiffies could be incremented nsecs after the initial call. So a
> > > granularity of at least 1 is going to be expected in any case.
> > >
> > > The important bit here is that the API should behave as expected. And
> > > the most logical way to code that is to check the return value. I can
> > > easily see people forgetting to re-check the condition, hence you get a
> > > bug. The fact that you and the original reporter already had accidents
> > > with this is a clear sign that the logical way to use the API is not the
> > > correct one.
> > >
> > > IMHO, the change definitely makes sense.
> >
> > Ok, so taking courage of this answer ;P How about also the following?
> >
> > diff --git a/kernel/timer.c b/kernel/timer.c
> > index dbf7a78..5a62456 100644
> > --- a/kernel/timer.c
> > +++ b/kernel/timer.c
> > @@ -1515,7 +1515,11 @@ signed long __sched schedule_timeout(signed long
> > timeout)
> > }
> > }
> >
> > - expire = timeout + jiffies;
> > + /*
> > + * We can't be sure how close we are to the next tick, so +1 to
> > + * guarantee that we wait at least timeout amount.
> > + */
> > + expire = timeout + jiffies + 1;
> >
> > setup_timer_on_stack(&timer, process_timeout, (unsigned long)current);
> > __mod_timer(&timer, expire, false, TIMER_NOT_PINNED);
> >
> >
> > It'd plug a similar hole for wait_event_timeout() and similar users, who
> > don't compensate for the above..
>
> Any jiffy based API is going to have this issue. I think it's different
> from the original patch, which just makes the API potentially return
> something that is confusing.
Yea, at least those that take a relative time. Usually the timeout is
given with a big overhead, so there it won't be a problem. But I also
found users like drivers/acpi/ec.c, that will pass a timeout of 1
jiffies, which may then result in premature timeouts.
> So not sure on the above, sorry.
Ok. A WARN to wait_event_timeout for the above case could still be a
useful guard..
--Imre
next prev parent reply other threads:[~2013-05-02 13:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-02 8:58 [PATCH] wait: fix false timeouts when using wait_event_timeout() Imre Deak
2013-05-02 9:36 ` Daniel Vetter
2013-05-07 23:12 ` Andrew Morton
2013-05-08 9:49 ` Imre Deak
2013-05-02 10:29 ` David Howells
2013-05-02 12:02 ` Imre Deak
2013-05-02 12:13 ` Daniel Vetter
2013-05-02 12:23 ` Jens Axboe
2013-05-02 12:29 ` David Howells
2013-05-02 12:34 ` Imre Deak
2013-05-02 12:54 ` Jens Axboe
2013-05-02 13:56 ` Imre Deak [this message]
2013-05-02 14:04 ` Daniel Vetter
2013-05-02 12:29 ` David Howells
2013-05-02 12:35 ` Jens Axboe
2013-05-02 19:56 ` Imre Deak
-- strict thread matches above, loose matches on Subject: below --
2013-06-04 19:28 Oleg Nesterov
2013-06-04 21:35 ` Imre Deak
2013-06-04 21:40 ` Imre Deak
2013-06-05 16:37 ` Oleg Nesterov
2013-06-05 19:07 ` Oleg Nesterov
2013-06-06 1:45 ` Tejun Heo
2013-06-06 18:47 ` Oleg Nesterov
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=1367503010.24182.29.camel@intelbox \
--to=imre.deak@intel.com \
--cc=axboe@kernel.dk \
--cc=daniel.vetter@ffwll.ch \
--cc=davej@redhat.com \
--cc=dhowells@redhat.com \
--cc=lczerner@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.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