Add the -f option to the rpc.umntall call to reduce boot-time stalls when
[dragonfly.git] / share / man / man9 / sleep.9
1 .\"
2 .\" Copyright (c) 1996 Joerg Wunsch
3 .\"
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD: src/share/man/man9/sleep.9,v 1.18.2.5 2001/12/17 11:30:19 ru Exp $
27 .\" $DragonFly: src/share/man/man9/sleep.9,v 1.2 2003/06/17 04:37:01 dillon Exp $
28 .\" "
29 .Dd December 17, 1998
30 .Os
31 .Dt SLEEP 9
32 .Sh NAME
33 .Nm sleep ,
34 .Nm tsleep ,
35 .Nm asleep ,
36 .Nm await ,
37 .Nm wakeup
38 .Nd wait for events
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/systm.h
42 .In sys/proc.h
43 .Ft int
44 .Fn tsleep "void *ident" "int priority" "const char *wmesg" "int timo"
45 .Ft int
46 .Fn asleep "void *ident" "int priority" "const char *wmesg" "int timo"
47 .Ft int
48 .Fn await "int priority" "int timo"
49 .Ft void
50 .Fn wakeup "void *ident"
51 .Ft void
52 .Fn wakeup_one "void *ident"
53 .Sh DESCRIPTION
54 The functions
55 .Fn tsleep
56 and
57 .Fn wakeup
58 handle event-based process blocking.  If a process must wait for an
59 external event, it is put on sleep by
60 .Nm tsleep .
61 The parameter
62 .Ar ident
63 is an arbitrary address that uniquely identifies the event on which
64 the process is being asleep.  All processes sleeping on a single
65 .Ar ident
66 are woken up later by
67 .Nm wakeup ,
68 often called from inside an interrupt routine, to indicate that the
69 resource the process was blocking on is available now.
70 .Pp
71 The parameter
72 .Ar wmesg
73 is a string describing the sleep condition for tools like
74 .Xr ps 1 .
75 Due to the limited space of those programs to display arbitrary strings,
76 this message should not be longer than 6 characters.
77 .Pp
78 The
79 .Fn wakeup_one
80 function is used to make the first process in the queue that is
81 sleeping on the parameter
82 .Fa ident
83 runnable.  This can prevent the system from becoming saturated
84 when a large number of processes are sleeping on the same address,
85 but only one of them can actually do any useful work when made
86 runnable.
87 .Pp
88 .Nm Tsleep
89 is the general sleep call.  Suspends the current process until a wakeup is
90 performed on the specified identifier.  The process will then be made
91 runnable with the specified
92 .Ar priority .
93 Sleeps at most
94 .Ar timo
95 \&/ hz seconds (0 means no timeout).  If
96 .Ar pri
97 includes the
98 .Dv PCATCH
99 flag, signals are checked before and after sleeping, else signals are
100 not checked.  Returns 0 if awakened,
101 .Er EWOULDBLOCK
102 if the timeout expires.  If
103 .Dv PCATCH
104 is set and a signal needs to be delivered,
105 .Er ERESTART
106 is returned if the current system call should be restarted if
107 possible, and
108 .Er EINTR
109 is returned if the system call should be interrupted by the signal
110 (return
111 .Er EINTR ) .
112 .Pp
113 .Nm Asleep
114 implements the new asynchronous sleep function.  It takes the same arguments
115 as
116 .Fn tsleep
117 and places the process on the appropriate wait queue, but
118 .Fn asleep
119 leaves the process runnable and returns immediately.  The caller is then
120 expected to, at some point in the future, call
121 .Fn await
122 to actually wait for the previously queued wait condition.
123 If
124 .Fn asleep
125 is called several times, only the most recent call is effective.
126 .Fn asleep
127 may be called with an
128 .Ar ident
129 value of NULL
130 to remove any previously queued condition.
131 .Pp
132 .Nm Await
133 implements the new asynchronous wait function.  When
134 .Fn asleep
135 is called on an identifier it associates the process with that
136 identifier but does not block.
137 .Fn await
138 will actually block the process until
139 .Fn wakeup
140 is called on that identifier any time after the
141 .Fn asleep .
142 If
143 .Fn wakeup
144 is called after you
145 .Fn asleep
146 but before you
147 .Fn await
148 then the
149 .Fn await
150 call is effectively a NOP.
151 If
152 .Fn await
153 is called multiple times without an intervening
154 .Fn asleep ,
155 the
156 .Fn await
157 is effectively a NOP but will also call
158 .Fn mswitch
159 for safety.  The
160 .Fn await
161 function allows you to override the priority and timeout values to be used.
162 If the value -1 is specified for an argument, the value is taken from the
163 previous
164 .Fn asleep
165 call.  If -1 is passed for the priority you must be prepared to catch signal
166 conditions if the prior call to
167 .Fn asleep
168 specified it in its priority.  If -1 is passed for the timeout you must be
169 prepared to catch a timeout condition if the prior call to
170 .Fn asleep
171 specified a timeout.  When you use -1, it is usually a good idea to not make
172 assumptions as to the arguments used by the prior
173 .Fn asleep
174 call.
175 .Pp
176 The
177 .Fn asleep
178 and
179 .Fn await
180 functions are mainly used by the kernel to shift the burden of blocking
181 away from extremely low level routines and to push it onto their callers.
182 This in turn allows more complex interlocking code to
183 .Em backout
184 of a temporary resource failure
185 (such as lack of memory) in order to release major locks prior to actually
186 blocking, and to then retry the operation on wakeup.  This key feature is
187 expected to be heavily used in SMP situations in order to allow code to make
188 better use of spinlocks.  A spinlock, by its very nature, cannot be used
189 around code that might block.  It is hoped that these capabilities will
190 make it easier to migrate the SMP master locks deeper into the kernel.
191 .Pp
192 These routines may also be used to avoid nasty spl*() calls to get around
193 race conditions with simple conditional test/wait interlocks.  You simply
194 call
195 .Fn asleep
196 prior to your test, then conditionally
197 .Fn await
198 only if the test fails.  It is usually a good idea to cancel an
199 .Fn asleep
200 if you wind up never calling the related
201 .Fn await ,
202 but it is not required.  If you do not want to waste cpu calling
203 .Fn asleep
204 unnecessarily, you can surround the whole thing with a second test.  The
205 race condition is still handled by the inside
206 .Fn asleep
207 call.
208 .Sh RETURN VALUES
209 See above.
210 .Sh SEE ALSO
211 .Xr ps 1 ,
212 .Xr malloc 9
213 .Sh HISTORY
214 The sleep/wakeup process synchronization mechanism is very old.  It
215 appeared in a very early version of Unix.
216 .Pp
217 .Nm Tsleep
218 appeared in
219 .Bx 4.4 .
220 .Pp
221 .Nm Asleep Ns / Ns Nm await
222 first appeared in
223 .Fx 3.0
224 and is designed to shift the burden of blocking
225 away from extremely low level routines and push it up to their callers.
226 .Pp
227 .Nm Sleep
228 used to be the traditional form.  It doesn't let you specify a timeout or a
229 .Ar wmesg ,
230 hence it has been discontinued.
231 .Sh AUTHORS
232 .An -nosplit
233 This man page was written by
234 .An J\(:org Wunsch .
235 .Nm Asleep
236 and
237 .Nm await
238 were designed and written by
239 .An Matthew Dillon .