All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: xenomai-core <xenomai@xenomai.org>
Subject: [Xenomai-core] [RFC][PATCH 1/2] Reprogram timer once per tick
Date: Tue, 10 Apr 2007 00:00:40 +0200	[thread overview]
Message-ID: <461AB788.3080705@domain.hid> (raw)

[-- Attachment #1: Type: text/plain, Size: 2498 bytes --]

This is an optimisation patch, long pending in my repos, aiming at
making the aperiodic timer tick handling more predictable. It suppresses
any xntimer_next_local_shot() as long as the tick handler is running.
This avoids potential multiple (costly) timer reprogramming when timer
handlers make use of xntimer_start.

Jan


---
 include/nucleus/pod.h |    1 +
 ksrc/nucleus/timer.c  |   15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

Index: xenomai/include/nucleus/pod.h
===================================================================
--- xenomai.orig/include/nucleus/pod.h
+++ xenomai/include/nucleus/pod.h
@@ -46,6 +46,7 @@
 #define XNKCOUT  0x80000000	/* Sched callout context */
 #define XNHTICK  0x40000000	/* Host tick pending  */
 #define XNRPICK  0x20000000	/* Check RPI state */
+#define XNINTCK  0x10000000	/* In master tick handler context */
 
 /* These flags are available to the real-time interfaces */
 #define XNPOD_SPARE0  0x01000000
Index: xenomai/ksrc/nucleus/timer.c
===================================================================
--- xenomai.orig/ksrc/nucleus/timer.c
+++ xenomai/ksrc/nucleus/timer.c
@@ -54,14 +54,16 @@ static inline void xntimer_dequeue_aperi
 	__setbits(timer->status, XNTIMER_DEQUEUED);
 }
 
-static inline void xntimer_next_local_shot(xnsched_t *this_sched)
+static void xntimer_next_local_shot(xnsched_t *this_sched)
 {
 	xntimerh_t *holder = xntimerq_head(&this_sched->timerqueue);
 	xnticks_t now, delay, xdate;
 	xntimer_t *timer;
 
-	if (!holder)
-		return;		/* No pending timer. */
+	/* Do not reprogram locally when inside the tick handler - will be
+	   done on exit anyway. Also exit if there is no pending timer. */
+	if (testbits(this_sched->status, XNINTCK) || !holder)
+		return;
 
 	timer = aplink2timer(holder);
 
@@ -184,6 +186,11 @@ void xntimer_tick_aperiodic(void)
 	xntimer_t *timer;
 	xnticks_t now;
 
+	/* Optimisation: any local timer reprogramming triggered by invoked
+	   timer handlers can wait until we leave the tick handler. Use this
+	   status flag as hint to xntimer_start_aperiodic. */
+	__setbits(sched->status, XNINTCK);
+
 	now = xnarch_get_cpu_tsc();
 	while ((holder = xntimerq_head(timerq)) != NULL) {
 		timer = aplink2timer(holder);
@@ -237,6 +244,8 @@ void xntimer_tick_aperiodic(void)
 		xntimer_enqueue_aperiodic(timer);
 	}
 
+	__clrbits(sched->status, XNINTCK);
+
 	xntimer_next_local_shot(sched);
 }
 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

                 reply	other threads:[~2007-04-09 22:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=461AB788.3080705@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.