xref: /netbsd-src/share/man/man9/cpu_switchto.9 (revision 203a6ec972e998170d399df0d4eeff549e6480ae)
1.\"	$NetBSD: cpu_switchto.9,v 1.14 2011/06/03 08:06:54 wiz 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 June 2, 2011
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 .
67If the architecture does non-interlocked adaptive mutex release,
68.Fn cpu_switchto
69does an equivalent of
70.Xr membar_producer 3 ,
71before and after the modification of
72.Xr curlwp 9 .
73.It
74.Fn cpu_switchto
75should be called at
76.Dv IPL_SCHED .
77When the function returns, the caller should lower
78the priority level as soon as possible.
79.It
80.Fn cpu_switchto
81might be called with spin mutexes held.
82.El
83.Pp
84The function takes the following arguments.
85.Bl -tag -width "returning " -offset indent
86.It Fa oldlwp
87Specify the
88.Tn LWP
89from which the switch is going to be made, i.e., the calling
90.Tn LWP .
91If it was
92.Dv NULL ,
93the context of the
94.Tn LWP
95currently running on this processor is not saved.
96.It Fa newlwp
97Specify the
98.Tn LWP
99to which to switch.
100It must not be
101.Dv NULL .
102.It Fa returning
103Only meaningful if the architecture implements fast software interrupts.
104If true, it indicates that
105.Fa oldlwp
106is a soft interrupt
107.Tn LWP
108that is blocking.
109It is a good indication that any kind of address space or user activity
110can be completely ignored.
111For example:
112.Xr ras_lookup 9 ,
113cache flushes, TLB wirings, adjusting lazy
114.Tn FPU
115state.
116All that is required is to restore the register state and stack, and
117return to the interrupted
118.Tn LWP .
119.El
120.\" ------------------------------------------------------------
121.Sh RETURN VALUES
122The
123.Fn cpu_switchto
124function does not return until another
125.Tn LWP
126calls
127.Fn cpu_switchto .
128It returns the
129.Vt oldlwp
130argument of the
131.Fn cpu_switchto
132which is called to switch back to our
133.Tn LWP .
134It is either a
135.Tn LWP
136which called
137.Fn cpu_switchto
138to switch to us or
139.Dv NULL
140in case the
141.Tn LWP
142was exiting.
143.\" ------------------------------------------------------------
144.Sh SEE ALSO
145.Xr membar_producer 3 ,
146.Xr swapcontext 3 ,
147.Xr intro 9 ,
148.Xr mutex 9 ,
149.Xr spl 9
150