From owner-p4-projects@FreeBSD.ORG Sun Jun 27 04:50:56 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E916716A4D0; Sun, 27 Jun 2004 04:50:55 +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 AC5A516A4CE for ; Sun, 27 Jun 2004 04:50:55 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9194A43D2D for ; Sun, 27 Jun 2004 04:50:55 +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 i5R4onkF089214 for ; Sun, 27 Jun 2004 04:50:49 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i5R4on4j089211 for perforce@freebsd.org; Sun, 27 Jun 2004 04:50:49 GMT (envelope-from davidxu@freebsd.org) Date: Sun, 27 Jun 2004 04:50:49 GMT Message-Id: <200406270450.i5R4on4j089211@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 55897 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: Sun, 27 Jun 2004 04:50:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=55897 Change 55897 by davidxu@davidxu_alona on 2004/06/27 04:49:52 Add code to hand off lwpid from kernel to thread, clear single step status when entering scheduler to let scheduler run in full speed. rename _thr_active_threads to _thread_active_threads to be consistent with other exported names. Affected files ... .. //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_kern.c#2 edit .. //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_private.h#3 edit Differences ... ==== //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_kern.c#2 (text+ko) ==== @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -222,7 +223,7 @@ * dump core. */ sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); - _thr_active_threads = 1; + _thread_active_threads = 1; /* * Enter a loop to remove and free all threads other than @@ -355,7 +356,7 @@ * dump core. */ sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); - _thr_active_threads = 1; + _thread_active_threads = 1; #endif } @@ -435,6 +436,9 @@ PANIC("kse_create() failed\n"); return (-1); } + _thr_initial->tcb->tcb_tmbx.tm_lwp = + _kse_initial->k_kcb->kcb_kmbx.km_lwp; + _thread_activated = 1; #ifndef SYSTEM_SCOPE_ONLY /* Set current thread to initial thread */ @@ -630,6 +634,20 @@ if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) kse_sched_single(&curkse->k_kcb->kcb_kmbx); else { + if (__predict_false(_libkse_debug != 0)) { + /* + * Because debugger saves single step status in thread + * mailbox's tm_dflags, we can safely clear single + * step status here. the single step status will be + * restored by kse_switchin when the thread is + * switched in again. This also lets uts run in full + * speed. + */ + ttrace(PT_CLEARSTEP, getpid(), + curkse->k_kcb->kcb_kmbx.km_lwp, + (caddr_t) 1, 0); + } + KSE_SET_SWITCH(curkse); _thread_enter_uts(curthread->tcb, curkse->k_kcb); } @@ -697,7 +715,7 @@ curkse->k_flags |= KF_INITIALIZED; first = 1; curthread->active = 1; - + /* Setup kernel signal masks for new thread. */ __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); /* @@ -992,8 +1010,10 @@ if (ret != 0) PANIC("Can't resume thread in critical region\n"); } - else if ((curthread->flags & THR_FLAGS_IN_RUNQ) == 0) + else if ((curthread->flags & THR_FLAGS_IN_RUNQ) == 0) { + curthread->tcb->tcb_tmbx.tm_lwp = 0; kse_switchout_thread(curkse, curthread); + } curkse->k_curthread = NULL; #ifdef DEBUG_THREAD_KERN @@ -2447,7 +2467,7 @@ */ thread->uniqueid = next_uniqueid++; THR_LIST_ADD(thread); - _thr_active_threads++; + _thread_active_threads++; KSE_LOCK_RELEASE(curkse, &_thread_list_lock); _kse_critical_leave(crit); } @@ -2465,7 +2485,7 @@ curkse = _get_curkse(); KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); THR_LIST_REMOVE(thread); - _thr_active_threads--; + _thread_active_threads--; KSE_LOCK_RELEASE(curkse, &_thread_list_lock); _kse_critical_leave(crit); } @@ -2498,4 +2518,3 @@ } return (NULL); } - ==== //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_private.h#3 (text+ko) ==== @@ -582,15 +582,12 @@ int seqno; }; - #define MAX_THR_LOCKLEVEL 5 /* * Thread structure. */ struct pthread { - /* - * Thread mailbox is first so it cal be aligned properly. - */ + /* Thread control block */ struct tcb *tcb; /* @@ -982,6 +979,7 @@ SCLASS struct pthread *_thr_initial SCLASS_PRESET(NULL); /* For debugger */ SCLASS int _libkse_debug SCLASS_PRESET(0); +SCLASS int _thread_activated SCLASS_PRESET(0); /* List of all threads: */ SCLASS TAILQ_HEAD(, pthread) _thread_list @@ -991,7 +989,7 @@ SCLASS TAILQ_HEAD(, pthread) _thread_gc_list SCLASS_PRESET(TAILQ_HEAD_INITIALIZER(_thread_gc_list)); -SCLASS int _thr_active_threads SCLASS_PRESET(1); +SCLASS int _thread_active_threads SCLASS_PRESET(1); SCLASS TAILQ_HEAD(atfork_head, pthread_atfork) _thr_atfork_list; SCLASS pthread_mutex_t _thr_atfork_mutex;