Skip to contentSkip to conversation

simplify xntimer_start

PATCH Applied Jan Kiszka 2 participants 2 messages Jul 18, 2006 – Jul 19, 2006

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 2/2 simplify xntimer_start

Almost all callers of xntimer_start already run in nklock-protected context. Therefore, we can save the lock reacquisition in that function and turn it even into a trivial inliner. This patch also takes care of the two exceptions of the rule above in xnpod_start_timer and psos+'s tm_start_event_timer.

Jan

---
 include/nucleus/timer.h |   51 +++++++++++++++++++++++++++++++++++++++++++++---
 ksrc/nucleus/pod.c      |    2 +
 ksrc/nucleus/timer.c    |   49 ----------------------------------------------
 ksrc/skins/psos+/tm.c   |    4 ++-
 4 files changed, 53 insertions(+), 53 deletions(-)
nucleus/timer.h renamed from nucleus/timer.h.orig +48 -3
Index: include/nucleus/timer.h
===================================================================
@@ -290,9 +290,52 @@ void xntimer_init(xntimer_t *timer,
 
 void xntimer_destroy(xntimer_t *timer);
 
-void xntimer_start(xntimer_t *timer,
-		   xnticks_t value,
-		   xnticks_t interval);
+/*!
+ * \fn void xntimer_start(xntimer_t *timer,xnticks_t value,xnticks_t interval)
+ * \brief Arm a timer.
+ *
+ * Activates a timer so that the associated timeout handler will be
+ * fired after each expiration time. A timer can be either periodic or
+ * single-shot, depending on the reload value passed to this
+ * routine. The given timer must have been previously initialized by a
+ * call to xntimer_init().
+ *
+ * @param timer The address of a valid timer descriptor.
+ *
+ * @param value The relative date of the initial timer shot, expressed
+ * in clock ticks (see note).
+ *
+ * @param interval The reload value of the timer. It is a periodic
+ * interval value to be used for reprogramming the next timer shot,
+ * expressed in clock ticks (see note). If @a interval is equal to
+ * XN_INFINITE, the timer will not be reloaded after it has expired.
+ *
+ * @return 0 is always returned.
+ *
+ * Environments:
+ *
+ * This service can be called from:
+ *
+ * - Kernel module initialization/cleanup code
+ * - Interrupt service routine
+ * - Kernel-based task
+ * - User-space task
+ *
+ * Rescheduling: never.
+ *
+ * @note This service is sensitive to the current operation mode of
+ * the system timer, as defined by the xnpod_start_timer() service. In
+ * periodic mode, clock ticks are interpreted as periodic jiffies. In
+ * oneshot mode, clock ticks are interpreted as nanoseconds.
+ *
+ * @note Must be called with nklock held, IRQs off.
+ */
+
+static inline void xntimer_start(xntimer_t *timer,
+                                 xnticks_t value, xnticks_t interval)
+{
+    nktimer->do_timer_start(timer, value, interval);
+}
 
 /*!
  * \fn int xntimer_stop(xntimer_t *timer)
@@ -315,6 +358,8 @@ void xntimer_start(xntimer_t *timer,
  * - User-space task
  *
  * Rescheduling: never.
+ *
+ * @note Must be called with nklock held, IRQs off.
  */
 
 static inline void xntimer_stop(xntimer_t *timer)
nucleus/pod.c renamed from nucleus/pod.c.orig +2 -0
Index: ksrc/nucleus/pod.c
===================================================================
@@ -3095,8 +3095,10 @@ int xnpod_start_timer(u_long nstick, xni
 
 	xntimer_set_sched(&nkpod->htimer, xnpod_sched_slot(XNTIMER_KEEPER_ID));
 
+	xnlock_get_irqsave(&nklock, s);
 	xntimer_start(&nkpod->htimer, delta,
 		      XNARCH_HOST_TICK / nkpod->tickvalue);
+	xnlock_put_irqrestore(&nklock, s);
 
 	return 0;
 }
nucleus/timer.c renamed from nucleus/timer.c.orig +0 -49

61 lines not on this page · raw message

skins/psos+/tm.c renamed from skins/psos+/tm.c.orig +3 -1
Index: ksrc/skins/psos+/tm.c
===================================================================
@@ -87,12 +87,14 @@ static u_long tm_start_event_timer(u_lon
 	tm->magic = PSOS_TM_MAGIC;
 
 	xnlock_get_irqsave(&nklock, s);
+
 	appendq(&psostimerq, &tm->link);
 	appendgq(&tm->owner->alarmq, tm);
-	xnlock_put_irqrestore(&nklock, s);
 
 	xntimer_start(&tm->timerbase, ticks, interval);
 
+	xnlock_put_irqrestore(&nklock, s);
+
 	return SUCCESS;
 }
 
#1 lore raw
Quoted 5 lines · Jan Kiszka

Almost all callers of xntimer_start already run in nklock-protected context. Therefore, we can save the lock reacquisition in that function and turn it even into a trivial inliner. This patch also takes care of the two exceptions of the rule above in xnpod_start_timer and psos+'s tm_start_event_timer.

Applied, thanks.

Quoted 6 lines

Jan
_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Signature · 1 line
Philippe.