Normally context switches happen in mi_switch() but there are 3 cases
authorclaudio <claudio@openbsd.org>
Tue, 24 Oct 2023 13:20:09 +0000 (13:20 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 24 Oct 2023 13:20:09 +0000 (13:20 +0000)
commitbb00e81153b2ff3fcf42c8955e50b70f573a8323
tree2a093c5c54e3a824b918db36126050b81b812783
parent5892e0f17a8473a472abbf5044b174c6c7d3a82b
Normally context switches happen in mi_switch() but there are 3 cases
where a switch happens outside. Cleanup these code paths and make the
machine independent.

- when a process forks (fork, tfork, kthread), the new proc needs to
  somehow be scheduled for the first time. This is done by proc_trampoline.
  Since proc_trampoline is machine dependent assembler code change
  the MP specific proc_trampoline_mp() to proc_trampoline_mi() and make
  sure it is now always called.
- cpu_hatch: when booting APs the code needs to jump to the first proc
  running on that CPU. This should be the idle thread for that CPU.
- sched_exit: when a proc exits it needs to switch away from itself and
  then instruct the reaper to clean up the rest. This is done by switching
  to the idle loop.

Since the last two cases require a context switch to the idle proc factor
out the common code to sched_toidle() and use it in those places.

Tested by many on all archs.
OK miod@ mpi@ cheloha@
33 files changed:
sys/arch/alpha/alpha/cpu.c
sys/arch/alpha/alpha/locore.s
sys/arch/alpha/alpha/vm_machdep.c
sys/arch/amd64/amd64/cpu.c
sys/arch/amd64/amd64/locore.S
sys/arch/arm/arm/cpu.c
sys/arch/arm/arm/cpuswitch7.S
sys/arch/arm64/arm64/cpu.c
sys/arch/arm64/arm64/cpuswitch.S
sys/arch/hppa/dev/cpu.c
sys/arch/hppa/hppa/locore.S
sys/arch/i386/i386/cpu.c
sys/arch/i386/i386/locore.s
sys/arch/loongson/loongson/machdep.c
sys/arch/luna88k/luna88k/machdep.c
sys/arch/m88k/m88k/eh_common.S
sys/arch/macppc/macppc/cpu.c
sys/arch/macppc/macppc/locore.S
sys/arch/macppc/macppc/machdep.c
sys/arch/mips64/mips64/clock.c
sys/arch/mips64/mips64/context.S
sys/arch/octeon/octeon/machdep.c
sys/arch/powerpc64/powerpc64/cpu.c
sys/arch/powerpc64/powerpc64/locore.S
sys/arch/riscv64/riscv64/cpu.c
sys/arch/riscv64/riscv64/cpuswitch.S
sys/arch/sh/sh/locore_subr.S
sys/arch/sh/sh/vm_machdep.c
sys/arch/sparc64/sparc64/cpu.c
sys/arch/sparc64/sparc64/locore.s
sys/kern/kern_fork.c
sys/kern/kern_sched.c
sys/sys/sched.h