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. */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to