xref: /freebsd/share/man/man9/sleepqueue.9 (revision 1b6c76a2fe091c74f08427e6c870851025a9cf67)
1.\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
14.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
17.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23.\"
24.\" $FreeBSD$
25.\"
26.Dd November 3, 2000
27.Dt SLEEPQUEUE 9
28.Os
29.Sh NAME
30.Nm endtsleep ,
31.Nm sleepinit ,
32.Nm unsleep
33.Nd manage the queues of sleeping processes
34.Sh SYNOPSIS
35.Fd #include <sys/param.h>
36.Fd #include <sys/proc.h>
37.Ft void
38.Fn endtsleep "void *arg"
39.Ft void
40.Fn sleepinit "void"
41.Ft void
42.Fn unsleep "struct proc *p"
43.Sh DESCRIPTION
44The sleep queues used by
45.Xr msleep 9
46and friends are stored in a hash array.
47The address of the wait channel is used to generate an index into the array.
48Each entry in the array is a queue of processes that are sleeping on wait
49channels that hash to that index.
50.Xr msleep 9
51places processes into their appropriate queues directly.
52To handle timeouts, the
53.Fn endtsleep
54function is registered as a
55.Xr timeout 9 .
56When the process is woken by either
57.Fn wakeup
58or
59.Fn wakeup_one ,
60the timeout is revoked via
61.Xr untimeout 9 .
62If the process is not awakened soon enough, then
63.Fn endtsleep
64is called with
65.Fa arg
66pointing to the
67.Vt "struct proc"
68of the process that timed out.
69.Fn endtsleep
70undoes the sleep and makes the process runnable if it is in the
71.Dv SSLEEP
72state.
73The sleep queues and the hash array are protected internally by the
74.Va sched_lock
75mutex.
76.Pp
77.Fn unsleep
78simply removes the process
79.Fa p
80from its sleep queue.
81.Pp
82.Fn sleepinit
83is called during system startup and initializes the scheduler quantum
84.Pq Va sched_quantum
85and the sleep queues.
86.Sh SEE ALSO
87.Xr msleep 9 ,
88.Xr runqueue 9 ,
89.Xr scheduler 9
90