[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] spinlock: Modify recursive spinlock definitions to support up to 4095 CPUs.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1224519405 -3600
# Node ID 54d74fc0037ce688e79759ca632d3918f7aaa399
# Parent  f4dab783b58b41f2c67a66d6d095887faec3c296
spinlock: Modify recursive spinlock definitions to support up to 4095 CPUs.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 xen/common/spinlock.c      |    9 ++++++++-
 xen/include/xen/spinlock.h |    6 +++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff -r f4dab783b58b -r 54d74fc0037c xen/common/spinlock.c
--- a/xen/common/spinlock.c     Mon Oct 20 16:49:25 2008 +0100
+++ b/xen/common/spinlock.c     Mon Oct 20 17:16:45 2008 +0100
@@ -57,11 +57,18 @@ void _spin_lock_recursive(spinlock_t *lo
 void _spin_lock_recursive(spinlock_t *lock)
 {
     int cpu = smp_processor_id();
+
+    /* Don't allow overflow of recurse_cpu field. */
+    BUILD_BUG_ON(NR_CPUS > 0xfffu);
+
     if ( likely(lock->recurse_cpu != cpu) )
     {
         spin_lock(lock);
         lock->recurse_cpu = cpu;
     }
+
+    /* We support only fairly shallow recursion, else the counter overflows. */
+    ASSERT(lock->recurse_cnt < 0xfu);
     lock->recurse_cnt++;
 }
 
@@ -69,7 +76,7 @@ void _spin_unlock_recursive(spinlock_t *
 {
     if ( likely(--lock->recurse_cnt == 0) )
     {
-        lock->recurse_cpu = -1;
+        lock->recurse_cpu = 0xfffu;
         spin_unlock(lock);
     }
 }
diff -r f4dab783b58b -r 54d74fc0037c xen/include/xen/spinlock.h
--- a/xen/include/xen/spinlock.h        Mon Oct 20 16:49:25 2008 +0100
+++ b/xen/include/xen/spinlock.h        Mon Oct 20 17:16:45 2008 +0100
@@ -7,11 +7,11 @@
 
 typedef struct {
     raw_spinlock_t raw;
-    s8 recurse_cpu;
-    u8 recurse_cnt;
+    u16 recurse_cpu:12;
+    u16 recurse_cnt:4;
 } spinlock_t;
 
-#define SPIN_LOCK_UNLOCKED { _RAW_SPIN_LOCK_UNLOCKED, -1, 0 }
+#define SPIN_LOCK_UNLOCKED { _RAW_SPIN_LOCK_UNLOCKED, 0xfffu, 0 }
 #define DEFINE_SPINLOCK(l) spinlock_t l = SPIN_LOCK_UNLOCKED
 #define spin_lock_init(l) (*(l) = (spinlock_t)SPIN_LOCK_UNLOCKED)
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.