Module: xenomai-gch
Branch: for-forge
Commit: 75431f17f45f61425de7e4c809536f11722eb4d2
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=75431f17f45f61425de7e4c809536f11722eb4d2

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Oct 19 21:43:37 2014 +0200

cobalt/spinlocks: rebase on linux spinlocks

---

 include/cobalt/kernel/lock.h |   35 ++++++++++++++++++-----------------
 kernel/cobalt/debug.c        |    2 +-
 kernel/cobalt/lock.c         |   15 ---------------
 3 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/include/cobalt/kernel/lock.h b/include/cobalt/kernel/lock.h
index b0c34bf..e590b85 100644
--- a/include/cobalt/kernel/lock.h
+++ b/include/cobalt/kernel/lock.h
@@ -66,7 +66,8 @@ typedef unsigned long spl_t;
 #if XENO_DEBUG(LOCKING)
 
 struct xnlock {
-       atomic_t owner;
+       unsigned owner;
+       arch_spinlock_t alock;
        const char *file;
        const char *function;
        unsigned int line;
@@ -84,7 +85,8 @@ struct xnlockinfo {
 };
 
 #define XNARCH_LOCK_UNLOCKED (struct xnlock) { \
-       { ~0 },                                 \
+       ~0,                                     \
+       __ARCH_SPIN_LOCK_UNLOCKED,              \
        NULL,                                   \
        NULL,                                   \
        0,                                      \
@@ -117,10 +119,15 @@ DECLARE_PER_CPU(struct xnlockinfo, xnlock_stats);
 #else /* !XENO_DEBUG(LOCKING) */
 
 struct xnlock {
-       atomic_t owner;
+       unsigned owner;
+       arch_spinlock_t alock;
 };
 
-#define XNARCH_LOCK_UNLOCKED           (struct xnlock) { { ~0 } }
+#define XNARCH_LOCK_UNLOCKED                   \
+       (struct xnlock) {                       \
+               ~0,                             \
+               __ARCH_SPIN_LOCK_UNLOCKED,      \
+       }
 
 #define XNLOCK_DBG_CONTEXT
 #define XNLOCK_DBG_CONTEXT_ARGS
@@ -175,20 +182,18 @@ static inline void xnlock_init (struct xnlock *lock)
 #define DEFINE_XNLOCK(lock)            struct xnlock lock = 
XNARCH_LOCK_UNLOCKED
 #define DEFINE_PRIVATE_XNLOCK(lock)    static DEFINE_XNLOCK(lock)
 
-void __xnlock_spin(int cpu, struct xnlock *lock /*, */ 
XNLOCK_DBG_CONTEXT_ARGS);
-
 static inline int ____xnlock_get(struct xnlock *lock /*, */ 
XNLOCK_DBG_CONTEXT_ARGS)
 {
        int cpu = ipipe_processor_id();
        unsigned long long start;
 
-       if (atomic_read(&lock->owner) == cpu)
+       if (lock->owner == cpu)
                return 2;
 
        xnlock_dbg_prepare_acquire(&start);
 
-       if (unlikely(atomic_cmpxchg(&lock->owner, ~0, cpu) != ~0))
-               __xnlock_spin(cpu, lock /*, */ XNLOCK_DBG_PASS_CONTEXT);
+       arch_spin_lock(&lock->alock);
+       lock->owner = cpu;
 
        xnlock_dbg_acquired(lock, cpu, &start /*, */ XNLOCK_DBG_PASS_CONTEXT);
 
@@ -200,12 +205,8 @@ static inline void ____xnlock_put(struct xnlock *lock /*, 
*/ XNLOCK_DBG_CONTEXT_
        if (xnlock_dbg_release(lock /*, */ XNLOCK_DBG_PASS_CONTEXT))
                return;
 
-       /*
-        * Make sure all data written inside the lock is visible to
-        * other CPUs before we release the lock.
-        */
-       mb();
-       atomic_set(&lock->owner, ~0);
+       lock->owner = ~0U;
+       arch_spin_unlock(&lock->alock);
 }
 
 #ifndef CONFIG_XENO_ARCH_OUTOFLINE_XNLOCK
@@ -250,7 +251,7 @@ static inline void __xnlock_put_irqrestore(struct xnlock 
*lock, spl_t flags
 static inline int xnlock_is_owner(struct xnlock *lock)
 {
        if (__locking_active__)
-               return atomic_read(&lock->owner) == ipipe_processor_id();
+               return lock->owner == ipipe_processor_id();
 
        return 1;
 }
@@ -266,7 +267,7 @@ static inline int __xnlock_get(struct xnlock *lock /*, */ 
XNLOCK_DBG_CONTEXT_ARG
 static inline void __xnlock_put(struct xnlock *lock /*, */ 
XNLOCK_DBG_CONTEXT_ARGS)
 {
        if (__locking_active__)
-               ___xnlock_put(lock /*, */ XNLOCK_DBG_PASS_CONTEXT);     
+               ___xnlock_put(lock /*, */ XNLOCK_DBG_PASS_CONTEXT);
 }
 
 #undef __locking_active__
diff --git a/kernel/cobalt/debug.c b/kernel/cobalt/debug.c
index ad72a3e..ef46e0b 100644
--- a/kernel/cobalt/debug.c
+++ b/kernel/cobalt/debug.c
@@ -598,7 +598,7 @@ int xnlock_dbg_release(struct xnlock *lock,
                lock->function = "invalid";
        }
 
-       if (unlikely(atomic_read(&lock->owner) != cpu)) {
+       if (unlikely(lock->owner != cpu)) {
                ipipe_prepare_panic();
                printk(XENO_ERR "lock %p already unlocked on CPU #%d\n"
                                "          last owner = %s:%u (%s(), CPU 
#%d)\n",
diff --git a/kernel/cobalt/lock.c b/kernel/cobalt/lock.c
index 5c339b5..a1b2e37 100644
--- a/kernel/cobalt/lock.c
+++ b/kernel/cobalt/lock.c
@@ -42,21 +42,6 @@ DEFINE_XNLOCK(nklock);
 #if defined(CONFIG_SMP) || XENO_DEBUG(LOCKING)
 EXPORT_SYMBOL_GPL(nklock);
 
-void __xnlock_spin(int cpu, struct xnlock *lock /*, */ XNLOCK_DBG_CONTEXT_ARGS)
-{
-       unsigned int spin_limit;
-
-       xnlock_dbg_prepare_spin(&spin_limit);
-
-       while (atomic_cmpxchg(&lock->owner, ~0, cpu) != ~0)
-               do {
-                       cpu_relax();
-                       xnlock_dbg_spinning(lock, cpu, &spin_limit /*, */
-                                           XNLOCK_DBG_PASS_CONTEXT);
-               } while(atomic_read(&lock->owner) != ~0);
-}
-EXPORT_SYMBOL_GPL(__xnlock_spin);
-
 #ifdef CONFIG_XENO_ARCH_OUTOFLINE_XNLOCK
 int ___xnlock_get(struct xnlock *lock /*, */ XNLOCK_DBG_CONTEXT_ARGS)
 {


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to