| Main index | Section 9 | 日本語 | Options |
#include <sys/param.h>
#include <sys/proc.h>
The various major uses of mi_switch() can be enumerated as follows:
The flags argument to mi_switch() indicates the context switch type. One of the following must be passed:
| SWT_OWEPREEMPT | Switch due to delayed preemption after exiting a critical section. |
| SWT_TURNSTILE | Switch after propagating scheduling priority to the owner of a resource. |
| SWT_SLEEPQ | Begin waiting on a sleepqueue(9). |
| SWT_RELINQUISH | Yield call. |
| SWT_NEEDRESCHED | Rescheduling was requested. |
| SWT_IDLE | Switch from the idle thread. |
| SWT_IWAIT | A kernel thread which handles interrupts has finished work and must wait for interrupts to schedule additional work. |
| SWT_SUSPEND | Thread suspended. |
| SWT_REMOTEPREEMPT | Preemption by a higher-priority thread, initiated by a remote processor. |
| SWT_REMOTEWAKEIDLE | Idle thread preempted, initiated by a remote processor. |
| SWT_BIND | The running thread has been bound to another processor and must be switched out. |
In addition to the switch type, callers must specify the nature of the switch by performing a bitwise OR with one of the SW_VOL or SW_INVOL flags, but not both. Respectively, these flags denote whether the context switch is voluntary or involuntary on the part of the current thread. For an involuntary context switch in which the running thread is being preempted, the caller should also pass the SW_PREEMPT flag.
Upon entry to mi_switch(), the current thread must be holding its assigned thread lock. It may be unlocked as part of the context switch. After they have been rescheduled and execution resumes, threads will exit mi_switch() with their thread lock unlocked.
mi_switch() records the amount of time the current thread has been running before handing control over to the scheduler, via sched_switch(). After selecting a new thread to run, the scheduler will call cpu_switch() to perform the low-level context switch.
cpu_switch() is the machine-dependent function that performs the actual switch from the running thread oldtd to the chosen thread newtd.
| MI_SWITCH (9) | January 7, 2025 |
| Main index | Section 9 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems. | ” |
| — Jamie Zawinski | ||