Skip to contentSkip to conversation

wait: fix false timeouts when using wait_event_timeout()

PATCH In review Imre Deak 5 participants 16 messages May 2, 2013 – May 8, 2013 Scheduler

lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/1 wait: fix false timeouts when using wait_event_timeout()

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

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".

---
 include/linux/wait.h |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
include/linux/wait.h +11 -5
index 7cb64d4..5336842 100644
@@ -217,6 +217,8 @@ do {									\
 		if (!ret)						\
 			break;						\
 	}								\
+	if (!ret && (condition))					\
+		ret = 1;						\
 	finish_wait(&wq, &__wait);					\
 } while (0)
 
@@ -233,8 +235,9 @@ do {									\
  * 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, and the remaining
- * jiffies if the condition evaluated to true before the timeout elapsed.
+ * The function returns 0 if the @timeout elapsed, or the remaining
+ * jiffies (at least 1) if the @condition evaluated to %true before
+ * the @timeout elapsed.
  */
 #define wait_event_timeout(wq, condition, timeout)			\
 ({									\
@@ -302,6 +305,8 @@ do {									\
 		ret = -ERESTARTSYS;					\
 		break;							\
 	}								\
+	if (!ret && (condition))					\
+		ret = 1;						\
 	finish_wait(&wq, &__wait);					\
 } while (0)
 
@@ -318,9 +323,10 @@ do {									\
  * 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.
+ * Returns:
+ * 0 if the @timeout elapsed, -%ERESTARTSYS if it was interrupted by
+ * a signal, or the remaining jiffies (at least 1) if the @condition
+ * evaluated to %true before the @timeout elapsed.
  */
 #define wait_event_interruptible_timeout(wq, condition, timeout)	\
 ({									\
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

Quoted 6 lines

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".

We have 3 instances of this bug in drm/i915. One case even where we switch between the interruptible and not interruptible wait_event_timeout variants, foolishly presuming they have the same semantics. I very much like this.

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#2 lore raw
Quoted 14 lines · On Thu, 2 May 2013 11:36:56 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 13 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

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".

Quoted 6 lines
Quoted 1 line

We have 3 instances of this bug in drm/i915. One case even where we switch between the interruptible and not interruptible wait_event_timeout variants, foolishly presuming they have the same semantics. I very much like this.

Let's think about scheduling this fix.

Are any of the bugs which we expect this patch fixes serious enough to warrant merging it into 3.10? And -stable?

author
#3 lore raw
Quoted 23 lines · Andrew Morton
Quoted 14 lines · On Thu, 2 May 2013 11:36:56 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 13 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

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".

Quoted 6 lines
Quoted 1 line

We have 3 instances of this bug in drm/i915. One case even where we switch between the interruptible and not interruptible wait_event_timeout variants, foolishly presuming they have the same semantics. I very much like this.

Quoted 4 lines

Let's think about scheduling this fix.

Are any of the bugs which we expect this patch fixes serious enough to warrant merging it into 3.10? And -stable?

There is at least [1], but I'm sure there is more similar reports about i915. I'd vote for -stable at least.

--Imre

[1] https://bugs.freedesktop.org/show_bug.cgi?id=64133

#4 lore raw
In reply to Imre Deak
Quoted 7 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

Fun.

Quoted 4 lines

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.

I'm not sure there's a good answer - except maybe making the timer expiry handler check the condition (which would likely get really yucky really quickly).

David

author
#5 lore raw
Quoted 12 lines · David Howells
Quoted 7 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

Fun.

Quoted 7 lines
Quoted 4 lines

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.

I'm trying to understand what sequence do you mean. I can think of the following - as an example - in case of starting a transaction that will set a completion flag:

waiter completion handler
start transaction
set completion_flag
ret = wait_event_timeout(timeout, completion_flag)

In this case ret will be timeout which is the original behavior, so should be ok. One exception is if timeout=0 to begin with, since then - after this change - ret will be 1. But I can't see how that use case is useful. I guess I'm missing something, could you elaborate?

--Imre

Quoted 5 lines

I'm not sure there's a good answer - except maybe making the timer expiry handler check the condition (which would likely get really yucky really quickly).

David

#6 lore raw
In reply to David Howells
Quoted 7 lines · David Howells
Quoted 4 lines

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).
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#7 lore raw
Quoted 30 lines · Daniel Vetter
Quoted 7 lines · David Howells
Quoted 4 lines

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.

Quoted 3 lines

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.

Signature · 1 line
Jens Axboe
#8 lore raw
Quoted 1 line · Jens Axboe

IMHO, the change definitely makes sense.

Yeah... I think I agree.

David

author
#9 lore raw
In reply to Jens Axboe
Quoted 40 lines · Jens Axboe
Quoted 30 lines · Daniel Vetter
Quoted 7 lines · David Howells
Quoted 4 lines

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.

Quoted 3 lines

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.

Quoted 8 lines

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?

kernel/timer.c +0 -0
index dbf7a78..5a62456 100644
@@ -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..

--Imre

#10 lore raw
Quoted 72 lines · Imre Deak
Quoted 40 lines · Jens Axboe
Quoted 30 lines · Daniel Vetter
Quoted 7 lines · David Howells
Quoted 4 lines

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.

Quoted 3 lines

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.

Quoted 8 lines

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?

kernel/timer.c +5 -1
index dbf7a78..5a62456 100644
@@ -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);

Quoted 2 lines

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.

So not sure on the above, sorry.

Signature · 1 line
Jens Axboe
author
#11 lore raw
Quoted 73 lines · Jens Axboe
Quoted 72 lines · Imre Deak
Quoted 40 lines · Jens Axboe
Quoted 30 lines · Daniel Vetter
Quoted 7 lines · David Howells
Quoted 4 lines

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.

Quoted 3 lines

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.

Quoted 8 lines

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?

kernel/timer.c +5 -1
index dbf7a78..5a62456 100644
@@ -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);

Quoted 6 lines
Quoted 2 lines

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.

Quoted 1 line

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

#12 lore raw
Quoted 81 lines · Imre Deak
Quoted 73 lines · Jens Axboe
Quoted 72 lines · Imre Deak
Quoted 40 lines · Jens Axboe
Quoted 30 lines · Daniel Vetter
Quoted 7 lines · David Howells
Quoted 4 lines

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.

Quoted 3 lines

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.

Quoted 8 lines

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?

kernel/timer.c +5 -1
index dbf7a78..5a62456 100644
@@ -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);
Quoted 6 lines
Quoted 2 lines

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.

Quoted 4 lines

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.

In drm/i915 we have a bunch of those 1 jiffie timeouts, too, especially with low HZ configs. For easy comparison with hw docs we try to stick to the documented timeout limits and convert them with msec_to_jiffies (which does the right thing wrt rounding). But since these timeouts are often in the low ms range, that often means just 1 jiffie timeouts. So the timeout could be off by a large factor (and we have the bugzillas to prove it happens in reality).

I'm not sure whether sprinkling +1 all over the codebase is a that nice approach. Adding the +1 in sched_timeout otoh would give us a nice idiot proof interface for driver guys like me. We also have some custom register wait loops using msleep(1) and jiffy based timeouts, and there our driver macro does the +1. That helped a lot in avoiding stupid bugs, but now we've converted a few things over to interrupts + timeout and the bugs are back ...
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

Acked-by on v1 1/1
#13 lore raw
In reply to Imre Deak
Quoted 8 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

Quoted 6 lines

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".

Acked-by
#14 lore raw
Quoted 10 lines · David Howells
Quoted 8 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

Quoted 8 lines
Quoted 6 lines

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".

You can add mine, too:

Signature · 1 line
Jens Axboe
author
#15 lore raw
Quoted 16 lines · Jens Axboe
Quoted 15 lines · David Howells
Quoted 13 lines · Imre Deak

Many callers of the wait_event_timeout() and wait_event_interruptible_timeout() expect that the return value will be positive if the specified condition becomes true before the timeout elapses. However, at the moment this isn't guaranteed. If the wake-up handler is delayed enough, the time remaining until timeout will be calculated as 0 - and passed back as a return value - even if the condition became true before the timeout has passed.

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".

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

You can add mine, too:

Ok, I think we agree that the +1 thing in schedule_timeout() discussed in this thread should be handled separately, so if there is no other objection I'd be happy if this patch was merged through someone's tree as-is.

--Imre