Commit 2953ef24 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched/wait: Change timeout logic

Commit 4c663cfc ("wait: fix false timeouts when using
wait_event_timeout()") introduced an additional condition check after
a timeout but there's a few issues;

 - it forgot one site
 - it put the check after the main loop; not at the actual timeout
   check.

Cure both; by wrapping the condition (as suggested by Oleg), this
avoids double evaluation of 'condition' which could be quite big.
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20131002092528.028892896@infradead.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 2f2a2b60
...@@ -179,6 +179,14 @@ wait_queue_head_t *bit_waitqueue(void *, int); ...@@ -179,6 +179,14 @@ wait_queue_head_t *bit_waitqueue(void *, int);
#define wake_up_interruptible_sync_poll(x, m) \ #define wake_up_interruptible_sync_poll(x, m) \
__wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m)) __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
#define ___wait_cond_timeout(condition, ret) \
({ \
bool __cond = (condition); \
if (__cond && !ret) \
ret = 1; \
__cond || !ret; \
})
#define __wait_event(wq, condition) \ #define __wait_event(wq, condition) \
do { \ do { \
DEFINE_WAIT(__wait); \ DEFINE_WAIT(__wait); \
...@@ -217,14 +225,10 @@ do { \ ...@@ -217,14 +225,10 @@ do { \
\ \
for (;;) { \ for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
if (condition) \ if (___wait_cond_timeout(condition, ret)) \
break; \ break; \
ret = schedule_timeout(ret); \ ret = schedule_timeout(ret); \
if (!ret) \
break; \
} \ } \
if (!ret && (condition)) \
ret = 1; \
finish_wait(&wq, &__wait); \ finish_wait(&wq, &__wait); \
} while (0) } while (0)
...@@ -299,18 +303,14 @@ do { \ ...@@ -299,18 +303,14 @@ do { \
\ \
for (;;) { \ for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
if (condition) \ if (___wait_cond_timeout(condition, ret)) \
break; \ break; \
if (signal_pending(current)) { \ if (signal_pending(current)) { \
ret = -ERESTARTSYS; \ ret = -ERESTARTSYS; \
break; \ break; \
} \ } \
ret = schedule_timeout(ret); \ ret = schedule_timeout(ret); \
if (!ret) \
break; \
} \ } \
if (!ret && (condition)) \
ret = 1; \
finish_wait(&wq, &__wait); \ finish_wait(&wq, &__wait); \
} while (0) } while (0)
...@@ -815,7 +815,7 @@ do { \ ...@@ -815,7 +815,7 @@ do { \
\ \
for (;;) { \ for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
if (condition) \ if (___wait_cond_timeout(condition, ret)) \
break; \ break; \
if (signal_pending(current)) { \ if (signal_pending(current)) { \
ret = -ERESTARTSYS; \ ret = -ERESTARTSYS; \
...@@ -824,8 +824,6 @@ do { \ ...@@ -824,8 +824,6 @@ do { \
spin_unlock_irq(&lock); \ spin_unlock_irq(&lock); \
ret = schedule_timeout(ret); \ ret = schedule_timeout(ret); \
spin_lock_irq(&lock); \ spin_lock_irq(&lock); \
if (!ret) \
break; \
} \ } \
finish_wait(&wq, &__wait); \ finish_wait(&wq, &__wait); \
} while (0) } while (0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment