diff options
author | Peter Zijlstra <peterz@infradead.org> | 2013-10-04 16:06:53 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2013-11-06 01:49:19 -0500 |
commit | b8a216269ec0ce2e961d32e6d640d7010b8a818e (patch) | |
tree | 802be45e08abcc5246d33c5422203ce1d87ce854 /kernel | |
parent | b4145872f7049e429718b40b86e1b46659988398 (diff) |
sched: Move completion code from core.c to completion.c
Completions already have their own header file: linux/completion.h
Move the implementation out of kernel/sched/core.c and into its own
file: kernel/sched/completion.c.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/n/tip-x2y49rmxu5dljt66ai2lcfuw@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/sched/Makefile | 2 | ||||
-rw-r--r-- | kernel/sched/completion.c | 299 | ||||
-rw-r--r-- | kernel/sched/core.c | 284 |
3 files changed, 300 insertions, 285 deletions
diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile index f8d3f4baa1a1..7b621409cf15 100644 --- a/kernel/sched/Makefile +++ b/kernel/sched/Makefile | |||
@@ -12,7 +12,7 @@ CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer | |||
12 | endif | 12 | endif |
13 | 13 | ||
14 | obj-y += core.o proc.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o | 14 | obj-y += core.o proc.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o |
15 | obj-y += wait.o | 15 | obj-y += wait.o completion.o |
16 | obj-$(CONFIG_SMP) += cpupri.o | 16 | obj-$(CONFIG_SMP) += cpupri.o |
17 | obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o | 17 | obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o |
18 | obj-$(CONFIG_SCHEDSTATS) += stats.o | 18 | obj-$(CONFIG_SCHEDSTATS) += stats.o |
diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c new file mode 100644 index 000000000000..a63f4dc27909 --- /dev/null +++ b/kernel/sched/completion.c | |||
@@ -0,0 +1,299 @@ | |||
1 | /* | ||
2 | * Generic wait-for-completion handler; | ||
3 | * | ||
4 | * It differs from semaphores in that their default case is the opposite, | ||
5 | * wait_for_completion default blocks whereas semaphore default non-block. The | ||
6 | * interface also makes it easy to 'complete' multiple waiting threads, | ||
7 | * something which isn't entirely natural for semaphores. | ||
8 | * | ||
9 | * But more importantly, the primitive documents the usage. Semaphores would | ||
10 | * typically be used for exclusion which gives rise to priority inversion. | ||
11 | * Waiting for completion is a typically sync point, but not an exclusion point. | ||
12 | */ | ||
13 | |||
14 | #include <linux/sched.h> | ||
15 | #include <linux/completion.h> | ||
16 | |||
17 | /** | ||
18 | * complete: - signals a single thread waiting on this completion | ||
19 | * @x: holds the state of this particular completion | ||
20 | * | ||
21 | * This will wake up a single thread waiting on this completion. Threads will be | ||
22 | * awakened in the same order in which they were queued. | ||
23 | * | ||
24 | * See also complete_all(), wait_for_completion() and related routines. | ||
25 | * | ||
26 | * It may be assumed that this function implies a write memory barrier before | ||
27 | * changing the task state if and only if any tasks are woken up. | ||
28 | */ | ||
29 | void complete(struct completion *x) | ||
30 | { | ||
31 | unsigned long flags; | ||
32 | |||
33 | spin_lock_irqsave(&x->wait.lock, flags); | ||
34 | x->done++; | ||
35 | __wake_up_locked(&x->wait, TASK_NORMAL, 1); | ||
36 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
37 | } | ||
38 | EXPORT_SYMBOL(complete); | ||
39 | |||
40 | /** | ||
41 | * complete_all: - signals all threads waiting on this completion | ||
42 | * @x: holds the state of this particular completion | ||
43 | * | ||
44 | * This will wake up all threads waiting on this particular completion event. | ||
45 | * | ||
46 | * It may be assumed that this function implies a write memory barrier before | ||
47 | * changing the task state if and only if any tasks are woken up. | ||
48 | */ | ||
49 | void complete_all(struct completion *x) | ||
50 | { | ||
51 | unsigned long flags; | ||
52 | |||
53 | spin_lock_irqsave(&x->wait.lock, flags); | ||
54 | x->done += UINT_MAX/2; | ||
55 | __wake_up_locked(&x->wait, TASK_NORMAL, 0); | ||
56 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
57 | } | ||
58 | EXPORT_SYMBOL(complete_all); | ||
59 | |||
60 | static inline long __sched | ||
61 | do_wait_for_common(struct completion *x, | ||
62 | long (*action)(long), long timeout, int state) | ||
63 | { | ||
64 | if (!x->done) { | ||
65 | DECLARE_WAITQUEUE(wait, current); | ||
66 | |||
67 | __add_wait_queue_tail_exclusive(&x->wait, &wait); | ||
68 | do { | ||
69 | if (signal_pending_state(state, current)) { | ||
70 | timeout = -ERESTARTSYS; | ||
71 | break; | ||
72 | } | ||
73 | __set_current_state(state); | ||
74 | spin_unlock_irq(&x->wait.lock); | ||
75 | timeout = action(timeout); | ||
76 | spin_lock_irq(&x->wait.lock); | ||
77 | } while (!x->done && timeout); | ||
78 | __remove_wait_queue(&x->wait, &wait); | ||
79 | if (!x->done) | ||
80 | return timeout; | ||
81 | } | ||
82 | x->done--; | ||
83 | return timeout ?: 1; | ||
84 | } | ||
85 | |||
86 | static inline long __sched | ||
87 | __wait_for_common(struct completion *x, | ||
88 | long (*action)(long), long timeout, int state) | ||
89 | { | ||
90 | might_sleep(); | ||
91 | |||
92 | spin_lock_irq(&x->wait.lock); | ||
93 | timeout = do_wait_for_common(x, action, timeout, state); | ||
94 | spin_unlock_irq(&x->wait.lock); | ||
95 | return timeout; | ||
96 | } | ||
97 | |||
98 | static long __sched | ||
99 | wait_for_common(struct completion *x, long timeout, int state) | ||
100 | { | ||
101 | return __wait_for_common(x, schedule_timeout, timeout, state); | ||
102 | } | ||
103 | |||
104 | static long __sched | ||
105 | wait_for_common_io(struct completion *x, long timeout, int state) | ||
106 | { | ||
107 | return __wait_for_common(x, io_schedule_timeout, timeout, state); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * wait_for_completion: - waits for completion of a task | ||
112 | * @x: holds the state of this particular completion | ||
113 | * | ||
114 | * This waits to be signaled for completion of a specific task. It is NOT | ||
115 | * interruptible and there is no timeout. | ||
116 | * | ||
117 | * See also similar routines (i.e. wait_for_completion_timeout()) with timeout | ||
118 | * and interrupt capability. Also see complete(). | ||
119 | */ | ||
120 | void __sched wait_for_completion(struct completion *x) | ||
121 | { | ||
122 | wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); | ||
123 | } | ||
124 | EXPORT_SYMBOL(wait_for_completion); | ||
125 | |||
126 | /** | ||
127 | * wait_for_completion_timeout: - waits for completion of a task (w/timeout) | ||
128 | * @x: holds the state of this particular completion | ||
129 | * @timeout: timeout value in jiffies | ||
130 | * | ||
131 | * This waits for either a completion of a specific task to be signaled or for a | ||
132 | * specified timeout to expire. The timeout is in jiffies. It is not | ||
133 | * interruptible. | ||
134 | * | ||
135 | * Return: 0 if timed out, and positive (at least 1, or number of jiffies left | ||
136 | * till timeout) if completed. | ||
137 | */ | ||
138 | unsigned long __sched | ||
139 | wait_for_completion_timeout(struct completion *x, unsigned long timeout) | ||
140 | { | ||
141 | return wait_for_common(x, timeout, TASK_UNINTERRUPTIBLE); | ||
142 | } | ||
143 | EXPORT_SYMBOL(wait_for_completion_timeout); | ||
144 | |||
145 | /** | ||
146 | * wait_for_completion_io: - waits for completion of a task | ||
147 | * @x: holds the state of this particular completion | ||
148 | * | ||
149 | * This waits to be signaled for completion of a specific task. It is NOT | ||
150 | * interruptible and there is no timeout. The caller is accounted as waiting | ||
151 | * for IO. | ||
152 | */ | ||
153 | void __sched wait_for_completion_io(struct completion *x) | ||
154 | { | ||
155 | wait_for_common_io(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); | ||
156 | } | ||
157 | EXPORT_SYMBOL(wait_for_completion_io); | ||
158 | |||
159 | /** | ||
160 | * wait_for_completion_io_timeout: - waits for completion of a task (w/timeout) | ||
161 | * @x: holds the state of this particular completion | ||
162 | * @timeout: timeout value in jiffies | ||
163 | * | ||
164 | * This waits for either a completion of a specific task to be signaled or for a | ||
165 | * specified timeout to expire. The timeout is in jiffies. It is not | ||
166 | * interruptible. The caller is accounted as waiting for IO. | ||
167 | * | ||
168 | * Return: 0 if timed out, and positive (at least 1, or number of jiffies left | ||
169 | * till timeout) if completed. | ||
170 | */ | ||
171 | unsigned long __sched | ||
172 | wait_for_completion_io_timeout(struct completion *x, unsigned long timeout) | ||
173 | { | ||
174 | return wait_for_common_io(x, timeout, TASK_UNINTERRUPTIBLE); | ||
175 | } | ||
176 | EXPORT_SYMBOL(wait_for_completion_io_timeout); | ||
177 | |||
178 | /** | ||
179 | * wait_for_completion_interruptible: - waits for completion of a task (w/intr) | ||
180 | * @x: holds the state of this particular completion | ||
181 | * | ||
182 | * This waits for completion of a specific task to be signaled. It is | ||
183 | * interruptible. | ||
184 | * | ||
185 | * Return: -ERESTARTSYS if interrupted, 0 if completed. | ||
186 | */ | ||
187 | int __sched wait_for_completion_interruptible(struct completion *x) | ||
188 | { | ||
189 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); | ||
190 | if (t == -ERESTARTSYS) | ||
191 | return t; | ||
192 | return 0; | ||
193 | } | ||
194 | EXPORT_SYMBOL(wait_for_completion_interruptible); | ||
195 | |||
196 | /** | ||
197 | * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr)) | ||
198 | * @x: holds the state of this particular completion | ||
199 | * @timeout: timeout value in jiffies | ||
200 | * | ||
201 | * This waits for either a completion of a specific task to be signaled or for a | ||
202 | * specified timeout to expire. It is interruptible. The timeout is in jiffies. | ||
203 | * | ||
204 | * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1, | ||
205 | * or number of jiffies left till timeout) if completed. | ||
206 | */ | ||
207 | long __sched | ||
208 | wait_for_completion_interruptible_timeout(struct completion *x, | ||
209 | unsigned long timeout) | ||
210 | { | ||
211 | return wait_for_common(x, timeout, TASK_INTERRUPTIBLE); | ||
212 | } | ||
213 | EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); | ||
214 | |||
215 | /** | ||
216 | * wait_for_completion_killable: - waits for completion of a task (killable) | ||
217 | * @x: holds the state of this particular completion | ||
218 | * | ||
219 | * This waits to be signaled for completion of a specific task. It can be | ||
220 | * interrupted by a kill signal. | ||
221 | * | ||
222 | * Return: -ERESTARTSYS if interrupted, 0 if completed. | ||
223 | */ | ||
224 | int __sched wait_for_completion_killable(struct completion *x) | ||
225 | { | ||
226 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); | ||
227 | if (t == -ERESTARTSYS) | ||
228 | return t; | ||
229 | return 0; | ||
230 | } | ||
231 | EXPORT_SYMBOL(wait_for_completion_killable); | ||
232 | |||
233 | /** | ||
234 | * wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable)) | ||
235 | * @x: holds the state of this particular completion | ||
236 | * @timeout: timeout value in jiffies | ||
237 | * | ||
238 | * This waits for either a completion of a specific task to be | ||
239 | * signaled or for a specified timeout to expire. It can be | ||
240 | * interrupted by a kill signal. The timeout is in jiffies. | ||
241 | * | ||
242 | * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1, | ||
243 | * or number of jiffies left till timeout) if completed. | ||
244 | */ | ||
245 | long __sched | ||
246 | wait_for_completion_killable_timeout(struct completion *x, | ||
247 | unsigned long timeout) | ||
248 | { | ||
249 | return wait_for_common(x, timeout, TASK_KILLABLE); | ||
250 | } | ||
251 | EXPORT_SYMBOL(wait_for_completion_killable_timeout); | ||
252 | |||
253 | /** | ||
254 | * try_wait_for_completion - try to decrement a completion without blocking | ||
255 | * @x: completion structure | ||
256 | * | ||
257 | * Return: 0 if a decrement cannot be done without blocking | ||
258 | * 1 if a decrement succeeded. | ||
259 | * | ||
260 | * If a completion is being used as a counting completion, | ||
261 | * attempt to decrement the counter without blocking. This | ||
262 | * enables us to avoid waiting if the resource the completion | ||
263 | * is protecting is not available. | ||
264 | */ | ||
265 | bool try_wait_for_completion(struct completion *x) | ||
266 | { | ||
267 | unsigned long flags; | ||
268 | int ret = 1; | ||
269 | |||
270 | spin_lock_irqsave(&x->wait.lock, flags); | ||
271 | if (!x->done) | ||
272 | ret = 0; | ||
273 | else | ||
274 | x->done--; | ||
275 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
276 | return ret; | ||
277 | } | ||
278 | EXPORT_SYMBOL(try_wait_for_completion); | ||
279 | |||
280 | /** | ||
281 | * completion_done - Test to see if a completion has any waiters | ||
282 | * @x: completion structure | ||
283 | * | ||
284 | * Return: 0 if there are waiters (wait_for_completion() in progress) | ||
285 | * 1 if there are no waiters. | ||
286 | * | ||
287 | */ | ||
288 | bool completion_done(struct completion *x) | ||
289 | { | ||
290 | unsigned long flags; | ||
291 | int ret = 1; | ||
292 | |||
293 | spin_lock_irqsave(&x->wait.lock, flags); | ||
294 | if (!x->done) | ||
295 | ret = 0; | ||
296 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
297 | return ret; | ||
298 | } | ||
299 | EXPORT_SYMBOL(completion_done); | ||
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 91b28454c218..aa066f306be2 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -2688,290 +2688,6 @@ int default_wake_function(wait_queue_t *curr, unsigned mode, int wake_flags, | |||
2688 | } | 2688 | } |
2689 | EXPORT_SYMBOL(default_wake_function); | 2689 | EXPORT_SYMBOL(default_wake_function); |
2690 | 2690 | ||
2691 | /** | ||
2692 | * complete: - signals a single thread waiting on this completion | ||
2693 | * @x: holds the state of this particular completion | ||
2694 | * | ||
2695 | * This will wake up a single thread waiting on this completion. Threads will be | ||
2696 | * awakened in the same order in which they were queued. | ||
2697 | * | ||
2698 | * See also complete_all(), wait_for_completion() and related routines. | ||
2699 | * | ||
2700 | * It may be assumed that this function implies a write memory barrier before | ||
2701 | * changing the task state if and only if any tasks are woken up. | ||
2702 | */ | ||
2703 | void complete(struct completion *x) | ||
2704 | { | ||
2705 | unsigned long flags; | ||
2706 | |||
2707 | spin_lock_irqsave(&x->wait.lock, flags); | ||
2708 | x->done++; | ||
2709 | __wake_up_locked(&x->wait, TASK_NORMAL, 1); | ||
2710 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
2711 | } | ||
2712 | EXPORT_SYMBOL(complete); | ||
2713 | |||
2714 | /** | ||
2715 | * complete_all: - signals all threads waiting on this completion | ||
2716 | * @x: holds the state of this particular completion | ||
2717 | * | ||
2718 | * This will wake up all threads waiting on this particular completion event. | ||
2719 | * | ||
2720 | * It may be assumed that this function implies a write memory barrier before | ||
2721 | * changing the task state if and only if any tasks are woken up. | ||
2722 | */ | ||
2723 | void complete_all(struct completion *x) | ||
2724 | { | ||
2725 | unsigned long flags; | ||
2726 | |||
2727 | spin_lock_irqsave(&x->wait.lock, flags); | ||
2728 | x->done += UINT_MAX/2; | ||
2729 | __wake_up_locked(&x->wait, TASK_NORMAL, 0); | ||
2730 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
2731 | } | ||
2732 | EXPORT_SYMBOL(complete_all); | ||
2733 | |||
2734 | static inline long __sched | ||
2735 | do_wait_for_common(struct completion *x, | ||
2736 | long (*action)(long), long timeout, int state) | ||
2737 | { | ||
2738 | if (!x->done) { | ||
2739 | DECLARE_WAITQUEUE(wait, current); | ||
2740 | |||
2741 | __add_wait_queue_tail_exclusive(&x->wait, &wait); | ||
2742 | do { | ||
2743 | if (signal_pending_state(state, current)) { | ||
2744 | timeout = -ERESTARTSYS; | ||
2745 | break; | ||
2746 | } | ||
2747 | __set_current_state(state); | ||
2748 | spin_unlock_irq(&x->wait.lock); | ||
2749 | timeout = action(timeout); | ||
2750 | spin_lock_irq(&x->wait.lock); | ||
2751 | } while (!x->done && timeout); | ||
2752 | __remove_wait_queue(&x->wait, &wait); | ||
2753 | if (!x->done) | ||
2754 | return timeout; | ||
2755 | } | ||
2756 | x->done--; | ||
2757 | return timeout ?: 1; | ||
2758 | } | ||
2759 | |||
2760 | static inline long __sched | ||
2761 | __wait_for_common(struct completion *x, | ||
2762 | long (*action)(long), long timeout, int state) | ||
2763 | { | ||
2764 | might_sleep(); | ||
2765 | |||
2766 | spin_lock_irq(&x->wait.lock); | ||
2767 | timeout = do_wait_for_common(x, action, timeout, state); | ||
2768 | spin_unlock_irq(&x->wait.lock); | ||
2769 | return timeout; | ||
2770 | } | ||
2771 | |||
2772 | static long __sched | ||
2773 | wait_for_common(struct completion *x, long timeout, int state) | ||
2774 | { | ||
2775 | return __wait_for_common(x, schedule_timeout, timeout, state); | ||
2776 | } | ||
2777 | |||
2778 | static long __sched | ||
2779 | wait_for_common_io(struct completion *x, long timeout, int state) | ||
2780 | { | ||
2781 | return __wait_for_common(x, io_schedule_timeout, timeout, state); | ||
2782 | } | ||
2783 | |||
2784 | /** | ||
2785 | * wait_for_completion: - waits for completion of a task | ||
2786 | * @x: holds the state of this particular completion | ||
2787 | * | ||
2788 | * This waits to be signaled for completion of a specific task. It is NOT | ||
2789 | * interruptible and there is no timeout. | ||
2790 | * | ||
2791 | * See also similar routines (i.e. wait_for_completion_timeout()) with timeout | ||
2792 | * and interrupt capability. Also see complete(). | ||
2793 | */ | ||
2794 | void __sched wait_for_completion(struct completion *x) | ||
2795 | { | ||
2796 | wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); | ||
2797 | } | ||
2798 | EXPORT_SYMBOL(wait_for_completion); | ||
2799 | |||
2800 | /** | ||
2801 | * wait_for_completion_timeout: - waits for completion of a task (w/timeout) | ||
2802 | * @x: holds the state of this particular completion | ||
2803 | * @timeout: timeout value in jiffies | ||
2804 | * | ||
2805 | * This waits for either a completion of a specific task to be signaled or for a | ||
2806 | * specified timeout to expire. The timeout is in jiffies. It is not | ||
2807 | * interruptible. | ||
2808 | * | ||
2809 | * Return: 0 if timed out, and positive (at least 1, or number of jiffies left | ||
2810 | * till timeout) if completed. | ||
2811 | */ | ||
2812 | unsigned long __sched | ||
2813 | wait_for_completion_timeout(struct completion *x, unsigned long timeout) | ||
2814 | { | ||
2815 | return wait_for_common(x, timeout, TASK_UNINTERRUPTIBLE); | ||
2816 | } | ||
2817 | EXPORT_SYMBOL(wait_for_completion_timeout); | ||
2818 | |||
2819 | /** | ||
2820 | * wait_for_completion_io: - waits for completion of a task | ||
2821 | * @x: holds the state of this particular completion | ||
2822 | * | ||
2823 | * This waits to be signaled for completion of a specific task. It is NOT | ||
2824 | * interruptible and there is no timeout. The caller is accounted as waiting | ||
2825 | * for IO. | ||
2826 | */ | ||
2827 | void __sched wait_for_completion_io(struct completion *x) | ||
2828 | { | ||
2829 | wait_for_common_io(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); | ||
2830 | } | ||
2831 | EXPORT_SYMBOL(wait_for_completion_io); | ||
2832 | |||
2833 | /** | ||
2834 | * wait_for_completion_io_timeout: - waits for completion of a task (w/timeout) | ||
2835 | * @x: holds the state of this particular completion | ||
2836 | * @timeout: timeout value in jiffies | ||
2837 | * | ||
2838 | * This waits for either a completion of a specific task to be signaled or for a | ||
2839 | * specified timeout to expire. The timeout is in jiffies. It is not | ||
2840 | * interruptible. The caller is accounted as waiting for IO. | ||
2841 | * | ||
2842 | * Return: 0 if timed out, and positive (at least 1, or number of jiffies left | ||
2843 | * till timeout) if completed. | ||
2844 | */ | ||
2845 | unsigned long __sched | ||
2846 | wait_for_completion_io_timeout(struct completion *x, unsigned long timeout) | ||
2847 | { | ||
2848 | return wait_for_common_io(x, timeout, TASK_UNINTERRUPTIBLE); | ||
2849 | } | ||
2850 | EXPORT_SYMBOL(wait_for_completion_io_timeout); | ||
2851 | |||
2852 | /** | ||
2853 | * wait_for_completion_interruptible: - waits for completion of a task (w/intr) | ||
2854 | * @x: holds the state of this particular completion | ||
2855 | * | ||
2856 | * This waits for completion of a specific task to be signaled. It is | ||
2857 | * interruptible. | ||
2858 | * | ||
2859 | * Return: -ERESTARTSYS if interrupted, 0 if completed. | ||
2860 | */ | ||
2861 | int __sched wait_for_completion_interruptible(struct completion *x) | ||
2862 | { | ||
2863 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); | ||
2864 | if (t == -ERESTARTSYS) | ||
2865 | return t; | ||
2866 | return 0; | ||
2867 | } | ||
2868 | EXPORT_SYMBOL(wait_for_completion_interruptible); | ||
2869 | |||
2870 | /** | ||
2871 | * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr)) | ||
2872 | * @x: holds the state of this particular completion | ||
2873 | * @timeout: timeout value in jiffies | ||
2874 | * | ||
2875 | * This waits for either a completion of a specific task to be signaled or for a | ||
2876 | * specified timeout to expire. It is interruptible. The timeout is in jiffies. | ||
2877 | * | ||
2878 | * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1, | ||
2879 | * or number of jiffies left till timeout) if completed. | ||
2880 | */ | ||
2881 | long __sched | ||
2882 | wait_for_completion_interruptible_timeout(struct completion *x, | ||
2883 | unsigned long timeout) | ||
2884 | { | ||
2885 | return wait_for_common(x, timeout, TASK_INTERRUPTIBLE); | ||
2886 | } | ||
2887 | EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); | ||
2888 | |||
2889 | /** | ||
2890 | * wait_for_completion_killable: - waits for completion of a task (killable) | ||
2891 | * @x: holds the state of this particular completion | ||
2892 | * | ||
2893 | * This waits to be signaled for completion of a specific task. It can be | ||
2894 | * interrupted by a kill signal. | ||
2895 | * | ||
2896 | * Return: -ERESTARTSYS if interrupted, 0 if completed. | ||
2897 | */ | ||
2898 | int __sched wait_for_completion_killable(struct completion *x) | ||
2899 | { | ||
2900 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); | ||
2901 | if (t == -ERESTARTSYS) | ||
2902 | return t; | ||
2903 | return 0; | ||
2904 | } | ||
2905 | EXPORT_SYMBOL(wait_for_completion_killable); | ||
2906 | |||
2907 | /** | ||
2908 | * wait_for_completion_killable_timeout: - waits for completion of a task (w/(to,killable)) | ||
2909 | * @x: holds the state of this particular completion | ||
2910 | * @timeout: timeout value in jiffies | ||
2911 | * | ||
2912 | * This waits for either a completion of a specific task to be | ||
2913 | * signaled or for a specified timeout to expire. It can be | ||
2914 | * interrupted by a kill signal. The timeout is in jiffies. | ||
2915 | * | ||
2916 | * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1, | ||
2917 | * or number of jiffies left till timeout) if completed. | ||
2918 | */ | ||
2919 | long __sched | ||
2920 | wait_for_completion_killable_timeout(struct completion *x, | ||
2921 | unsigned long timeout) | ||
2922 | { | ||
2923 | return wait_for_common(x, timeout, TASK_KILLABLE); | ||
2924 | } | ||
2925 | EXPORT_SYMBOL(wait_for_completion_killable_timeout); | ||
2926 | |||
2927 | /** | ||
2928 | * try_wait_for_completion - try to decrement a completion without blocking | ||
2929 | * @x: completion structure | ||
2930 | * | ||
2931 | * Return: 0 if a decrement cannot be done without blocking | ||
2932 | * 1 if a decrement succeeded. | ||
2933 | * | ||
2934 | * If a completion is being used as a counting completion, | ||
2935 | * attempt to decrement the counter without blocking. This | ||
2936 | * enables us to avoid waiting if the resource the completion | ||
2937 | * is protecting is not available. | ||
2938 | */ | ||
2939 | bool try_wait_for_completion(struct completion *x) | ||
2940 | { | ||
2941 | unsigned long flags; | ||
2942 | int ret = 1; | ||
2943 | |||
2944 | spin_lock_irqsave(&x->wait.lock, flags); | ||
2945 | if (!x->done) | ||
2946 | ret = 0; | ||
2947 | else | ||
2948 | x->done--; | ||
2949 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
2950 | return ret; | ||
2951 | } | ||
2952 | EXPORT_SYMBOL(try_wait_for_completion); | ||
2953 | |||
2954 | /** | ||
2955 | * completion_done - Test to see if a completion has any waiters | ||
2956 | * @x: completion structure | ||
2957 | * | ||
2958 | * Return: 0 if there are waiters (wait_for_completion() in progress) | ||
2959 | * 1 if there are no waiters. | ||
2960 | * | ||
2961 | */ | ||
2962 | bool completion_done(struct completion *x) | ||
2963 | { | ||
2964 | unsigned long flags; | ||
2965 | int ret = 1; | ||
2966 | |||
2967 | spin_lock_irqsave(&x->wait.lock, flags); | ||
2968 | if (!x->done) | ||
2969 | ret = 0; | ||
2970 | spin_unlock_irqrestore(&x->wait.lock, flags); | ||
2971 | return ret; | ||
2972 | } | ||
2973 | EXPORT_SYMBOL(completion_done); | ||
2974 | |||
2975 | static long __sched | 2691 | static long __sched |
2976 | sleep_on_common(wait_queue_head_t *q, int state, long timeout) | 2692 | sleep_on_common(wait_queue_head_t *q, int state, long timeout) |
2977 | { | 2693 | { |