1 .\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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.
34 .Nd manage the queue of runnable processes
38 .Vt "extern struct rq itqueues[]" ;
39 .Vt "extern struct rq rtqueues[]" ;
40 .Vt "extern struct rq queues[]" ;
41 .Vt "extern struct rq idqueues[]" ;
43 .Fn choosethread "void"
45 .Fn procrunnable "void"
47 .Fn remrunqueue "struct thread *td"
49 .Fn setrunqueue "struct thread *td"
51 The run queue consists of four priority queues:
53 for interrupt threads,
55 for realtime priority processes,
57 for time sharing processes, and
59 for idle priority processes.
60 Each priority queue consists of an array of
62 queue header structures.
63 Each queue header identifies a list of runnable processes of equal priority.
64 Each queue also has a single word that contains a bit mask identifying
65 non-empty queues to assist in selecting a process quickly.
72 The run queues are protected by the
77 returns zero if there are no runnable processes other than the idle process.
78 If there is at least one runnable process other than the idle process, it
79 will return a non-zero value.
84 need to be held when this function is called.
85 There is a small race window where one CPU may place a process on the run queue
86 when there are currently no other runnable processes while another CPU is
87 calling this function.
88 In that case the second CPU will simply travel through the idle loop one
89 additional time before noticing that there is a runnable process.
90 This works because idle CPUs are not halted in SMP systems.
91 If idle CPUs are halted in SMP systems, then this race condition might have
92 more serious repercussions in the losing case, and
94 may have to require that the
99 returns the highest priority runnable thread.
100 If there are no runnable threads, then the idle thread is returned.
101 This function is called by
105 to determine which thread to switch to.
107 must be called with the
114 to the tail of the appropriate queue in the proper priority queue.
115 The thread must be runnable, i.e.\&
119 This function must be called with the
129 is not on a run queue, then the kernel will
131 This function must be called with the