svn commit: r285760 - in stable/9/sys: cddl/dev/lockstat kern sys

Mark Johnston markj at FreeBSD.org
Tue Jul 21 17:19:06 UTC 2015


Author: markj
Date: Tue Jul 21 17:19:03 2015
New Revision: 285760
URL: https://svnweb.freebsd.org/changeset/base/285760

Log:
  MFC r285663, r285664, r285667:
  Ensure that locstat_nsecs() has no effect when lockstat probes are not
  enabled or when the profiled lock carries the LO_NOPROFILE flag.
  
  PR:	201642, 201517

Modified:
  stable/9/sys/cddl/dev/lockstat/lockstat.c
  stable/9/sys/kern/kern_lockstat.c
  stable/9/sys/kern/kern_mutex.c
  stable/9/sys/kern/kern_rwlock.c
  stable/9/sys/kern/kern_sx.c
  stable/9/sys/sys/lockstat.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/sys/   (props changed)

Modified: stable/9/sys/cddl/dev/lockstat/lockstat.c
==============================================================================
--- stable/9/sys/cddl/dev/lockstat/lockstat.c	Tue Jul 21 17:16:37 2015	(r285759)
+++ stable/9/sys/cddl/dev/lockstat/lockstat.c	Tue Jul 21 17:19:03 2015	(r285760)
@@ -160,6 +160,8 @@ lockstat_enable(void *arg, dtrace_id_t i
 
 	ASSERT(!lockstat_probemap[probe->lsp_probe]);
 
+	lockstat_enabled++;
+
 	lockstat_probemap[probe->lsp_probe] = id;
 #ifdef DOODAD
 	membar_producer();
@@ -183,6 +185,8 @@ lockstat_disable(void *arg, dtrace_id_t 
 
 	ASSERT(lockstat_probemap[probe->lsp_probe]);
 
+	lockstat_enabled--;
+
 	lockstat_probemap[probe->lsp_probe] = 0;
 #ifdef DOODAD
 	lockstat_hot_patch();

Modified: stable/9/sys/kern/kern_lockstat.c
==============================================================================
--- stable/9/sys/kern/kern_lockstat.c	Tue Jul 21 17:16:37 2015	(r285759)
+++ stable/9/sys/kern/kern_lockstat.c	Tue Jul 21 17:19:03 2015	(r285760)
@@ -36,9 +36,10 @@
 
 #ifdef KDTRACE_HOOKS
 
-#include <sys/time.h>
 #include <sys/types.h>
+#include <sys/lock.h>
 #include <sys/lockstat.h>
+#include <sys/time.h>
 
 /*
  * The following must match the type definition of dtrace_probe.  It is  
@@ -47,14 +48,19 @@
 uint32_t lockstat_probemap[LS_NPROBES];
 void (*lockstat_probe_func)(uint32_t, uintptr_t, uintptr_t,
     uintptr_t, uintptr_t, uintptr_t);
-
+int lockstat_enabled = 0;
 
 uint64_t 
-lockstat_nsecs(void)
+lockstat_nsecs(struct lock_object *lo)
 {
 	struct bintime bt;
 	uint64_t ns;
 
+	if (!lockstat_enabled)
+		return (0);
+	if ((lo->lo_flags & LO_NOPROFILE) != 0)
+		return (0);
+
 	binuptime(&bt);
 	ns = bt.sec * (uint64_t)1000000000;
 	ns += ((uint64_t)1000000000 * (uint32_t)(bt.frac >> 32)) >> 32;

Modified: stable/9/sys/kern/kern_mutex.c
==============================================================================
--- stable/9/sys/kern/kern_mutex.c	Tue Jul 21 17:16:37 2015	(r285759)
+++ stable/9/sys/kern/kern_mutex.c	Tue Jul 21 17:19:03 2015	(r285760)
@@ -381,7 +381,7 @@ _mtx_lock_sleep(struct mtx *m, uintptr_t
 		    "_mtx_lock_sleep: %s contested (lock=%p) at %s:%d",
 		    m->lock_object.lo_name, (void *)m->mtx_lock, file, line);
 #ifdef KDTRACE_HOOKS
-	all_time -= lockstat_nsecs();
+	all_time -= lockstat_nsecs(&m->lock_object);
 #endif
 
 	while (!_mtx_obtain_lock(m, tid)) {
@@ -471,16 +471,16 @@ _mtx_lock_sleep(struct mtx *m, uintptr_t
 		 * Block on the turnstile.
 		 */
 #ifdef KDTRACE_HOOKS
-		sleep_time -= lockstat_nsecs();
+		sleep_time -= lockstat_nsecs(&m->lock_object);
 #endif
 		turnstile_wait(ts, mtx_owner(m), TS_EXCLUSIVE_QUEUE);
 #ifdef KDTRACE_HOOKS
-		sleep_time += lockstat_nsecs();
+		sleep_time += lockstat_nsecs(&m->lock_object);
 		sleep_cnt++;
 #endif
 	}
 #ifdef KDTRACE_HOOKS
-	all_time += lockstat_nsecs();
+	all_time += lockstat_nsecs(&m->lock_object);
 #endif
 #ifdef KTR
 	if (cont_logged) {
@@ -553,7 +553,7 @@ _mtx_lock_spin(struct mtx *m, uintptr_t 
 #endif
 	lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime);
 #ifdef KDTRACE_HOOKS
-	spin_time -= lockstat_nsecs();
+	spin_time -= lockstat_nsecs(&m->lock_object);
 #endif
 	while (!_mtx_obtain_lock(m, tid)) {
 
@@ -573,7 +573,7 @@ _mtx_lock_spin(struct mtx *m, uintptr_t 
 		spinlock_enter();
 	}
 #ifdef KDTRACE_HOOKS
-	spin_time += lockstat_nsecs();
+	spin_time += lockstat_nsecs(&m->lock_object);
 #endif
 
 	if (LOCK_LOG_TEST(&m->lock_object, opts))
@@ -581,7 +581,10 @@ _mtx_lock_spin(struct mtx *m, uintptr_t 
 
 	LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_MTX_SPIN_LOCK_ACQUIRE, m,
 	    contested, waittime, (file), (line));
-	LOCKSTAT_RECORD1(LS_MTX_SPIN_LOCK_SPIN, m, spin_time);
+#ifdef KDTRACE_HOOKS
+	if (spin_time != 0)
+		LOCKSTAT_RECORD1(LS_MTX_SPIN_LOCK_SPIN, m, spin_time);
+#endif
 }
 #endif /* SMP */
 
@@ -606,7 +609,7 @@ _thread_lock_flags(struct thread *td, in
 		return;
 
 #ifdef KDTRACE_HOOKS
-	spin_time -= lockstat_nsecs();
+	spin_time -= lockstat_nsecs(&td->td_lock->lock_object);
 #endif
 	for (;;) {
 retry:
@@ -654,7 +657,7 @@ retry:
 		__mtx_unlock_spin(m);	/* does spinlock_exit() */
 	}
 #ifdef KDTRACE_HOOKS
-	spin_time += lockstat_nsecs();
+	spin_time += lockstat_nsecs(&m->lock_object);
 #endif
 	if (m->mtx_recurse == 0)
 		LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_MTX_SPIN_LOCK_ACQUIRE,

Modified: stable/9/sys/kern/kern_rwlock.c
==============================================================================
--- stable/9/sys/kern/kern_rwlock.c	Tue Jul 21 17:16:37 2015	(r285759)
+++ stable/9/sys/kern/kern_rwlock.c	Tue Jul 21 17:19:03 2015	(r285760)
@@ -347,7 +347,7 @@ _rw_rlock(struct rwlock *rw, const char 
 	WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER, file, line, NULL);
 
 #ifdef KDTRACE_HOOKS
-	all_time -= lockstat_nsecs();
+	all_time -= lockstat_nsecs(&rw->lock_object);
 	state = rw->rw_lock;
 #endif
 	for (;;) {
@@ -488,11 +488,11 @@ _rw_rlock(struct rwlock *rw, const char 
 			CTR2(KTR_LOCK, "%s: %p blocking on turnstile", __func__,
 			    rw);
 #ifdef KDTRACE_HOOKS
-		sleep_time -= lockstat_nsecs();
+		sleep_time -= lockstat_nsecs(&rw->lock_object);
 #endif
 		turnstile_wait(ts, rw_owner(rw), TS_SHARED_QUEUE);
 #ifdef KDTRACE_HOOKS
-		sleep_time += lockstat_nsecs();
+		sleep_time += lockstat_nsecs(&rw->lock_object);
 		sleep_cnt++;
 #endif
 		if (LOCK_LOG_TEST(&rw->lock_object, 0))
@@ -500,7 +500,7 @@ _rw_rlock(struct rwlock *rw, const char 
 			    __func__, rw);
 	}
 #ifdef KDTRACE_HOOKS
-	all_time += lockstat_nsecs();
+	all_time += lockstat_nsecs(&rw->lock_object);
 	if (sleep_time)
 		LOCKSTAT_RECORD4(LS_RW_RLOCK_BLOCK, rw, sleep_time,
 		    LOCKSTAT_READER, (state & RW_LOCK_READ) == 0,
@@ -713,7 +713,7 @@ _rw_wlock_hard(struct rwlock *rw, uintpt
 		    rw->lock_object.lo_name, (void *)rw->rw_lock, file, line);
 
 #ifdef KDTRACE_HOOKS
-	all_time -= lockstat_nsecs();
+	all_time -= lockstat_nsecs(&rw->lock_object);
 	state = rw->rw_lock;
 #endif
 	while (!_rw_write_lock(rw, tid)) {
@@ -829,11 +829,11 @@ _rw_wlock_hard(struct rwlock *rw, uintpt
 			CTR2(KTR_LOCK, "%s: %p blocking on turnstile", __func__,
 			    rw);
 #ifdef KDTRACE_HOOKS
-		sleep_time -= lockstat_nsecs();
+		sleep_time -= lockstat_nsecs(&rw->lock_object);
 #endif
 		turnstile_wait(ts, rw_owner(rw), TS_EXCLUSIVE_QUEUE);
 #ifdef KDTRACE_HOOKS
-		sleep_time += lockstat_nsecs();
+		sleep_time += lockstat_nsecs(&rw->lock_object);
 		sleep_cnt++;
 #endif
 		if (LOCK_LOG_TEST(&rw->lock_object, 0))
@@ -844,7 +844,7 @@ _rw_wlock_hard(struct rwlock *rw, uintpt
 #endif
 	}
 #ifdef KDTRACE_HOOKS
-	all_time += lockstat_nsecs();
+	all_time += lockstat_nsecs(&rw->lock_object);
 	if (sleep_time)
 		LOCKSTAT_RECORD4(LS_RW_WLOCK_BLOCK, rw, sleep_time,
 		    LOCKSTAT_WRITER, (state & RW_LOCK_READ) == 0,

Modified: stable/9/sys/kern/kern_sx.c
==============================================================================
--- stable/9/sys/kern/kern_sx.c	Tue Jul 21 17:16:37 2015	(r285759)
+++ stable/9/sys/kern/kern_sx.c	Tue Jul 21 17:19:03 2015	(r285760)
@@ -540,7 +540,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t 
 		    sx->lock_object.lo_name, (void *)sx->sx_lock, file, line);
 
 #ifdef KDTRACE_HOOKS
-	all_time -= lockstat_nsecs();
+	all_time -= lockstat_nsecs(&sx->lock_object);
 	state = sx->sx_lock;
 #endif
 	while (!atomic_cmpset_acq_ptr(&sx->sx_lock, SX_LOCK_UNLOCKED, tid)) {
@@ -679,7 +679,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t 
 			    __func__, sx);
 
 #ifdef KDTRACE_HOOKS
-		sleep_time -= lockstat_nsecs();
+		sleep_time -= lockstat_nsecs(&sx->lock_object);
 #endif
 		GIANT_SAVE();
 		sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
@@ -690,7 +690,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t 
 		else
 			error = sleepq_wait_sig(&sx->lock_object, 0);
 #ifdef KDTRACE_HOOKS
-		sleep_time += lockstat_nsecs();
+		sleep_time += lockstat_nsecs(&sx->lock_object);
 		sleep_cnt++;
 #endif
 		if (error) {
@@ -705,7 +705,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t 
 			    __func__, sx);
 	}
 #ifdef KDTRACE_HOOKS
-	all_time += lockstat_nsecs();
+	all_time += lockstat_nsecs(&sx->lock_object);
 	if (sleep_time)
 		LOCKSTAT_RECORD4(LS_SX_XLOCK_BLOCK, sx, sleep_time,
 		    LOCKSTAT_WRITER, (state & SX_LOCK_SHARED) == 0,
@@ -816,7 +816,7 @@ _sx_slock_hard(struct sx *sx, int opts, 
 
 #ifdef KDTRACE_HOOKS
 	state = sx->sx_lock;
-	all_time -= lockstat_nsecs();
+	all_time -= lockstat_nsecs(&sx->lock_object);
 #endif
 
 	/*
@@ -938,7 +938,7 @@ _sx_slock_hard(struct sx *sx, int opts, 
 			    __func__, sx);
 
 #ifdef KDTRACE_HOOKS
-		sleep_time -= lockstat_nsecs();
+		sleep_time -= lockstat_nsecs(&sx->lock_object);
 #endif
 		GIANT_SAVE();
 		sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
@@ -949,7 +949,7 @@ _sx_slock_hard(struct sx *sx, int opts, 
 		else
 			error = sleepq_wait_sig(&sx->lock_object, 0);
 #ifdef KDTRACE_HOOKS
-		sleep_time += lockstat_nsecs();
+		sleep_time += lockstat_nsecs(&sx->lock_object);
 		sleep_cnt++;
 #endif
 		if (error) {
@@ -964,7 +964,7 @@ _sx_slock_hard(struct sx *sx, int opts, 
 			    __func__, sx);
 	}
 #ifdef KDTRACE_HOOKS
-	all_time += lockstat_nsecs();
+	all_time += lockstat_nsecs(&sx->lock_object);
 	if (sleep_time)
 		LOCKSTAT_RECORD4(LS_SX_SLOCK_BLOCK, sx, sleep_time,
 		    LOCKSTAT_READER, (state & SX_LOCK_SHARED) == 0,

Modified: stable/9/sys/sys/lockstat.h
==============================================================================
--- stable/9/sys/sys/lockstat.h	Tue Jul 21 17:16:37 2015	(r285759)
+++ stable/9/sys/sys/lockstat.h	Tue Jul 21 17:19:03 2015	(r285760)
@@ -149,11 +149,13 @@
  * The following must match the type definition of dtrace_probe.  It is
  * defined this way to avoid having to rely on CDDL code.
  */
+struct lock_object;
 extern uint32_t lockstat_probemap[LS_NPROBES];
 typedef void (*lockstat_probe_func_t)(uint32_t, uintptr_t arg0, uintptr_t arg1,
     uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
 extern lockstat_probe_func_t lockstat_probe_func;
-extern uint64_t lockstat_nsecs(void);
+extern uint64_t lockstat_nsecs(struct lock_object *);
+extern int lockstat_enabled;
 
 #ifdef	KDTRACE_HOOKS
 /*


More information about the svn-src-stable-9 mailing list