|
31 | 31 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32 | 32 | .\" POSSIBILITY OF SUCH DAMAGE.
|
33 | 33 | .\"
|
34 |
| -.Dd January 9, 2023 |
| 34 | +.Dd January 7, 2025 |
35 | 35 | .Dt MI_SWITCH 9
|
36 | 36 | .Os
|
37 | 37 | .Sh NAME
|
38 |
| -.Nm mi_switch , |
39 |
| -.Nm cpu_switch , |
40 |
| -.Nm cpu_throw |
| 38 | +.Nm mi_switch |
41 | 39 | .Nd switch to another thread context
|
42 | 40 | .Sh SYNOPSIS
|
43 | 41 | .In sys/param.h
|
44 | 42 | .In sys/proc.h
|
45 | 43 | .Ft void
|
46 | 44 | .Fn mi_switch "int flags"
|
47 |
| -.Ft void |
48 |
| -.Fn cpu_switch "struct thread *oldtd" "struct thread *newtd" "struct mtx *lock" |
49 |
| -.Ft void |
50 |
| -.Fn cpu_throw "struct thread *oldtd" "struct thread *newtd" |
51 | 45 | .Sh DESCRIPTION
|
52 | 46 | The
|
53 | 47 | .Fn mi_switch
|
@@ -168,63 +162,9 @@ running thread
|
168 | 162 | .Fa oldtd
|
169 | 163 | to the chosen thread
|
170 | 164 | .Fa newtd .
|
171 |
| -First, it saves the context of |
172 |
| -.Fa oldtd |
173 |
| -to its Process Control Block |
174 |
| -.Po |
175 |
| -PCB, |
176 |
| -.Vt struct pcb |
177 |
| -.Pc , |
178 |
| -pointed at by |
179 |
| -.Va oldtd->td_pcb . |
180 |
| -The function then updates important per-CPU state such as the |
181 |
| -.Dv curthread |
182 |
| -variable, and activates |
183 |
| -.Fa newtd\&'s |
184 |
| -virtual address space using its associated |
185 |
| -.Xr pmap 9 |
186 |
| -structure. |
187 |
| -Finally, it reads in the saved context from |
188 |
| -.Fa newtd\&'s |
189 |
| -PCB. |
190 |
| -CPU instruction flow continues in the new thread context, on |
191 |
| -.Fa newtd\&'s |
192 |
| -kernel stack. |
193 |
| -The return from |
194 |
| -.Fn cpu_switch |
195 |
| -can be understood as a completion of the function call initiated by |
196 |
| -.Fa newtd |
197 |
| -when it was previously switched out, at some point in the distant (relative to |
198 |
| -CPU time) past. |
199 |
| -.Pp |
200 |
| -The |
201 |
| -.Fa mtx |
202 |
| -argument to |
203 |
| -.Fn cpu_switch |
204 |
| -is used to pass the mutex which will be stored as |
205 |
| -.Fa oldtd\&'s |
206 |
| -thread lock at the moment that |
207 |
| -.Fa oldtd |
208 |
| -is completely switched out. |
209 |
| -This is an implementation detail of |
210 |
| -.Fn sched_switch . |
211 |
| -.Pp |
212 |
| -.Fn cpu_throw |
213 |
| -is similar to |
214 |
| -.Fn cpu_switch |
215 |
| -except that it does not save the context of the old thread. |
216 |
| -This function is useful when the kernel does not have an old thread |
217 |
| -context to save, such as when CPUs other than the boot CPU perform their |
218 |
| -first task switch, or when the kernel does not care about the state of the |
219 |
| -old thread, such as in |
220 |
| -.Xr thread_exit 9 |
221 |
| -when the kernel terminates the current thread and switches into a new |
222 |
| -thread, |
223 |
| -.Fa newtd . |
224 |
| -The |
225 |
| -.Fa oldtd |
226 |
| -argument is unused. |
227 | 165 | .Sh SEE ALSO
|
| 166 | +.Xr cpu_switch 9 , |
| 167 | +.Xr cpu_throw 9 , |
228 | 168 | .Xr critical_exit 9 ,
|
229 | 169 | .Xr issignal 9 ,
|
230 | 170 | .Xr kern_yield 9 ,
|
|
0 commit comments