summaryrefslogtreecommitdiffstats
path: root/include/linux/wait.h
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2014-07-07 01:16:04 -0400
committerIngo Molnar <mingo@kernel.org>2014-07-16 09:10:39 -0400
commit743162013d40ca612b4cb53d3a200dff2d9ab26e (patch)
treeb688e8afdbb96d18c7466b088b2dc21156a0bedd /include/linux/wait.h
parentd26fad5b38e1c4667d4f2604936e59c837caa54d (diff)
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action' function to be provided which does the actual waiting. There are over 20 such functions, many of them identical. Most cases can be satisfied by one of just two functions, one which uses io_schedule() and one which just uses schedule(). So: Rename wait_on_bit and wait_on_bit_lock to wait_on_bit_action and wait_on_bit_lock_action to make it explicit that they need an action function. Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io which are *not* given an action function but implicitly use a standard one. The decision to error-out if a signal is pending is now made based on the 'mode' argument rather than being encoded in the action function. All instances of the old wait_on_bit and wait_on_bit_lock which can use the new version have been changed accordingly and their action functions have been discarded. wait_on_bit{_lock} does not return any specific error code in the event of a signal so the caller must check for non-zero and interpolate their own error code as appropriate. The wait_on_bit() call in __fscache_wait_on_invalidate() was ambiguous as it specified TASK_UNINTERRUPTIBLE but used fscache_wait_bit_interruptible as an action function. David Howells confirms this should be uniformly "uninterruptible" The main remaining user of wait_on_bit{,_lock}_action is NFS which needs to use a freezer-aware schedule() call. A comment in fs/gfs2/glock.c notes that having multiple 'action' functions is useful as they display differently in the 'wchan' field of 'ps'. (and /proc/$PID/wchan). As the new bit_wait{,_io} functions are tagged "__sched", they will not show up at all, but something higher in the stack. So the distinction will still be visible, only with different function names (gds2_glock_wait versus gfs2_glock_dq_wait in the gfs2/glock.c case). Since first version of this patch (against 3.15) two new action functions appeared, on in NFS and one in CIFS. CIFS also now uses an action function that makes the same freezer aware schedule call as NFS. Signed-off-by: NeilBrown <neilb@suse.de> Acked-by: David Howells <dhowells@redhat.com> (fscache, keys) Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2) Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Steve French <sfrench@samba.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/wait.h')
-rw-r--r--include/linux/wait.h115
1 files changed, 111 insertions, 4 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h
index bd68819f0815..73960ff09e56 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -854,11 +854,14 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
854 (wait)->flags = 0; \ 854 (wait)->flags = 0; \
855 } while (0) 855 } while (0)
856 856
857
858extern int bit_wait(void *);
859extern int bit_wait_io(void *);
860
857/** 861/**
858 * wait_on_bit - wait for a bit to be cleared 862 * wait_on_bit - wait for a bit to be cleared
859 * @word: the word being waited on, a kernel virtual address 863 * @word: the word being waited on, a kernel virtual address
860 * @bit: the bit of the word being waited on 864 * @bit: the bit of the word being waited on
861 * @action: the function used to sleep, which may take special actions
862 * @mode: the task state to sleep in 865 * @mode: the task state to sleep in
863 * 866 *
864 * There is a standard hashed waitqueue table for generic use. This 867 * There is a standard hashed waitqueue table for generic use. This
@@ -867,9 +870,62 @@ int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
867 * call wait_on_bit() in threads waiting for the bit to clear. 870 * call wait_on_bit() in threads waiting for the bit to clear.
868 * One uses wait_on_bit() where one is waiting for the bit to clear, 871 * One uses wait_on_bit() where one is waiting for the bit to clear,
869 * but has no intention of setting it. 872 * but has no intention of setting it.
873 * Returned value will be zero if the bit was cleared, or non-zero
874 * if the process received a signal and the mode permitted wakeup
875 * on that signal.
876 */
877static inline int
878wait_on_bit(void *word, int bit, unsigned mode)
879{
880 if (!test_bit(bit, word))
881 return 0;
882 return out_of_line_wait_on_bit(word, bit,
883 bit_wait,
884 mode);
885}
886
887/**
888 * wait_on_bit_io - wait for a bit to be cleared
889 * @word: the word being waited on, a kernel virtual address
890 * @bit: the bit of the word being waited on
891 * @mode: the task state to sleep in
892 *
893 * Use the standard hashed waitqueue table to wait for a bit
894 * to be cleared. This is similar to wait_on_bit(), but calls
895 * io_schedule() instead of schedule() for the actual waiting.
896 *
897 * Returned value will be zero if the bit was cleared, or non-zero
898 * if the process received a signal and the mode permitted wakeup
899 * on that signal.
900 */
901static inline int
902wait_on_bit_io(void *word, int bit, unsigned mode)
903{
904 if (!test_bit(bit, word))
905 return 0;
906 return out_of_line_wait_on_bit(word, bit,
907 bit_wait_io,
908 mode);
909}
910
911/**
912 * wait_on_bit_action - wait for a bit to be cleared
913 * @word: the word being waited on, a kernel virtual address
914 * @bit: the bit of the word being waited on
915 * @action: the function used to sleep, which may take special actions
916 * @mode: the task state to sleep in
917 *
918 * Use the standard hashed waitqueue table to wait for a bit
919 * to be cleared, and allow the waiting action to be specified.
920 * This is like wait_on_bit() but allows fine control of how the waiting
921 * is done.
922 *
923 * Returned value will be zero if the bit was cleared, or non-zero
924 * if the process received a signal and the mode permitted wakeup
925 * on that signal.
870 */ 926 */
871static inline int 927static inline int
872wait_on_bit(void *word, int bit, int (*action)(void *), unsigned mode) 928wait_on_bit_action(void *word, int bit, int (*action)(void *), unsigned mode)
873{ 929{
874 if (!test_bit(bit, word)) 930 if (!test_bit(bit, word))
875 return 0; 931 return 0;
@@ -880,7 +936,6 @@ wait_on_bit(void *word, int bit, int (*action)(void *), unsigned mode)
880 * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it 936 * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
881 * @word: the word being waited on, a kernel virtual address 937 * @word: the word being waited on, a kernel virtual address
882 * @bit: the bit of the word being waited on 938 * @bit: the bit of the word being waited on
883 * @action: the function used to sleep, which may take special actions
884 * @mode: the task state to sleep in 939 * @mode: the task state to sleep in
885 * 940 *
886 * There is a standard hashed waitqueue table for generic use. This 941 * There is a standard hashed waitqueue table for generic use. This
@@ -891,9 +946,61 @@ wait_on_bit(void *word, int bit, int (*action)(void *), unsigned mode)
891 * wait_on_bit() in threads waiting to be able to set the bit. 946 * wait_on_bit() in threads waiting to be able to set the bit.
892 * One uses wait_on_bit_lock() where one is waiting for the bit to 947 * One uses wait_on_bit_lock() where one is waiting for the bit to
893 * clear with the intention of setting it, and when done, clearing it. 948 * clear with the intention of setting it, and when done, clearing it.
949 *
950 * Returns zero if the bit was (eventually) found to be clear and was
951 * set. Returns non-zero if a signal was delivered to the process and
952 * the @mode allows that signal to wake the process.
953 */
954static inline int
955wait_on_bit_lock(void *word, int bit, unsigned mode)
956{
957 if (!test_and_set_bit(bit, word))
958 return 0;
959 return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode);
960}
961
962/**
963 * wait_on_bit_lock_io - wait for a bit to be cleared, when wanting to set it
964 * @word: the word being waited on, a kernel virtual address
965 * @bit: the bit of the word being waited on
966 * @mode: the task state to sleep in
967 *
968 * Use the standard hashed waitqueue table to wait for a bit
969 * to be cleared and then to atomically set it. This is similar
970 * to wait_on_bit(), but calls io_schedule() instead of schedule()
971 * for the actual waiting.
972 *
973 * Returns zero if the bit was (eventually) found to be clear and was
974 * set. Returns non-zero if a signal was delivered to the process and
975 * the @mode allows that signal to wake the process.
976 */
977static inline int
978wait_on_bit_lock_io(void *word, int bit, unsigned mode)
979{
980 if (!test_and_set_bit(bit, word))
981 return 0;
982 return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode);
983}
984
985/**
986 * wait_on_bit_lock_action - wait for a bit to be cleared, when wanting to set it
987 * @word: the word being waited on, a kernel virtual address
988 * @bit: the bit of the word being waited on
989 * @action: the function used to sleep, which may take special actions
990 * @mode: the task state to sleep in
991 *
992 * Use the standard hashed waitqueue table to wait for a bit
993 * to be cleared and then to set it, and allow the waiting action
994 * to be specified.
995 * This is like wait_on_bit() but allows fine control of how the waiting
996 * is done.
997 *
998 * Returns zero if the bit was (eventually) found to be clear and was
999 * set. Returns non-zero if a signal was delivered to the process and
1000 * the @mode allows that signal to wake the process.
894 */ 1001 */
895static inline int 1002static inline int
896wait_on_bit_lock(void *word, int bit, int (*action)(void *), unsigned mode) 1003wait_on_bit_lock_action(void *word, int bit, int (*action)(void *), unsigned mode)
897{ 1004{
898 if (!test_and_set_bit(bit, word)) 1005 if (!test_and_set_bit(bit, word))
899 return 0; 1006 return 0;