From e5c830a47d6178217ddc1e192e4c28a9c2857ec2 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 29 May 2006 16:50:06 +0000 Subject: [PATCH] Shortcut two common spinlock situations and don't bother KTR logging them. --- sys/kern/kern_spinlock.c | 13 ++++++++++++- sys/sys/spinlock2.h | 12 ++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_spinlock.c b/sys/kern/kern_spinlock.c index a1be17636a..13f4206948 100644 --- a/sys/kern/kern_spinlock.c +++ b/sys/kern/kern_spinlock.c @@ -29,7 +29,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_spinlock.c,v 1.5 2006/05/29 07:29:14 dillon Exp $ + * $DragonFly: src/sys/kern/kern_spinlock.c,v 1.6 2006/05/29 16:50:05 dillon Exp $ */ #include @@ -200,8 +200,19 @@ spin_lock_rd_contested(struct spinlock *mtx) globaldata_t gd = mycpu; int value = mtx->lock; + /* + * Shortcut the op if we can just set the cache bit. This case + * occurs when the last lock was an exclusive lock. + */ + while ((value & SPINLOCK_EXCLUSIVE) == 0) { + if (atomic_cmpset_int(&mtx->lock, value, value|gd->gd_cpumask)) + return; + value = mtx->lock; + } + exponential_init(&backoff, mtx); ++spinlocks_contested1; + logspin(beg, mtx, 'r'); while ((value & gd->gd_cpumask) == 0) { diff --git a/sys/sys/spinlock2.h b/sys/sys/spinlock2.h index 5a4f30d307..8e599655f9 100644 --- a/sys/sys/spinlock2.h +++ b/sys/sys/spinlock2.h @@ -29,7 +29,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/spinlock2.h,v 1.9 2006/05/21 20:23:27 dillon Exp $ + * $DragonFly: src/sys/sys/spinlock2.h,v 1.10 2006/05/29 16:50:06 dillon Exp $ */ #ifndef _SYS_SPINLOCK2_H_ @@ -92,7 +92,8 @@ spin_trylock_wr(struct spinlock *mtx) #endif /* - * Obtain an exclusive spinlock and return. + * Obtain an exclusive spinlock and return. Shortcut the case where the only + * cached read lock was from our own cpu (it can just be cleared). */ static __inline void spin_lock_wr_quick(globaldata_t gd, struct spinlock *mtx) @@ -103,8 +104,11 @@ spin_lock_wr_quick(globaldata_t gd, struct spinlock *mtx) ++gd->gd_spinlocks_wr; #ifdef SMP - if ((value = atomic_swap_int(&mtx->lock, SPINLOCK_EXCLUSIVE)) != 0) - spin_lock_wr_contested(mtx, value); + if ((value = atomic_swap_int(&mtx->lock, SPINLOCK_EXCLUSIVE)) != 0) { + value &= ~gd->gd_cpumask; + if (value) + spin_lock_wr_contested(mtx, value); + } #endif } -- 2.41.0