[Xenomai-git] Gilles Chanteperdrix : cobalt/spinlocks: rebase on linux spinlocks

2014-10-19 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: ddf709785b96115f7803fab3363fe1805323b7fa
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=ddf709785b96115f7803fab3363fe1805323b7fa

Author: Gilles Chanteperdrix 
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_li

[Xenomai-git] Gilles Chanteperdrix : lib/cobalt: wrap time and gettimeofday calls

2014-10-19 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: 7b891e43a22f939a5010d975984f4f6d87c2eda4
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=7b891e43a22f939a5010d975984f4f6d87c2eda4

Author: Gilles Chanteperdrix 
Date:   Sat Sep 20 23:06:02 2014 +0200

lib/cobalt: wrap time and gettimeofday calls

---

 include/cobalt/time.h   |2 ++
 lib/cobalt/assert_context.c |7 ---
 lib/cobalt/clock.c  |   23 +++
 lib/cobalt/cobalt.wrappers  |2 ++
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/time.h b/include/cobalt/time.h
index c5d7412..fed8957 100644
--- a/include/cobalt/time.h
+++ b/include/cobalt/time.h
@@ -44,6 +44,8 @@ COBALT_DECL(int, clock_nanosleep(clockid_t clock_id,
 const struct timespec *rqtp,
 struct timespec *rmtp));
 
+COBALT_DECL(time_t, time(time_t *t));
+
 COBALT_DECL(int, nanosleep(const struct timespec *rqtp,
   struct timespec *rmtp));
 
diff --git a/lib/cobalt/assert_context.c b/lib/cobalt/assert_context.c
index 6b49f3d..48690dc 100644
--- a/lib/cobalt/assert_context.c
+++ b/lib/cobalt/assert_context.c
@@ -75,10 +75,3 @@ COBALT_IMPL(void, free, (void *ptr))
assert_nrt();
__STD(free(ptr));
 }
-
-/* vsyscall-based services */
-COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
-{
-   assert_nrt();
-   return __STD(gettimeofday(tv, tz));
-}
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 501cdec..b35dfd4 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -356,4 +357,26 @@ COBALT_IMPL(unsigned int, sleep, (unsigned int seconds))
return 0;
 }
 
+COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
+{
+   struct timespec ts;
+   int ret = __WRAP(clock_gettime(CLOCK_REALTIME, &ts));
+   if (ret == 0) {
+   tv->tv_sec = ts.tv_sec;
+   tv->tv_usec = ts.tv_nsec / 1000;
+   }
+   return ret;
+}
+
+COBALT_IMPL(time_t, time, (time_t *t))
+{
+   struct timespec ts;
+   int ret = __WRAP(clock_gettime(CLOCK_REALTIME, &ts));
+   if (ret)
+   return (time_t)-1;
+
+   if (t)
+   *t = ts.tv_sec;
+   return ts.tv_sec;
+}
 /** @} */
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 10cb36a..b8c9942 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -104,3 +104,5 @@
 --wrap kill
 --wrap sleep
 --wrap mmap
+--wrap gettimeofday
+--wrap time


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


[Xenomai-git] Gilles Chanteperdrix : spinlocks: rebase on linux spinlocks

2014-10-19 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: c7e66bb9ec28875c0fffefaf4c2b512f979a68c3
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=c7e66bb9ec28875c0fffefaf4c2b512f979a68c3

Author: Gilles Chanteperdrix 
Date:   Sun Oct 19 21:43:37 2014 +0200

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;
-