- 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
This commit is contained in:
David Xu 2010-10-17 11:01:52 +00:00
parent bb317aa6ea
commit 21ecd1e977
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=213950
3 changed files with 9 additions and 21 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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. */