Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
>> Jan Kiszka wrote:
>>  > Ok, I think it's time to summarise some results of this thread:
>>  > 
>>  >  - xntimers will be of three kinds: real-time absolute, monotonic
>>  >    absolute, and monotonic relative ones (ie. all POSIX). I'm currently
>>  >    in favour of passing this property on timer start and not pushing
>>  >    parts or more of it into timer init.
>>
>> The posix skin can live without monotonic absolute timers: monotonic
>> timeout could simply be converted to relative timeouts.
>>
> 
> The POSIX skin will not be the only user, and I rather see disadvantages
> /wrt the hot-path (multiple timer readouts + conversions) when moving
> over emulation mode again.
> 
> Anyway, I hope I can come up with some patches over the next days,
> clarifying what we actually need to change (not much I think).

Here is a first draft of a (hopefully final) xntimer_start API change.
Well, it does have some impact on this new interface and its users (but
those will need individual review anyway). So please let me know if you
think I'm on the right track -- before I generate useless changes.

Note: This snippet does not yet address isolated time bases or
re-adjustments of running timers with XNTIMER_REALTIME set. But that
will be straightforward then. Likely...

Jan


Index: xenomai/include/nucleus/timer.h
===================================================================
--- xenomai.orig/include/nucleus/timer.h
+++ xenomai/include/nucleus/timer.h
@@ -35,7 +35,9 @@
 #define XNTIMER_DEQUEUED  0x00000001
 #define XNTIMER_KILLED    0x00000002
 #define XNTIMER_PERIODIC  0x00000004
-#define XNTIMER_MONOTONIC 0x00000008
+#define XNTIMER_REALTIME  0x00000008
+
+#define XNTIMER_ABSOLUTE  0x00000010 /* only used for timer start */
 
 /* These flags are available to the real-time interfaces */
 #define XNTIMER_SPARE0  0x01000000
@@ -47,6 +49,14 @@
 #define XNTIMER_SPARE6  0x40000000
 #define XNTIMER_SPARE7  0x80000000
 
+/* Timer operation modes */
+typedef enum xntimer_mode {
+       XNTM_MONOREL = 0,
+       XNTM_MONOABS = XNTIMER_ABSOLUTE,
+       XNTM_REALABS = XNTIMER_REALTIME | XNTIMER_ABSOLUTE
+} xntimer_mode_t;
+
+/* Timer priorities */
 #define XNTIMER_LOPRIO  (-999999999)
 #define XNTIMER_STDPRIO 0
 #define XNTIMER_HIPRIO  999999999
@@ -284,10 +294,6 @@ typedef struct xntimed_slave {
 #endif /* !CONFIG_SMP */
 #define xntimer_interval(t)    ((t)->interval)
 #define xntimer_set_cookie(t,c)        ((t)->cookie = (c))
-#define xntimer_set_monotonic(t) \
-       __setbits((t)->status, XNTIMER_MONOTONIC)
-#define xntimer_set_realtime(t) \
-       __clrbits((t)->status, XNTIMER_MONOTONIC)
 
 #ifdef CONFIG_XENO_OPT_TIMING_PERIODIC
 #define xntimer_base(t)                ((t)->base)
@@ -409,7 +415,7 @@ static inline void xntimer_set_name(xnti
 
 static inline int xntimer_start(xntimer_t *timer,
                                xnticks_t value, xnticks_t interval,
-                               int mode)
+                               xntimer_mode_t mode)
 {
        return timer->base->ops->start_timer(timer, value, interval, mode);
 }
@@ -590,7 +596,7 @@ void xntslave_stop(xntslave_t *slave);
 int xntimer_start_aperiodic(xntimer_t *timer,
                            xnticks_t value,
                            xnticks_t interval,
-                           int mode);
+                           xntimer_mode_t mode);
 
 void xntimer_stop_aperiodic(xntimer_t *timer);
 
@@ -604,7 +610,7 @@ xnticks_t xntimer_get_raw_expiry_aperiod
 
 static inline int xntimer_start(xntimer_t *timer,
                                xnticks_t value, xnticks_t interval,
-                               int mode)
+                               xntimer_mode_t mode)
 {
        return xntimer_start_aperiodic(timer, value, interval, mode);
 }
Index: xenomai/include/nucleus/types.h
===================================================================
--- xenomai.orig/include/nucleus/types.h
+++ xenomai/include/nucleus/types.h
@@ -62,8 +62,6 @@ typedef int (*xniack_t)(unsigned irq);
 
 #define XN_INFINITE   (0)
 #define XN_NONBLOCK   ((xnticks_t)-1)
-#define XN_RELATIVE   0
-#define XN_ABSOLUTE   1
 
 #define XN_APERIODIC_TICK  0
 #define XN_NO_TICK         ((xnticks_t)-1)
Index: xenomai/ksrc/nucleus/timer.c
===================================================================
--- xenomai.orig/ksrc/nucleus/timer.c
+++ xenomai/ksrc/nucleus/timer.c
@@ -91,7 +91,7 @@ static inline void xntimer_next_remote_s
 
 int xntimer_start_aperiodic(xntimer_t *timer,
                            xnticks_t value, xnticks_t interval,
-                           int mode)
+                           xntimer_mode_t mode)
 {
        xnticks_t date, now;
 
@@ -100,14 +100,20 @@ int xntimer_start_aperiodic(xntimer_t *t
 
        now = xnarch_get_cpu_tsc();
 
-       if (mode == XN_RELATIVE)
+       switch (mode) {
+       case XNTM_MONOREL:
                date = xnarch_ns_to_tsc(value) + now;
-       else {
-               if (!testbits(timer->status, XNTIMER_MONOTONIC))
-                       value -= nktbase.wallclock_offset;
+               __clrbits(timer->status, XNTIMER_REALTIME);
+               break;
+       case XNTM_REALABS:
+               value -= nktbase.wallclock_offset;
+               /* fall through */
+       default: /* XNTM_MONOABS || XNTM_REALABS */
                date = xnarch_ns_to_tsc(value);
                if (date <= now)
                        return -ETIMEDOUT;
+               __setbits(timer->status, XNTIMER_REALTIME);
+               break;
        }
 
        xntimerh_date(&timer->aplink) = date;
@@ -282,18 +288,24 @@ static inline void xntimer_dequeue_perio
 
 static int xntimer_start_periodic(xntimer_t *timer,
                                  xnticks_t value, xnticks_t interval,
-                                 int mode)
+                                 xntimer_mode_t mode)
 {
        if (!testbits(timer->status, XNTIMER_DEQUEUED))
                xntimer_dequeue_periodic(timer);
 
-       if (mode == XN_RELATIVE)
+       switch (mode) {
+       case XNTM_MONOREL:
                value += timer->base->jiffies;
-       else {
-               if (!testbits(timer->status, XNTIMER_MONOTONIC))
-                       value -= timer->base->wallclock_offset;
+               __clrbits(timer->status, XNTIMER_REALTIME);
+               break;
+       case XNTM_REALABS:
+               value -= timer->base->wallclock_offset;
+               /* fall through */
+       default: /* XNTM_MONOABS || XNTM_REALABS */
                if (value <= timer->base->jiffies)
                        return -ETIMEDOUT;
+               __setbits(timer->status, XNTIMER_REALTIME);
+               break;
        }
 
        xntlholder_date(&timer->plink) = value;
@@ -479,7 +491,7 @@ void xntslave_start(xntslave_t *slave, x
                /* Spread ticks by timer latency to avoid too much nklock
                   contention and impose some servicing order. */
                xntimer_start(&pc->timer, start + cpu * nklatency,
-                             interval, XN_ABSOLUTE);
+                             interval, XNTM_MONOABS);
                xnlock_put_irqrestore(&nklock, s);
        }
 }

Attachment: signature.asc
Description: OpenPGP digital signature

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

Reply via email to