aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/wait.h
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2017-06-20 06:19:09 -0400
committerIngo Molnar <mingo@kernel.org>2017-06-20 06:19:09 -0400
commit5dd43ce2f69d42a71dcacdb13d17d8c0ac1fe8f7 (patch)
tree8fd9fc956274bf3b64b4ec736cdb38d9ba9bf6c3 /include/linux/wait.h
parent4b1c480bfa3b246e292f4d50167756252a9717ed (diff)
sched/wait: Split out the wait_bit*() APIs from <linux/wait.h> into <linux/wait_bit.h>
The wait_bit*() types and APIs are mixed into wait.h, but they are a pretty orthogonal extension of wait-queues. Furthermore, only about 50 kernel files use these APIs, while over 1000 use the regular wait-queue functionality. So clean up the main wait.h by moving the wait-bit functionality out of it, into a separate .h and .c file: include/linux/wait_bit.h for types and APIs kernel/sched/wait_bit.c for the implementation Update all header dependencies. This reduces the size of wait.h rather significantly, by about 30%. Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/wait.h')
-rw-r--r--include/linux/wait.h250
1 files changed, 0 insertions, 250 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 0805098f3589..629489746f8a 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -29,18 +29,6 @@ struct wait_queue_entry {
29 struct list_head task_list; 29 struct list_head task_list;
30}; 30};
31 31
32struct wait_bit_key {
33 void *flags;
34 int bit_nr;
35#define WAIT_ATOMIC_T_BIT_NR -1
36 unsigned long timeout;
37};
38
39struct wait_bit_queue_entry {
40 struct wait_bit_key key;
41 struct wait_queue_entry wq_entry;
42};
43
44struct wait_queue_head { 32struct wait_queue_head {
45 spinlock_t lock; 33 spinlock_t lock;
46 struct list_head task_list; 34 struct list_head task_list;
@@ -68,12 +56,6 @@ struct task_struct;
68#define DECLARE_WAIT_QUEUE_HEAD(name) \ 56#define DECLARE_WAIT_QUEUE_HEAD(name) \
69 struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name) 57 struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
70 58
71#define __WAIT_BIT_KEY_INITIALIZER(word, bit) \
72 { .flags = word, .bit_nr = bit, }
73
74#define __WAIT_ATOMIC_T_KEY_INITIALIZER(p) \
75 { .flags = p, .bit_nr = WAIT_ATOMIC_T_BIT_NR, }
76
77extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *); 59extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *);
78 60
79#define init_waitqueue_head(wq_head) \ 61#define init_waitqueue_head(wq_head) \
@@ -200,22 +182,11 @@ __remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq
200 list_del(&wq_entry->task_list); 182 list_del(&wq_entry->task_list);
201} 183}
202 184
203typedef int wait_bit_action_f(struct wait_bit_key *key, int mode);
204void __wake_up(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key); 185void __wake_up(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
205void __wake_up_locked_key(struct wait_queue_head *wq_head, unsigned int mode, void *key); 186void __wake_up_locked_key(struct wait_queue_head *wq_head, unsigned int mode, void *key);
206void __wake_up_sync_key(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key); 187void __wake_up_sync_key(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
207void __wake_up_locked(struct wait_queue_head *wq_head, unsigned int mode, int nr); 188void __wake_up_locked(struct wait_queue_head *wq_head, unsigned int mode, int nr);
208void __wake_up_sync(struct wait_queue_head *wq_head, unsigned int mode, int nr); 189void __wake_up_sync(struct wait_queue_head *wq_head, unsigned int mode, int nr);
209void __wake_up_bit(struct wait_queue_head *wq_head, void *word, int bit);
210int __wait_on_bit(struct wait_queue_head *wq_head, struct wait_bit_queue_entry *wbq_entry, wait_bit_action_f *action, unsigned int mode);
211int __wait_on_bit_lock(struct wait_queue_head *wq_head, struct wait_bit_queue_entry *wbq_entry, wait_bit_action_f *action, unsigned int mode);
212void wake_up_bit(void *word, int bit);
213void wake_up_atomic_t(atomic_t *p);
214int out_of_line_wait_on_bit(void *word, int, wait_bit_action_f *action, unsigned int mode);
215int out_of_line_wait_on_bit_timeout(void *word, int, wait_bit_action_f *action, unsigned int mode, unsigned long timeout);
216int out_of_line_wait_on_bit_lock(void *word, int, wait_bit_action_f *action, unsigned int mode);
217int out_of_line_wait_on_atomic_t(atomic_t *p, int (*)(atomic_t *), unsigned int mode);
218struct wait_queue_head *bit_waitqueue(void *word, int bit);
219 190
220#define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL) 191#define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL)
221#define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL) 192#define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL)
@@ -976,7 +947,6 @@ void finish_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_en
976long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout); 947long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout);
977int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key); 948int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
978int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key); 949int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
979int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
980 950
981#define DEFINE_WAIT_FUNC(name, function) \ 951#define DEFINE_WAIT_FUNC(name, function) \
982 struct wait_queue_entry name = { \ 952 struct wait_queue_entry name = { \
@@ -987,17 +957,6 @@ int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync
987 957
988#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function) 958#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
989 959
990#define DEFINE_WAIT_BIT(name, word, bit) \
991 struct wait_bit_queue_entry name = { \
992 .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \
993 .wq_entry = { \
994 .private = current, \
995 .func = wake_bit_function, \
996 .task_list = \
997 LIST_HEAD_INIT((name).wq_entry.task_list), \
998 }, \
999 }
1000
1001#define init_wait(wait) \ 960#define init_wait(wait) \
1002 do { \ 961 do { \
1003 (wait)->private = current; \ 962 (wait)->private = current; \
@@ -1006,213 +965,4 @@ int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync
1006 (wait)->flags = 0; \ 965 (wait)->flags = 0; \
1007 } while (0) 966 } while (0)
1008 967
1009
1010extern int bit_wait(struct wait_bit_key *key, int bit);
1011extern int bit_wait_io(struct wait_bit_key *key, int bit);
1012extern int bit_wait_timeout(struct wait_bit_key *key, int bit);
1013extern int bit_wait_io_timeout(struct wait_bit_key *key, int bit);
1014
1015/**
1016 * wait_on_bit - wait for a bit to be cleared
1017 * @word: the word being waited on, a kernel virtual address
1018 * @bit: the bit of the word being waited on
1019 * @mode: the task state to sleep in
1020 *
1021 * There is a standard hashed waitqueue table for generic use. This
1022 * is the part of the hashtable's accessor API that waits on a bit.
1023 * For instance, if one were to have waiters on a bitflag, one would
1024 * call wait_on_bit() in threads waiting for the bit to clear.
1025 * One uses wait_on_bit() where one is waiting for the bit to clear,
1026 * but has no intention of setting it.
1027 * Returned value will be zero if the bit was cleared, or non-zero
1028 * if the process received a signal and the mode permitted wakeup
1029 * on that signal.
1030 */
1031static inline int
1032wait_on_bit(unsigned long *word, int bit, unsigned mode)
1033{
1034 might_sleep();
1035 if (!test_bit(bit, word))
1036 return 0;
1037 return out_of_line_wait_on_bit(word, bit,
1038 bit_wait,
1039 mode);
1040}
1041
1042/**
1043 * wait_on_bit_io - wait for a bit to be cleared
1044 * @word: the word being waited on, a kernel virtual address
1045 * @bit: the bit of the word being waited on
1046 * @mode: the task state to sleep in
1047 *
1048 * Use the standard hashed waitqueue table to wait for a bit
1049 * to be cleared. This is similar to wait_on_bit(), but calls
1050 * io_schedule() instead of schedule() for the actual waiting.
1051 *
1052 * Returned value will be zero if the bit was cleared, or non-zero
1053 * if the process received a signal and the mode permitted wakeup
1054 * on that signal.
1055 */
1056static inline int
1057wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
1058{
1059 might_sleep();
1060 if (!test_bit(bit, word))
1061 return 0;
1062 return out_of_line_wait_on_bit(word, bit,
1063 bit_wait_io,
1064 mode);
1065}
1066
1067/**
1068 * wait_on_bit_timeout - wait for a bit to be cleared or a timeout elapses
1069 * @word: the word being waited on, a kernel virtual address
1070 * @bit: the bit of the word being waited on
1071 * @mode: the task state to sleep in
1072 * @timeout: timeout, in jiffies
1073 *
1074 * Use the standard hashed waitqueue table to wait for a bit
1075 * to be cleared. This is similar to wait_on_bit(), except also takes a
1076 * timeout parameter.
1077 *
1078 * Returned value will be zero if the bit was cleared before the
1079 * @timeout elapsed, or non-zero if the @timeout elapsed or process
1080 * received a signal and the mode permitted wakeup on that signal.
1081 */
1082static inline int
1083wait_on_bit_timeout(unsigned long *word, int bit, unsigned mode,
1084 unsigned long timeout)
1085{
1086 might_sleep();
1087 if (!test_bit(bit, word))
1088 return 0;
1089 return out_of_line_wait_on_bit_timeout(word, bit,
1090 bit_wait_timeout,
1091 mode, timeout);
1092}
1093
1094/**
1095 * wait_on_bit_action - wait for a bit to be cleared
1096 * @word: the word being waited on, a kernel virtual address
1097 * @bit: the bit of the word being waited on
1098 * @action: the function used to sleep, which may take special actions
1099 * @mode: the task state to sleep in
1100 *
1101 * Use the standard hashed waitqueue table to wait for a bit
1102 * to be cleared, and allow the waiting action to be specified.
1103 * This is like wait_on_bit() but allows fine control of how the waiting
1104 * is done.
1105 *
1106 * Returned value will be zero if the bit was cleared, or non-zero
1107 * if the process received a signal and the mode permitted wakeup
1108 * on that signal.
1109 */
1110static inline int
1111wait_on_bit_action(unsigned long *word, int bit, wait_bit_action_f *action,
1112 unsigned mode)
1113{
1114 might_sleep();
1115 if (!test_bit(bit, word))
1116 return 0;
1117 return out_of_line_wait_on_bit(word, bit, action, mode);
1118}
1119
1120/**
1121 * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
1122 * @word: the word being waited on, a kernel virtual address
1123 * @bit: the bit of the word being waited on
1124 * @mode: the task state to sleep in
1125 *
1126 * There is a standard hashed waitqueue table for generic use. This
1127 * is the part of the hashtable's accessor API that waits on a bit
1128 * when one intends to set it, for instance, trying to lock bitflags.
1129 * For instance, if one were to have waiters trying to set bitflag
1130 * and waiting for it to clear before setting it, one would call
1131 * wait_on_bit() in threads waiting to be able to set the bit.
1132 * One uses wait_on_bit_lock() where one is waiting for the bit to
1133 * clear with the intention of setting it, and when done, clearing it.
1134 *
1135 * Returns zero if the bit was (eventually) found to be clear and was
1136 * set. Returns non-zero if a signal was delivered to the process and
1137 * the @mode allows that signal to wake the process.
1138 */
1139static inline int
1140wait_on_bit_lock(unsigned long *word, int bit, unsigned mode)
1141{
1142 might_sleep();
1143 if (!test_and_set_bit(bit, word))
1144 return 0;
1145 return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode);
1146}
1147
1148/**
1149 * wait_on_bit_lock_io - wait for a bit to be cleared, when wanting to set it
1150 * @word: the word being waited on, a kernel virtual address
1151 * @bit: the bit of the word being waited on
1152 * @mode: the task state to sleep in
1153 *
1154 * Use the standard hashed waitqueue table to wait for a bit
1155 * to be cleared and then to atomically set it. This is similar
1156 * to wait_on_bit(), but calls io_schedule() instead of schedule()
1157 * for the actual waiting.
1158 *
1159 * Returns zero if the bit was (eventually) found to be clear and was
1160 * set. Returns non-zero if a signal was delivered to the process and
1161 * the @mode allows that signal to wake the process.
1162 */
1163static inline int
1164wait_on_bit_lock_io(unsigned long *word, int bit, unsigned mode)
1165{
1166 might_sleep();
1167 if (!test_and_set_bit(bit, word))
1168 return 0;
1169 return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode);
1170}
1171
1172/**
1173 * wait_on_bit_lock_action - wait for a bit to be cleared, when wanting to set it
1174 * @word: the word being waited on, a kernel virtual address
1175 * @bit: the bit of the word being waited on
1176 * @action: the function used to sleep, which may take special actions
1177 * @mode: the task state to sleep in
1178 *
1179 * Use the standard hashed waitqueue table to wait for a bit
1180 * to be cleared and then to set it, and allow the waiting action
1181 * to be specified.
1182 * This is like wait_on_bit() but allows fine control of how the waiting
1183 * is done.
1184 *
1185 * Returns zero if the bit was (eventually) found to be clear and was
1186 * set. Returns non-zero if a signal was delivered to the process and
1187 * the @mode allows that signal to wake the process.
1188 */
1189static inline int
1190wait_on_bit_lock_action(unsigned long *word, int bit, wait_bit_action_f *action,
1191 unsigned mode)
1192{
1193 might_sleep();
1194 if (!test_and_set_bit(bit, word))
1195 return 0;
1196 return out_of_line_wait_on_bit_lock(word, bit, action, mode);
1197}
1198
1199/**
1200 * wait_on_atomic_t - Wait for an atomic_t to become 0
1201 * @val: The atomic value being waited on, a kernel virtual address
1202 * @action: the function used to sleep, which may take special actions
1203 * @mode: the task state to sleep in
1204 *
1205 * Wait for an atomic_t to become 0. We abuse the bit-wait waitqueue table for
1206 * the purpose of getting a waitqueue, but we set the key to a bit number
1207 * outside of the target 'word'.
1208 */
1209static inline
1210int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode)
1211{
1212 might_sleep();
1213 if (atomic_read(val) == 0)
1214 return 0;
1215 return out_of_line_wait_on_atomic_t(val, action, mode);
1216}
1217
1218#endif /* _LINUX_WAIT_H */ 968#endif /* _LINUX_WAIT_H */