[rtems-libbsd commit] TIMEOUT(9): Start callout timer later

Sebastian Huber sebh at rtems.org
Wed Nov 13 16:38:35 UTC 2013


Module:    rtems-libbsd
Branch:    master
Commit:    7f1836cfe611e386e7fd47c9451e82d0ea709002
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=7f1836cfe611e386e7fd47c9451e82d0ea709002

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov 13 16:16:29 2013 +0100

TIMEOUT(9): Start callout timer later

This avoid race conditions during initialization.

---

 freebsd/sys/kern/kern_timeout.c |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/freebsd/sys/kern/kern_timeout.c b/freebsd/sys/kern/kern_timeout.c
index 4ef7909..1ca98d9 100644
--- a/freebsd/sys/kern/kern_timeout.c
+++ b/freebsd/sys/kern/kern_timeout.c
@@ -216,7 +216,9 @@ cc_cme_migrating(struct callout_cpu *cc)
  *	and may be called more then once.
  */
 #ifdef __rtems__
-static void rtems_bsd_timeout_init(void *);
+static void rtems_bsd_timeout_init_early(void *);
+
+static void callout_cpu_init(struct callout_cpu *);
 
 static void
 rtems_bsd_callout_timer(rtems_id id, void *arg)
@@ -231,13 +233,29 @@ rtems_bsd_callout_timer(rtems_id id, void *arg)
 	callout_tick();
 }
 
-static void callout_cpu_init(struct callout_cpu *);
+static void
+rtems_bsd_timeout_init_late(void *unused)
+{
+	rtems_status_code sc;
+	rtems_id id;
 
-SYSINIT(rtems_bsd_timeout, SI_SUB_VM, SI_ORDER_FIRST, rtems_bsd_timeout_init,
-    NULL);
+	(void) unused;
+
+	sc = rtems_timer_create(rtems_build_name('_', 'C', 'L', 'O'), &id);
+	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
+
+	sc = rtems_timer_server_fire_after(id, 1, rtems_bsd_callout_timer, NULL);
+	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
+}
+
+SYSINIT(rtems_bsd_timeout_early, SI_SUB_VM, SI_ORDER_FIRST,
+    rtems_bsd_timeout_init_early, NULL);
+
+SYSINIT(rtems_bsd_timeout_late, SI_SUB_RUN_SCHEDULER, SI_ORDER_FIRST,
+    rtems_bsd_timeout_init_late, NULL);
 
 static void
-rtems_bsd_timeout_init(void *unused)
+rtems_bsd_timeout_init_early(void *unused)
 #else /* __rtems__ */
 caddr_t
 kern_timeout_callwheel_alloc(caddr_t v)
@@ -245,8 +263,6 @@ kern_timeout_callwheel_alloc(caddr_t v)
 {
 	struct callout_cpu *cc;
 #ifdef __rtems__
-	rtems_status_code sc;
-	rtems_id id;
 	caddr_t v;
 
 	(void) unused;
@@ -275,12 +291,6 @@ kern_timeout_callwheel_alloc(caddr_t v)
 	return(v);
 #else /* __rtems__ */
 	callout_cpu_init(cc);
-
-	sc = rtems_timer_create(rtems_build_name('_', 'C', 'L', 'O'), &id);
-	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
-
-	sc = rtems_timer_server_fire_after(id, 1, rtems_bsd_callout_timer, NULL);
-	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 #endif /* __rtems__ */
 }
 




More information about the vc mailing list