diff options
author | 2019-11-04 18:06:02 +0000 | |
---|---|---|
committer | 2019-11-04 18:06:02 +0000 | |
commit | 2afc0175809bf995111e1d7f5854505c04a2b2db (patch) | |
tree | d6670666745dc89ac1dc77a40c059986df6ece37 | |
parent | Regularly poll and report kubsan findings using the timeout(9) API (diff) | |
download | wireguard-openbsd-2afc0175809bf995111e1d7f5854505c04a2b2db.tar.xz wireguard-openbsd-2afc0175809bf995111e1d7f5854505c04a2b2db.zip |
Restore the old way of dispatching dead procs through idle proc.
The new way needs more thought.
-rw-r--r-- | sys/kern/kern_exit.c | 28 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 23 | ||||
-rw-r--r-- | sys/kern/sched_bsd.c | 3 | ||||
-rw-r--r-- | sys/sys/proc.h | 4 | ||||
-rw-r--r-- | sys/sys/syscall_mi.h | 3 |
5 files changed, 34 insertions, 27 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 570aa737f2f..4c6f30cbdf8 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.179 2019/11/02 05:31:20 visa Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.180 2019/11/04 18:06:02 visa Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -367,27 +367,21 @@ struct mutex deadproc_mutex = struct proclist deadproc = LIST_HEAD_INITIALIZER(deadproc); /* - * Move dead procs from the CPU's local list to the reaper list and - * wake up the reaper. + * We are called from cpu_exit() once it is safe to schedule the + * dead process's resources to be freed. * - * This is called once it is safe to free the resources of dead processes. + * 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. */ void -dispatch_deadproc(void) +exit2(struct proc *p) { - struct proc *dead; - struct schedstate_percpu *spc = &curcpu()->ci_schedstate; - - if (LIST_EMPTY(&spc->spc_deadproc)) - return; - - KERNEL_ASSERT_UNLOCKED(); - mtx_enter(&deadproc_mutex); - while ((dead = LIST_FIRST(&spc->spc_deadproc)) != NULL) { - LIST_REMOVE(dead, p_hash); - LIST_INSERT_HEAD(&deadproc, dead, p_hash); - } + LIST_INSERT_HEAD(&deadproc, p, p_hash); mtx_leave(&deadproc_mutex); wakeup(&deadproc); diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 94ebd833ab1..46de8fa7800 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.61 2019/11/02 05:31:20 visa Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.62 2019/11/04 18:06:03 visa Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org> * @@ -159,10 +159,17 @@ 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); @@ -197,7 +204,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. We move the list to the reaper list after context switch. + * proc and have idle clean up that list and move it to the reaper list. * 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. */ @@ -205,8 +212,14 @@ 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 @@ -216,8 +229,10 @@ sched_exit(struct proc *p) #endif SCHED_LOCK(s); - mi_switch(); - panic("mi_switch returned"); + idle = spc->spc_idleproc; + idle->p_stat = SRUN; + cpu_switchto(NULL, idle); + panic("cpu_switchto returned"); } /* diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 8f988ae7c57..5219a9121b6 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.58 2019/11/02 05:31:20 visa Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.59 2019/11/04 18:06:03 visa Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -413,7 +413,6 @@ mi_switch(void) SCHED_ASSERT_UNLOCKED(); - dispatch_deadproc(); smr_idle(); /* diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 066a0f98c11..5830b02e13f 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.277 2019/11/02 05:31:20 visa Exp $ */ +/* $OpenBSD: proc.h,v 1.278 2019/11/04 18:06:03 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 571447f790e..1e071933349 100644 --- a/sys/sys/syscall_mi.h +++ b/sys/sys/syscall_mi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall_mi.h,v 1.22 2019/11/02 05:31:20 visa Exp $ */ +/* $OpenBSD: syscall_mi.h,v 1.23 2019/11/04 18:06:03 visa Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -138,7 +138,6 @@ mi_child_return(struct proc *p) KERNEL_UNLOCK(); #endif - dispatch_deadproc(); userret(p); #ifdef KTRACE |