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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Oct  1 11:35:00 2014 +0200

cobalt/timer: anticipate trigger date when starting timer

---

 include/cobalt/kernel/timer.h |   21 +++++++++++++++++----
 kernel/cobalt/clock.c         |   27 +++------------------------
 kernel/cobalt/timer.c         |   10 +++++++++-
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index dcb6927..772a430 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -268,12 +268,25 @@ static inline xntimerq_t *xntimer_this_queue(struct 
xntimer *timer)
        return &tmd->q;
 }
 
-static inline void xntimer_update_date(struct xntimer *timer)
+static inline unsigned long xntimer_get_gravity(struct xntimer *timer)
 {
-       xntimerh_date(&timer->aplink) = timer->start_date +
-               xnclock_ns_to_ticks(xntimer_clock(timer),
-                               timer->periodic_ticks * timer->interval_ns);
+       struct xnclock *clock = xntimer_clock(timer);
+
+       if (timer->status & XNTIMER_KGRAVITY)
+               return clock->gravity.kernel;
+
+       if (timer->status & XNTIMER_UGRAVITY)
+               return clock->gravity.user;
 
+       return clock->gravity.irq;
+}
+
+static inline void xntimer_update_date(struct xntimer *timer)
+{
+       xntimerh_date(&timer->aplink) = timer->start_date
+               + xnclock_ns_to_ticks(xntimer_clock(timer),
+                       timer->periodic_ticks * timer->interval_ns)
+               - xntimer_get_gravity(timer);
 }
 
 static inline xnticks_t xntimer_pexpect(struct xntimer *timer)
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 962e1f9..2303959 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -121,17 +121,6 @@ EXPORT_SYMBOL_GPL(xnclock_core_ticks_to_ns_rounded);
 EXPORT_SYMBOL_GPL(xnclock_core_ns_to_ticks);
 EXPORT_SYMBOL_GPL(xnclock_divrem_billion);
 
-static inline unsigned long get_timer_gravity(struct xntimer *timer)
-{
-       if (timer->status & XNTIMER_KGRAVITY)
-               return nkclock.gravity.kernel;
-
-       if (timer->status & XNTIMER_UGRAVITY)
-               return nkclock.gravity.user;
-
-       return nkclock.gravity.irq;
-}
-
 void xnclock_core_local_shot(struct xnsched *sched)
 {
        struct xntimerdata *tmd;
@@ -186,16 +175,7 @@ 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));
-
+       delay = xntimerh_date(&timer->aplink) - xnclock_core_read_raw();
        if (delay < 0)
                delay = 0;
        else if (delay > ULONG_MAX)
@@ -695,9 +675,9 @@ void xnclock_tick(struct xnclock *clock)
 {
        xntimerq_t *timerq = &xnclock_this_timerdata(clock)->q;
        struct xnsched *sched = xnsched_current();
-       xnticks_t now, interval_ticks;
        struct xntimer *timer;
        xnsticks_t delta;
+       xnticks_t now;
        xntimerh_t *h;
 
        /*
@@ -767,9 +747,8 @@ void xnclock_tick(struct xnclock *clock)
                    (XNTIMER_PERIODIC|XNTIMER_DEQUEUED|XNTIMER_RUNNING))
                        continue;
        advance:
-               interval_ticks = 1;
                do {
-                       timer->periodic_ticks += interval_ticks;
+                       timer->periodic_ticks++;
                        xntimer_update_date(timer);
                } while (xntimerh_date(&timer->aplink) < now);
        requeue:
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 9e6f8e5..a18482a 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -144,7 +144,15 @@ int xntimer_start(struct xntimer *timer,
                break;
        }
 
-       xntimerh_date(&timer->aplink) = date;
+       /*
+        * To cope with the basic system latency, we apply a clock
+        * gravity value, which is the amount of time expressed in
+        * clock ticks by which we should anticipate the shot for any
+        * outstanding timer. The gravity value varies with the type
+        * of context the timer wakes up, i.e. irq handler, kernel or
+        * user thread.
+        */
+       xntimerh_date(&timer->aplink) = date - xntimer_get_gravity(timer);
 
        timer->interval_ns = XN_INFINITE;
        timer->interval = XN_INFINITE;


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

Reply via email to