summaryrefslogtreecommitdiffstats
path: root/kernel/sched/wait.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2014-09-24 23:55:19 -0400
committerTrond Myklebust <trond.myklebust@primarydata.com>2014-09-25 08:23:57 -0400
commitcbbce82209490df8b68da9aec0d642451fe0a668 (patch)
tree0c8d643c6bc34332c8b00300a6440f87701039c3 /kernel/sched/wait.c
parente87b4c7a7ac6d895846570dec637744cf7050df3 (diff)
SCHED: add some "wait..on_bit...timeout()" interfaces.
In commit c1221321b7c25b53204447cff9949a6d5a7ddddc sched: Allow wait_on_bit_action() functions to support a timeout I suggested that a "wait_on_bit_timeout()" interface would not meet my need. This isn't true - I was just over-engineering. Including a 'private' field in wait_bit_key instead of a focused "timeout" field was just premature generalization. If some other use is ever found, it can be generalized or added later. So this patch renames "private" to "timeout" with a meaning "stop waiting when "jiffies" reaches or passes "timeout", and adds two of the many possible wait..bit..timeout() interfaces: wait_on_page_bit_killable_timeout(), which is the one I want to use, and out_of_line_wait_on_bit_timeout() which is a reasonably general example. Others can be added as needed. Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: NeilBrown <neilb@suse.de> Acked-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Diffstat (limited to 'kernel/sched/wait.c')
-rw-r--r--kernel/sched/wait.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index 15cab1a4f84e..5a62915f47a8 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -343,6 +343,18 @@ int __sched out_of_line_wait_on_bit(void *word, int bit,
343} 343}
344EXPORT_SYMBOL(out_of_line_wait_on_bit); 344EXPORT_SYMBOL(out_of_line_wait_on_bit);
345 345
346int __sched out_of_line_wait_on_bit_timeout(
347 void *word, int bit, wait_bit_action_f *action,
348 unsigned mode, unsigned long timeout)
349{
350 wait_queue_head_t *wq = bit_waitqueue(word, bit);
351 DEFINE_WAIT_BIT(wait, word, bit);
352
353 wait.key.timeout = jiffies + timeout;
354 return __wait_on_bit(wq, &wait, action, mode);
355}
356EXPORT_SYMBOL_GPL(out_of_line_wait_on_bit_timeout);
357
346int __sched 358int __sched
347__wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q, 359__wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
348 wait_bit_action_f *action, unsigned mode) 360 wait_bit_action_f *action, unsigned mode)
@@ -520,3 +532,27 @@ __sched int bit_wait_io(struct wait_bit_key *word)
520 return 0; 532 return 0;
521} 533}
522EXPORT_SYMBOL(bit_wait_io); 534EXPORT_SYMBOL(bit_wait_io);
535
536__sched int bit_wait_timeout(struct wait_bit_key *word)
537{
538 unsigned long now = ACCESS_ONCE(jiffies);
539 if (signal_pending_state(current->state, current))
540 return 1;
541 if (time_after_eq(now, word->timeout))
542 return -EAGAIN;
543 schedule_timeout(word->timeout - now);
544 return 0;
545}
546EXPORT_SYMBOL_GPL(bit_wait_timeout);
547
548__sched int bit_wait_io_timeout(struct wait_bit_key *word)
549{
550 unsigned long now = ACCESS_ONCE(jiffies);
551 if (signal_pending_state(current->state, current))
552 return 1;
553 if (time_after_eq(now, word->timeout))
554 return -EAGAIN;
555 io_schedule_timeout(word->timeout - now);
556 return 0;
557}
558EXPORT_SYMBOL_GPL(bit_wait_io_timeout);