PERFORCE change 121575 for review

John Baldwin jhb at FreeBSD.org
Wed Jun 13 13:53:55 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=121575

Change 121575 by jhb at jhb_mutex on 2007/06/13 13:53:32

	Try to de-pessimize ktrace locking some.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_exit.c#124 edit
.. //depot/projects/smpng/sys/kern/kern_ktrace.c#60 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_exit.c#124 (text+ko) ====

@@ -355,26 +355,32 @@
 	mtx_unlock(&Giant);	
 #ifdef KTRACE
 	/*
-	 * Drain any pending records on the thread and release the trace
-	 * file.  It might be better if drain-and-clear were atomic.
+	 * Disable tracing, then drain any pending records and release
+	 * the trace file.
 	 */
-	ktrprocexit(td);
-	PROC_LOCK(p);
-	mtx_lock(&ktrace_mtx);
-	p->p_traceflag = 0;	/* don't trace the vrele() */
-	tracevp = p->p_tracevp;
-	p->p_tracevp = NULL;
-	tracecred = p->p_tracecred;
-	p->p_tracecred = NULL;
-	mtx_unlock(&ktrace_mtx);
-	PROC_UNLOCK(p);
-	if (tracevp != NULL) {
-		locked = VFS_LOCK_GIANT(tracevp->v_mount);
-		vrele(tracevp);
-		VFS_UNLOCK_GIANT(locked);
+	if (p->p_traceflag != 0) {
+		PROC_LOCK(p);
+		mtx_lock(&ktrace_mtx);
+		p->p_traceflag = 0;
+		mtx_unlock(&ktrace_mtx);
+		PROC_UNLOCK(p);
+		ktrprocexit(td);
+		PROC_LOCK(p);
+		mtx_lock(&ktrace_mtx);
+		tracevp = p->p_tracevp;
+		p->p_tracevp = NULL;
+		tracecred = p->p_tracecred;
+		p->p_tracecred = NULL;
+		mtx_unlock(&ktrace_mtx);
+		PROC_UNLOCK(p);
+		if (tracevp != NULL) {
+			locked = VFS_LOCK_GIANT(tracevp->v_mount);
+			vrele(tracevp);
+			VFS_UNLOCK_GIANT(locked);
+		}
+		if (tracecred != NULL)
+			crfree(tracecred);
 	}
-	if (tracecred != NULL)
-		crfree(tracecred);
 #endif
 	/*
 	 * Release reference to text vnode

==== //depot/projects/smpng/sys/kern/kern_ktrace.c#60 (text+ko) ====

@@ -444,6 +444,8 @@
 ktruserret(struct thread *td)
 {
 
+	if (STAILQ_EMPTY(&td->td_proc->p_ktr))
+		return;
 	ktrace_enter(td);
 	sx_xlock(&ktrace_sx);
 	ktr_drain(td);


More information about the p4-projects mailing list