* [PATCH]: add a new wait_event_interruptible_timeout_modify helper
@ 2008-09-26 2:57 Anirban Sinha
[not found] ` <816CA40C-41C0-4CCF-A75B-F67F1A2B0510@anirban.org>
2008-09-26 15:01 ` [PATCH]: " Linus Torvalds
0 siblings, 2 replies; 4+ messages in thread
From: Anirban Sinha @ 2008-09-26 2:57 UTC (permalink / raw)
To: linux-kernel, mingo, Oleg Nesterov, torvalds; +Cc: kernel
Index: 2.6-git/include/linux/wait.h
===================================================================
--- 2.6-git.orig/include/linux/wait.h 2008-06-20 21:21:11.000000000
-0700
+++ 2.6-git/include/linux/wait.h 2008-09-25 19:41:37.000000000 -0700
@@ -335,6 +335,55 @@
__ret; \
})
+#define __wait_event_interruptible_timeout_modify(wq, condition, ret,
timeout) \
+do { \
+ DEFINE_WAIT(__wait); \
+ \
+ for (;;) { \
+ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
+ if (condition) \
+ break; \
+ if (!signal_pending(current)) { \
+ ret = schedule_timeout(ret); \
+ *(&timeout) = ret; \
+ if (!ret) \
+ break; \
+ continue; \
+ } \
+ ret = -ERESTARTSYS; \
+ break; \
+ } \
+ finish_wait(&wq, &__wait); \
+} while (0)
+
+/**
+ * wait_event_interruptible_timeout_modify - sleep until a condition
gets true or a timeout elapses.
+ * @wq: the waitqueue to wait on
+ * @condition: a C expression for the event to wait for
+ * @timeout: timeout, in jiffies
+ *
+ * The process is put to sleep (TASK_INTERRUPTIBLE) until the
+ * @condition evaluates to true or a signal is received.
+ * The @condition is checked each time the waitqueue @wq is woken up.
+ *
+ * wake_up() has to be called after changing any variable that could
+ * change the result of the wait condition.
+ *
+ * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
+ * was interrupted by a signal, and the remaining jiffies otherwise
+ * if the condition evaluated to true before the timeout elapsed.
+ * It also modifies the @timeout value so that if the sleep is
interrupted
+ * by a signal, the caller can call this helper again with the updated
+ * timeout.
+ */
+#define wait_event_interruptible_timeout_modify(wq, condition,
timeout) \
+({ \
+ long __ret = timeout; \
+ if (!(condition)) \
+ __wait_event_interruptible_timeout_modify(wq, condition, __ret,
timeout); \
+ __ret; \
+})
+
#define __wait_event_interruptible_exclusive(wq, condition, ret) \
do { \
DEFINE_WAIT(__wait); \
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH]: correction: add a new wait_event_interruptible_timeout_modify helper
[not found] ` <816CA40C-41C0-4CCF-A75B-F67F1A2B0510@anirban.org>
@ 2008-09-26 7:11 ` Anirban Sinha
2008-09-26 15:21 ` Oleg Nesterov
0 siblings, 1 reply; 4+ messages in thread
From: Anirban Sinha @ 2008-09-26 7:11 UTC (permalink / raw)
To: linux-kernel; +Cc: Ingo Molnar, Oleg Nesterov, Linus Torvalds, Anirban Sinha
arrghh!!! my bad. corrected patch is pasted below:
Index: 2.6-git/include/linux/wait.h
===================================================================
--- 2.6-git.orig/include/linux/wait.h 2008-06-20 21:21:11.000000000
-0700
+++ 2.6-git/include/linux/wait.h 2008-09-25 19:41:37.000000000 -0700
@@ -335,6 +335,55 @@
__ret; \
})
+#define __wait_event_interruptible_timeout_modify(wq, condition, ret,
timeout) \
+do { \
+ DEFINE_WAIT(__wait); \
+ \
+ for (;;) { \
+ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
+ if (condition) \
+ break; \
+ if (!signal_pending(current)) { \
+ ret = schedule_timeout(ret); \
+ timeout = ret; \
+ if (!ret) \
+ break; \
+ continue; \
+ } \
+ ret = -ERESTARTSYS; \
+ break; \
+ } \
+ finish_wait(&wq, &__wait); \
+} while (0)
+
+/**
+ * wait_event_interruptible_timeout_modify - sleep until a condition
gets true or a timeout elapses.
+ * @wq: the waitqueue to wait on
+ * @condition: a C expression for the event to wait for
+ * @timeout: timeout, in jiffies
+ *
+ * The process is put to sleep (TASK_INTERRUPTIBLE) until the
+ * @condition evaluates to true or a signal is received.
+ * The @condition is checked each time the waitqueue @wq is woken up.
+ *
+ * wake_up() has to be called after changing any variable that could
+ * change the result of the wait condition.
+ *
+ * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
+ * was interrupted by a signal, and the remaining jiffies otherwise
+ * if the condition evaluated to true before the timeout elapsed.
+ * It also modifies the @timeout value so that if the sleep is
interrupted
+ * by a signal, the caller can call this helper again with the updated
+ * timeout.
+ */
+#define wait_event_interruptible_timeout_modify(wq, condition,
timeout) \
+({ \
+ long __ret = timeout; \
+ if (!(condition)) \
+ __wait_event_interruptible_timeout_modify(wq, condition, __ret,
timeout); \
+ __ret; \
+})
+
#define __wait_event_interruptible_exclusive(wq, condition, ret) \
do { \
DEFINE_WAIT(__wait); \
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH]: add a new wait_event_interruptible_timeout_modify helper
2008-09-26 2:57 [PATCH]: add a new wait_event_interruptible_timeout_modify helper Anirban Sinha
[not found] ` <816CA40C-41C0-4CCF-A75B-F67F1A2B0510@anirban.org>
@ 2008-09-26 15:01 ` Linus Torvalds
1 sibling, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2008-09-26 15:01 UTC (permalink / raw)
To: Anirban Sinha; +Cc: linux-kernel, mingo, Oleg Nesterov
On Thu, 25 Sep 2008, Anirban Sinha wrote:
> +
> +/**
> + * wait_event_interruptible_timeout_modify - sleep until a condition gets true or a timeout elapses.
> + * @wq: the waitqueue to wait on
> + * @condition: a C expression for the event to wait for
> + * @timeout: timeout, in jiffies
> + *
> + * The process is put to sleep (TASK_INTERRUPTIBLE) until the
> + * @condition evaluates to true or a signal is received.
> + * The @condition is checked each time the waitqueue @wq is woken up.
> + *
> + * wake_up() has to be called after changing any variable that could
> + * change the result of the wait condition.
> + *
> + * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
> + * was interrupted by a signal, and the remaining jiffies otherwise
> + * if the condition evaluated to true before the timeout elapsed.
> + * It also modifies the @timeout value so that if the sleep is interrupted
> + * by a signal, the caller can call this helper again with the updated
> + * timeout.
Grr.
I'd _much_ rather just have a
wait_event_interruptible_until(wr, condition, abs_timeout)
where the timeout is just given as an end value, and the user can just
pre-calculate it once and the return code handling is simpler (either
"success" or "EINTR").
Giving an absolute value also means that there is no rounding creep or
anything like that in a loop, which otherwise happens very easily (even
if we wouldn't normally really care).
And quite frankly, people can do that themselves even without a helper
function, with simply
unsigned long end = jiffies + timeout;
...
rc = wait_event_interruptible_timeout(wq, event, end - jiffies);
if (rc < 0)
goto out;
and now you always know the end-point, and 'end - jiffies' is always the
remaining timeout.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH]: correction: add a new wait_event_interruptible_timeout_modify helper
2008-09-26 7:11 ` [PATCH]: correction: " Anirban Sinha
@ 2008-09-26 15:21 ` Oleg Nesterov
0 siblings, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2008-09-26 15:21 UTC (permalink / raw)
To: Anirban Sinha; +Cc: linux-kernel, Ingo Molnar, Linus Torvalds
On 09/26, Anirban Sinha wrote:
>
> arrghh!!! my bad. corrected patch is pasted below:
The patch has numerous whitespace damages, please fix your mailer.
But more importantly, it lacks the changelog. And this changelog
should be very convincing, otherwise I'm afraid the patch will be
ignored. It is not common to add the helper which has no users in
kernel.
> + * It also modifies the @timeout value so that if the sleep is
> interrupted
> + * by a signal, the caller can call this helper again with the updated
> + * timeout.
This is a bit misleading... If the task was interrupted, the next
call will check "condition" and return immediately because of
signal_pending(). We should return to the user-space before we
can do interruptible sleep again.
Why do you need this helper? Given that it is trivial to read
jiffies before and after wait_event_interruptible_timeout(),
it doesn't seem to buy too much.
Oleg.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-09-26 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-26 2:57 [PATCH]: add a new wait_event_interruptible_timeout_modify helper Anirban Sinha
[not found] ` <816CA40C-41C0-4CCF-A75B-F67F1A2B0510@anirban.org>
2008-09-26 7:11 ` [PATCH]: correction: " Anirban Sinha
2008-09-26 15:21 ` Oleg Nesterov
2008-09-26 15:01 ` [PATCH]: " Linus Torvalds
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®