kernel -- Add pool spinlocks interface.
authorVenkatesh Srinivas <me@endeavour.zapto.org>
Thu, 6 Oct 2011 01:40:03 +0000 (18:40 -0700)
committerVenkatesh Srinivas <me@endeavour.zapto.org>
Thu, 6 Oct 2011 01:40:03 +0000 (18:40 -0700)
sys/kern/kern_spinlock.c
sys/sys/spinlock2.h

index 6afc8d7..e5a2c4b 100644 (file)
@@ -96,6 +96,9 @@ SYSCTL_INT(_debug, OID_AUTO, spinlocks_bolim, CTLFLAG_RW,
     &spinlocks_backoff_limit, 0,
     "Contested spinlock backoff limit");
 
+#define SPINLOCK_NUM_POOL      (1024)
+static struct spinlock pool_spinlocks[SPINLOCK_NUM_POOL];
+
 struct exponential_backoff {
        int backoff;
        int nsec;
@@ -155,6 +158,35 @@ spin_lock_wr_contested2(struct spinlock *mtx)
        logspin(end, mtx, 'w');
 }
 
+static __inline int
+_spin_pool_hash(void *ptr)
+{
+       int i;
+       i = ((int) (uintptr_t) ptr >> 2) ^ ((int) (uintptr_t) ptr >> 12);
+       i &= (SPINLOCK_NUM_POOL - 1);
+       return (i);
+}
+
+struct spinlock *
+spin_pool_lock(void *chan)
+{
+       struct spinlock *sp;
+
+       sp = &pool_spinlocks[_spin_pool_hash(chan)];
+       spin_lock(sp);
+
+       return (sp);
+}
+
+void
+spin_pool_unlock(void *chan)
+{
+       struct spinlock *sp;
+
+       sp = &pool_spinlocks[_spin_pool_hash(chan)];
+       spin_unlock(sp);
+}
+
 /*
  * Handle exponential backoff and indefinite waits.
  *
index 1f1c196..4d56608 100644 (file)
@@ -191,6 +191,9 @@ spin_uninit(struct spinlock *mtx)
        /* unused */
 }
 
+struct spinlock *spin_pool_lock(void *);
+void spin_pool_unlock(void *);
+
 #endif /* _KERNEL */
 #endif /* _SYS_SPINLOCK2_H_ */