[haiku-commits] r35021 - in haiku/trunk: headers/private/kernel src/system/kernel

Author: bonefish
Date: 2010-01-11 23:13:11 +0100 (Mon, 11 Jan 2010)
New Revision: 35021
Changeset: http://dev.haiku-os.org/changeset/35021/haiku

Modified:
   haiku/trunk/headers/private/kernel/smp.h
   haiku/trunk/src/system/kernel/smp.cpp
Log:
* Inline {acquire,release}_spinlock(), when spinlock debugging is disabled.
* Use atomic_{and,or}() instead of atomic_set(), as there are no built-ins
  for the latter.


Modified: haiku/trunk/headers/private/kernel/smp.h
===================================================================
--- haiku/trunk/headers/private/kernel/smp.h    2010-01-11 22:10:12 UTC (rev 
35020)
+++ haiku/trunk/headers/private/kernel/smp.h    2010-01-11 22:13:11 UTC (rev 
35021)
@@ -62,8 +62,37 @@
 
 int smp_intercpu_int_handler(int32 cpu);
 
+void _acquire_spinlock(spinlock* lock);
+
 #ifdef __cplusplus
 }
 #endif
 
+
+// Unless spinlock debug features are enabled, try to inline
+// {acquire,release}_spinlock().
+#if !DEBUG_SPINLOCKS && !B_DEBUG_SPINLOCK_CONTENTION
+
+static inline void
+acquire_spinlock_inline(spinlock* lock)
+{
+       if (atomic_or((int32*)lock, 1) == 0)
+               return;
+       _acquire_spinlock(lock);
+}
+
+
+static inline void
+release_spinlock_inline(spinlock* lock)
+{
+       atomic_and((int32*)lock, 0);
+}
+
+
+#define acquire_spinlock(lock) acquire_spinlock_inline(lock)
+#define release_spinlock(lock) release_spinlock_inline(lock)
+
+#endif // !DEBUG_SPINLOCKS && !B_DEBUG_SPINLOCK_CONTENTION
+
+
 #endif /* KERNEL_SMP_H */

Modified: haiku/trunk/src/system/kernel/smp.cpp
===================================================================
--- haiku/trunk/src/system/kernel/smp.cpp       2010-01-11 22:10:12 UTC (rev 
35020)
+++ haiku/trunk/src/system/kernel/smp.cpp       2010-01-11 22:13:11 UTC (rev 
35021)
@@ -40,6 +40,10 @@
 #endif
 
 
+#undef acquire_spinlock
+#undef release_spinlock
+
+
 #define MSG_POOL_SIZE (SMP_MAX_CPUS * 4)
 
 // These macros define the number of unsuccessful iterations in
@@ -282,7 +286,7 @@
 
 
 void
-acquire_spinlock(spinlock *lock)
+_acquire_spinlock(spinlock *lock)
 {
 #if DEBUG_SPINLOCKS
        if (are_interrupts_enabled()) {
@@ -309,7 +313,7 @@
                                process_all_pending_ici(currentCPU);
                                PAUSE();
                        }
-                       if (atomic_set((int32 *)lock, 1) == 0)
+                       if (atomic_or((int32 *)lock, 1) == 0)
                                break;
                }
 
@@ -320,7 +324,7 @@
        } else {
 #if DEBUG_SPINLOCKS
                int32 oldValue;
-               oldValue = atomic_set((int32 *)lock, 1);
+               oldValue = atomic_or((int32 *)lock, 1);
                if (oldValue != 0) {
                        panic("acquire_spinlock: attempt to acquire lock %p 
twice on "
                                "non-SMP system (last caller: %p, value %ld)", 
lock,
@@ -363,13 +367,13 @@
                                PAUSE();
                        }
 
-                       if (atomic_set((int32 *)lock, 1) == 0)
+                       if (atomic_or((int32 *)lock, 1) == 0)
                                break;
                }
 #endif
        } else {
 #if DEBUG_SPINLOCKS
-               if (atomic_set((int32 *)lock, 1) != 0) {
+               if (atomic_or((int32 *)lock, 1) != 0) {
                        panic("acquire_spinlock_nocheck: attempt to acquire 
lock %p twice "
                                "on non-SMP system\n", lock);
                }
@@ -406,7 +410,7 @@
                                process_all_pending_ici(currentCPU);
                                PAUSE();
                        }
-                       if (atomic_set((int32 *)lock, 1) == 0)
+                       if (atomic_or((int32 *)lock, 1) == 0)
                                break;
                }
 
@@ -417,7 +421,7 @@
        } else {
 #if DEBUG_SPINLOCKS
                int32 oldValue;
-               oldValue = atomic_set((int32 *)lock, 1);
+               oldValue = atomic_or((int32 *)lock, 1);
                if (oldValue != 0) {
                        panic("acquire_spinlock_cpu(): attempt to acquire lock 
%p twice on "
                                "non-SMP system (last caller: %p, value %ld)", 
lock,
@@ -442,7 +446,7 @@
                        panic("release_spinlock: attempt to release lock %p 
with interrupts enabled\n", lock);
 #if B_DEBUG_SPINLOCK_CONTENTION
                {
-                       int32 count = atomic_set(&lock->lock, 0) - 1;
+                       int32 count = atomic_and(&lock->lock, 0) - 1;
                        if (count < 0) {
                                panic("release_spinlock: lock %p was already 
released\n", lock);
                        } else {
@@ -454,14 +458,14 @@
                        }
                }
 #else
-               if (atomic_set((int32 *)lock, 0) != 1)
+               if (atomic_and((int32 *)lock, 0) != 1)
                        panic("release_spinlock: lock %p was already 
released\n", lock);
 #endif
        } else {
 #if DEBUG_SPINLOCKS
                if (are_interrupts_enabled())
                        panic("release_spinlock: attempt to release lock %p 
with interrupts enabled\n", lock);
-               if (atomic_set((int32 *)lock, 0) != 1)
+               if (atomic_and((int32 *)lock, 0) != 1)
                        panic("release_spinlock: lock %p was already 
released\n", lock);
 #endif
 #if DEBUG_SPINLOCK_LATENCIES
@@ -1220,3 +1224,5 @@
        arch_cpu_memory_write_barrier();
 }
 
+
+#pragma weak acquire_spinlock=_acquire_spinlock


Other related posts:

  • » [haiku-commits] r35021 - in haiku/trunk: headers/private/kernel src/system/kernel - ingo_weinhold