Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Nov 2017 02:21:24 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325918 - head/sys/kern
Message-ID:  <201711170221.vAH2LOR0042850@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Fri Nov 17 02:21:24 2017
New Revision: 325918
URL: https://svnweb.freebsd.org/changeset/base/325918

Log:
  rwlock: avoid branches in the slow path if lockstat is disabled

Modified:
  head/sys/kern/kern_rwlock.c

Modified: head/sys/kern/kern_rwlock.c
==============================================================================
--- head/sys/kern/kern_rwlock.c	Fri Nov 17 02:21:07 2017	(r325917)
+++ head/sys/kern/kern_rwlock.c	Fri Nov 17 02:21:24 2017	(r325918)
@@ -424,11 +424,14 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *
 	struct lock_delay_arg lda;
 #endif
 #ifdef KDTRACE_HOOKS
-	uintptr_t state;
 	u_int sleep_cnt = 0;
 	int64_t sleep_time = 0;
 	int64_t all_time = 0;
 #endif
+#if defined(KDTRACE_HOOKS) || defined(LOCK_PROFILING)
+	uintptr_t state;
+	int doing_lockprof;
+#endif
 
 	if (SCHEDULER_STOPPED())
 		return;
@@ -440,12 +443,17 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *
 #endif
 	rw = rwlock2rw(c);
 
-#ifdef KDTRACE_HOOKS
-	all_time -= lockstat_nsecs(&rw->lock_object);
-#endif
-#ifdef KDTRACE_HOOKS
+#ifdef LOCK_PROFILING
+	doing_lockprof = 1;
 	state = v;
+#elif defined(KDTRACE_HOOKS)
+	doing_lockprof = lockstat_enabled;
+	if (__predict_false(doing_lockprof)) {
+		all_time -= lockstat_nsecs(&rw->lock_object);
+		state = v;
+	}
 #endif
+
 	for (;;) {
 		if (__rw_rlock_try(rw, td, &v, file, line))
 			break;
@@ -583,6 +591,10 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *
 			    __func__, rw);
 		v = RW_READ_VALUE(rw);
 	}
+#if defined(KDTRACE_HOOKS) || defined(LOCK_PROFILING)
+	if (__predict_true(!doing_lockprof))
+		return;
+#endif
 #ifdef KDTRACE_HOOKS
 	all_time += lockstat_nsecs(&rw->lock_object);
 	if (sleep_time)



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