summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exit.c
diff options
context:
space:
mode:
authorvisa <visa@openbsd.org>2019-11-02 05:31:20 +0000
committervisa <visa@openbsd.org>2019-11-02 05:31:20 +0000
commitdfa1de3e618fc84112edc97684a632dc38416c64 (patch)
tree6adbc7d6d7e6b3ff2876fc3e63b6f09aac9440f2 /sys/kern/kern_exit.c
parentswitch ASN1_STRING_data() with constified ASN1_STRING_get0_data() (diff)
downloadwireguard-openbsd-dfa1de3e618fc84112edc97684a632dc38416c64.tar.xz
wireguard-openbsd-dfa1de3e618fc84112edc97684a632dc38416c64.zip
Move dead procs to the reaper queue immediately after context switch.
This eliminates a forced context switch to the idle proc. In addition, sched_exit() no longer needs to sum proc runtime because mi_switch() will do it. OK mpi@ a while ago
Diffstat (limited to 'sys/kern/kern_exit.c')
-rw-r--r--sys/kern/kern_exit.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index ab2f0de086d..570aa737f2f 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.178 2019/06/21 09:39:48 visa Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.179 2019/11/02 05:31:20 visa Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -367,21 +367,27 @@ struct mutex deadproc_mutex =
struct proclist deadproc = LIST_HEAD_INITIALIZER(deadproc);
/*
- * We are called from cpu_exit() once it is safe to schedule the
- * dead process's resources to be freed.
+ * Move dead procs from the CPU's local list to the reaper list and
+ * wake up the reaper.
*
- * NOTE: One must be careful with locking in this routine. It's
- * called from a critical section in machine-dependent code, so
- * we should refrain from changing any interrupt state.
- *
- * We lock the deadproc list, place the proc on that list (using
- * the p_hash member), and wake up the reaper.
+ * This is called once it is safe to free the resources of dead processes.
*/
void
-exit2(struct proc *p)
+dispatch_deadproc(void)
{
+ struct proc *dead;
+ struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
+
+ if (LIST_EMPTY(&spc->spc_deadproc))
+ return;
+
+ KERNEL_ASSERT_UNLOCKED();
+
mtx_enter(&deadproc_mutex);
- LIST_INSERT_HEAD(&deadproc, p, p_hash);
+ while ((dead = LIST_FIRST(&spc->spc_deadproc)) != NULL) {
+ LIST_REMOVE(dead, p_hash);
+ LIST_INSERT_HEAD(&deadproc, dead, p_hash);
+ }
mtx_leave(&deadproc_mutex);
wakeup(&deadproc);