Module: xenomai-forge
Branch: next
Commit: 577d8569826a990d93aca21d102a3c4a29caafac
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=577d8569826a990d93aca21d102a3c4a29caafac

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jun 14 15:46:18 2013 +0200

cobalt: move TSC read helper to dedicated header

---

 include/asm-arm/Makefile.am        |    1 +
 include/asm-arm/bits/bind.h        |    4 +-
 include/asm-arm/syscall.h          |  113 +-----------------------------
 include/asm-arm/tsc.h              |  136 ++++++++++++++++++++++++++++++++++++
 include/asm-blackfin/Makefile.am   |    1 +
 include/asm-blackfin/syscall.h     |   48 ++++---------
 include/asm-blackfin/tsc.h         |   50 +++++++++++++
 include/asm-nios2/Makefile.am      |    1 +
 include/asm-nios2/syscall.h        |   53 +--------------
 include/asm-nios2/tsc.h            |   79 +++++++++++++++++++++
 include/asm-powerpc/Makefile.am    |    1 +
 include/asm-powerpc/syscall.h      |   27 +-------
 include/asm-powerpc/tsc.h          |   54 ++++++++++++++
 include/asm-sh/Makefile.am         |    1 +
 include/asm-sh/syscall.h           |   35 +---------
 include/asm-sh/tsc.h               |   60 ++++++++++++++++
 include/asm-x86/Makefile.am        |    1 +
 include/asm-x86/syscall.h          |   17 +----
 include/asm-x86/tsc.h              |   43 +++++++++++
 include/copperplate/clockobj.h     |    1 +
 kernel/cobalt/arch/arm/syscall.c   |   12 +---
 lib/cobalt/assert_context.c        |    2 +-
 lib/cobalt/clock.c                 |    1 +
 testsuite/regression/posix/leaks.c |    1 +
 24 files changed, 459 insertions(+), 283 deletions(-)

diff --git a/include/asm-arm/Makefile.am b/include/asm-arm/Makefile.am
index 23c0f0d..17f9488 100644
--- a/include/asm-arm/Makefile.am
+++ b/include/asm-arm/Makefile.am
@@ -8,6 +8,7 @@ includesub_HEADERS =    \
        fptest.h        \
        machine.h       \
        syscall.h       \
+       tsc.h           \
        thread.h        \
        wrappers.h
 
diff --git a/include/asm-arm/bits/bind.h b/include/asm-arm/bits/bind.h
index 09e2366..48930f3 100644
--- a/include/asm-arm/bits/bind.h
+++ b/include/asm-arm/bits/bind.h
@@ -47,8 +47,8 @@ static inline void xeno_arm_features_check(struct xnfeatinfo 
*finfo)
 #if CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_KUSER
        default:
                __xn_tscinfo.kuser_tsc_get =
-                       (rdtsc_t *)(0xffff1004 -
-                                   ((*(unsigned *)(0xffff0ffc) + 3) << 5));
+                       (__xn_rdtsc_t *)(0xffff1004 -
+                                        ((*(unsigned *)(0xffff0ffc) + 3) << 
5));
                goto domap;
 
 #elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING            \
diff --git a/include/asm-arm/syscall.h b/include/asm-arm/syscall.h
index 4a03e23..6a7decc 100644
--- a/include/asm-arm/syscall.h
+++ b/include/asm-arm/syscall.h
@@ -4,9 +4,6 @@
  * ARM port
  *   Copyright (C) 2005 Stelian Pop
  *
- * Copyright (C) 2007 Sebastian Smolorz <se...@gmx.net>
- *     Support for TSC emulation in user space for decrementing counters
- *
  * Xenomai is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
  * by the Free Software Foundation; either version 2 of the License,
@@ -28,6 +25,7 @@
 
 #include <asm-generic/xenomai/syscall.h>
 #include <asm/xenomai/features.h>
+#include <asm/xenomai/tsc.h>
 
 #define __xn_mux_code(shifted_id,op) ((op << 24)|shifted_id|(sc_nucleus_mux & 
0xffff))
 #define __xn_mux_shifted_id(id) ((id << 16) & 0xff0000)
@@ -226,10 +224,6 @@ int xnarch_local_syscall(unsigned long a1, unsigned long 
a2,
 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5)                \
        XENOMAI_DO_SYSCALL(5,id,op,a1,a2,a3,a4,a5)
 
-#ifdef CONFIG_XENO_ARM_TSC_TYPE
-#define XNARCH_HAVE_NONPRIV_TSC  1
-#endif /* CONFIG_XENO_ARM_TSC_TYPE */
-
 #endif /* __KERNEL__ */
 
 #define XENOMAI_SYSARCH_ATOMIC_ADD_RETURN      0
@@ -238,109 +232,4 @@ int xnarch_local_syscall(unsigned long a1, unsigned long 
a2,
 #define XENOMAI_SYSARCH_XCHG                   3
 #define XENOMAI_SYSARCH_TSCINFO                 4
 
-typedef unsigned long long __xn_rdtsc_t(volatile unsigned int *);
-
-struct __xn_tscinfo {
-       int type;               /* Must remain first member */
-       unsigned int mask;
-       volatile unsigned int *counter;
-       volatile unsigned int *last_cnt; /* Only used by decrementers */
-       volatile unsigned long long *tsc;
-};
-
-#ifndef __KERNEL__
-/*
- *  Putting kuser_tsc_get and kinfo.counter in the same struct results
- * in less operations in PIC code, thus optimizes.
- */
-typedef unsigned long long rdtsc_t(volatile unsigned int *vaddr);
-struct __xn_full_tscinfo {
-       struct __xn_tscinfo kinfo;
-       rdtsc_t *kuser_tsc_get;
-};
-extern struct __xn_full_tscinfo __xn_tscinfo;
-
-#ifdef CONFIG_XENO_ARM_TSC_TYPE
-static inline unsigned long long __xn_rdtsc(void)
-{
-#if CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_KUSER
-       return __xn_tscinfo.kuser_tsc_get(__xn_tscinfo.kinfo.counter);
-
-#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING
-       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
-       volatile unsigned *const counterp = __xn_tscinfo.kinfo.counter;
-       const unsigned mask = __xn_tscinfo.kinfo.mask;
-       register unsigned long long result;
-       unsigned counter;
-
-       __asm__ ("ldmia %1, %M0\n": "=r"(result): "r"(tscp), "m"(*tscp));
-       __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
-       counter = *counterp;
-
-       if ((counter & mask) < ((unsigned) result & mask))
-               result += mask + 1ULL;
-       return (result & ~((unsigned long long) mask)) | (counter & mask);
-
-#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING_COUNTDOWN
-       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
-       volatile unsigned *const counterp = __xn_tscinfo.kinfo.counter;
-       const unsigned mask = __xn_tscinfo.kinfo.mask;
-       register unsigned long long result;
-       unsigned counter;
-
-       __asm__ ("ldmia %1, %M0\n": "=r"(result): "r"(tscp), "m"(*tscp));
-       __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
-       counter = mask - *counterp;
-
-       if ((counter & mask) > ((unsigned) result & mask))
-               result += mask + 1ULL;
-       return (result & ~((unsigned long long) mask)) | (counter & mask);
-
-#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING_FAST_WRAP
-       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
-       volatile unsigned *const counterp = __xn_tscinfo.kinfo.counter;
-       const unsigned mask = __xn_tscinfo.kinfo.mask;
-       register unsigned long long after, before;
-       unsigned counter;
-
-       __asm__ ("ldmia %1, %M0\n": "=r"(after): "r"(tscp), "m"(*tscp));
-       do {
-               before = after;
-               counter = *counterp;
-               __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
-               __asm__ ("ldmia %1, %M0\n" : "=r"(after): "r"(tscp), 
"m"(*tscp));
-       } while (((unsigned) after) != ((unsigned) before));
-       if ((counter & mask) < ((unsigned) before & mask))
-               before += mask + 1;
-       return (before & ~((unsigned long long) mask)) | (counter & mask);
-
-#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_DECREMENTER
-       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
-       volatile unsigned *const counterp = __xn_tscinfo.kinfo.counter;
-       volatile unsigned *const last_cntp = __xn_tscinfo.kinfo.last_cnt;
-       const unsigned mask = __xn_tscinfo.kinfo.mask;
-       register unsigned long long after, before;
-       unsigned counter, last_cnt;
-
-       __asm__ ("ldmia %1, %M0\n": "=r"(after): "r"(tscp), "m"(*tscp));
-       do {
-               before = after;
-               counter = *counterp;
-               last_cnt = *last_cntp;
-               /* compiler barrier. */
-               __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
-               __asm__ ("ldmia %1, %M0\n": "=r"(after): "r"(tscp), "m"(*tscp));
-       } while (after != before);
-
-       counter &= mask;
-       last_cnt &= mask;
-       if (counter > last_cnt)
-               before += mask + 1ULL;
-       return (before + last_cnt - counter);
-
-#endif /* CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_DECREMENTER */
-}
-#endif /* CONFIG_XENO_ARM_TSC_TYPE */
-#endif /* !__KERNEL__ */
-
 #endif /* !_XENO_ASM_ARM_SYSCALL_H */
diff --git a/include/asm-arm/tsc.h b/include/asm-arm/tsc.h
new file mode 100644
index 0000000..c80e560
--- /dev/null
+++ b/include/asm-arm/tsc.h
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2001,2002,2003,2004 Philippe Gerum <r...@xenomai.org>.
+ * Copyright (C) 2013 Gilles Chanteperdrix <g...@xenomai.org>.
+ *
+ * ARM port
+ *   Copyright (C) 2005 Stelian Pop
+ *
+ * Copyright (C) 2007 Sebastian Smolorz <se...@gmx.net>
+ *     Support for TSC emulation in user space for decrementing counters
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_ARM_TSC_H
+#define _XENO_ASM_ARM_TSC_H
+
+#include <asm/xenomai/features.h>
+
+struct __xn_tscinfo {
+       int type;               /* Must remain first member */
+       unsigned mask;
+       volatile unsigned int *counter;
+       volatile unsigned int *last_cnt; /* Only used by decrementers */
+       volatile unsigned long long *tsc;
+};
+
+#ifndef __KERNEL__
+/*
+ * Putting kuser_tsc_get and kinfo.counter in the same struct results
+ * in less operations in PIC code, thus optimizes.
+ */
+typedef unsigned long long __xn_rdtsc_t(volatile unsigned *vaddr);
+struct __xn_full_tscinfo {
+       struct __xn_tscinfo kinfo;
+       __xn_rdtsc_t *kuser_tsc_get;
+};
+extern struct __xn_full_tscinfo __xn_tscinfo;
+
+#ifdef CONFIG_XENO_ARM_TSC_TYPE
+static inline unsigned long long __xn_rdtsc(void)
+{
+#if CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_KUSER
+       return __xn_tscinfo.kuser_tsc_get(__xn_tscinfo.kinfo.counter);
+
+#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING
+       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
+       volatile unsigned int *const counterp = __xn_tscinfo.kinfo.counter;
+       const unsigned int mask = __xn_tscinfo.kinfo.mask;
+       register unsigned long long result;
+       unsigned int counter;
+
+       __asm__ ("ldmia %1, %M0\n": "=r"(result): "r"(tscp), "m"(*tscp));
+       __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
+       counter = *counterp;
+
+       if ((counter & mask) < ((unsigned) result & mask))
+               result += mask + 1ULL;
+       return (result & ~((unsigned long long) mask)) | (counter & mask);
+
+#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING_COUNTDOWN
+       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
+       volatile unsigned int *const counterp = __xn_tscinfo.kinfo.counter;
+       const unsigned int mask = __xn_tscinfo.kinfo.mask;
+       register unsigned long long result;
+       unsigned int counter;
+
+       __asm__ ("ldmia %1, %M0\n": "=r"(result): "r"(tscp), "m"(*tscp));
+       __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
+       counter = mask - *counterp;
+
+       if ((counter & mask) > ((unsigned) result & mask))
+               result += mask + 1ULL;
+       return (result & ~((unsigned long long) mask)) | (counter & mask);
+
+#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING_FAST_WRAP
+       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
+       volatile unsigned int *const counterp = __xn_tscinfo.kinfo.counter;
+       const unsigned int mask = __xn_tscinfo.kinfo.mask;
+       register unsigned long long after, before;
+       unsigned int counter;
+
+       __asm__ ("ldmia %1, %M0\n": "=r"(after): "r"(tscp), "m"(*tscp));
+       do {
+               before = after;
+               counter = *counterp;
+               __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
+               __asm__ ("ldmia %1, %M0\n" : "=r"(after): "r"(tscp), 
"m"(*tscp));
+       } while (((unsigned) after) != ((unsigned) before));
+       if ((counter & mask) < ((unsigned) before & mask))
+               before += mask + 1;
+       return (before & ~((unsigned long long) mask)) | (counter & mask);
+
+#elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_DECREMENTER
+       volatile unsigned long long *const tscp = __xn_tscinfo.kinfo.tsc;
+       volatile unsigned int *const counterp = __xn_tscinfo.kinfo.counter;
+       volatile unsigned int *const last_cntp = __xn_tscinfo.kinfo.last_cnt;
+       const unsigned int mask = __xn_tscinfo.kinfo.mask;
+       register unsigned long long after, before;
+       unsigned int counter, last_cnt;
+
+       __asm__ ("ldmia %1, %M0\n": "=r"(after): "r"(tscp), "m"(*tscp));
+       do {
+               before = after;
+               counter = *counterp;
+               last_cnt = *last_cntp;
+               /* compiler barrier. */
+               __asm__ __volatile__ ("" : /* */ : /* */ : "memory");
+               __asm__ ("ldmia %1, %M0\n": "=r"(after): "r"(tscp), "m"(*tscp));
+       } while (after != before);
+
+       counter &= mask;
+       last_cnt &= mask;
+       if (counter > last_cnt)
+               before += mask + 1ULL;
+       return (before + last_cnt - counter);
+
+#endif /* CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_DECREMENTER */
+}
+#endif /* CONFIG_XENO_ARM_TSC_TYPE */
+
+#endif /* !__KERNEL__ */
+
+#endif /* !_XENO_ASM_ARM_TSC_H */
diff --git a/include/asm-blackfin/Makefile.am b/include/asm-blackfin/Makefile.am
index 974ff0c..9aedf51 100644
--- a/include/asm-blackfin/Makefile.am
+++ b/include/asm-blackfin/Makefile.am
@@ -9,6 +9,7 @@ includesub_HEADERS =    \
        machine.h       \
        syscall.h       \
        thread.h        \
+       tsc.h           \
        wrappers.h
 
 SUBDIRS = bits
diff --git a/include/asm-blackfin/syscall.h b/include/asm-blackfin/syscall.h
index ea225c4..dfcc24c 100644
--- a/include/asm-blackfin/syscall.h
+++ b/include/asm-blackfin/syscall.h
@@ -21,17 +21,22 @@
 #define _XENO_ASM_BLACKFIN_SYSCALL_H
 
 #include <asm-generic/xenomai/syscall.h>
+#include <asm/xenomai/tsc.h>
 
-/* The way we mangle Xenomai syscalls with our multiplexer
-   marker. Note: watch out for the p0 sign convention used by Linux
-   (i.e. negative syscall number in orig_p0 meaning "non-syscall
-   entry"). */
+/*
+ * The way we mangle Xenomai syscalls with our multiplexer
+ * marker. Note: watch out for the p0 sign convention used by Linux
+ * (i.e. negative syscall number in orig_p0 meaning "non-syscall
+ * entry").
+ */
 #define __xn_mux_code(shifted_id,op) (shifted_id|((op << 16) & 
0xff0000)|(sc_nucleus_mux & 0xffff))
 #define __xn_mux_shifted_id(id) (id << 24)
 
-/* Local syscalls -- the braindamage thing about this arch is the
-   absence of atomic ops usable from user-space; so we export what
-   we need as syscalls implementing those ops from kernel space. Sigh... */
+/*
+ * Local syscalls -- the braindamage thing about this arch is the
+ * absence of atomic ops usable from user-space; so we export what we
+ * need as syscalls implementing those ops from kernel space. Sigh...
+ */
 #define __xn_lsys_xchg        0
 
 #ifdef __KERNEL__
@@ -56,8 +61,10 @@
 
 #define __xn_linux_mux_p(regs, nr)  (__xn_reg_mux(regs) == (nr))
 
-/* Purposedly used inlines and not macros for the following routines
-   so that we don't risk spurious side-effects on the value arg. */
+/*
+ * Purposedly used inlines and not macros for the following routines
+ * so that we don't risk spurious side-effects on the value arg.
+ */
 
 static inline void __xn_success_return(struct pt_regs *regs, int v)
 {
@@ -133,29 +140,6 @@ int xnarch_local_syscall(unsigned long a1, unsigned long 
a2,
 #define XENOMAI_SKINCALL4(id,op,a1,a2,a3,a4)    
XENOMAI_DO_SYSCALL(4,id,op,a1,a2,a3,a4)
 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5) 
XENOMAI_DO_SYSCALL(5,id,op,a1,a2,a3,a4,a5)
 
-static inline unsigned long long __xn_rdtsc (void)
-{
-    union {
-       struct {
-           unsigned long l;
-           unsigned long h;
-       } s;
-       unsigned long long t;
-    } u;
-    unsigned long cy2;
-
-    __asm__ __volatile__ (     "1: %0 = CYCLES2\n"
-                               "%1 = CYCLES\n"
-                               "%2 = CYCLES2\n"
-                               "CC = %2 == %0\n"
-                               "if !cc jump 1b\n"
-                               :"=d" (u.s.h),
-                               "=d" (u.s.l),
-                               "=d" (cy2)
-                               : /*no input*/ : "cc");
-    return u.t;
-}
-
 int shm_open(const char *name, int oflag, mode_t mode);
 inline __attribute__((weak))
 int shm_open(const char *name, int oflag, mode_t mode)
diff --git a/include/asm-blackfin/tsc.h b/include/asm-blackfin/tsc.h
new file mode 100644
index 0000000..9d970e6
--- /dev/null
+++ b/include/asm-blackfin/tsc.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2005 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_BLACKFIN_TSC_H
+#define _XENO_ASM_BLACKFIN_TSC_H
+
+#ifndef __KERNEL__
+
+static inline unsigned long long __xn_rdtsc (void)
+{
+       union {
+               struct {
+                       unsigned long l;
+                       unsigned long h;
+               } s;
+               unsigned long long t;
+       } u;
+       unsigned long cy2;
+
+       __asm__ __volatile__ (  "1: %0 = CYCLES2\n"
+                               "%1 = CYCLES\n"
+                               "%2 = CYCLES2\n"
+                               "CC = %2 == %0\n"
+                               "if !cc jump 1b\n"
+                               :"=d" (u.s.h),
+                                "=d" (u.s.l),
+                                "=d" (cy2)
+                               : /*no input*/ : "cc");
+       return u.t;
+}
+
+#endif /* !__KERNEL__ */
+
+#endif /* !_XENO_ASM_BLACKFIN_TSC_H */
diff --git a/include/asm-nios2/Makefile.am b/include/asm-nios2/Makefile.am
index 93f699f..77a2253 100644
--- a/include/asm-nios2/Makefile.am
+++ b/include/asm-nios2/Makefile.am
@@ -9,6 +9,7 @@ includesub_HEADERS =    \
        machine.h       \
        syscall.h       \
        thread.h        \
+       tsc.h           \
        wrappers.h
 
 SUBDIRS = bits
diff --git a/include/asm-nios2/syscall.h b/include/asm-nios2/syscall.h
index 9dd2c6b..f294811 100644
--- a/include/asm-nios2/syscall.h
+++ b/include/asm-nios2/syscall.h
@@ -21,6 +21,7 @@
 #define _XENO_ASM_NIOS2_SYSCALL_H
 
 #include <asm-generic/xenomai/syscall.h>
+#include <asm/xenomai/tsc.h>
 
 #define __xn_mux_shifted_id(id)             (id << 24)
 #define __xn_mux_code(shifted_id,op) (shifted_id|((op << 16) & 
0xff0000)|(sc_nucleus_mux & 0xffff))
@@ -229,58 +230,6 @@ int xnarch_local_syscall(unsigned long a1, unsigned long 
a2,
 #define XENOMAI_SKINCALL4(id,op,a1,a2,a3,a4)    
XENOMAI_DO_SYSCALL(4,id,op,a1,a2,a3,a4)
 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5) 
XENOMAI_DO_SYSCALL(5,id,op,a1,a2,a3,a4,a5)
 
-extern volatile void *xeno_nios2_hrclock;
-
-static inline unsigned long long __xn_rdtsc(void)
-{
-       volatile unsigned short *hrclock;
-       int64_t t0, t1;
-
-       hrclock = xeno_nios2_hrclock;
-
-#define hrclock_wrsnap(reg, val)               \
-       (*(hrclock + (12 + ((reg) * 2)))) = (val)
-
-#define hrclock_rdsnap(reg)                    \
-       (int64_t)(*(hrclock + (12 + ((reg) * 2)))) << (reg * 16)
-
-#define hrclock_peeksnap()                                             \
-       ({                                                              \
-               int64_t __snap;                                         \
-               __snap = hrclock_rdsnap(3) | hrclock_rdsnap(2) |        \
-                       hrclock_rdsnap(1) | hrclock_rdsnap(0);          \
-               __snap;                                                 \
-       })
-
-#define hrclock_getsnap()                                              \
-       ({                                                              \
-               hrclock_wrsnap(0, 0);                                   \
-               hrclock_peeksnap();                                     \
-       })
-
-       /*
-        * We compete with both the kernel and userland applications
-        * which may request a snapshot as well, but we don't have any
-        * simple mutual exclusion mechanism at hand to avoid
-        * races. In order to keep the overhead of reading the hrclock
-        * from userland low, we make sure to read two consecutive
-        * coherent snapshots. In case both readings do not match, we
-        * have to request a fresh snapshot anew, since it means that
-        * we have been preempted in the middle of the operation.
-        */
-       do {
-               t0 = hrclock_getsnap(); /* Request snapshot and read it */
-               __asm__ __volatile__("": : :"memory");
-               t1 = hrclock_peeksnap(); /* Confirm first reading */
-       } while (t0 != t1);
-
-#undef hrclock_getsnap
-#undef hrclock_rdsnap
-#undef hrclock_wrsnap
-
-       return ~t0;
-}
-
 /*
  * uClibc does not always provide the following symbols for this arch;
  * provide placeholders here. Note: let the compiler decides whether
diff --git a/include/asm-nios2/tsc.h b/include/asm-nios2/tsc.h
new file mode 100644
index 0000000..5af2adf
--- /dev/null
+++ b/include/asm-nios2/tsc.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2009 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_NIOS2_TSC_H
+#define _XENO_ASM_NIOS2_TSC_H
+
+#ifndef __KERNEL__
+
+extern volatile void *xeno_nios2_hrclock;
+
+static inline unsigned long long __xn_rdtsc(void)
+{
+       volatile unsigned short *hrclock;
+       int64_t t0, t1;
+
+       hrclock = xeno_nios2_hrclock;
+
+#define hrclock_wrsnap(reg, val)               \
+       (*(hrclock + (12 + ((reg) * 2)))) = (val)
+
+#define hrclock_rdsnap(reg)                    \
+       (int64_t)(*(hrclock + (12 + ((reg) * 2)))) << (reg * 16)
+
+#define hrclock_peeksnap()                                             \
+       ({                                                              \
+               int64_t __snap;                                         \
+               __snap = hrclock_rdsnap(3) | hrclock_rdsnap(2) |        \
+                       hrclock_rdsnap(1) | hrclock_rdsnap(0);          \
+               __snap;                                                 \
+       })
+
+#define hrclock_getsnap()                                              \
+       ({                                                              \
+               hrclock_wrsnap(0, 0);                                   \
+               hrclock_peeksnap();                                     \
+       })
+
+       /*
+        * We compete with both the kernel and userland applications
+        * which may request a snapshot as well, but we don't have any
+        * simple mutual exclusion mechanism at hand to avoid
+        * races. In order to keep the overhead of reading the hrclock
+        * from userland low, we make sure to read two consecutive
+        * coherent snapshots. In case both readings do not match, we
+        * have to request a fresh snapshot anew, since it means that
+        * we have been preempted in the middle of the operation.
+        */
+       do {
+               t0 = hrclock_getsnap(); /* Request snapshot and read it */
+               __asm__ __volatile__("": : :"memory");
+               t1 = hrclock_peeksnap(); /* Confirm first reading */
+       } while (t0 != t1);
+
+#undef hrclock_getsnap
+#undef hrclock_rdsnap
+#undef hrclock_wrsnap
+
+       return ~t0;
+}
+
+#endif /* !__KERNEL__ */
+
+#endif /* !_XENO_ASM_NIOS2_TSC_H */
diff --git a/include/asm-powerpc/Makefile.am b/include/asm-powerpc/Makefile.am
index 3697a6a..0756d72 100644
--- a/include/asm-powerpc/Makefile.am
+++ b/include/asm-powerpc/Makefile.am
@@ -9,6 +9,7 @@ includesub_HEADERS =    \
        machine.h       \
        syscall.h       \
        thread.h        \
+       tsc.h           \
        wrappers.h
 
 SUBDIRS = bits
diff --git a/include/asm-powerpc/syscall.h b/include/asm-powerpc/syscall.h
index 264e593..d1b57a7 100644
--- a/include/asm-powerpc/syscall.h
+++ b/include/asm-powerpc/syscall.h
@@ -24,6 +24,7 @@
 #define _XENO_ASM_POWERPC_SYSCALL_H
 
 #include <asm-generic/xenomai/syscall.h>
+#include <asm/xenomai/tsc.h>
 
 #define __xn_mux_code(shifted_id,op) ((op << 24)|shifted_id|(sc_nucleus_mux & 
0xffff))
 #define __xn_mux_shifted_id(id) ((id << 16) & 0xff0000)
@@ -161,32 +162,6 @@ int xnarch_local_syscall(unsigned long a1, unsigned long 
a2,
 #define XENOMAI_SKINCALL4(id,op,a1,a2,a3,a4)    
XENOMAI_DO_SYSCALL(4,id,op,a1,a2,a3,a4)
 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5) 
XENOMAI_DO_SYSCALL(5,id,op,a1,a2,a3,a4,a5)
 
-static inline unsigned long long __xn_rdtsc(void)
-#if defined(__powerpc64__)
-{
-       unsigned long long t;
-
-       __asm__ __volatile__("mftb %0\n":"=r"(t));
-       return t;
-}
-#else                          /* !__powerpc64__ */
-{
-       union {
-               unsigned long long t;
-               unsigned long v[2];
-       } u;
-       unsigned long __tbu;
-
-       __asm__ __volatile__("1: mfspr %0,269\n"
-                            "mfspr %1,268\n"
-                            "mfspr %2,269\n"
-                            "cmpw %2,%0\n"
-                            "bne- 1b\n":"=r"(u.v[0]),
-                            "=r"(u.v[1]), "=r"(__tbu));
-       return u.t;
-}
-#endif /* __powerpc64__ */
-
 #endif /* __KERNEL__ */
 
 #endif /* !_XENO_ASM_POWERPC_SYSCALL_H */
diff --git a/include/asm-powerpc/tsc.h b/include/asm-powerpc/tsc.h
new file mode 100644
index 0000000..3b82b75
--- /dev/null
+++ b/include/asm-powerpc/tsc.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2001,2002,2003,2004 Philippe Gerum <r...@xenomai.org>.
+ *
+ * 64-bit PowerPC adoption
+ *   copyright (C) 2005 Taneli Vähäkangas and Heikki Lindholm
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_POWERPC_TSC_H
+#define _XENO_ASM_POWERPC_TSC_H
+
+#ifndef __KERNEL__
+
+static inline unsigned long long __xn_rdtsc(void)
+{
+#if defined(__powerpc64__)
+       unsigned long long t;
+
+       __asm__ __volatile__("mftb %0\n":"=r"(t));
+       return t;
+#else  /* !__powerpc64__ */
+       union {
+               unsigned long long t;
+               unsigned long v[2];
+       } u;
+       unsigned long __tbu;
+
+       __asm__ __volatile__("1: mfspr %0,269\n"
+                            "mfspr %1,268\n"
+                            "mfspr %2,269\n"
+                            "cmpw %2,%0\n"
+                            "bne- 1b\n":"=r"(u.v[0]),
+                            "=r"(u.v[1]), "=r"(__tbu));
+       return u.t;
+#endif /* __powerpc64__ */
+}
+
+#endif /* !__KERNEL__ */
+
+#endif /* !_XENO_ASM_POWERPC_TSC_H */
diff --git a/include/asm-sh/Makefile.am b/include/asm-sh/Makefile.am
index 322e5df..077750c 100644
--- a/include/asm-sh/Makefile.am
+++ b/include/asm-sh/Makefile.am
@@ -9,6 +9,7 @@ includesub_HEADERS =    \
        machine.h       \
        syscall.h       \
        thread.h        \
+       tsc.h           \
        wrappers.h
 
 SUBDIRS = bits
diff --git a/include/asm-sh/syscall.h b/include/asm-sh/syscall.h
index d64da2a..cce3754 100644
--- a/include/asm-sh/syscall.h
+++ b/include/asm-sh/syscall.h
@@ -21,6 +21,7 @@
 #define _XENO_ASM_SH_SYSCALL_H
 
 #include <asm-generic/xenomai/syscall.h>
+#include <asm/xenomai/tsc.h>
 
 #define __xn_mux_shifted_id(id)             (id << 24)
 #define __xn_mux_code(shifted_id,op) (shifted_id|((op << 16) & 
0xff0000)|(sc_nucleus_mux & 0xffff))
@@ -78,7 +79,6 @@ static inline int xnarch_local_syscall(void)
 #else /* !__KERNEL__ */
 
 #include <errno.h>
-#include <endian.h>
 #include <asm/xenomai/atomic.h>
 
 /*
@@ -185,37 +185,6 @@ static inline int xnarch_local_syscall(void)
 #define XENOMAI_SKINCALL4(id,op,a1,a2,a3,a4)    
XENOMAI_DO_SYSCALL(4,id,op,a1,a2,a3,a4)
 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5) 
XENOMAI_DO_SYSCALL(5,id,op,a1,a2,a3,a4,a5)
 
-struct xnarch_tsc_area {
-       struct {
-#if __BYTE_ORDER == __BIG_ENDIAN
-               unsigned long high;
-               unsigned long low;
-#else /* __LITTLE_ENDIAN */
-               unsigned long low;
-               unsigned long high;
-#endif /* __LITTLE_ENDIAN */
-       } tsc;
-       unsigned long counter_pa;
-};
-
-extern volatile struct xnarch_tsc_area *xeno_sh_tsc;
-
-extern volatile unsigned long *xeno_sh_tcnt;
-
-static inline unsigned long long __xn_rdtsc(void)
-{
-       unsigned long long tsc;
-       unsigned long low;
-
-       tsc = xeno_sh_tsc->tsc.high;
-       low = *xeno_sh_tcnt ^ 0xffffffffUL;
-       if (low < xeno_sh_tsc->tsc.low)
-               tsc++;
-       tsc = (tsc << 32)|low;
-
-       return tsc;
-}
-
-#endif /* __KERNEL__ */
+#endif /* !__KERNEL__ */
 
 #endif /* !_XENO_ASM_SH_SYSCALL_H */
diff --git a/include/asm-sh/tsc.h b/include/asm-sh/tsc.h
new file mode 100644
index 0000000..b6cf743
--- /dev/null
+++ b/include/asm-sh/tsc.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2011 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_SH_TSC_H
+#define _XENO_ASM_SH_TSC_H
+
+#ifndef __KERNEL__
+
+#include <endian.h>
+
+struct xnarch_tsc_area {
+       struct {
+#if __BYTE_ORDER == __BIG_ENDIAN
+               unsigned long high;
+               unsigned long low;
+#else /* __LITTLE_ENDIAN */
+               unsigned long low;
+               unsigned long high;
+#endif /* __LITTLE_ENDIAN */
+       } tsc;
+       unsigned long counter_pa;
+};
+
+extern volatile struct xnarch_tsc_area *xeno_sh_tsc;
+
+extern volatile unsigned long *xeno_sh_tcnt;
+
+static inline unsigned long long __xn_rdtsc(void)
+{
+       unsigned long long tsc;
+       unsigned long low;
+
+       tsc = xeno_sh_tsc->tsc.high;
+       low = *xeno_sh_tcnt ^ 0xffffffffUL;
+       if (low < xeno_sh_tsc->tsc.low)
+               tsc++;
+       tsc = (tsc << 32)|low;
+
+       return tsc;
+}
+
+#endif /* !__KERNEL__ */
+
+#endif /* !_XENO_ASM_SH_TSC_H */
diff --git a/include/asm-x86/Makefile.am b/include/asm-x86/Makefile.am
index b0d4b59..35f6ee4 100644
--- a/include/asm-x86/Makefile.am
+++ b/include/asm-x86/Makefile.am
@@ -12,6 +12,7 @@ includesub_HEADERS =  \
        smi.h           \
        syscall.h       \
        thread.h        \
+       tsc.h           \
        wrappers.h
 
 SUBDIRS = bits
diff --git a/include/asm-x86/syscall.h b/include/asm-x86/syscall.h
index 484c071..485bfca 100644
--- a/include/asm-x86/syscall.h
+++ b/include/asm-x86/syscall.h
@@ -31,6 +31,7 @@
 #include <asm/uaccess.h>
 #include <asm/ptrace.h>
 #include <asm/xenomai/wrappers.h>
+#include <asm/xenomai/tsc.h>
 
 /* Register mapping for accessing syscall args. */
 
@@ -319,22 +320,6 @@ static inline void __xn_get_ebp(void **dest)
 #define XENOMAI_SKINCALL4(id,op,a1,a2,a3,a4)   
XENOMAI_SKIN_MUX(4,id,op,a1,a2,a3,a4)
 #define XENOMAI_SKINCALL5(id,op,a1,a2,a3,a4,a5)        
XENOMAI_SKIN_MUX(5,id,op,a1,a2,a3,a4,a5)
 
-static inline unsigned long long __xn_rdtsc(void)
-{
-#ifdef __i386__
-       unsigned long long t;
-
-       asm volatile ("rdtsc" : "=A" (t));
-       return t;
-
-#else /* x86_64 */
-       unsigned int __a,__d;
-
-       asm volatile ("rdtsc" : "=a" (__a), "=d" (__d));
-       return ((unsigned long)__a) | (((unsigned long)__d) << 32);
-#endif /* x86_64 */
-}
-
 #endif /* !__KERNEL__ */
 
 #endif /* !_XENO_ASM_X86_SYSCALL_H */
diff --git a/include/asm-x86/tsc.h b/include/asm-x86/tsc.h
new file mode 100644
index 0000000..dc29be1
--- /dev/null
+++ b/include/asm-x86/tsc.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2001,2002,2003,2007 Philippe Gerum <r...@xenomai.org>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _XENO_ASM_X86_TSC_H
+#define _XENO_ASM_X86_TSC_H
+
+#ifndef __KERNEL__
+
+static inline unsigned long long __xn_rdtsc(void)
+{
+#ifdef __i386__
+       unsigned long long t;
+
+       __asm__ __volatile__ ("rdtsc" : "=A" (t));
+       return t;
+
+#else /* x86_64 */
+       unsigned int __a,__d;
+
+       __asm__ __volatile__ ("rdtsc" : "=a" (__a), "=d" (__d));
+       return ((unsigned long)__a) | (((unsigned long)__d) << 32);
+#endif /* x86_64 */
+}
+
+#endif /* !__KERNEL__ */
+
+#endif /* _XENO_ASM_X86_TSC_H */
diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h
index f006986..677d34c 100644
--- a/include/copperplate/clockobj.h
+++ b/include/copperplate/clockobj.h
@@ -159,6 +159,7 @@ int clockobj_destroy(struct clockobj *clkobj);
 #ifdef CONFIG_XENO_COBALT
 
 #include <asm/xenomai/arith.h>
+#include <asm/xenomai/tsc.h>
 #include <asm-generic/xenomai/timeconv.h>
 
 static inline ticks_t clockobj_get_tsc(void)
diff --git a/kernel/cobalt/arch/arm/syscall.c b/kernel/cobalt/arch/arm/syscall.c
index 3897d4d..1cc4b0d 100644
--- a/kernel/cobalt/arch/arm/syscall.c
+++ b/kernel/cobalt/arch/arm/syscall.c
@@ -25,18 +25,13 @@ int xnarch_local_syscall(unsigned long a1, unsigned long a2,
                         unsigned long a3, unsigned long a4,
                         unsigned long a5)
 {
-       int ret = -EINVAL;
-       /*
-        * If the pipeline supports user-space TSC emulation, provide
-        * a syscall for retrieving the TSC information.
-        */
-#ifdef IPIPE_TSC_TYPE_NONE
        struct ipipe_sysinfo ipipe_info;
        struct __ipipe_tscinfo *p = &ipipe_info.arch.tsc;
        struct __xn_tscinfo info;
+       int ret;
 
        if (a1 != XENOMAI_SYSARCH_TSCINFO)
-               return ret;
+               return  = -EINVAL;
 
        ret = ipipe_get_sysinfo(&ipipe_info);
        if (ret)
@@ -92,7 +87,6 @@ int xnarch_local_syscall(unsigned long a1, unsigned long a2,
 
        if (__xn_copy_to_user((void *)a2, &info, sizeof(info)))
                return -EFAULT;
-#endif /* IPIPE_TSC_TYPE_NONE */
 
-       return ret;
+       return 0;
 }
diff --git a/lib/cobalt/assert_context.c b/lib/cobalt/assert_context.c
index be363db..269c384 100644
--- a/lib/cobalt/assert_context.c
+++ b/lib/cobalt/assert_context.c
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <rtdk.h>
 #include <nucleus/thread.h>
-#include <asm-generic/syscall.h>
+#include <asm/xenomai/syscall.h>
 #include <asm-generic/current.h>
 #include <unistd.h>
 
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 5bf154b..4e402a7 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -24,6 +24,7 @@
 #include <cobalt/syscall.h>
 #include <time.h>
 #include <asm/xenomai/arith.h>
+#include <asm/xenomai/tsc.h>
 #include <asm-generic/xenomai/timeconv.h>
 #include <sys/types.h>
 #include <nucleus/vdso.h>
diff --git a/testsuite/regression/posix/leaks.c 
b/testsuite/regression/posix/leaks.c
index 7822fb1..976b88a 100644
--- a/testsuite/regression/posix/leaks.c
+++ b/testsuite/regression/posix/leaks.c
@@ -11,6 +11,7 @@
 #include <signal.h>
 
 #include <nucleus/heap.h>
+#include <asm/xenomai/syscall.h>
 
 #include "check.h"
 


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

Reply via email to