From owner-freebsd-current Tue Aug 21 11: 0: 6 2001 Delivered-To: freebsd-current@freebsd.org Received: from mail.wrs.com (unknown-1-11.windriver.com [147.11.1.11]) by hub.freebsd.org (Postfix) with ESMTP id 3968E37B405 for ; Tue, 21 Aug 2001 10:59:44 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: from laptop.baldwin.cx (john@[147.11.46.201]) by mail.wrs.com (8.9.3/8.9.1) with ESMTP id KAA08675 for ; Tue, 21 Aug 2001 10:59:42 -0700 (PDT) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Tue, 21 Aug 2001 10:59:48 -0700 (PDT) From: John Baldwin To: current@FreeBSD.org Subject: [PATCH] Fix for hanging sound Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG There is a bug in the msleep/endtsleep race workaround. Please test the patch at http://www.FreeBSD.org/~jhb/patches/timeout.patch Index: kern/kern_condvar.c =================================================================== RCS file: /usr/cvs/src/sys/kern/kern_condvar.c,v retrieving revision 1.11 diff -u -r1.11 kern_condvar.c --- kern/kern_condvar.c 2001/07/06 01:16:42 1.11 +++ kern/kern_condvar.c 2001/08/21 17:57:08 @@ -345,8 +345,17 @@ if (p->p_sflag & PS_TIMEOUT) { p->p_sflag &= ~PS_TIMEOUT; rval = EWOULDBLOCK; - } else - callout_stop(&p->p_slpcallout); + } else if (p->p_sflag & PS_TIMOFAIL) + p->p_sflag &= ~PS_TIMOFAIL; + } else if (callout_stop(&p->p_slpcallout) == 0) { + /* + * Work around race with cv_timedwait_end similar to that + * between msleep and endtsleep. + */ + p->p_sflag |= PS_TIMEOUT; + p->p_stats->p_ru.ru_nivcsw++; + mi_switch(); + } mtx_unlock_spin(&sched_lock); #ifdef KTRACE @@ -407,8 +416,17 @@ if (p->p_sflag & PS_TIMEOUT) { p->p_sflag &= ~PS_TIMEOUT; rval = EWOULDBLOCK; - } else - callout_stop(&p->p_slpcallout); + } else if (p->p_sflag & PS_TIMOFAIL) + p->p_sflag &= ~PS_TIMOFAIL; + } else if (callout_stop(&p->p_slpcallout) == 0) { + /* + * Work around race with cv_timedwait_end similar to that + * between msleep and endtsleep. + */ + p->p_sflag |= PS_TIMEOUT; + p->p_stats->p_ru.ru_nivcsw++; + mi_switch(); + } mtx_unlock_spin(&sched_lock); PICKUP_GIANT(); @@ -538,12 +556,16 @@ CTR3(KTR_PROC, "cv_timedwait_end: proc %p (pid %d, %s)", p, p->p_pid, p->p_comm); mtx_lock_spin(&sched_lock); - if (p->p_wchan != NULL) { + if (p->p_sflag & PS_TIMEOUT) { + p->p_sflag &= ~PS_TIMEOUT; + setrunqueue(p); + } else if (p->p_wchan != NULL) { if (p->p_stat == SSLEEP) setrunnable(p); else cv_waitq_remove(p); p->p_sflag |= PS_TIMEOUT; - } + } else + p->p_sflag |= PS_TIMOFAIL; mtx_unlock_spin(&sched_lock); } Index: kern/kern_synch.c =================================================================== RCS file: /usr/cvs/src/sys/kern/kern_synch.c,v retrieving revision 1.155 diff -u -r1.155 kern_synch.c --- kern/kern_synch.c 2001/08/10 22:53:28 1.155 +++ kern/kern_synch.c 2001/08/21 17:57:08 @@ -451,6 +455,8 @@ p->p_sflag &= ~PS_TIMEOUT; if (sig == 0) rval = EWOULDBLOCK; + } else if (p->p_sflag & PS_TIMOFAIL) + p->p_sflag &= ~PS_TIMOFAIL; } else if (timo && callout_stop(&p->p_slpcallout) == 0) { /* * This isn't supposed to be pretty. If we are here, then @@ -524,7 +530,8 @@ else unsleep(p); p->p_sflag |= PS_TIMEOUT; - } + } else + p->p_sflag |= PS_TIMOFAIL; mtx_unlock_spin(&sched_lock); } Index: sys/proc.h =================================================================== RCS file: /usr/cvs/src/sys/sys/proc.h,v retrieving revision 1.174 diff -u -r1.174 proc.h --- sys/proc.h 2001/08/10 22:53:32 1.174 +++ sys/proc.h 2001/08/21 17:57:08 @@ -321,6 +321,7 @@ #define PS_SWAPPING 0x00200 /* Process is being swapped. */ #define PS_ASTPENDING 0x00400 /* Process has a pending ast. */ #define PS_NEEDRESCHED 0x00800 /* Process needs to yield. */ +#define PS_TIMOFAIL 0x01000 /* Timeout from sleep after we were awake. */ #define P_MAGIC 0xbeefface -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message