mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Kalle Kankare <kalle.kankare@vincit.fi>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>
Subject: Re: During high load wait_event_timeout might return a wrong value
Date: Tue, 10 Nov 2015 12:09:56 +0100	[thread overview]
Message-ID: <20151110110956.GY17308@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20151110091812.1e7f326e@kalleka-typewriter>

On Tue, Nov 10, 2015 at 09:18:12AM +0200, Kalle Kankare wrote:
> Hi,
> 
> The problem is that the call to might_sleep might sleep and the return
> value of wait_event_timeout does not account for the time slept in
> there.
> 
> The might_sleep includes a call to __schedule if
> CONFIG_PREEMPT_VOLUNTARY is defined.
> 
> A problematic scenario can be like the following:
> 
> - A driver calls wait_event_timeout with timeout = 10 jiffies, starts sleeping in might_sleep.
> - An interrupt handler sets the condition true at 5 jiffies and calls wake_up for the waitqueue.
> - Due to high load the might_sleep wakes up at 100 jiffies.
> - In the next if the __wait_cond_timeout returns 1 without manipulating __ret.
> - wait_event_timeout returns 10 where it should have returned 1 to denote that a timeout was reached.
> 
> Or am I misunderstanding what the return value should be ?

No, but you count a preemption as sleep, and this is incorrect.

Also, as with all the sleep APIs, the timeout is a minimum. We're
allowed to actually sleep longer. Conversely any reported sleep time is
therefore also subject to similar inequality. And this is for actual
sleep time.

Further note that the time returned does not include scheduling
latencies -- like the time it takes for the woken task to actually get
scheduled.

Similarly, preemptions, like possible with any PREEMPT setting (be it
voluntary or forced) will add scheduling latencies, which are not to be
confused with actual sleeping.


      reply	other threads:[~2015-11-10 11:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10  7:18 Kalle Kankare
2015-11-10 11:09 ` Peter Zijlstra [this message]

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=20151110110956.GY17308@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=kalle.kankare@vincit.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.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®