From c4440309813730fe6d939ae0480936826dd0d2dc Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 21 Oct 2003 04:14:58 +0000 Subject: [PATCH] A hackish fix to a bug uio_yield(). --- sys/i386/i386/trap.c | 14 +++++++++++++- sys/kern/kern_switch.c | 23 ++++++++++++----------- sys/platform/pc32/i386/trap.c | 14 +++++++++++++- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 2f7e01fdd4..59de2b3302 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.36 2003/10/17 07:30:43 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.37 2003/10/21 04:14:58 dillon Exp $ */ /* @@ -167,6 +167,12 @@ SYSCTL_INT(_machdep, OID_AUTO, fast_release, CTLFLAG_RW, static int slow_release; SYSCTL_INT(_machdep, OID_AUTO, slow_release, CTLFLAG_RW, &slow_release, 0, "Passive Release was nonoptimal"); +static int pass_release; +SYSCTL_INT(_machdep, OID_AUTO, pass_release, CTLFLAG_RW, + &pass_release, 0, "Passive Release on switch"); +static int pass_hold; +SYSCTL_INT(_machdep, OID_AUTO, pass_hold, CTLFLAG_RW, + &pass_hold, 0, "Passive Held on switch"); MALLOC_DEFINE(M_SYSMSG, "sysmsg", "sysmsg structure"); @@ -193,6 +199,12 @@ passive_release(struct thread *td) if ((p->p_flag & P_CURPROC) && (td->td_flags & TDF_RUNQ) == 0) { td->td_release = NULL; release_curproc(p); + ++pass_release; + } else if ((p->p_flag & (P_CURPROC|P_PASSIVE_ACQ)) == (P_CURPROC|P_PASSIVE_ACQ)) { + td->td_release = NULL; + release_curproc(p); + } else { + ++pass_hold; } } diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c index d9ada4e197..0c90f248aa 100644 --- a/sys/kern/kern_switch.c +++ b/sys/kern/kern_switch.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_switch.c,v 1.3.2.1 2000/05/16 06:58:12 dillon Exp $ - * $DragonFly: src/sys/kern/Attic/kern_switch.c,v 1.12 2003/10/17 07:44:18 dillon Exp $ + * $DragonFly: src/sys/kern/Attic/kern_switch.c,v 1.13 2003/10/21 04:14:55 dillon Exp $ */ #include @@ -596,16 +596,15 @@ acquire_curproc(struct proc *p) /* * Yield / synchronous reschedule. This is a bit tricky because the trap - * code might have set a lazy release on the switch function. The first - * thing we do is call lwkt_switch() to resolve the lazy release (if any). - * Then, if we are a process, we want to allow another process to run. + * code might have set a lazy release on the switch function. The lazy + * release normally doesn't release the P_CURPROC designation unless we + * are blocking at the time of the switch (no longer on the run queue), which + * we aren't. We need to release our P_CURPROC designation in order to + * properly allow another user process to run. This is done by creating + * a special case by setting P_PASSIVE_ACQ prior to calling lwkt_switch(). * - * The only way to do that is to acquire and then release P_CURPROC. We - * have to release it because the kernel expects it to be released as a - * sanity check when it goes to sleep. - * - * XXX we need a way to ensure that we wake up eventually from a yield, - * even if we are an idprio process. + * This code is confusing and really needs to be cleaned up. Plus I don't + * think it actually works as expected. */ void uio_yield(void) @@ -613,12 +612,14 @@ uio_yield(void) struct thread *td = curthread; struct proc *p = td->td_proc; - lwkt_switch(); if (p) { p->p_flag |= P_PASSIVE_ACQ; + lwkt_switch(); acquire_curproc(p); release_curproc(p); p->p_flag &= ~P_PASSIVE_ACQ; + } else { + lwkt_switch(); } } diff --git a/sys/platform/pc32/i386/trap.c b/sys/platform/pc32/i386/trap.c index b7defdde1e..77cdba7413 100644 --- a/sys/platform/pc32/i386/trap.c +++ b/sys/platform/pc32/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.36 2003/10/17 07:30:43 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.37 2003/10/21 04:14:58 dillon Exp $ */ /* @@ -167,6 +167,12 @@ SYSCTL_INT(_machdep, OID_AUTO, fast_release, CTLFLAG_RW, static int slow_release; SYSCTL_INT(_machdep, OID_AUTO, slow_release, CTLFLAG_RW, &slow_release, 0, "Passive Release was nonoptimal"); +static int pass_release; +SYSCTL_INT(_machdep, OID_AUTO, pass_release, CTLFLAG_RW, + &pass_release, 0, "Passive Release on switch"); +static int pass_hold; +SYSCTL_INT(_machdep, OID_AUTO, pass_hold, CTLFLAG_RW, + &pass_hold, 0, "Passive Held on switch"); MALLOC_DEFINE(M_SYSMSG, "sysmsg", "sysmsg structure"); @@ -193,6 +199,12 @@ passive_release(struct thread *td) if ((p->p_flag & P_CURPROC) && (td->td_flags & TDF_RUNQ) == 0) { td->td_release = NULL; release_curproc(p); + ++pass_release; + } else if ((p->p_flag & (P_CURPROC|P_PASSIVE_ACQ)) == (P_CURPROC|P_PASSIVE_ACQ)) { + td->td_release = NULL; + release_curproc(p); + } else { + ++pass_hold; } } -- 2.41.0