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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue May 19 12:02:05 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-x86/bits/timer.h |    2 +-
 3 files changed, 18 insertions(+), 5 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 c752970..134b0e3 100644
--- a/include/asm-generic/arith.h
+++ b/include/asm-generic/arith.h
@@ -146,9 +146,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);
@@ -157,6 +157,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 */
+
 #ifndef rthal_llimd
 /* Division of an unsigned 96 bits ((h << 32) + l) by an unsigned 32 bits. 
    Building block for llimd. Without const qualifiers, gcc reload registers
@@ -275,6 +287,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_llmulshft             rthal_llmulshft
 #define xnarch_get_cpu_tsc           rthal_rdtsc
diff --git a/include/asm-x86/bits/timer.h b/include/asm-x86/bits/timer.h
index b742763..d6432ab 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