1 .\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org>
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\" notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\" notice, this list of conditions and the following disclaimer in the
10 .\" documentation and/or other materials provided with the distribution.
12 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
13 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
16 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 .Nd manage the queue of runnable processes
37 .Vt "extern struct rq itqueues[]" ;
38 .Vt "extern struct rq rtqueues[]" ;
39 .Vt "extern struct rq queues[]" ;
40 .Vt "extern struct rq idqueues[]" ;
42 .Fn choosethread "void"
44 .Fn procrunnable "void"
46 .Fn remrunqueue "struct thread *td"
48 .Fn setrunqueue "struct thread *td"
50 The run queue consists of four priority queues:
52 for interrupt threads,
54 for realtime priority processes,
56 for time sharing processes, and
58 for idle priority processes.
59 Each priority queue consists of an array of
61 queue header structures.
62 Each queue header identifies a list of runnable processes of equal priority.
63 Each queue also has a single word that contains a bit mask identifying
64 non-empty queues to assist in selecting a process quickly.
71 The run queues are protected by the
76 returns zero if there are no runnable processes other than the idle process.
77 If there is at least one runnable process other than the idle process, it
78 will return a non-zero value.
83 need to be held when this function is called.
84 There is a small race window where one CPU may place a process on the run queue
85 when there are currently no other runnable processes while another CPU is
86 calling this function.
87 In that case the second CPU will simply travel through the idle loop one
88 additional time before noticing that there is a runnable process.
89 This works because idle CPUs are not halted in SMP systems.
90 If idle CPUs are halted in SMP systems, then this race condition might have
91 more serious repercussions in the losing case, and
93 may have to require that the
98 returns the highest priority runnable thread.
99 If there are no runnable threads, then the idle thread is returned.
100 This function is called by
104 to determine which thread to switch to.
106 must be called with the
113 to the tail of the appropriate queue in the proper priority queue.
114 The thread must be runnable, i.e.\&
118 This function must be called with the
128 is not on a run queue, then the kernel will
130 This function must be called with the