summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2019-11-02 05:31:21 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2019-11-02 05:31:21 +0000
commit80422eddff8b985a84712af8752c17a7e2ccfac5 (patch)
tree5a2eb118f48104931aa44c527b3ded5d004974cf
parentad7df6334f1d977c46a54e366d32bc5051871066 (diff)
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
-rw-r--r--sys/kern/kern_exit.c28
-rw-r--r--sys/kern/kern_sched.c23
-rw-r--r--sys/kern/sched_bsd.c3
-rw-r--r--sys/sys/proc.h4
-rw-r--r--sys/sys/syscall_mi.h3
5 files changed, 27 insertions, 34 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);
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index a32dbba110d..94ebd833ab1 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sched.c,v 1.60 2019/11/01 20:58:01 mpi Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.61 2019/11/02 05:31:20 visa Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
@@ -159,17 +159,10 @@ sched_idle(void *v)
while (1) {
while (!cpu_is_idle(curcpu())) {
- struct proc *dead;
-
SCHED_LOCK(s);
p->p_stat = SSLEEP;
mi_switch();
SCHED_UNLOCK(s);
-
- while ((dead = LIST_FIRST(&spc->spc_deadproc))) {
- LIST_REMOVE(dead, p_hash);
- exit2(dead);
- }
}
splassert(IPL_NONE);
@@ -204,7 +197,7 @@ sched_idle(void *v)
* and waking up the reaper without risking having our address space and
* stack torn from under us before we manage to switch to another proc.
* Therefore we have a per-cpu list of dead processes where we put this
- * proc and have idle clean up that list and move it to the reaper list.
+ * proc. We move the list to the reaper list after context switch.
* All this will be unnecessary once we can bind the reaper this cpu
* and not risk having it switch to another in case it sleeps.
*/
@@ -212,14 +205,8 @@ void
sched_exit(struct proc *p)
{
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
- struct timespec ts;
- struct proc *idle;
int s;
- nanouptime(&ts);
- timespecsub(&ts, &spc->spc_runtime, &ts);
- timespecadd(&p->p_rtime, &ts, &p->p_rtime);
-
LIST_INSERT_HEAD(&spc->spc_deadproc, p, p_hash);
#ifdef MULTIPROCESSOR
@@ -229,10 +216,8 @@ sched_exit(struct proc *p)
#endif
SCHED_LOCK(s);
- idle = spc->spc_idleproc;
- idle->p_stat = SRUN;
- cpu_switchto(NULL, idle);
- panic("cpu_switchto returned");
+ mi_switch();
+ panic("mi_switch returned");
}
/*
diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c
index c237dac5bad..8f988ae7c57 100644
--- a/sys/kern/sched_bsd.c
+++ b/sys/kern/sched_bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sched_bsd.c,v 1.57 2019/11/01 20:58:01 mpi Exp $ */
+/* $OpenBSD: sched_bsd.c,v 1.58 2019/11/02 05:31:20 visa Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*-
@@ -413,6 +413,7 @@ mi_switch(void)
SCHED_ASSERT_UNLOCKED();
+ dispatch_deadproc();
smr_idle();
/*
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index e6e3408ec68..066a0f98c11 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.276 2019/11/01 19:13:52 mpi Exp $ */
+/* $OpenBSD: proc.h,v 1.277 2019/11/02 05:31:20 visa Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -567,8 +567,8 @@ void setrunnable(struct proc *);
void endtsleep(void *);
void unsleep(struct proc *);
void reaper(void *);
+void dispatch_deadproc(void);
void exit1(struct proc *, int, int);
-void exit2(struct proc *);
int dowait4(struct proc *, pid_t, int *, int, struct rusage *,
register_t *);
void cpu_fork(struct proc *_curp, struct proc *_child, void *_stack,
diff --git a/sys/sys/syscall_mi.h b/sys/sys/syscall_mi.h
index 3909bb419d7..571447f790e 100644
--- a/sys/sys/syscall_mi.h
+++ b/sys/sys/syscall_mi.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall_mi.h,v 1.21 2019/06/14 05:52:42 deraadt Exp $ */
+/* $OpenBSD: syscall_mi.h,v 1.22 2019/11/02 05:31:20 visa Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -138,6 +138,7 @@ mi_child_return(struct proc *p)
KERNEL_UNLOCK();
#endif
+ dispatch_deadproc();
userret(p);
#ifdef KTRACE