Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Jul 2015 17:16:38 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r285759 - in stable/10/sys: cddl/dev/lockstat kern sys
Message-ID:  <201507211716.t6LHGcx1058896@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Jul 21 17:16:37 2015
New Revision: 285759
URL: https://svnweb.freebsd.org/changeset/base/285759

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
  Approved by:	re (gjb)
  Tested by:	Jason Unovitch

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

Modified: stable/10/sys/cddl/dev/lockstat/lockstat.c
==============================================================================
--- stable/10/sys/cddl/dev/lockstat/lockstat.c	Tue Jul 21 17:14:24 2015	(r285758)
+++ stable/10/sys/cddl/dev/lockstat/lockstat.c	Tue Jul 21 17:16:37 2015	(r285759)
@@ -161,6 +161,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();
@@ -184,6 +186,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/10/sys/kern/kern_lockstat.c
==============================================================================
--- stable/10/sys/kern/kern_lockstat.c	Tue Jul 21 17:14:24 2015	(r285758)
+++ stable/10/sys/kern/kern_lockstat.c	Tue Jul 21 17:16:37 2015	(r285759)
@@ -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/10/sys/kern/kern_mutex.c
==============================================================================
--- stable/10/sys/kern/kern_mutex.c	Tue Jul 21 17:14:24 2015	(r285758)
+++ stable/10/sys/kern/kern_mutex.c	Tue Jul 21 17:16:37 2015	(r285759)
@@ -420,7 +420,7 @@ __mtx_lock_sleep(volatile uintptr_t *c, 
 		    "_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)) {
@@ -517,16 +517,16 @@ __mtx_lock_sleep(volatile uintptr_t *c, 
 		 * 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) {
@@ -604,7 +604,7 @@ _mtx_lock_spin_cookie(volatile 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)) {
 
@@ -624,7 +624,7 @@ _mtx_lock_spin_cookie(volatile 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))
@@ -634,7 +634,10 @@ _mtx_lock_spin_cookie(volatile 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 */
 
@@ -659,7 +662,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:
@@ -707,7 +710,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/10/sys/kern/kern_rwlock.c
==============================================================================
--- stable/10/sys/kern/kern_rwlock.c	Tue Jul 21 17:14:24 2015	(r285758)
+++ stable/10/sys/kern/kern_rwlock.c	Tue Jul 21 17:16:37 2015	(r285759)
@@ -379,7 +379,7 @@ __rw_rlock(volatile uintptr_t *c, const 
 	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 (;;) {
@@ -530,11 +530,11 @@ __rw_rlock(volatile uintptr_t *c, const 
 			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))
@@ -542,7 +542,7 @@ __rw_rlock(volatile uintptr_t *c, const 
 			    __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,
@@ -765,7 +765,7 @@ __rw_wlock_hard(volatile uintptr_t *c, u
 		    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)) {
@@ -891,11 +891,11 @@ __rw_wlock_hard(volatile uintptr_t *c, u
 			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))
@@ -906,7 +906,7 @@ __rw_wlock_hard(volatile uintptr_t *c, u
 #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/10/sys/kern/kern_sx.c
==============================================================================
--- stable/10/sys/kern/kern_sx.c	Tue Jul 21 17:14:24 2015	(r285758)
+++ stable/10/sys/kern/kern_sx.c	Tue Jul 21 17:16:37 2015	(r285759)
@@ -544,7 +544,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)) {
@@ -694,7 +694,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,
@@ -705,7 +705,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) {
@@ -720,7 +720,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,
@@ -831,7 +831,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
 
 	/*
@@ -958,7 +958,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,
@@ -969,7 +969,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) {
@@ -984,7 +984,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/10/sys/sys/lockstat.h
==============================================================================
--- stable/10/sys/sys/lockstat.h	Tue Jul 21 17:14:24 2015	(r285758)
+++ stable/10/sys/sys/lockstat.h	Tue Jul 21 17:16:37 2015	(r285759)
@@ -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
 /*



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