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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Tue Feb 14 21:59:33 2012 +0100

arm: optimize tsc emulation

---

 include/asm-arm/bits/bind.h           |   19 ++++++++++++-------
 include/asm-arm/syscall.h             |   16 +++++++++-------
 src/testsuite/regression/native/tsc.c |    2 +-
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/include/asm-arm/bits/bind.h b/include/asm-arm/bits/bind.h
index 78f0f68..59c4534 100644
--- a/include/asm-arm/bits/bind.h
+++ b/include/asm-arm/bits/bind.h
@@ -13,8 +13,10 @@
 #include <asm-generic/xenomai/bits/bind.h>
 #include <asm/xenomai/syscall.h>
 
-__attribute__((weak)) struct __xn_tscinfo __xn_tscinfo = {
-  type: -1
+struct __xn_full_tscinfo __xn_tscinfo = {
+       .kinfo = {
+               .type = -1,
+       },
 };
 
 static inline void xeno_arm_features_check(struct xnfeatinfo *finfo)
@@ -25,7 +27,7 @@ static inline void xeno_arm_features_check(struct xnfeatinfo 
*finfo)
        int err, fd;
        void *addr;
 
-       if (__xn_tscinfo.type != -1)
+       if (__xn_tscinfo.kinfo.type != -1)
                return;
 
        err = XENOMAI_SYSCALL2(__xn_sys_arch,
@@ -41,12 +43,15 @@ static inline void xeno_arm_features_check(struct 
xnfeatinfo *finfo)
 
        page_size = sysconf(_SC_PAGESIZE);
 
-       switch(__xn_tscinfo.type) {
+       switch(__xn_tscinfo.kinfo.type) {
 #if CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_KUSER
        case __XN_TSC_TYPE_FREERUNNING:
        case __XN_TSC_TYPE_FREERUNNING_COUNTDOWN:
        case __XN_TSC_TYPE_FREERUNNING_FAST_WRAP:
        case __XN_TSC_TYPE_DECREMENTER:
+               __xn_tscinfo.kuser_tsc_get = 
+                       (rdtsc_t *)(0xffff1004 -
+                                   ((*(unsigned *)(0xffff0ffc) + 3) << 5));
                goto domap;
 
 #elif CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING            \
@@ -55,7 +60,7 @@ static inline void xeno_arm_features_check(struct xnfeatinfo 
*finfo)
        case __XN_TSC_TYPE_FREERUNNING:
        case __XN_TSC_TYPE_FREERUNNING_COUNTDOWN:
 #if CONFIG_XENO_ARM_TSC_TYPE == __XN_TSC_TYPE_FREERUNNING_FAST_WRAP
-               if (__xn_tscinfo.mask >= ((1 << 28) - 1)) {
+               if (__xn_tscinfo.kinfo.mask >= ((1 << 28) - 1)) {
                        fprintf(stderr, "Hardware tsc is not a fast wrapping"
                                " one, select the correct platform, or fix\n"
                                "configure.in\n");
@@ -83,7 +88,7 @@ static inline void xeno_arm_features_check(struct xnfeatinfo 
*finfo)
        }
 
   domap:
-       phys_addr = (unsigned long) __xn_tscinfo.counter;
+       phys_addr = (unsigned long) __xn_tscinfo.kinfo.counter;
 
        addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED,
                    fd, phys_addr & ~(page_size - 1));
@@ -92,7 +97,7 @@ static inline void xeno_arm_features_check(struct xnfeatinfo 
*finfo)
                exit(EXIT_FAILURE);
        }
 
-       __xn_tscinfo.counter =
+       __xn_tscinfo.kinfo.counter =
                ((volatile unsigned *)
                 ((char *) addr + (phys_addr & (page_size - 1))));
 
diff --git a/include/asm-arm/syscall.h b/include/asm-arm/syscall.h
index 2f45dda..5ca1bf0 100644
--- a/include/asm-arm/syscall.h
+++ b/include/asm-arm/syscall.h
@@ -241,18 +241,20 @@ struct __xn_tscinfo {
 };
 
 #ifndef __KERNEL__
-extern struct __xn_tscinfo __xn_tscinfo;
+/* 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 *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
-       typedef unsigned long long rdtsc_t(volatile unsigned *vaddr);
-       rdtsc_t *const kuser_tsc_get =
-               (rdtsc_t *)(0xffff1004 -
-                           ((*(unsigned *)(0xffff0ffc) + 3) << 5));
-
-       return kuser_tsc_get(__xn_tscinfo.counter);
+       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.tsc;
diff --git a/src/testsuite/regression/native/tsc.c 
b/src/testsuite/regression/native/tsc.c
index cf6c357..225bce7 100644
--- a/src/testsuite/regression/native/tsc.c
+++ b/src/testsuite/regression/native/tsc.c
@@ -29,7 +29,7 @@ int main(int argc, const char *argv[])
 
 #ifdef __ARMEL__
        if (argc == 2 && !strcmp(argv[1], "-w")) {
-               secs = (rt_timer_tsc2ns(__xn_tscinfo.mask + 1ULL) + 999999999) 
/ 1000000000;
+               secs = (rt_timer_tsc2ns(__xn_tscinfo.kinfo.mask + 1ULL) + 
999999999) / 1000000000;
                fprintf(stderr, "ARM: counter wrap time: %Lu seconds\n", secs);
                min = (2 * secs + 59) / 60;
                secs = min * 60;


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

Reply via email to