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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Jul 19 08:55:37 2014 +0200

cobalt/clock: prevent early timer shots

Hardware-induced latency such as cache activity may fluctuate a lot
especially on low end SoCs. For this reason we cannot assume that
resuming the target context of a timer would always take longer than
the delay represented by its gravity value.

Practically, this translates to:

- applying a gravity value when arming the clock chip hardware is
  fine, and can be considered as a valuable optimization, with up to
  100% success rate in reducing the latency if such value has been
  properly calibrated.

- adjusting a timer expiration date by the gravity delay in the clock
  handler is wrong, since the target context might resume in less time
  than such delay expresses, leading to ugly negative latencies.

If a mis-calibrated gravity value causes early shots from the clock
chip, the effect shall be compensated by the clock handler, by
postponing activation of early timers until due date, even at the
expense of additional overhead: that would call for better latency
tuning.

---

 kernel/cobalt/clock.c |   25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 8807b31..34bb425 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -186,6 +186,13 @@ void xnclock_core_local_shot(struct xnsched *sched)
                }
        }
 
+       /*
+        * The gravity value gives the amount of time expressed in
+        * clock ticks, by which we should anticipate the next shot
+        * for the given timer, to account for the typical system
+        * latency when delivering the event to an irq handler, or a
+        * kernel/user thread.
+        */
        delay = xntimerh_date(&timer->aplink) -
                (xnclock_core_read_raw() + get_timer_gravity(timer));
 
@@ -689,7 +696,6 @@ void xnclock_tick(struct xnclock *clock)
        xntimerq_t *timerq = &xnclock_this_timerdata(clock)->q;
        struct xnsched *sched = xnsched_current();
        xnticks_t now, interval_ticks;
-       unsigned long gravity;
        struct xntimer *timer;
        xnsticks_t delta;
        xntimerh_t *h;
@@ -704,21 +710,8 @@ void xnclock_tick(struct xnclock *clock)
        now = xnclock_read_raw(clock);
        while ((h = xntimerq_head(timerq)) != NULL) {
                timer = container_of(h, struct xntimer, aplink);
-               /*
-                * If the delay to the next shot is greater than the
-                * timer gravity value, we may stop scanning the timer
-                * queue, since timeout dates are ordered by
-                * increasing values.
-                *
-                * The gravity gives the amount of time expressed in
-                * clock ticks, by which we should anticipate the next
-                * shot for the given timer, to account for the
-                * typical system latency when delivering the event to
-                * an irq handler, or a kernel/user thread.
-                */
-               gravity = get_timer_gravity(timer);
                delta = (xnsticks_t)(xntimerh_date(&timer->aplink) - now);
-               if (delta > (xnsticks_t)gravity)
+               if (delta > 0)
                        break;
 
                trace_cobalt_timer_expire(timer);
@@ -778,7 +771,7 @@ void xnclock_tick(struct xnclock *clock)
                do {
                        timer->periodic_ticks += interval_ticks;
                        xntimer_update_date(timer);
-               } while (xntimerh_date(&timer->aplink) < now + gravity);
+               } while (xntimerh_date(&timer->aplink) < now);
        requeue:
 #ifdef CONFIG_SMP
                /*


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

Reply via email to