Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Jun 2004 04:50:49 GMT
From:      David Xu <davidxu@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 55897 for review
Message-ID:  <200406270450.i5R4on4j089211@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/types.h>
 #include <sys/kse.h>
+#include <sys/ptrace.h>
 #include <sys/signalvar.h>
 #include <sys/queue.h>
 #include <machine/atomic.h>
@@ -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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406270450.i5R4on4j089211>