^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * The implementation of the wait_bit*() and related waiting APIs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "sched.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define WAIT_TABLE_BITS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define WAIT_TABLE_SIZE (1 << WAIT_TABLE_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static wait_queue_head_t bit_wait_table[WAIT_TABLE_SIZE] __cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) wait_queue_head_t *bit_waitqueue(void *word, int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) const int shift = BITS_PER_LONG == 32 ? 5 : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long val = (unsigned long)word << shift | bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) return bit_wait_table + hash_long(val, WAIT_TABLE_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) EXPORT_SYMBOL(bit_waitqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct wait_bit_key *key = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct wait_bit_queue_entry *wait_bit = container_of(wq_entry, struct wait_bit_queue_entry, wq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) if (wait_bit->key.flags != key->flags ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) wait_bit->key.bit_nr != key->bit_nr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) test_bit(key->bit_nr, key->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return autoremove_wake_function(wq_entry, mode, sync, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) EXPORT_SYMBOL(wake_bit_function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * To allow interruptible waiting and asynchronous (i.e. nonblocking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * waiting, the actions of __wait_on_bit() and __wait_on_bit_lock() are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * permitted return codes. Nonzero return codes halt waiting and return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int __sched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __wait_on_bit(struct wait_queue_head *wq_head, struct wait_bit_queue_entry *wbq_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) wait_bit_action_f *action, unsigned mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) prepare_to_wait(wq_head, &wbq_entry->wq_entry, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ret = (*action)(&wbq_entry->key, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) } while (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags) && !ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) finish_wait(wq_head, &wbq_entry->wq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) EXPORT_SYMBOL(__wait_on_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int __sched out_of_line_wait_on_bit(void *word, int bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) wait_bit_action_f *action, unsigned mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct wait_queue_head *wq_head = bit_waitqueue(word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) DEFINE_WAIT_BIT(wq_entry, word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return __wait_on_bit(wq_head, &wq_entry, action, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) EXPORT_SYMBOL(out_of_line_wait_on_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int __sched out_of_line_wait_on_bit_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) void *word, int bit, wait_bit_action_f *action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned mode, unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct wait_queue_head *wq_head = bit_waitqueue(word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) DEFINE_WAIT_BIT(wq_entry, word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) wq_entry.key.timeout = jiffies + timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return __wait_on_bit(wq_head, &wq_entry, action, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) EXPORT_SYMBOL_GPL(out_of_line_wait_on_bit_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int __sched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __wait_on_bit_lock(struct wait_queue_head *wq_head, struct wait_bit_queue_entry *wbq_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) wait_bit_action_f *action, unsigned mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) prepare_to_wait_exclusive(wq_head, &wbq_entry->wq_entry, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (test_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ret = action(&wbq_entry->key, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * See the comment in prepare_to_wait_event().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * finish_wait() does not necessarily takes wwq_head->lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * but test_and_set_bit() implies mb() which pairs with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * smp_mb__after_atomic() before wake_up_page().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) finish_wait(wq_head, &wbq_entry->wq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (!test_and_set_bit(wbq_entry->key.bit_nr, wbq_entry->key.flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) finish_wait(wq_head, &wbq_entry->wq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) } else if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) EXPORT_SYMBOL(__wait_on_bit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int __sched out_of_line_wait_on_bit_lock(void *word, int bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) wait_bit_action_f *action, unsigned mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct wait_queue_head *wq_head = bit_waitqueue(word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) DEFINE_WAIT_BIT(wq_entry, word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return __wait_on_bit_lock(wq_head, &wq_entry, action, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) EXPORT_SYMBOL(out_of_line_wait_on_bit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void __wake_up_bit(struct wait_queue_head *wq_head, void *word, int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct wait_bit_key key = __WAIT_BIT_KEY_INITIALIZER(word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (waitqueue_active(wq_head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __wake_up(wq_head, TASK_NORMAL, 1, &key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) EXPORT_SYMBOL(__wake_up_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * wake_up_bit - wake up a waiter on a bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @word: the word being waited on, a kernel virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @bit: the bit of the word being waited on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * There is a standard hashed waitqueue table for generic use. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * is the part of the hashtable's accessor API that wakes up waiters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * on a bit. For instance, if one were to have waiters on a bitflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * one would call wake_up_bit() after clearing the bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * In order for this to function properly, as it uses waitqueue_active()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * internally, some kind of memory barrier must be done prior to calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * this. Typically, this will be smp_mb__after_atomic(), but in some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * cases where bitflags are manipulated non-atomically under a lock, one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * may need to use a less regular barrier, such fs/inode.c's smp_mb(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * because spin_unlock() does not guarantee a memory barrier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) void wake_up_bit(void *word, int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __wake_up_bit(bit_waitqueue(word, bit), word, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) EXPORT_SYMBOL(wake_up_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) wait_queue_head_t *__var_waitqueue(void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return bit_wait_table + hash_ptr(p, WAIT_TABLE_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) EXPORT_SYMBOL(__var_waitqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) var_wake_function(struct wait_queue_entry *wq_entry, unsigned int mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int sync, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct wait_bit_key *key = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct wait_bit_queue_entry *wbq_entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) container_of(wq_entry, struct wait_bit_queue_entry, wq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (wbq_entry->key.flags != key->flags ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) wbq_entry->key.bit_nr != key->bit_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return autoremove_wake_function(wq_entry, mode, sync, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) void init_wait_var_entry(struct wait_bit_queue_entry *wbq_entry, void *var, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *wbq_entry = (struct wait_bit_queue_entry){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .key = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .flags = (var),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .bit_nr = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .wq_entry = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .flags = flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .private = current,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .func = var_wake_function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .entry = LIST_HEAD_INIT(wbq_entry->wq_entry.entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) EXPORT_SYMBOL(init_wait_var_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) void wake_up_var(void *var)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) __wake_up_bit(__var_waitqueue(var), var, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) EXPORT_SYMBOL(wake_up_var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) __sched int bit_wait(struct wait_bit_key *word, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (signal_pending_state(mode, current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) EXPORT_SYMBOL(bit_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) __sched int bit_wait_io(struct wait_bit_key *word, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) io_schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (signal_pending_state(mode, current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) EXPORT_SYMBOL(bit_wait_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) __sched int bit_wait_timeout(struct wait_bit_key *word, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned long now = READ_ONCE(jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (time_after_eq(now, word->timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) schedule_timeout(word->timeout - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (signal_pending_state(mode, current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) EXPORT_SYMBOL_GPL(bit_wait_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) __sched int bit_wait_io_timeout(struct wait_bit_key *word, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned long now = READ_ONCE(jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (time_after_eq(now, word->timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) io_schedule_timeout(word->timeout - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (signal_pending_state(mode, current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) EXPORT_SYMBOL_GPL(bit_wait_io_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) void __init wait_bit_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) for (i = 0; i < WAIT_TABLE_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) init_waitqueue_head(bit_wait_table + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }