Date: Wed, 12 Jun 2002 19:29:41 -0700 (PDT) From: Julian Elischer <julian@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 12794 for review Message-ID: <200206130229.g5D2Tfb71880@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=12794 Change 12794 by julian@julian_jules1 on 2002/06/12 19:29:39 thread exit cleanup Affected files ... ... //depot/projects/kse/sys/i386/i386/trap.c#48 edit ... //depot/projects/kse/sys/kern/init_sysent.c#19 edit ... //depot/projects/kse/sys/kern/kern_exit.c#53 edit ... //depot/projects/kse/sys/kern/kern_proc.c#65 edit ... //depot/projects/kse/sys/kern/kern_thread.c#63 edit ... //depot/projects/kse/sys/kern/subr_trap.c#61 edit ... //depot/projects/kse/sys/kern/syscalls.c#19 edit ... //depot/projects/kse/sys/kern/syscalls.master#18 edit ... //depot/projects/kse/sys/sys/proc.h#107 edit ... //depot/projects/kse/sys/sys/syscall.h#19 edit ... //depot/projects/kse/sys/sys/syscall.mk#19 edit ... //depot/projects/kse/sys/sys/sysproto.h#23 edit Differences ... ==== //depot/projects/kse/sys/i386/i386/trap.c#48 (text+ko) ==== @@ -273,6 +273,7 @@ * But check if the are the single thread first! */ if ((p->p_flag & P_WEXIT) && (p->p_singlethread != td)) { + PROC_LOCK(p); thread_exit(); /* NOTREACHED */ } ==== //depot/projects/kse/sys/kern/init_sysent.c#19 (text+ko) ==== @@ -2,7 +2,7 @@ * System call switch table. * * DO NOT EDIT-- this file is automatically generated. - * $FreeBSD: src/sys/kern/init_sysent.c,v 1.123 2002/05/28 06:16:07 marcel Exp $ + * $FreeBSD$ * created from FreeBSD: src/sys/kern/syscalls.master,v 1.112 2002/05/28 05:58:06 marcel Exp */ @@ -405,7 +405,7 @@ { 0, (sy_call_t *)kse_wakeup }, /* 380 = kse_wakeup */ { AS(kse_new_args), (sy_call_t *)kse_new }, /* 381 = kse_new */ { AS(thread_wakeup_args), (sy_call_t *)thread_wakeup }, /* 382 = thread_wakeup */ - { 0, (sy_call_t *)kse_yield }, /* 383 = kse_yield */ + { SYF_MPSAFE | 0, (sy_call_t *)kse_yield }, /* 383 = kse_yield */ { 0, (sy_call_t *)nosys }, /* 384 = __mac_get_proc */ { 0, (sy_call_t *)nosys }, /* 385 = __mac_set_proc */ { 0, (sy_call_t *)nosys }, /* 386 = __mac_get_fd */ ==== //depot/projects/kse/sys/kern/kern_exit.c#53 (text+ko) ==== @@ -485,8 +485,6 @@ wakeup(p->p_pptr); PROC_UNLOCK(p->p_pptr); - PROC_UNLOCK(p); - cnt.v_swtch++; binuptime(PCPU_PTR(switchtime)); PCPU_SET(switchticks, ticks); @@ -605,6 +603,7 @@ mtx_unlock_spin(&sched_lock); } + thread_reap(); /* check for zombie threads */ td->td_retval[0] = p->p_pid; #ifdef COMPAT_43 if (compat) ==== //depot/projects/kse/sys/kern/kern_proc.c#65 (text+ko) ==== @@ -187,8 +187,8 @@ kse_yield(struct thread *td, struct kse_yield_args *uap) { + PROC_LOCK(td->td_proc); mtx_lock_spin(&sched_lock); - mtx_unlock(&Giant); thread_exit(); /* NOTREACHED */ return(0); ==== //depot/projects/kse/sys/kern/kern_thread.c#63 (text+ko) ==== @@ -72,6 +72,11 @@ #define RANGEOF(type, start, end) (offsetof(type, end) - offsetof(type, start)) +tdlist_head_t zombie_threads = TAILQ_HEAD_INITIALIZER(zombie_threads); +struct mtx zombie_thread_lock; +MTX_SYSINIT(zombie_thread_lock", zombie_thread_lock, + "zombie_thread_lock", MTX_SPIN); + /* * Pepare a thread for use. */ @@ -231,11 +236,43 @@ } /* + * Stash an embarasingly esxtra thread into the zombie thread queue. + */ +void +thread_stash(struct thread *td) +{ + mtx_lock_spin(&zombie_thread_lock); + TAILQ_INSERT_HEAD(&zombie_threads, td, td_runq); + mtx_unlock_spin(&zombie_thread_lock); +} + +/* + * reap any zombie threads for this Processor. + */ +void +thread_reap(void) +{ + struct thread *td_reaped, *td_next; + + mtx_lock_spin(&zombie_thread_lock); + td_reaped = TAILQ_FIRST(&zombie_threads); + while (td_reaped) { + td_next = TAILQ_NEXT(td_reaped, td_runq); + TAILQ_REMOVE(&zombie_threads, td_reaped, td_runq); + thread_free(td_reaped); + td_reaped = td_next; + } + mtx_unlock_spin(&zombie_thread_lock); + +} + +/* * Allocate a thread. */ struct thread * thread_alloc(void) { + thread_reap(); /* check if any zombies to get */ return (uma_zalloc(thread_zone, M_WAITOK)); } @@ -300,24 +337,22 @@ { struct thread *td; struct kse *ke; + struct proc *p; + p = td->td_proc; td = curthread; ke = td->td_kse; - PROC_LOCK(td->td_proc); + PROC_LOCK_ASSERT(p, MA_OWNED); CTR1(KTR_PROC, "thread_exit: thread %p", td); KASSERT(!mtx_owned(&Giant), ("dying thread owns giant")); if (ke->ke_tdspare != NULL) { - mtx_unlock_spin(&sched_lock); - mtx_lock(&Giant); - thread_free(ke->ke_tdspare); - mtx_unlock(&Giant); - mtx_lock_spin(&sched_lock); + thread_stash(ke->ke_tdspare); } cpu_thread_exit(td); /* XXXSMP */ thread_unlink(td); - PROC_UNLOCK(td->td_proc); ke->ke_tdspare = td; + PROC_UNLOCK(p); cpu_throw(); /* NOTREACHED */ } @@ -521,7 +556,6 @@ * this thread should just suicide. */ if (p->p_flag & P_SINGLE_EXIT) { - PROC_UNLOCK(p); mtx_lock_spin(&sched_lock); while (mtx_owned(&Giant)) mtx_unlock(&Giant); ==== //depot/projects/kse/sys/kern/subr_trap.c#61 (text+ko) ==== @@ -182,6 +182,7 @@ * to be returned? * For now, just let another KSE run (easiest). */ + PROC_LOCK(p); mtx_lock_spin(&sched_lock); thread_exit(); /* Abandon current thread. */ /* NOTREACHED */ ==== //depot/projects/kse/sys/kern/syscalls.c#19 (text+ko) ==== @@ -2,7 +2,7 @@ * System call names. * * DO NOT EDIT-- this file is automatically generated. - * $FreeBSD: src/sys/kern/syscalls.c,v 1.110 2002/05/28 06:16:07 marcel Exp $ + * $FreeBSD$ * created from FreeBSD: src/sys/kern/syscalls.master,v 1.112 2002/05/28 05:58:06 marcel Exp */ ==== //depot/projects/kse/sys/kern/syscalls.master#18 (text+ko) ==== @@ -552,7 +552,7 @@ 381 STD BSD { int kse_new(struct kse_mailbox * mbx, \ int new_grp_flag); } 382 STD BSD { int thread_wakeup(struct thread_mailbox *tmbx); } -383 STD BSD { int kse_yield(void); } +383 MSTD BSD { int kse_yield(void); } 384 UNIMPL BSD __mac_get_proc 385 UNIMPL BSD __mac_set_proc 386 UNIMPL BSD __mac_get_fd ==== //depot/projects/kse/sys/sys/proc.h#107 (text+ko) ==== @@ -822,11 +822,13 @@ void thread_exit(void) __dead2; int thread_export_context(struct thread *td); void thread_link(struct thread *td, struct ksegrp *kg); +void thread_reap(void); struct thread *thread_schedule_upcall(struct thread *td, struct kse *ke); int thread_single(int how); #define SNGLE_WAIT 0 /* values for 'how' */ #define SNGLE_EXIT 1 void thread_single_end(void); +void thread_stash(struct thread *td); int thread_suspend_check(int how); void thread_unsuspend(struct proc *p); ==== //depot/projects/kse/sys/sys/syscall.h#19 (text+ko) ==== @@ -2,7 +2,7 @@ * System call numbers. * * DO NOT EDIT-- this file is automatically generated. - * $FreeBSD: src/sys/sys/syscall.h,v 1.109 2002/05/28 06:16:07 marcel Exp $ + * $FreeBSD$ * created from FreeBSD: src/sys/kern/syscalls.master,v 1.112 2002/05/28 05:58:06 marcel Exp */ ==== //depot/projects/kse/sys/sys/syscall.mk#19 (text+ko) ==== @@ -1,6 +1,6 @@ # FreeBSD system call names. # DO NOT EDIT-- this file is automatically generated. -# $FreeBSD: src/sys/sys/syscall.mk,v 1.64 2002/05/28 06:16:07 marcel Exp $ +# $FreeBSD$ # created from FreeBSD: src/sys/kern/syscalls.master,v 1.112 2002/05/28 05:58:06 marcel Exp MIASM = \ syscall.o \ ==== //depot/projects/kse/sys/sys/sysproto.h#23 (text+ko) ==== @@ -2,7 +2,7 @@ * System call prototypes. * * DO NOT EDIT-- this file is automatically generated. - * $FreeBSD: src/sys/sys/sysproto.h,v 1.101 2002/05/28 06:16:07 marcel Exp $ + * $FreeBSD$ * created from FreeBSD: src/sys/kern/syscalls.master,v 1.112 2002/05/28 05:58:06 marcel Exp */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206130229.g5D2Tfb71880>