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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon May 18 16:11:49 2009 +0200

Round up results of tsc -> timer ticks conversions when programming
the tick device hardware.

Rounding down would cause lots of early shots by a few nanoseconds
being detected in xntimer_tick_aperiodic(), due to rounding errors.

---

 include/asm-arm/bits/timer.h     |    2 +-
 include/asm-generic/arith.h      |   19 ++++++++++++++++---
 include/asm-powerpc/bits/timer.h |    2 +-
 include/asm-x86/bits/timer.h     |    2 +-
 4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/include/asm-arm/bits/timer.h b/include/asm-arm/bits/timer.h
index 2014167..9433b43 100644
--- a/include/asm-arm/bits/timer.h
+++ b/include/asm-arm/bits/timer.h
@@ -29,7 +29,7 @@
 
 static inline void xnarch_program_timer_shot(unsigned long delay)
 {
-       rthal_timer_program_shot(rthal_imuldiv
+       rthal_timer_program_shot(rthal_imuldiv_up
                                 (delay, RTHAL_TIMER_FREQ, RTHAL_CPU_FREQ));
 }
 
diff --git a/include/asm-generic/arith.h b/include/asm-generic/arith.h
index 65d36cf..5ef3544 100644
--- a/include/asm-generic/arith.h
+++ b/include/asm-generic/arith.h
@@ -147,9 +147,9 @@ __rthal_generic_divmod64(unsigned long long a,
 #endif /* !rthal_divmod64 */
 
 #ifndef rthal_imuldiv
-static inline __attribute__((__const__)) int __rthal_generic_imuldiv (int i,
-                                                                 int mult,
-                                                                 int div)
+static inline __attribute__((__const__)) int __rthal_generic_imuldiv(int i,
+                                                                    int mult,
+                                                                    int div)
 {
     /* Returns (int)i = (unsigned long long)i*(unsigned)(mult)/(unsigned)div. 
*/
     const unsigned long long ull = rthal_ullmul(i, mult);
@@ -158,6 +158,18 @@ static inline __attribute__((__const__)) int 
__rthal_generic_imuldiv (int i,
 #define rthal_imuldiv(i,m,d) __rthal_generic_imuldiv((i),(m),(d))
 #endif /* !rthal_imuldiv */
 
+#ifndef rthal_imuldiv_up
+static inline __attribute__((__const__)) int __rthal_generic_imuldiv_up(int i,
+                                                                       int 
mult,
+                                                                       int div)
+{
+       /* Same as __rthal_generic_imuldiv, rounding up. */
+       const unsigned long long ull = rthal_ullmul(i, mult);
+       return rthal_uldivrem(ull + div - 1, div, NULL);
+}
+#define rthal_imuldiv_up(i,m,d) __rthal_generic_imuldiv_up((i),(m),(d))
+#endif /* !rthal_imuldiv_up */
+
 /* Division of an unsigned 96 bits ((h << 32) + l) by an unsigned 32 bits. 
    Building block for llimd. Without const qualifiers, gcc reload registers
    after each call to uldivrem. */
@@ -368,6 +380,7 @@ static inline void xnarch_init_llmulshft(const unsigned 
m_in,
 #define xnarch_mod64(a,b)            ({ unsigned long long _rem; \
                                        rthal_divmod64((a),(b),&_rem); _rem; })
 #define xnarch_imuldiv               rthal_imuldiv
+#define xnarch_imuldiv_up            rthal_imuldiv_up
 #define xnarch_llimd                 rthal_llimd
 #define xnarch_nodiv_llimd           rthal_nodiv_llimd
 #define xnarch_llmulshft             rthal_llmulshft
diff --git a/include/asm-powerpc/bits/timer.h b/include/asm-powerpc/bits/timer.h
index 137a6ed..0bccb7a 100644
--- a/include/asm-powerpc/bits/timer.h
+++ b/include/asm-powerpc/bits/timer.h
@@ -36,7 +36,7 @@ static inline void xnarch_program_timer_shot(unsigned long 
delay)
         * extra call to the tick handler would simply occur after 4
         * billions ticks.
         */
-       rthal_timer_program_shot(rthal_imuldiv
+       rthal_timer_program_shot(rthal_imuldiv_up
                                 (delay, RTHAL_TIMER_FREQ, RTHAL_CPU_FREQ));
 }
 
diff --git a/include/asm-x86/bits/timer.h b/include/asm-x86/bits/timer.h
index d957c54..54aee83 100644
--- a/include/asm-x86/bits/timer.h
+++ b/include/asm-x86/bits/timer.h
@@ -32,7 +32,7 @@ static inline void xnarch_program_timer_shot(unsigned long 
delay)
         * now. Would a timer needs more, an extra call to the tick
         * handler would simply occur after 4 billions ticks.
         */
-       rthal_timer_program_shot(rthal_imuldiv
+       rthal_timer_program_shot(rthal_imuldiv_up
                                 (delay, RTHAL_TIMER_FREQ, RTHAL_CPU_FREQ));
 #ifdef CONFIG_XENO_HW_NMI_DEBUG_LATENCY
        {


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

Reply via email to