xref: /netbsd-src/share/man/man9/cpu_switchto.9 (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1.\"	$NetBSD: cpu_switchto.9,v 1.11 2010/04/13 06:05:56 jruoho Exp $
2.\"
3.\" Copyright (c)2007 YAMAMOTO Takashi,
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.\" ------------------------------------------------------------
28.Dd April 13, 2010
29.Dt CPU_SWITCHTO 9
30.Os
31.\" ------------------------------------------------------------
32.Sh NAME
33.Nm cpu_switchto
34.Nd machine-dependent
35.Tn LWP
36context switching interface
37.\" ------------------------------------------------------------
38.Sh SYNOPSIS
39.In sys/cpu.h
40.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41.Ft lwp_t *
42.Fn cpu_switchto \
43"lwp_t *oldlwp" "lwp_t *newlwp" "bool returning"
44.\" ------------------------------------------------------------
45.Sh DESCRIPTION
46The
47.Fn cpu_switchto
48function saves the context of the
49.Tn LWP
50which is currently running on the processor,
51and restores the context of the
52.Tn LWP
53specified by
54.Fa newlwp .
55.Pp
56Remarks:
57.Bl -enum -offset indent
58.It
59.Fn cpu_switchto
60does not switch address spaces.
61.It
62.Fn cpu_switchto
63sets
64.Xr curlwp 9
65to
66.Fa newlwp .
67.It
68.Fn cpu_switchto
69should be called at
70.Dv IPL_SCHED .
71When the function returns, the caller should lower
72the priority level as soon as possible.
73.It
74.Fn cpu_switchto
75might be called with spin mutexes held.
76.El
77.Pp
78The function takes the following arguments.
79.Bl -tag -width "returning " -offset indent
80.It Fa oldlwp
81Specify the
82.Tn LWP
83from which the switch is going to be made, i.e., the calling
84.Tn LWP .
85If it was
86.Dv NULL ,
87the context of the
88.Tn LWP
89currently running on this processor is not saved.
90.It Fa newlwp
91Specify the
92.Tn LWP
93to which to switch.
94It must not be
95.Dv NULL .
96.It Fa returning
97Only meaningful if the architecture implements fast software interrupts.
98If true, it indicates that
99.Fa oldlwp
100is a soft interrupt
101.Tn LWP
102that is blocking.
103It is a good indication that any kind of address space or user activity
104can be completely ignored.
105For example:
106.Xr ras_lookup 9 ,
107cache flushes, TLB wirings, adjusting lazy
108.Tn FPU
109state.
110All that is required is to restore the register state and stack, and
111return to the interrupted
112.Tn LWP .
113.El
114.\" ------------------------------------------------------------
115.Sh RETURN VALUES
116The
117.Fn cpu_switchto
118function does not return until another
119.Tn LWP
120calls
121.Fn cpu_switchto .
122It returns the
123.Vt oldlwp
124argument of the
125.Fn cpu_switchto
126which is called to switch back to our
127.Tn LWP .
128It is either a
129.Tn LWP
130which called
131.Fn cpu_switchto
132to switch to us or
133.Dv NULL
134in case the
135.Tn LWP
136was exiting.
137.\" ------------------------------------------------------------
138.Sh SEE ALSO
139.Xr swapcontext 3 ,
140.Xr intro 9 ,
141.Xr mutex 9 ,
142.Xr spl 9
143