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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Jul 21 15:13:29 2015 +0200

cobalt/kernel: introduce late machine init handler

---

 kernel/cobalt/arch/arm/machine.c                   |    1 +
 kernel/cobalt/arch/blackfin/machine.c              |   25 ++++++++++----------
 kernel/cobalt/arch/nios2/machine.c                 |    1 +
 kernel/cobalt/arch/powerpc/machine.c               |    1 +
 kernel/cobalt/arch/sh/machine.c                    |    1 +
 kernel/cobalt/arch/x86/machine.c                   |    1 +
 .../cobalt/include/asm-generic/xenomai/machine.h   |    1 +
 kernel/cobalt/init.c                               |   12 ++++++++++
 8 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/kernel/cobalt/arch/arm/machine.c b/kernel/cobalt/arch/arm/machine.c
index bb50d2b..f48d4a8 100644
--- a/kernel/cobalt/arch/arm/machine.c
+++ b/kernel/cobalt/arch/arm/machine.c
@@ -111,6 +111,7 @@ static const char *const fault_labels[] = {
 struct cobalt_machine cobalt_machine = {
        .name = "arm",
        .init = NULL,
+       .late_init = NULL,
        .cleanup = NULL,
        .calibrate = mach_arm_calibrate,
        .prefault = mach_arm_prefault,
diff --git a/kernel/cobalt/arch/blackfin/machine.c 
b/kernel/cobalt/arch/blackfin/machine.c
index 8175d9d..b0a70fe 100644
--- a/kernel/cobalt/arch/blackfin/machine.c
+++ b/kernel/cobalt/arch/blackfin/machine.c
@@ -28,27 +28,25 @@ static unsigned long mach_blackfin_calibrate(void)
 
 static void schedule_deferred(void)
 {
+       xnsched_run();
+}
+
+static int mach_blackfin_late_init(void)
+{
        /*
-        * We have a small race window which turns out to be
-        * innocuous, i.e.:
+        * We hook the rescheduling handler late in the init sequence
+        * to prevent the race below from happening:
         *
         * mach_setup() ...
         *    IRQ/syscall
         *        => irq_tail_hook
         *           => xnsched_run()
         *    ...
-        * xnsys_init()
+        * xenomai_init()
         *
-        * in which case, we would call xnsched_run() for a not yet
-        * initialized system. However, we would be covered by the
-        * check for XNSCHED in xnsched_run(), which basically makes
-        * this call a nop.
+        * in which case, we would spuriously call xnsched_run()
+        * before the scheduler slot is initialized.
         */
-       xnsched_run();
-}
-
-static int mach_blackfin_init(void)
-{
        __ipipe_irq_tail_hook = (unsigned long)schedule_deferred;
 
        return 0;
@@ -83,7 +81,8 @@ static const char *const fault_labels[] = {
 
 struct cobalt_machine cobalt_machine = {
        .name = "blackfin",
-       .init = mach_blackfin_init,
+       .init = NULL,
+       .late_init = mach_blackfin_late_init,
        .cleanup = mach_blackfin_cleanup,
        .calibrate = mach_blackfin_calibrate,
        .prefault = NULL,
diff --git a/kernel/cobalt/arch/nios2/machine.c 
b/kernel/cobalt/arch/nios2/machine.c
index 39f5cc1..1c5b194 100644
--- a/kernel/cobalt/arch/nios2/machine.c
+++ b/kernel/cobalt/arch/nios2/machine.c
@@ -53,6 +53,7 @@ static const char *const fault_labels[] = {
 struct cobalt_machine cobalt_machine = {
        .name = "nios2",
        .init = NULL,
+       .late_init = NULL,
        .cleanup = NULL,
        .calibrate = mach_nios2_calibrate,
        .prefault = NULL,
diff --git a/kernel/cobalt/arch/powerpc/machine.c 
b/kernel/cobalt/arch/powerpc/machine.c
index 62c339c..2e1643a 100644
--- a/kernel/cobalt/arch/powerpc/machine.c
+++ b/kernel/cobalt/arch/powerpc/machine.c
@@ -65,6 +65,7 @@ static const char *const fault_labels[] = {
 struct cobalt_machine cobalt_machine = {
        .name = "powerpc",
        .init = mach_powerpc_init,
+       .late_init = NULL,
        .cleanup = NULL,
        .calibrate = mach_powerpc_calibrate,
        .prefault = NULL,
diff --git a/kernel/cobalt/arch/sh/machine.c b/kernel/cobalt/arch/sh/machine.c
index 327632c..f331b9d 100644
--- a/kernel/cobalt/arch/sh/machine.c
+++ b/kernel/cobalt/arch/sh/machine.c
@@ -52,6 +52,7 @@ static const char *const fault_labels[] = {
 struct cobalt_machine cobalt_machine = {
        .name = "sh",
        .init = NULL,
+       .late_init = NULL,
        .cleanup = NULL,
        .calibrate = mach_sh_calibrate,
        .prefault = NULL,
diff --git a/kernel/cobalt/arch/x86/machine.c b/kernel/cobalt/arch/x86/machine.c
index 67a3729..4ca5cd8 100644
--- a/kernel/cobalt/arch/x86/machine.c
+++ b/kernel/cobalt/arch/x86/machine.c
@@ -184,6 +184,7 @@ static const char *const fault_labels[] = {
 struct cobalt_machine cobalt_machine = {
        .name = "x86",
        .init = mach_x86_init,
+       .late_init = NULL,
        .cleanup = mach_x86_cleanup,
        .calibrate = mach_x86_calibrate,
        .prefault = NULL,
diff --git a/kernel/cobalt/include/asm-generic/xenomai/machine.h 
b/kernel/cobalt/include/asm-generic/xenomai/machine.h
index f0c0562..25764f9 100644
--- a/kernel/cobalt/include/asm-generic/xenomai/machine.h
+++ b/kernel/cobalt/include/asm-generic/xenomai/machine.h
@@ -29,6 +29,7 @@ struct vm_area_struct;
 struct cobalt_machine {
        const char *name;
        int (*init)(void);
+       int (*late_init)(void);
        void (*cleanup)(void);
        void (*prefault)(struct vm_area_struct *vma);
        unsigned long (*calibrate)(void);
diff --git a/kernel/cobalt/init.c b/kernel/cobalt/init.c
index 25d49b6..d89e21d 100644
--- a/kernel/cobalt/init.c
+++ b/kernel/cobalt/init.c
@@ -239,6 +239,14 @@ fail_apc:
        return ret;
 }
 
+static inline int __init mach_late_setup(void)
+{
+       if (cobalt_machine.late_init)
+               return cobalt_machine.late_init();
+
+       return 0;
+}
+
 static __init void mach_cleanup(void)
 {
        ipipe_unregister_head(&xnsched_realtime_domain);
@@ -368,6 +376,10 @@ static int __init xenomai_init(void)
        if (ret)
                goto cleanup_select;
 
+       ret = mach_late_setup();
+       if (ret)
+               goto cleanup_sys;
+
        ret = rtdm_init();
        if (ret)
                goto cleanup_sys;


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

Reply via email to