From owner-p4-projects@FreeBSD.ORG Mon Jul 5 11:47:43 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 756E516A4D0; Mon, 5 Jul 2004 11:47:43 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 213D916A4CE for ; Mon, 5 Jul 2004 11:47:43 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 065D643D45 for ; Mon, 5 Jul 2004 11:47:43 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i65Blgix084665 for ; Mon, 5 Jul 2004 11:47:42 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i65Blg1a084662 for perforce@freebsd.org; Mon, 5 Jul 2004 11:47:42 GMT (envelope-from davidxu@freebsd.org) Date: Mon, 5 Jul 2004 11:47:42 GMT Message-Id: <200407051147.i65Blg1a084662@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 56496 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2004 11:47:44 -0000 http://perforce.freebsd.org/chv.cgi?CH=56496 Change 56496 by davidxu@davidxu_alona on 2004/07/05 11:47:36 Allow multiple threads to report debug event at same time, the last thread will win the race, and others will retry, debugger has chance to select a thread to be replied. Affected files ... .. //depot/projects/davidxu_ksedbg/src/sys/kern/kern_sig.c#5 edit .. //depot/projects/davidxu_ksedbg/src/sys/sys/proc.h#4 edit Differences ... ==== //depot/projects/davidxu_ksedbg/src/sys/kern/kern_sig.c#5 (text+ko) ==== @@ -2005,16 +2005,39 @@ { struct proc *p = td->td_proc; struct thread *td0; - int newsig; PROC_LOCK_ASSERT(p, MA_OWNED); WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &p->p_mtx.mtx_object, "Stopping for traced signal"); - while (P_SHOULDSTOP(p)) { - if (p->p_flag & P_SINGLE_EXIT) + mtx_lock_spin(&sched_lock); + td->td_flags |= TDF_XSIG; + mtx_unlock_spin(&sched_lock); + td->td_xsig = sig; + while (td->td_flags & TDF_XSIG) { + if (p->p_flag & P_SINGLE_EXIT) { + mtx_lock_spin(&sched_lock); + td->td_flags &= ~TDF_XSIG; + mtx_unlock_spin(&sched_lock); return (sig); + } + /* + * Just make wait() to work, the last stopped thread + * will win. + */ + p->p_xstat = sig; + p->p_xthread = td; + p->p_flag |= (P_STOPPED_SIG|P_STOPPED_TRACE); mtx_lock_spin(&sched_lock); + FOREACH_THREAD_IN_PROC(p, td0) { + if (TD_IS_SLEEPING(td0) && + (td0->td_flags & TDF_SINTR) && + !TD_IS_SUSPENDED(td0)) { + thread_suspend_one(td0); + } else if (td != td0) { + td0->td_flags |= TDF_ASTPENDING; + } + } thread_stopped(p); thread_suspend_one(td); PROC_UNLOCK(p); @@ -2024,33 +2047,7 @@ PICKUP_GIANT(); PROC_LOCK(p); } - p->p_xstat = sig; - p->p_xthread = td; - p->p_flag |= (P_STOPPED_SIG|P_STOPPED_TRACE); - mtx_lock_spin(&sched_lock); - FOREACH_THREAD_IN_PROC(p, td0) { - if (TD_IS_SLEEPING(td0) && - (td0->td_flags & TDF_SINTR) && - !TD_IS_SUSPENDED(td0)) { - thread_suspend_one(td0); - } else if (td != td0) { - td0->td_flags |= TDF_ASTPENDING; - } - } - thread_stopped(p); - thread_suspend_one(td); - PROC_UNLOCK(p); - DROP_GIANT(); - mi_switch(SW_INVOL, NULL); - mtx_unlock_spin(&sched_lock); - PICKUP_GIANT(); - PROC_LOCK(p); - newsig = p->p_xstat; - p->p_xstat = newsig; - mtx_lock_spin(&sched_lock); - thread_unsuspend(p); - mtx_unlock_spin(&sched_lock); - return (newsig); + return (td->td_xsig); } /* ==== //depot/projects/davidxu_ksedbg/src/sys/sys/proc.h#4 (text+ko) ==== @@ -303,7 +303,7 @@ volatile u_int td_generation; /* (k) Enable detection of preemption */ stack_t td_sigstk; /* (k) Stack ptr and on-stack flag. */ int td_kflags; /* (c) Flags for KSE threading. */ - + int td_xsig; /* (c) Signal for ptrace */ #define td_endzero td_base_pri /* Copied during fork1() or thread_sched_upcall(). */ @@ -354,6 +354,7 @@ #define TDF_OWEUPC 0x008000 /* Owe thread an addupc() call at next AST. */ #define TDF_NEEDRESCHED 0x010000 /* Thread needs to yield. */ #define TDF_NEEDSIGCHK 0x020000 /* Thread may need signal delivery. */ +#define TDF_XSIG 0x040000 /* Thread is exchanging signal under traced */ #define TDF_UMTXWAKEUP 0x080000 /* Libthr thread must not sleep on a umtx. */ #define TDF_THRWAKEUP 0x100000 /* Libthr thread must not suspend itself. */