From owner-svn-src-head@FreeBSD.ORG Sun Oct 17 11:01:52 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BCE4E1065675; Sun, 17 Oct 2010 11:01:52 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AAB608FC1B; Sun, 17 Oct 2010 11:01:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o9HB1qds027251; Sun, 17 Oct 2010 11:01:52 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9HB1qwJ027247; Sun, 17 Oct 2010 11:01:52 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201010171101.o9HB1qwJ027247@svn.freebsd.org> From: David Xu Date: Sun, 17 Oct 2010 11:01:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r213950 - in head/sys: kern sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Oct 2010 11:01:52 -0000 Author: davidxu Date: Sun Oct 17 11:01:52 2010 New Revision: 213950 URL: http://svn.freebsd.org/changeset/base/213950 Log: - Insert thread0 into correct thread hash link list. - In thr_exit() and kthread_exit(), only remove thread from hash if it can directly exit, otherwise let exit1() do it. - In thread_suspend_check(), fix cleanup code when thread needs to exit. This change seems fixed the "Bad link elm " panic found by Peter Holm. Stress testing: pho Modified: head/sys/kern/init_main.c head/sys/kern/kern_thread.c head/sys/sys/proc.h Modified: head/sys/kern/init_main.c ============================================================================== --- head/sys/kern/init_main.c Sun Oct 17 09:13:47 2010 (r213949) +++ head/sys/kern/init_main.c Sun Oct 17 11:01:52 2010 (r213950) @@ -443,7 +443,6 @@ proc0_init(void *dummy __unused) */ LIST_INSERT_HEAD(&allproc, p, p_list); LIST_INSERT_HEAD(PIDHASH(0), p, p_hash); - LIST_INSERT_HEAD(TIDHASH(0), td, td_hash); mtx_init(&pgrp0.pg_mtx, "process group", NULL, MTX_DEF | MTX_DUPOK); p->p_pgrp = &pgrp0; LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash); @@ -462,6 +461,7 @@ proc0_init(void *dummy __unused) STAILQ_INIT(&p->p_ktr); p->p_nice = NZERO; td->td_tid = PID_MAX + 1; + LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); td->td_state = TDS_RUNNING; td->td_pri_class = PRI_TIMESHARE; td->td_user_pri = PUSER; Modified: head/sys/kern/kern_thread.c ============================================================================== --- head/sys/kern/kern_thread.c Sun Oct 17 09:13:47 2010 (r213949) +++ head/sys/kern/kern_thread.c Sun Oct 17 11:01:52 2010 (r213950) @@ -746,25 +746,23 @@ thread_suspend_check(int return_instead) (p->p_flag & P_SINGLE_BOUNDARY) && return_instead) return (ERESTART); - /* If thread will exit, flush its pending signals */ - if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) - sigqueue_flush(&td->td_sigqueue); - - PROC_SLOCK(p); - thread_stopped(p); /* * If the process is waiting for us to exit, * this thread should just suicide. * Assumes that P_SINGLE_EXIT implies P_STOPPED_SINGLE. */ if ((p->p_flag & P_SINGLE_EXIT) && (p->p_singlethread != td)) { - PROC_SUNLOCK(p); PROC_UNLOCK(p); tidhash_remove(td); PROC_LOCK(p); + tdsigcleanup(td); PROC_SLOCK(p); + thread_stopped(p); thread_exit(); } + + PROC_SLOCK(p); + thread_stopped(p); if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) { if (p->p_numthreads == p->p_suspcount + 1) { thread_lock(p->p_singlethread); @@ -981,12 +979,7 @@ void tidhash_add(struct thread *td) { rw_wlock(&tidhash_lock); - thread_lock(td); - if ((td->td_flags & TDF_TIDHASH) == 0) { - LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); - td->td_flags |= TDF_TIDHASH; - } - thread_unlock(td); + LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); rw_wunlock(&tidhash_lock); } @@ -994,11 +987,6 @@ void tidhash_remove(struct thread *td) { rw_wlock(&tidhash_lock); - thread_lock(td); - if ((td->td_flags & TDF_TIDHASH) != 0) { - LIST_REMOVE(td, td_hash); - td->td_flags &= ~TDF_TIDHASH; - } - thread_unlock(td); + LIST_REMOVE(td, td_hash); rw_wunlock(&tidhash_lock); } Modified: head/sys/sys/proc.h ============================================================================== --- head/sys/sys/proc.h Sun Oct 17 09:13:47 2010 (r213949) +++ head/sys/sys/proc.h Sun Oct 17 11:01:52 2010 (r213950) @@ -353,7 +353,7 @@ do { \ #define TDF_NEEDRESCHED 0x00010000 /* Thread needs to yield. */ #define TDF_NEEDSIGCHK 0x00020000 /* Thread may need signal delivery. */ #define TDF_NOLOAD 0x00040000 /* Ignore during load avg calculations. */ -#define TDF_TIDHASH 0x00080000 /* Thread is on hash table. */ +#define TDF_UNUSED19 0x00080000 /* --available-- */ #define TDF_THRWAKEUP 0x00100000 /* Libthr thread must not suspend itself. */ #define TDF_UNUSED21 0x00200000 /* --available-- */ #define TDF_SWAPINREQ 0x00400000 /* Swapin request due to wakeup. */