From ae7d25a4d736392ecf325f3f1386d405e572e830 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 17 Nov 2017 02:22:51 +0000 Subject: [PATCH] locks: pull up PMC_SOFT_CALLs out of slow path loops --- sys/kern/kern_rwlock.c | 23 +++++++++++++---------- sys/kern/kern_sx.c | 23 ++++++++++++----------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 61535962d14f..78b5f428073a 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -443,6 +443,12 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *td, uintptr_t v, #endif rw = rwlock2rw(c); +#ifdef HWPMC_HOOKS + PMC_SOFT_CALL( , , lock, failed); +#endif + lock_profile_obtain_lock_failed(&rw->lock_object, + &contested, &waittime); + #ifdef LOCK_PROFILING doing_lockprof = 1; state = v; @@ -460,11 +466,6 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *td, uintptr_t v, #ifdef KDTRACE_HOOKS lda.spin_cnt++; #endif -#ifdef HWPMC_HOOKS - PMC_SOFT_CALL( , , lock, failed); -#endif - lock_profile_obtain_lock_failed(&rw->lock_object, - &contested, &waittime); #ifdef ADAPTIVE_RWLOCKS /* @@ -890,6 +891,12 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, CTR5(KTR_LOCK, "%s: %s contested (lock=%p) at %s:%d", __func__, rw->lock_object.lo_name, (void *)rw->rw_lock, file, line); +#ifdef HWPMC_HOOKS + PMC_SOFT_CALL( , , lock, failed); +#endif + lock_profile_obtain_lock_failed(&rw->lock_object, + &contested, &waittime); + #ifdef LOCK_PROFILING doing_lockprof = 1; state = v; @@ -910,11 +917,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, #ifdef KDTRACE_HOOKS lda.spin_cnt++; #endif -#ifdef HWPMC_HOOKS - PMC_SOFT_CALL( , , lock, failed); -#endif - lock_profile_obtain_lock_failed(&rw->lock_object, - &contested, &waittime); + #ifdef ADAPTIVE_RWLOCKS /* * If the lock is write locked and the owner is diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index 7e7c0b0962f6..f3f38cfd996c 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -551,6 +551,12 @@ _sx_xlock_hard(struct sx *sx, uintptr_t x, uintptr_t tid, int opts, CTR5(KTR_LOCK, "%s: %s contested (lock=%p) at %s:%d", __func__, sx->lock_object.lo_name, (void *)sx->sx_lock, file, line); +#ifdef HWPMC_HOOKS + PMC_SOFT_CALL( , , lock, failed); +#endif + lock_profile_obtain_lock_failed(&sx->lock_object, &contested, + &waittime); + #ifdef LOCK_PROFILING extra_work = 1; state = x; @@ -571,11 +577,6 @@ _sx_xlock_hard(struct sx *sx, uintptr_t x, uintptr_t tid, int opts, #ifdef KDTRACE_HOOKS lda.spin_cnt++; #endif -#ifdef HWPMC_HOOKS - PMC_SOFT_CALL( , , lock, failed); -#endif - lock_profile_obtain_lock_failed(&sx->lock_object, &contested, - &waittime); #ifdef ADAPTIVE_SX /* * If the lock is write locked and the owner is @@ -889,6 +890,12 @@ _sx_slock_hard(struct sx *sx, int opts, const char *file, int line, uintptr_t x) lock_delay_arg_init(&lda, NULL); #endif +#ifdef HWPMC_HOOKS + PMC_SOFT_CALL( , , lock, failed); +#endif + lock_profile_obtain_lock_failed(&sx->lock_object, &contested, + &waittime); + #ifdef LOCK_PROFILING extra_work = 1; state = x; @@ -911,12 +918,6 @@ _sx_slock_hard(struct sx *sx, int opts, const char *file, int line, uintptr_t x) lda.spin_cnt++; #endif -#ifdef HWPMC_HOOKS - PMC_SOFT_CALL( , , lock, failed); -#endif - lock_profile_obtain_lock_failed(&sx->lock_object, &contested, - &waittime); - #ifdef ADAPTIVE_SX /* * If the owner is running on another CPU, spin until