1 .\" $NetBSD: mi_switch.9,v 1.2 2008/04/30 13:10:58 martin Exp $
3 .\" Copyright (c) 1996, 2002 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Paul Kranenburg.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd machine independent context switch prelude
38 .Fn mi_switch "struct lwp *l"
42 function implements the machine-independent prelude to an LWP context
44 It is called from only a few distinguished places in the kernel
45 code as a result of the principle of non-preemptable kernel mode
47 The three major uses of
49 can be enumerated as follows:
50 .Bl -enum -offset indent
54 and associated methods
55 when the current LWP voluntarily relinquishes the CPU to wait for
56 some resource to become available.
60 when the current LWP voluntarily relinquishes the CPU or when the
61 kernel prepares a return to user-mode execution.
63 In the signal handling code
64 if a signal is delivered that causes an LWP to stop
65 .Pq see Xr issignal 9 .
69 records the amount of time the current LWP has been running in the
70 LWP structure and checks this value against the CPU time limits
72 .Pq see Xr getrlimit 2 .
73 Exceeding the soft limit results in a
75 signal to be posted to the LWP, while exceeding the hard limit will
80 .Fa l-\*[Gt]l_switchto
86 to select a new LWP from the scheduler's runqueue structures.
87 If no runnable LWP is found, the idle LWP is used.
88 If the new LWP is not equal to the current one,
90 will hand over control to the machine-dependent function
92 to switch to the new LWP.
95 has to be called with the LWP lock held
100 interrupt protection level.
101 It returns with the LWP lock released.
104 returns 1 if a context switch was performed to a
105 different LWP, 0 otherwise.