Module: xenomai-head
Branch: master
Commit: 0fd8447277df530d4d231683b276a675d29656b8
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=0fd8447277df530d4d231683b276a675d29656b8

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Apr 29 00:03:32 2009 +0200

Make optimized tsc<->ns conversion routines available to user-space.

All existing ports exhibit optimized implementations of time
conversion routines in kernel space, based on reciprocal
multiplications, instead of divide operations. Such support was not
available to userland code, which still relied on the original
implemenation based on llimd().

This patch series fixes computation discrepancies that may be caused
by the different implementations between kernel and userland code, by
moving the time converters in a separate implementation file
(include/asm-generic/bits/timeconv.h). This file may be read both from
kernel and userland contexts to define tsc_to_ns and ns_to_tsc
operations.

---

 include/asm-arm/arith.h              |    2 -
 include/asm-arm/bits/init.h          |   34 +++++++-------
 include/asm-arm/bits/pod.h           |   19 --------
 include/asm-arm/features.h           |    3 +
 include/asm-blackfin/arith.h         |    2 +-
 include/asm-blackfin/bits/init.h     |   34 ++++++--------
 include/asm-blackfin/bits/pod.h      |   17 -------
 include/asm-blackfin/features.h      |    3 +
 include/asm-generic/Makefile.am      |    8 +++-
 include/asm-generic/Makefile.in      |    9 +++-
 include/asm-generic/arith.h          |    5 +-
 include/asm-generic/bits/Makefile.am |    3 +-
 include/asm-generic/bits/Makefile.in |    3 +-
 include/asm-generic/bits/pod.h       |   18 -------
 include/asm-generic/bits/timeconv.h  |   82 ++++++++++++++++++++++++++++++++++
 include/asm-generic/system.h         |    5 +--
 include/asm-powerpc/arith.h          |    2 +-
 include/asm-powerpc/bits/init.h      |   34 ++++++--------
 include/asm-powerpc/bits/pod.h       |   17 -------
 include/asm-powerpc/features.h       |    3 +
 include/asm-powerpc/syscall.h        |    5 ++-
 include/asm-x86/arith_32.h           |    4 +-
 include/asm-x86/arith_64.h           |    4 +-
 include/asm-x86/bits/init_32.h       |   31 ++++++-------
 include/asm-x86/bits/init_64.h       |   34 ++++++--------
 include/asm-x86/bits/pod_32.h        |   16 -------
 include/asm-x86/bits/pod_64.h        |   19 --------
 include/asm-x86/features_32.h        |    3 +
 include/asm-x86/features_64.h        |    3 +
 include/native/syscall.h             |    4 +-
 ksrc/skins/native/syscall.c          |   45 +------------------
 src/skins/native/init.c              |    2 -
 src/skins/native/timer.c             |   24 ++--------
 33 files changed, 212 insertions(+), 285 deletions(-)

diff --git a/include/asm-arm/arith.h b/include/asm-arm/arith.h
index 3d8d276..eca69ba 100644
--- a/include/asm-arm/arith.h
+++ b/include/asm-arm/arith.h
@@ -3,8 +3,6 @@
 
 #include <asm/xenomai/features.h>
 
-#define XNARCH_WANT_NODIV_MULDIV
-
 #if __LINUX_ARM_ARCH__ >= 4
 static inline __attribute__((__const__)) unsigned long long
 rthal_arm_nodiv_ullimd(const unsigned long long op,
diff --git a/include/asm-arm/bits/init.h b/include/asm-arm/bits/init.h
index e420295..2fd959f 100644
--- a/include/asm-arm/bits/init.h
+++ b/include/asm-arm/bits/init.h
@@ -29,6 +29,7 @@
 
 #include <linux/init.h>
 #include <asm/xenomai/calibration.h>
+#include <asm-generic/xenomai/bits/timeconv.h>
 
 int xnarch_escalation_virq;
 
@@ -67,34 +68,33 @@ int xnarch_calibrate_sched(void)
 
 static inline int xnarch_init(void)
 {
-       extern unsigned xnarch_tsc_scale, xnarch_tsc_shift, xnarch_tsc_divide;
-       extern rthal_u32frac_t xnarch_tsc_frac;
-       int err;
+       int ret;
 
-       err = rthal_init();
+       ret = rthal_init();
+       if (ret)
+               return ret;
 
-       if (err)
-               return err;
+#if defined(CONFIG_SMP) && defined(MODULE)
+       /*
+        * Make sure the init sequence is kept on the same CPU when
+        * running as a module.
+        */
+       set_cpus_allowed(current, cpumask_of_cpu(0));
+#endif /* CONFIG_SMP && MODULE */
 
-       xnarch_init_llmulshft(1000000000, RTHAL_CPU_FREQ,
-                             &xnarch_tsc_scale, &xnarch_tsc_shift);
-       xnarch_tsc_divide = 1 << xnarch_tsc_shift;
+       xnarch_init_timeconv(RTHAL_CPU_FREQ);
 
-       xnarch_init_u32frac(&xnarch_tsc_frac, xnarch_tsc_divide, 
xnarch_tsc_scale);
-
-       err = xnarch_calibrate_sched();
-
-       if (err)
-               return err;
+       ret = xnarch_calibrate_sched();
+       if (ret)
+               return ret;
 
        xnarch_escalation_virq = rthal_alloc_virq();
-
        if (xnarch_escalation_virq == 0)
                return -ENOSYS;
 
        rthal_virtualize_irq(&rthal_domain,
                             xnarch_escalation_virq,
-                            (rthal_irq_handler_t) & xnpod_schedule_handler,
+                            (rthal_irq_handler_t) &xnpod_schedule_handler,
                             NULL, NULL, IPIPE_HANDLE_MASK | IPIPE_WIRED_MASK);
 
        xnarch_old_trap_handler = rthal_trap_catch(&xnarch_trap_fault);
diff --git a/include/asm-arm/bits/pod.h b/include/asm-arm/bits/pod.h
index ccd55e7..2e71d5d 100644
--- a/include/asm-arm/bits/pod.h
+++ b/include/asm-arm/bits/pod.h
@@ -23,25 +23,6 @@
 #ifndef _XENO_ASM_ARM_BITS_POD_H
 #define _XENO_ASM_ARM_BITS_POD_H
 
-unsigned xnarch_tsc_scale;
-unsigned xnarch_tsc_shift;
-unsigned xnarch_tsc_divide;
-rthal_u32frac_t xnarch_tsc_frac;
-
-long long xnarch_tsc_to_ns(long long ts)
-{
-       return xnarch_llmulshft(ts, xnarch_tsc_scale, xnarch_tsc_shift);
-}
-#define XNARCH_TSC_TO_NS
-
-long long xnarch_ns_to_tsc(long long ns)
-{
-       return xnarch_nodiv_llimd(ns,
-                                 xnarch_tsc_frac.frac,
-                                 xnarch_tsc_frac.integ);
-}
-#define XNARCH_NS_TO_TSC
-
 #include <asm-generic/xenomai/bits/pod.h>
 
 void xnpod_welcome_thread(struct xnthread *, int);
diff --git a/include/asm-arm/features.h b/include/asm-arm/features.h
index a6d685f..43a9d82 100644
--- a/include/asm-arm/features.h
+++ b/include/asm-arm/features.h
@@ -98,6 +98,9 @@ static inline const char *get_feature_label (unsigned feature)
     }
 }
 
+#define XNARCH_HAVE_LLMULSHFT    1
+#define XNARCH_HAVE_NODIV_LLIMD  1
+
 #endif /* !_XENO_ASM_ARM_FEATURES_H */
 
 // vim: ts=4 et sw=4 sts=4
diff --git a/include/asm-blackfin/arith.h b/include/asm-blackfin/arith.h
index 429aa7a..49877e6 100644
--- a/include/asm-blackfin/arith.h
+++ b/include/asm-blackfin/arith.h
@@ -20,7 +20,7 @@
 #ifndef _XENO_ASM_BLACKFIN_ARITH_H
 #define _XENO_ASM_BLACKFIN_ARITH_H
 
-#define XNARCH_WANT_NODIV_MULDIV
+#include <asm/xenomai/features.h>
 
 #define __rthal_add96and64(l0, l1, l2, s0, s1)         \
        do {                                            \
diff --git a/include/asm-blackfin/bits/init.h b/include/asm-blackfin/bits/init.h
index 8d52641..e655ad9 100644
--- a/include/asm-blackfin/bits/init.h
+++ b/include/asm-blackfin/bits/init.h
@@ -26,6 +26,7 @@
 
 #include <linux/init.h>
 #include <asm/xenomai/calibration.h>
+#include <asm-generic/xenomai/bits/timeconv.h>
 
 int xnarch_escalation_virq;
 
@@ -66,42 +67,35 @@ int xnarch_calibrate_sched(void)
 
 static inline int xnarch_init(void)
 {
-       extern unsigned xnarch_tsc_scale, xnarch_tsc_shift, xnarch_tsc_divide;
-       extern rthal_u32frac_t xnarch_tsc_frac;
-       int err;
+       int ret;
 
        __ipipe_irq_tail_hook = (unsigned long)&xnpod_schedule_deferred;
 
-       err = rthal_init();
-
-       if (err)
-               return err;
+       ret = rthal_init();
+       if (ret)
+               return ret;
 
 #if defined(CONFIG_SMP) && defined(MODULE)
-       /* Make sure the init sequence is kept on the same CPU when
-          running as a module. */
+       /*
+        * Make sure the init sequence is kept on the same CPU when
+        * running as a module.
+        */
        set_cpus_allowed(current, cpumask_of_cpu(0));
 #endif /* CONFIG_SMP && MODULE */
 
-       xnarch_init_llmulshft(1000000000, RTHAL_CPU_FREQ,
-                             &xnarch_tsc_scale, &xnarch_tsc_shift);
-       xnarch_tsc_divide = 1 << xnarch_tsc_shift;
-
-       xnarch_init_u32frac(&xnarch_tsc_frac, xnarch_tsc_divide, 
xnarch_tsc_scale);
+       xnarch_init_timeconv(RTHAL_CPU_FREQ);
 
-       err = xnarch_calibrate_sched();
-
-       if (err)
-               return err;
+       ret = xnarch_calibrate_sched();
+       if (ret)
+               return ret;
 
        xnarch_escalation_virq = rthal_alloc_virq();
-
        if (xnarch_escalation_virq == 0)
                return -ENOSYS;
 
        rthal_virtualize_irq(&rthal_domain,
                             xnarch_escalation_virq,
-                            (rthal_irq_handler_t) & xnpod_schedule_handler,
+                            (rthal_irq_handler_t) &xnpod_schedule_handler,
                             NULL, NULL, IPIPE_HANDLE_MASK | IPIPE_WIRED_MASK);
 
        xnarch_old_trap_handler = rthal_trap_catch(&xnarch_trap_fault);
diff --git a/include/asm-blackfin/bits/pod.h b/include/asm-blackfin/bits/pod.h
index c88b315..83a404c 100644
--- a/include/asm-blackfin/bits/pod.h
+++ b/include/asm-blackfin/bits/pod.h
@@ -20,23 +20,6 @@
 #ifndef _XENO_ASM_BLACKFIN_BITS_POD_H
 #define _XENO_ASM_BLACKFIN_BITS_POD_H
 
-unsigned xnarch_tsc_scale;
-unsigned xnarch_tsc_shift;
-unsigned xnarch_tsc_divide;
-rthal_u32frac_t xnarch_tsc_frac;
-
-long long xnarch_tsc_to_ns(long long ts)
-{
-       return xnarch_llmulshft(ts, xnarch_tsc_scale, xnarch_tsc_shift);
-}
-#define XNARCH_TSC_TO_NS
-
-long long xnarch_ns_to_tsc(long long ns)
-{
-       return xnarch_nodiv_llimd(ns, xnarch_tsc_frac.frac, 
xnarch_tsc_frac.integ);
-}
-#define XNARCH_NS_TO_TSC
-
 #include <asm-generic/xenomai/bits/pod.h>
 
 void xnpod_welcome_thread(struct xnthread *, int);
diff --git a/include/asm-blackfin/features.h b/include/asm-blackfin/features.h
index 4e6e3f6..fa02c0c 100644
--- a/include/asm-blackfin/features.h
+++ b/include/asm-blackfin/features.h
@@ -38,4 +38,7 @@ static inline const char *get_feature_label (unsigned feature)
     return get_generic_feature_label(feature);
 }
 
+#define XNARCH_HAVE_LLMULSHFT    1
+#define XNARCH_HAVE_NODIV_LLIMD  1
+
 #endif /* !_XENO_ASM_BLACKFIN_FEATURES_H */
diff --git a/include/asm-generic/Makefile.am b/include/asm-generic/Makefile.am
index a2d1302..3238976 100644
--- a/include/asm-generic/Makefile.am
+++ b/include/asm-generic/Makefile.am
@@ -1,5 +1,11 @@
 includesubdir = $(includedir)/asm-generic
 
-includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = \
+       arith.h \
+       features.h \
+       hal.h \
+       syscall.h \
+       system.h \
+       wrappers.h
 
 SUBDIRS = bits
diff --git a/include/asm-generic/Makefile.in b/include/asm-generic/Makefile.in
index e658719..0493f81 100644
--- a/include/asm-generic/Makefile.in
+++ b/include/asm-generic/Makefile.in
@@ -232,7 +232,14 @@ target_vendor = @target_vendor@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 includesubdir = $(includedir)/asm-generic
-includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = \
+       arith.h \
+       features.h \
+       hal.h \
+       syscall.h \
+       system.h \
+       wrappers.h
+
 SUBDIRS = bits
 all: all-recursive
 
diff --git a/include/asm-generic/arith.h b/include/asm-generic/arith.h
index 2c363bd..65d36cf 100644
--- a/include/asm-generic/arith.h
+++ b/include/asm-generic/arith.h
@@ -40,6 +40,7 @@
 #endif
 
 #else /* !__KERNEL__ */
+#include <stddef.h>
 #include <endian.h>
 
 #if __BYTE_ORDER == __BIG_ENDIAN
@@ -250,7 +251,7 @@ __rthal_generic_llmulshft(const long long op,
 #define rthal_llmulshft(ll, m, s) __rthal_generic_llmulshft((ll), (m), (s))
 #endif /* !rthal_llmulshft */
 
-#ifdef XNARCH_WANT_NODIV_MULDIV
+#ifdef XNARCH_HAVE_NODIV_LLIMD
 
 /* Representation of a 32 bits fraction. */
 typedef struct {
@@ -334,7 +335,7 @@ __rthal_generic_nodiv_llimd (long long op, unsigned long 
long frac, unsigned int
 #define rthal_nodiv_llimd(ll,frac,integ) 
__rthal_generic_nodiv_llimd((ll),(frac),(integ))
 #endif /* !rthal_nodiv_llimd */
 
-#endif /* XNARCH_WANT_NODIV_MULDIV */
+#endif /* XNARCH_HAVE_NODIV_LLIMD */
 
 static inline void xnarch_init_llmulshft(const unsigned m_in,
                                         const unsigned d_in,
diff --git a/include/asm-generic/bits/Makefile.am 
b/include/asm-generic/bits/Makefile.am
index c95b2a4..4a60896 100644
--- a/include/asm-generic/bits/Makefile.am
+++ b/include/asm-generic/bits/Makefile.am
@@ -7,4 +7,5 @@ includesub_HEADERS = \
        intr.h \
        mlock_alert.h \
        pod.h \
-       sigshadow.h
+       sigshadow.h \
+       timeconv.h
diff --git a/include/asm-generic/bits/Makefile.in 
b/include/asm-generic/bits/Makefile.in
index 42ecac2..d4be904 100644
--- a/include/asm-generic/bits/Makefile.in
+++ b/include/asm-generic/bits/Makefile.in
@@ -229,7 +229,8 @@ includesub_HEADERS = \
        intr.h \
        mlock_alert.h \
        pod.h \
-       sigshadow.h
+       sigshadow.h \
+       timeconv.h
 
 all: all-am
 
diff --git a/include/asm-generic/bits/pod.h b/include/asm-generic/bits/pod.h
index 33d6f64..3cf09ff 100644
--- a/include/asm-generic/bits/pod.h
+++ b/include/asm-generic/bits/pod.h
@@ -270,24 +270,6 @@ unsigned long long xnarch_get_host_time(void)
 
 EXPORT_SYMBOL(xnarch_get_host_time);
 
-#ifndef XNARCH_TSC_TO_NS
-long long xnarch_tsc_to_ns(long long ts)
-{
-    return xnarch_llimd(ts,1000000000,RTHAL_CPU_FREQ);
-}
-#endif /* !XNARCH_TSC_TO_NS */
-
-EXPORT_SYMBOL(xnarch_tsc_to_ns);
-
-#ifndef XNARCH_NS_TO_TSC
-long long xnarch_ns_to_tsc(long long ns)
-{
-    return xnarch_llimd(ns,RTHAL_CPU_FREQ,1000000000);
-}
-#endif /* !XNARCH_NS_TO_TSC */
-
-EXPORT_SYMBOL(xnarch_ns_to_tsc);
-
 unsigned long long xnarch_get_cpu_time(void)
 {
     return xnarch_tsc_to_ns(xnarch_get_cpu_tsc());
diff --git a/include/asm-generic/bits/timeconv.h 
b/include/asm-generic/bits/timeconv.h
new file mode 100644
index 0000000..e6f4d11
--- /dev/null
+++ b/include/asm-generic/bits/timeconv.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2009 Philippe Gerum <r...@xenomai.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+
+#ifndef _XENO_ASM_GENERIC_BITS_TIMECONV_H
+#define _XENO_ASM_GENERIC_BITS_TIMECONV_H
+
+#include <asm/xenomai/arith.h>
+
+static unsigned long long cpufreq;
+
+#ifdef XNARCH_HAVE_LLMULSHFT
+static unsigned int tsc_scale, tsc_shift;
+#ifdef XNARCH_HAVE_NODIV_LLIMD
+static rthal_u32frac_t tsc_frac;
+#endif
+#endif
+
+#ifdef XNARCH_HAVE_LLMULSHFT
+long long xnarch_tsc_to_ns(long long ticks)
+{
+       return xnarch_llmulshft(ticks, tsc_scale, tsc_shift);
+}
+long long xnarch_tsc_to_ns_rounded(long long ticks)
+{
+       unsigned int shift = tsc_shift - 1;
+       return (xnarch_llmulshft(ticks, tsc_scale, shift) + 1) / 2;
+}
+#else  /* !XNARCH_HAVE_LLMULSHFT */
+long long xnarch_tsc_to_ns(long long ticks)
+{
+       return xnarch_llimd(ticks, 1000000000, cpufreq);
+}
+long long xnarch_tsc_to_ns_rounded(long long ticks)
+{
+       return (xnarch_llimd(ticks, 1000000000, cpufreq/2) + 1) / 2;
+}
+#endif /* !XNARCH_HAVE_LLMULSHFT */
+
+#ifdef XNARCH_HAVE_NODIV_LLIMD
+long long xnarch_ns_to_tsc(long long ns)
+{
+       return xnarch_nodiv_llimd(ns, tsc_frac.frac, tsc_frac.integ);
+}
+#else /* !XNARCH_HAVE_NODIV_LLIMD */
+long long xnarch_ns_to_tsc(long long ns)
+{
+       return xnarch_llimd(ns, cpufreq, 1000000000);
+}
+#endif /* !XNARCH_HAVE_NODIV_LLIMD */
+
+static inline void xnarch_init_timeconv(unsigned long long freq)
+{
+       cpufreq = freq;
+#ifdef XNARCH_HAVE_LLMULSHFT
+       xnarch_init_llmulshft(1000000000, freq, &tsc_scale, &tsc_shift);
+#ifdef XNARCH_HAVE_NODIV_LLIMD
+       xnarch_init_u32frac(&tsc_frac, 1 << tsc_shift, tsc_scale);
+#endif
+#endif
+}
+
+#ifdef __KERNEL__
+EXPORT_SYMBOL(xnarch_tsc_to_ns);
+EXPORT_SYMBOL(xnarch_ns_to_tsc);
+#endif /* __KERNEL__ */
+
+#endif /* !_XENO_ASM_GENERIC_BITS_TIMECONV_H */
diff --git a/include/asm-generic/system.h b/include/asm-generic/system.h
index 052c2b7..7d68a9d 100644
--- a/include/asm-generic/system.h
+++ b/include/asm-generic/system.h
@@ -281,10 +281,7 @@ unsigned long long xnarch_get_host_time(void);
 
 long long xnarch_tsc_to_ns(long long ts);
 
-static inline long long xnarch_tsc_to_ns_rounded(long long ts)
-{
-       return (xnarch_llimd(ts, 1000000000, RTHAL_CPU_FREQ/2) + 1) / 2;
-}
+long long xnarch_tsc_to_ns_rounded(long long ts);
 
 long long xnarch_ns_to_tsc(long long ns);
 
diff --git a/include/asm-powerpc/arith.h b/include/asm-powerpc/arith.h
index d4ceb10..9bcf7a0 100644
--- a/include/asm-powerpc/arith.h
+++ b/include/asm-powerpc/arith.h
@@ -19,7 +19,7 @@
 #ifndef _XENO_ASM_POWERPC_ARITH_H
 #define _XENO_ASM_POWERPC_ARITH_H
 
-#define XNARCH_WANT_NODIV_MULDIV
+#include <asm/xenomai/features.h>
 
 #ifdef __powerpc64__
 
diff --git a/include/asm-powerpc/bits/init.h b/include/asm-powerpc/bits/init.h
index 86dcb14..e90e1c6 100644
--- a/include/asm-powerpc/bits/init.h
+++ b/include/asm-powerpc/bits/init.h
@@ -29,6 +29,7 @@
 
 #include <linux/init.h>
 #include <asm/xenomai/calibration.h>
+#include <asm-generic/xenomai/bits/timeconv.h>
 
 int xnarch_escalation_virq;
 
@@ -67,40 +68,33 @@ int xnarch_calibrate_sched(void)
 
 static inline int xnarch_init(void)
 {
-       extern unsigned xnarch_tsc_scale, xnarch_tsc_shift, xnarch_tsc_divide;
-       extern rthal_u32frac_t xnarch_tsc_frac;
-       int err;
+       int ret;
 
-       err = rthal_init();
-
-       if (err)
-               return err;
+       ret = rthal_init();
+       if (ret)
+               return ret;
 
 #if defined(CONFIG_SMP) && defined(MODULE)
-       /* Make sure the init sequence is kept on the same CPU when
-          running as a module. */
+       /*
+        * Make sure the init sequence is kept on the same CPU when
+        * running as a module.
+        */
        set_cpus_allowed(current, cpumask_of_cpu(0));
 #endif /* CONFIG_SMP && MODULE */
 
-       xnarch_init_llmulshft(1000000000, RTHAL_CPU_FREQ,
-                             &xnarch_tsc_scale, &xnarch_tsc_shift);
-       xnarch_tsc_divide = 1 << xnarch_tsc_shift;
-
-       xnarch_init_u32frac(&xnarch_tsc_frac, xnarch_tsc_divide, 
xnarch_tsc_scale);
+       xnarch_init_timeconv(RTHAL_CPU_FREQ);
 
-       err = xnarch_calibrate_sched();
-
-       if (err)
-               return err;
+       ret = xnarch_calibrate_sched();
+       if (ret)
+               return ret;
 
        xnarch_escalation_virq = rthal_alloc_virq();
-
        if (xnarch_escalation_virq == 0)
                return -ENOSYS;
 
        rthal_virtualize_irq(&rthal_domain,
                             xnarch_escalation_virq,
-                            (rthal_irq_handler_t) & xnpod_schedule_handler,
+                            (rthal_irq_handler_t) &xnpod_schedule_handler,
                             NULL, NULL, IPIPE_HANDLE_MASK | IPIPE_WIRED_MASK);
 
        xnarch_old_trap_handler = rthal_trap_catch(&xnarch_trap_fault);
diff --git a/include/asm-powerpc/bits/pod.h b/include/asm-powerpc/bits/pod.h
index c335ccc..9973243 100644
--- a/include/asm-powerpc/bits/pod.h
+++ b/include/asm-powerpc/bits/pod.h
@@ -23,23 +23,6 @@
 #ifndef _XENO_ASM_POWERPC_BITS_POD_H
 #define _XENO_ASM_POWERPC_BITS_POD_H
 
-unsigned xnarch_tsc_scale;
-unsigned xnarch_tsc_shift;
-unsigned xnarch_tsc_divide;
-rthal_u32frac_t xnarch_tsc_frac;
-
-long long xnarch_tsc_to_ns(long long ts)
-{
-       return xnarch_llmulshft(ts, xnarch_tsc_scale, xnarch_tsc_shift);
-}
-#define XNARCH_TSC_TO_NS
-
-long long xnarch_ns_to_tsc(long long ns)
-{
-       return xnarch_nodiv_llimd(ns, xnarch_tsc_frac.frac, 
xnarch_tsc_frac.integ);
-}
-#define XNARCH_NS_TO_TSC
-
 #include <asm-generic/xenomai/bits/pod.h>
 
 void xnpod_welcome_thread(struct xnthread *, int);
diff --git a/include/asm-powerpc/features.h b/include/asm-powerpc/features.h
index b6165a3..ed8f6b0 100644
--- a/include/asm-powerpc/features.h
+++ b/include/asm-powerpc/features.h
@@ -38,4 +38,7 @@ static inline const char *get_feature_label(unsigned feature)
        return get_generic_feature_label(feature);
 }
 
+#define XNARCH_HAVE_LLMULSHFT    1
+#define XNARCH_HAVE_NODIV_LLIMD  1
+
 #endif /* !_XENO_ASM_POWERPC_FEATURES_H */
diff --git a/include/asm-powerpc/syscall.h b/include/asm-powerpc/syscall.h
index 00850b6..8b0f8d3 100644
--- a/include/asm-powerpc/syscall.h
+++ b/include/asm-powerpc/syscall.h
@@ -147,7 +147,7 @@ static inline int __xn_interrupted_p(struct pt_regs *regs)
 #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)
 
-#define CONFIG_XENO_HW_DIRECT_TSC 1
+#define CONFIG_XENO_HW_DIRECT_TSC  1
 
 static inline unsigned long long __xn_rdtsc(void)
 #if defined(__powerpc64__)
@@ -175,6 +175,9 @@ static inline unsigned long long __xn_rdtsc(void)
 }
 #endif /* __powerpc64__ */
 
+#define CONFIG_XENO_HAVE_LLMULSHFT    1
+#define CONFIG_XENO_HAVE_NODIV_LLIMD  1
+
 #endif /* __KERNEL__ */
 
 #endif /* !_XENO_ASM_POWERPC_SYSCALL_H */
diff --git a/include/asm-x86/arith_32.h b/include/asm-x86/arith_32.h
index 28dd6f5..517d391 100644
--- a/include/asm-x86/arith_32.h
+++ b/include/asm-x86/arith_32.h
@@ -38,6 +38,8 @@
 #define _XENO_ASM_X86_ARITH_32_H
 #define _XENO_ASM_X86_ARITH_H
 
+#include <asm/xenomai/features.h>
+
 #define __rthal_u64tou32(ull, h, l) ({          \
     unsigned long long _ull = (ull);            \
     (l) = _ull & 0xffffffff;                    \
@@ -135,8 +137,6 @@ __rthal_i386_ulldiv (const unsigned long long ull,
        __ret;                                                          \
 })
 
-#define XNARCH_WANT_NODIV_MULDIV
-
 static inline __attribute__((const)) unsigned long long
 __rthal_x86_nodiv_ullimd(const unsigned long long op,
                         const unsigned long long frac,
diff --git a/include/asm-x86/arith_64.h b/include/asm-x86/arith_64.h
index f1285ad..7f969b3 100644
--- a/include/asm-x86/arith_64.h
+++ b/include/asm-x86/arith_64.h
@@ -26,6 +26,8 @@
 #define _XENO_ASM_X86_ARITH_64_H
 #define _XENO_ASM_X86_ARITH_H
 
+#include <asm/xenomai/features.h>
+
 static inline __attribute__((__const__)) long long
 __rthal_x86_64_llimd (long long op, unsigned m, unsigned d)
 {
@@ -60,8 +62,6 @@ __rthal_x86_64_llmulshft(long long op, unsigned m, unsigned s)
 }
 #define rthal_llmulshft(op, m, s) __rthal_x86_64_llmulshft((op), (m), (s))
 
-#define XNARCH_WANT_NODIV_MULDIV
-
 static inline __attribute__((__const__)) unsigned long long
 __rthal_x86_64_nodiv_ullimd(unsigned long long op,
                            unsigned long long frac, unsigned rhs_integ)
diff --git a/include/asm-x86/bits/init_32.h b/include/asm-x86/bits/init_32.h
index 0545e66..5df0c5f 100644
--- a/include/asm-x86/bits/init_32.h
+++ b/include/asm-x86/bits/init_32.h
@@ -27,6 +27,7 @@
 
 #include <linux/init.h>
 #include <asm/xenomai/calibration.h>
+#include <asm-generic/xenomai/bits/timeconv.h>
 
 int xnarch_escalation_virq;
 
@@ -73,37 +74,33 @@ int xnarch_calibrate_sched(void)
 
 static inline int xnarch_init(void)
 {
-       extern unsigned xnarch_tsc_scale, xnarch_tsc_shift, xnarch_tsc_divide;
-       int err;
+       int ret;
 
-       err = rthal_init();
-
-       if (err)
-               return err;
+       ret = rthal_init();
+       if (ret)
+               return ret;
 
 #if defined(CONFIG_SMP) && defined(MODULE)
-       /* Make sure the init sequence is kept on the same CPU when
-          running as a module. */
+       /*
+        * Make sure the init sequence is kept on the same CPU when
+        * running as a module.
+        */
        set_cpus_allowed(current, cpumask_of_cpu(0));
 #endif /* CONFIG_SMP && MODULE */
 
-       xnarch_init_llmulshft(1000000000, RTHAL_CPU_FREQ,
-                             &xnarch_tsc_scale, &xnarch_tsc_shift);
-       xnarch_tsc_divide = 1 << xnarch_tsc_shift;
-
-       err = xnarch_calibrate_sched();
+       xnarch_init_timeconv(RTHAL_CPU_FREQ);
 
-       if (err)
-               return err;
+       ret = xnarch_calibrate_sched();
+       if (ret)
+               return ret;
 
        xnarch_escalation_virq = rthal_alloc_virq();
-
        if (xnarch_escalation_virq == 0)
                return -ENOSYS;
 
        rthal_virtualize_irq(&rthal_domain,
                             xnarch_escalation_virq,
-                            (rthal_irq_handler_t) & xnpod_schedule_handler,
+                            (rthal_irq_handler_t) &xnpod_schedule_handler,
                             NULL, NULL, IPIPE_HANDLE_MASK | IPIPE_WIRED_MASK);
 
        xnarch_old_trap_handler = rthal_trap_catch(&xnarch_trap_fault);
diff --git a/include/asm-x86/bits/init_64.h b/include/asm-x86/bits/init_64.h
index 1093b9c..075151b 100644
--- a/include/asm-x86/bits/init_64.h
+++ b/include/asm-x86/bits/init_64.h
@@ -27,6 +27,7 @@
 
 #include <linux/init.h>
 #include <asm/xenomai/calibration.h>
+#include <asm-generic/xenomai/bits/timeconv.h>
 
 int xnarch_escalation_virq;
 
@@ -70,40 +71,33 @@ int xnarch_calibrate_sched(void)
 
 static inline int xnarch_init(void)
 {
-       extern unsigned xnarch_tsc_scale, xnarch_tsc_shift, xnarch_tsc_divide;
-       extern rthal_u32frac_t xnarch_tsc_frac;
-       int err;
+       int ret;
 
-       err = rthal_init();
-
-       if (err)
-               return err;
+       ret = rthal_init();
+       if (ret)
+               return ret;
 
 #if defined(CONFIG_SMP) && defined(MODULE)
-       /* Make sure the init sequence is kept on the same CPU when
-          running as a module. */
+       /*
+        * Make sure the init sequence is kept on the same CPU when
+        * running as a module.
+        */
        set_cpus_allowed(current, cpumask_of_cpu(0));
 #endif /* CONFIG_SMP && MODULE */
 
-       xnarch_init_llmulshft(1000000000, RTHAL_CPU_FREQ,
-                             &xnarch_tsc_scale, &xnarch_tsc_shift);
-       xnarch_tsc_divide = 1 << xnarch_tsc_shift;
-
-       xnarch_init_u32frac(&xnarch_tsc_frac, xnarch_tsc_divide, 
xnarch_tsc_scale);
+       xnarch_init_timeconv(RTHAL_CPU_FREQ);
 
-       err = xnarch_calibrate_sched();
-
-       if (err)
-               return err;
+       ret = xnarch_calibrate_sched();
+       if (ret)
+               return ret;
 
        xnarch_escalation_virq = rthal_alloc_virq();
-
        if (xnarch_escalation_virq == 0)
                return -ENOSYS;
 
        rthal_virtualize_irq(&rthal_domain,
                             xnarch_escalation_virq,
-                            (rthal_irq_handler_t) & xnpod_schedule_handler,
+                            (rthal_irq_handler_t) &xnpod_schedule_handler,
                             NULL, NULL, IPIPE_HANDLE_MASK | IPIPE_WIRED_MASK);
 
        xnarch_old_trap_handler = rthal_trap_catch(&xnarch_trap_fault);
diff --git a/include/asm-x86/bits/pod_32.h b/include/asm-x86/bits/pod_32.h
index bf0ec8c..fb6c507 100644
--- a/include/asm-x86/bits/pod_32.h
+++ b/include/asm-x86/bits/pod_32.h
@@ -23,22 +23,6 @@
 #define _XENO_ASM_X86_BITS_POD_32_H
 #define _XENO_ASM_X86_BITS_POD_H
 
-unsigned xnarch_tsc_scale;
-unsigned xnarch_tsc_shift;
-unsigned xnarch_tsc_divide;
-
-long long xnarch_tsc_to_ns(long long ts)
-{
-       return xnarch_llmulshft(ts, xnarch_tsc_scale, xnarch_tsc_shift);
-}
-#define XNARCH_TSC_TO_NS
-
-long long xnarch_ns_to_tsc(long long ns)
-{
-       return xnarch_llimd(ns, xnarch_tsc_divide, xnarch_tsc_scale);
-}
-#define XNARCH_NS_TO_TSC
-
 #include <asm-generic/xenomai/bits/pod.h>
 #include <asm/xenomai/switch.h>
 
diff --git a/include/asm-x86/bits/pod_64.h b/include/asm-x86/bits/pod_64.h
index 0ca00f3..3eea0f5 100644
--- a/include/asm-x86/bits/pod_64.h
+++ b/include/asm-x86/bits/pod_64.h
@@ -22,25 +22,6 @@
 #define _XENO_ASM_X86_BITS_POD_64_H
 #define _XENO_ASM_X86_BITS_POD_H
 
-unsigned xnarch_tsc_scale;
-unsigned xnarch_tsc_shift;
-unsigned xnarch_tsc_divide;
-rthal_u32frac_t xnarch_tsc_frac;
-
-long long xnarch_tsc_to_ns(long long ts)
-{
-       return xnarch_llmulshft(ts, xnarch_tsc_scale, xnarch_tsc_shift);
-}
-#define XNARCH_TSC_TO_NS
-
-long long xnarch_ns_to_tsc(long long ns)
-{
-       return xnarch_nodiv_llimd(ns,
-                                 xnarch_tsc_frac.frac,
-                                 xnarch_tsc_frac.integ);
-}
-#define XNARCH_NS_TO_TSC
-
 #include <asm-generic/xenomai/bits/pod.h>
 #include <asm/xenomai/switch.h>
 
diff --git a/include/asm-x86/features_32.h b/include/asm-x86/features_32.h
index 157bb15..c3669ad 100644
--- a/include/asm-x86/features_32.h
+++ b/include/asm-x86/features_32.h
@@ -108,4 +108,7 @@ static inline void xeno_x86_features_check(void)
 #define xeno_arch_features_check() xeno_x86_features_check()
 #endif /* __KERNEL__ */
 
+#define XNARCH_HAVE_LLMULSHFT    1
+#define XNARCH_HAVE_NODIV_LLIMD  1
+
 #endif /* !_XENO_ASM_X86_FEATURES_32_H */
diff --git a/include/asm-x86/features_64.h b/include/asm-x86/features_64.h
index c58bd99..04b7ccb 100644
--- a/include/asm-x86/features_64.h
+++ b/include/asm-x86/features_64.h
@@ -39,4 +39,7 @@ static inline const char *get_feature_label (unsigned feature)
        return get_generic_feature_label(feature);
 }
 
+#define XNARCH_HAVE_LLMULSHFT    1
+#define XNARCH_HAVE_NODIV_LLIMD  1
+
 #endif /* !_XENO_ASM_X86_FEATURES_64_H */
diff --git a/include/native/syscall.h b/include/native/syscall.h
index ebe0322..5d8c79e 100644
--- a/include/native/syscall.h
+++ b/include/native/syscall.h
@@ -115,8 +115,8 @@
 #define __native_unimp_89           89
 #define __native_io_get_region      90
 #define __native_io_put_region      91
-#define __native_timer_ns2tsc       92
-#define __native_timer_tsc2ns       93
+#define __native_unimp_92           92
+#define __native_unimp_93           93
 #define __native_queue_write        94
 #define __native_queue_read         95
 #define __native_buffer_create      96
diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index a0890ef..850334f 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -966,27 +966,6 @@ static int __rt_timer_ns2ticks(struct pt_regs *regs)
 }
 
 /*
- * int __rt_timer_ns2tsc(SRTIME *ticksp, SRTIME *nsp)
- */
-
-static int __rt_timer_ns2tsc(struct pt_regs *regs)
-{
-       SRTIME ns, ticks;
-
-       if (__xn_safe_copy_from_user(&ns, (void __user *)__xn_reg_arg2(regs),
-                                    sizeof(ns)))
-               return -EFAULT;
-
-       ticks = rt_timer_ns2tsc(ns);
-
-       if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &ticks,
-                                  sizeof(ticks)))
-               return -EFAULT;
-
-       return 0;
-}
-
-/*
  * int __rt_timer_ticks2ns(SRTIME *nsp, SRTIME *ticksp)
  */
 
@@ -1007,26 +986,6 @@ static int __rt_timer_ticks2ns(struct pt_regs *regs)
 }
 
 /*
- * int __rt_timer_tsc2ns(SRTIME *nsp, SRTIME *ticksp)
- */
-
-static int __rt_timer_tsc2ns(struct pt_regs *regs)
-{
-       SRTIME ticks, ns;
-
-       if (__xn_safe_copy_from_user(&ticks, (void __user *)__xn_reg_arg2(regs),
-                                    sizeof(ticks)))
-               return -EFAULT;
-
-       ns = rt_timer_tsc2ns(ticks);
-
-       if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &ns, 
sizeof(ns)))
-               return -EFAULT;
-
-       return 0;
-}
-
-/*
  * int __rt_timer_inquire(RT_TIMER_INFO *info)
  */
 
@@ -4159,8 +4118,8 @@ static xnsysent_t __systab[] = {
        [__native_unimp_89] = {&__rt_call_not_available, __xn_exec_any},
        [__native_io_get_region] = {&__rt_io_get_region, __xn_exec_lostage},
        [__native_io_put_region] = {&__rt_io_put_region, __xn_exec_lostage},
-       [__native_timer_ns2tsc] = {&__rt_timer_ns2tsc, __xn_exec_any},
-       [__native_timer_tsc2ns] = {&__rt_timer_tsc2ns, __xn_exec_any},
+       [__native_unimp_92] = {&__rt_call_not_available, __xn_exec_any},
+       [__native_unimp_93] = {&__rt_call_not_available, __xn_exec_any},
        [__native_buffer_create] = {&__rt_buffer_create, __xn_exec_any},
        [__native_buffer_bind] = {&__rt_buffer_bind, __xn_exec_conforming},
        [__native_buffer_delete] = {&__rt_buffer_delete, __xn_exec_any},
diff --git a/src/skins/native/init.c b/src/skins/native/init.c
index c71b3d2..215acc1 100644
--- a/src/skins/native/init.c
+++ b/src/skins/native/init.c
@@ -57,9 +57,7 @@ void __init_xeno_interface(void)
        __native_muxid =
            xeno_bind_skin(XENO_SKIN_MAGIC, "native", "xeno_native");
 
-#ifdef CONFIG_XENO_HW_DIRECT_TSC
        native_timer_init(__native_muxid);
-#endif /* CONFIG_XENO_HW_DIRECT_TSC */
        
        __native_muxid = __xn_mux_shifted_id(__native_muxid);
 }
diff --git a/src/skins/native/timer.c b/src/skins/native/timer.c
index 89205a8..e1be37b 100644
--- a/src/skins/native/timer.c
+++ b/src/skins/native/timer.c
@@ -20,11 +20,10 @@
 #include <stdlib.h>
 #include <native/syscall.h>
 #include <native/timer.h>
-#include <asm/xenomai/arith.h>
+#include <asm-generic/xenomai/bits/timeconv.h>
 
 extern int __native_muxid;
 
-#ifdef CONFIG_XENO_HW_DIRECT_TSC
 static xnsysinfo_t sysinfo;
 
 void native_timer_init(int muxid)
@@ -35,8 +34,9 @@ void native_timer_init(int muxid)
                        "sys_info: %s\n", strerror(-err));
                exit(EXIT_FAILURE);
        }
+
+       xnarch_init_timeconv(sysinfo.cpufreq);
 }
-#endif /* CONFIG_XENO_HW_DIRECT_TSC */
 
 int rt_timer_set_mode(RTIME tickval)
 {
@@ -83,26 +83,12 @@ SRTIME rt_timer_ticks2ns(SRTIME ticks)
 
 SRTIME rt_timer_ns2tsc(SRTIME ns)
 {
-       RTIME ticks;
-
-#ifdef CONFIG_XENO_HW_DIRECT_TSC
-       ticks = xnarch_llimd(ns, sysinfo.cpufreq, 1000000000);
-#else /* !CONFIG_XENO_HW_DIRECT_TSC */
-       XENOMAI_SKINCALL2(__native_muxid, __native_timer_ns2tsc, &ticks, &ns);
-#endif /* !CONFIG_XENO_HW_DIRECT_TSC */
-       return ticks;
+       return xnarch_ns_to_tsc(ns);
 }
 
 SRTIME rt_timer_tsc2ns(SRTIME ticks)
 {
-       SRTIME ns;
-
-#ifdef CONFIG_XENO_HW_DIRECT_TSC
-       ns = xnarch_llimd(ticks, 1000000000, sysinfo.cpufreq);
-#else /* !CONFIG_XENO_HW_DIRECT_TSC */
-       XENOMAI_SKINCALL2(__native_muxid, __native_timer_tsc2ns, &ns, &ticks);
-#endif /* !CONFIG_XENO_HW_DIRECT_TSC */
-       return ns;
+       return xnarch_tsc_to_ns(ticks);
 }
 
 int rt_timer_inquire(RT_TIMER_INFO *info)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to