mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Ani Sinha <kernel@anirban.org>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu
Subject: Re: wait_event_interruptible_timeout
Date: Thu, 25 Sep 2008 20:45:17 +0400	[thread overview]
Message-ID: <20080925164517.GA194@tv-sign.ru> (raw)
In-Reply-To: <13c67e2c0809242105t77ca9a6k2faf1e85064967aa@mail.gmail.com>

On 09/24, Ani Sinha wrote:
>
> I have noticed an issue with wait_event_interruptible_timeout() API
> which I will try to explain below:
>
> wait_event_interruptible_timeout() is supposed to wait until one of
> the following happens:
>
> (a)    Timeout occurs (with no signals or the event of interest
> happening), in which case it returns 0
>
> (b)   The process receives a signal and wakes up prematurely (i.e.,
> before its timeout expired or the event of interest occurred). In this
> case, it returns ?ERESTARTSYS. I will come back to this later.
>
> (c)    Of course, the last obvious way to wake up is that the event of
> interest occurs and it wakes up all (or one) process on the wait
> queue. In that case, it returns the # of jiffies that is left before
> the timeout would have occurred (unslept or balance jiffies).
>
>
> What if I really wanted to sleep for timeout interval and no more?
> That is to say, if I wake up on a signal and I wanted to know how many
> jiffies I did used up while sleeping and how many I am left with (just
> like poll or select does)?

You can read jiffies before and after wait_event_interruptible_timeout().

> That way,  when I retry the API, I can tell
> it to sleep only by the amount of my balance sleeping time.

Something like

	unsigned long now = jiffies;
	ret = wait_event_interruptible_timeout(..., timeout);
	if (ret < 0) {
		next_timeout = now + timeout - jiffies;
		if (next_timeout < 0)
			next_timeout = 0;
	}

We can even add another wait_ helper which treats "timeout" as lvalue
and updates it before return. I dunno.

> Unfortunately, the interface looses this information since it
> overrides the return value with ERESTARTSYS.

Yes you are right, but

> I feel there is a need to
> modify the code in order to correct this behavior.

I'm afraid it would be a pain to modify this API. But please
do not hesitate to make the patch if you think the current API
can be improved. At worst, the patch will be nacked ;)

Oleg.


  reply	other threads:[~2008-09-25 16:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-25  4:05 wait_event_interruptible_timeout Ani Sinha
2008-09-25 16:45 ` Oleg Nesterov [this message]
2008-09-26  2:42   ` wait_event_interruptible_timeout Anirban Sinha

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=20080925164517.GA194@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=kernel@anirban.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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®