Module: xenomai-forge
Branch: next
Commit: b78c14c033ca12e976bd188c3f782c578b35e320
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b78c14c033ca12e976bd188c3f782c578b35e320

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jul 31 15:32:14 2013 +0200

cobalt/pod: drop PEXEC and FATAL condition bits

XNPEXEC makes no sense anymore as it used to protect our kernel
handlers from running when no real-time services are available yet.

It turns out that the Cobalt core is now initialized early, and those
handlers are not even installed until the interrupt pipeline is
requested to forward the trap and syscall events, which only
happens...after the system has been initialized.

Finally, exposing the fatal bit as a global state flag, only to test
it within the panic handler was quite overkill.

---

 include/cobalt/kernel/assert.h        |    4 +-
 include/cobalt/kernel/pod.h           |   14 +-----
 kernel/cobalt/arch/blackfin/machine.c |   19 ++++++-
 kernel/cobalt/pod.c                   |   46 +++++------------
 kernel/cobalt/registry.c              |    3 -
 kernel/cobalt/shadow.c                |   92 ++++++++------------------------
 kernel/cobalt/timer.c                 |    7 +--
 kernel/cobalt/vfile.c                 |    8 ---
 8 files changed, 59 insertions(+), 134 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 6bd00bd..c54b824 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -46,6 +46,8 @@
 #define CONFIG_XENO_OPT_DEBUG_NUCLEUS 0
 #endif /* CONFIG_XENO_OPT_DEBUG_NUCLEUS */
 
-void xnpod_fatal(const char *format, ...);
+extern void (*nkpanic)(const char *format, ...);
+
+#define xnpod_fatal(__fmt, __args...) nkpanic(__fmt, ##__args)
 
 #endif /* !_COBALT_KERNEL_ASSERT_H */
diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index c5b4290..d7e0d94 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -36,9 +36,7 @@
 #include <cobalt/kernel/lock.h>
 
 /* Pod status flags */
-#define XNFATAL  0x00000001    /* Fatal error in progress */
-#define XNPEXEC  0x00000002    /* Pod is active (a skin is attached) */
-#define XNCLKLK  0x00000004    /* All clocks locked */
+#define XNCLKLK  0x00000001    /* All clocks locked */
 
 #define XNPOD_NORMAL_EXIT  0x0
 #define XNPOD_FATAL_EXIT   0x1
@@ -102,16 +100,6 @@ static inline struct xnsched *xnpod_current_sched(void)
        return __this_cpu_ptr(&nksched);
 }
 
-static inline int xnpod_active_p(void)
-{
-       return nkpod->status & XNPEXEC;
-}
-
-static inline int xnpod_fatal_p(void)
-{
-       return nkpod->status & XNFATAL;
-}
-
 static inline int xnpod_interrupt_p(void)
 {
        return xnpod_current_sched()->lflags & XNINIRQ;
diff --git a/kernel/cobalt/arch/blackfin/machine.c 
b/kernel/cobalt/arch/blackfin/machine.c
index ef279d6..bdaec5b 100644
--- a/kernel/cobalt/arch/blackfin/machine.c
+++ b/kernel/cobalt/arch/blackfin/machine.c
@@ -28,8 +28,23 @@ static unsigned long mach_blackfin_calibrate(void)
 
 static void schedule_deferred(void)
 {
-       if (xnpod_active_p())
-               xnpod_schedule();
+       /*
+        * We have a small race window which turns out to be
+        * innocuous, i.e.:
+        *
+        * mach_setup() ...
+        *    IRQ/syscall
+        *        => irq_tail_hook
+        *           => xnpod_schedule()
+        *    ...
+        * xnpod_init()
+        *
+        * in which case, we would call xnpod_schedule() for a not yet
+        * initialized system. However, we would be covered by the
+        * check for XNSCHED in xnpod_schedule(), which basically
+        * makes this call a nop.
+        */
+       xnpod_schedule();
 }
 
 static int mach_blackfin_init(void)
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 5d911af..7bb8d07 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -36,6 +36,7 @@
 #include <linux/kallsyms.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
+#include <linux/kernel.h>
 #include <linux/wait.h>
 #include <cobalt/kernel/pod.h>
 #include <cobalt/kernel/timer.h>
@@ -55,6 +56,9 @@
 xnpod_t nkpod_struct;
 EXPORT_SYMBOL_GPL(nkpod_struct);
 
+void (*nkpanic)(const char *format, ...) = panic;
+EXPORT_SYMBOL_GPL(nkpanic);
+
 unsigned long nktimerlat;
 
 cpumask_t nkaffinity = XNPOD_ALL_CPUS;
@@ -133,11 +137,12 @@ static inline void __xnpod_switch_fpu(struct xnsched 
*sched)
 
 #endif /* !CONFIG_XENO_HW_FPU */
 
-void xnpod_fatal(const char *format, ...)
+static void fatal(const char *format, ...)
 {
        static char msg_buf[1024];
        struct xnthread *thread;
        struct xnsched *sched;
+       static int oopsed;
        char pbuf[16];
        xnticks_t now;
        unsigned cpu;
@@ -150,15 +155,15 @@ void xnpod_fatal(const char *format, ...)
 
        xnlock_get_irqsave(&nklock, s);
 
+       if (oopsed)
+               goto out;
+
+       oopsed = 1;
        va_start(ap, format);
        vsnprintf(msg_buf, sizeof(msg_buf), format, ap);
        printk(XENO_ERR "%s", msg_buf);
        va_end(ap);
 
-       if (!xnpod_active_p() || xnpod_fatal_p())
-               goto out;
-
-       nkpod->status |= XNFATAL;
        now = xnclock_read_monotonic(&nkclock);
 
        printk(KERN_ERR "\n %-3s  %-6s %-8s %-8s %-8s  %s\n",
@@ -199,7 +204,6 @@ out:
        for (;;)
                cpu_relax();
 }
-EXPORT_SYMBOL_GPL(xnpod_fatal);
 
 void __xnpod_schedule_handler(void) /* hw interrupts off. */
 {
@@ -276,7 +280,7 @@ int xnpod_init(void)
 
        xnregistry_init();
 
-       pod->status |= XNPEXEC;
+       nkpanic = fatal;
        smp_wmb();
        xnshadow_grab_events();
 
@@ -321,15 +325,6 @@ void xnpod_shutdown(int xtype)
        int cpu;
        spl_t s;
 
-       xnlock_get_irqsave(&nklock, s);
-
-       if (!xnpod_active_p()) {
-               xnlock_put_irqrestore(&nklock, s);
-               return;
-       }
-
-       xnlock_put_irqrestore(&nklock, s);
-
        xnpod_disable_timesource();
        xnshadow_release_events();
 #ifdef CONFIG_SMP
@@ -346,8 +341,6 @@ void xnpod_shutdown(int xtype)
 
        xnpod_schedule();
 
-       nkpod->status &= ~XNPEXEC;
-
        for_each_online_cpu(cpu) {
                sched = xnpod_sched_slot(cpu);
                xnsched_destroy(sched);
@@ -1814,7 +1807,7 @@ int xnpod_handle_exception(struct ipipe_trap_data *d)
        struct xnthread *thread;
        struct xnarchtcb *tcb;
 
-       if (!xnpod_active_p() || (!xnpod_interrupt_p() && xnpod_root_p()))
+       if (xnpod_root_p())
                return 0;
 
        thread = xnpod_current_thread();
@@ -1908,22 +1901,12 @@ EXPORT_SYMBOL_GPL(xnpod_handle_exception);
  */
 int xnpod_enable_timesource(void)
 {
-       int err, htickval, cpu;
        struct xnsched *sched;
+       int htickval, cpu;
        spl_t s;
 
-       xnlock_get_irqsave(&nklock, s);
-
-       if (!xnpod_active_p()) {
-               err = -ENOSYS;
-               xnlock_put_irqrestore(&nklock, s);
-               return err;
-       }
-
        trace_mark(xn_nucleus, enable_timesource, MARK_NOARGS);
 
-       xnlock_put_irqrestore(&nklock, s);
-
 #ifdef CONFIG_XENO_OPT_STATS
        /*
         * Only for statistical purpose, the timer interrupt is
@@ -2005,15 +1988,12 @@ EXPORT_SYMBOL_GPL(xnpod_enable_timesource);
  *
  * Rescheduling: never.
  */
-
 void xnpod_disable_timesource(void)
 {
        int cpu;
 
        trace_mark(xn_nucleus, disable_timesource, MARK_NOARGS);
 
-       if (!xnpod_active_p())
-               return;
        /*
         * We must not hold the nklock while stopping the hardware
         * timer, since this could cause deadlock situations to arise
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index c25e24a..f1fd73e 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -81,9 +81,6 @@ static struct xnvfile_directory registry_vfroot;
 
 static int usage_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
-       if (!xnpod_active_p())
-               return -ESRCH;
-
        xnvfile_printf(it, "%u/%u\n",
                       nr_active_objects,
                       CONFIG_XENO_OPT_REGISTRY_NRSLOTS);
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 4d0b761..062555c 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1303,10 +1303,8 @@ do_bind:
                goto muxid_eventcb;
 
        sys_ppd = personalities[user_muxid]->ops.attach_process();
-       if (IS_ERR(sys_ppd)) {
-               ret = PTR_ERR(sys_ppd);
-               goto fail;
-       }
+       if (IS_ERR(sys_ppd))
+               return PTR_ERR(sys_ppd);
 
        if (sys_ppd == NULL)
                goto muxid_eventcb;
@@ -1333,7 +1331,7 @@ muxid_eventcb:
 
        /* protect from the same process binding several times. */
        if (ppd)
-               goto eventcb_done;
+               return muxid;
 
        ppd = personality->ops.attach_process();
        if (IS_ERR(ppd)) {
@@ -1342,7 +1340,7 @@ muxid_eventcb:
        }
 
        if (ppd == NULL)
-               goto eventcb_done;
+               return muxid;
 
        ppd->key.muxid = muxid;
        ppd->key.mm = current->mm;
@@ -1357,34 +1355,15 @@ muxid_eventcb:
                ppd = NULL;
        }
 
-eventcb_done:
-
-       if (!xnpod_active_p()) {
-               /*
-                * Ok mate, but you really ought to call xnpod_init()
-                * at some point if you want me to be of some help
-                * here...
-                */
-               if (ppd) {
-                       ppd_remove(ppd);
-                       personality->ops.detach_process(ppd);
-               }
-
-               if (personality->module)
-                       module_put(personality->module);
-
-               ret = -ENOSYS;
+       return muxid;
 
-       fail_destroy_sys_ppd:
-               if (sys_ppd) {
-                       ppd_remove(sys_ppd);
-                       personalities[user_muxid]->ops.detach_process(sys_ppd);
-               }
-       fail:
-               return ret;
+ fail_destroy_sys_ppd:
+       if (sys_ppd) {
+               ppd_remove(sys_ppd);
+               personalities[user_muxid]->ops.detach_process(sys_ppd);
        }
 
-       return muxid;
+       return ret;
 }
 
 static int xnshadow_sys_info(int muxid, struct xnsysinfo __user *u_info)
@@ -1833,9 +1812,6 @@ static int handle_head_syscall(struct ipipe_domain *ipd, 
struct pt_regs *regs)
        unsigned long sysflags;
        struct xnsyscall *sc;
 
-       if (!xnpod_active_p())
-               goto no_personality;
-
        thread = xnshadow_current();
        if (thread)
                thread->regs = regs;
@@ -1903,7 +1879,6 @@ restart:
         */
        if (sysflags & __xn_exec_lostage) {
                /* Syscall must run into the Linux domain. */
-
                if (ipd == &xnarch_machdata.domain) {
                        /*
                         * Request originates from the Xenomai domain:
@@ -1919,8 +1894,8 @@ restart:
                         * handler, so that the syscall is executed
                         * from there.
                         */
-                       goto propagate_syscall;
-       } else if ((sysflags & (__xn_exec_histage | __xn_exec_current)) != 0) {
+                       return EVENT_PROPAGATE;
+       } else if (sysflags & (__xn_exec_histage | __xn_exec_current)) {
                /*
                 * Syscall must be processed either by Xenomai, or by
                 * the calling domain.
@@ -1933,7 +1908,7 @@ restart:
                         * the syscall is eventually executed from
                         * there.
                         */
-                       goto propagate_syscall;
+                       return EVENT_PROPAGATE;
                /*
                 * Request originates from the Xenomai domain: run the
                 * syscall immediately.
@@ -1954,10 +1929,8 @@ restart:
                     __xn_exec_adaptive);
                goto restart;
        }
-
 done:
        __xn_status_return(regs, ret);
-
        sigs = 0;
        if (!xnpod_root_p()) {
                if (signal_pending(current) ||
@@ -1994,7 +1967,7 @@ linux_syscall:
                 * just propagate the event so that we will fall back
                 * to linux_sysentry().
                 */
-               goto propagate_syscall;
+               return EVENT_PROPAGATE;
 
        /*
         * From now on, we know that we have a valid shadow thread
@@ -2007,31 +1980,15 @@ linux_syscall:
         */
        xnshadow_relax(1, SIGDEBUG_MIGRATE_SYSCALL);
 
-       goto propagate_syscall;
+       return EVENT_PROPAGATE;
 
-no_personality:
-       if (__xn_reg_mux_p(regs)) {
-               if (__xn_reg_mux(regs) == __xn_mux_code(0, sc_nucleus_bind))
-                       /*
-                        * Valid exception case for running a Xenomai
-                        * syscall with no attached context (yet): we
-                        * may be called to bind to a personality.
-                        */
-                       goto propagate_syscall;
 bad_syscall:
-               printk(XENO_WARN "bad syscall %ld/%ld\n",
-                      __xn_mux_id(regs), __xn_mux_op(regs));
-
-               __xn_error_return(regs, -ENOSYS);
-               return EVENT_STOP;
-       }
+       printk(XENO_WARN "bad syscall %ld/%ld\n",
+              __xn_mux_id(regs), __xn_mux_op(regs));
+       
+       __xn_error_return(regs, -ENOSYS);
 
-       /*
-        * Regular Linux syscall: propagate it to the Linux kernel.
-        */
-
-propagate_syscall:
-       return EVENT_PROPAGATE;
+       return EVENT_STOP;
 }
 
 static int handle_root_syscall(struct ipipe_domain *ipd, struct pt_regs *regs)
@@ -2065,8 +2022,8 @@ static int handle_root_syscall(struct ipipe_domain *ipd, 
struct pt_regs *regs)
 
        trace_mark(xn_nucleus, syscall_lostage_entry,
                   "thread %p thread_name %s muxid %d muxop %d",
-                  xnpod_active_p() ? xnpod_current_thread() : NULL,
-                  xnpod_active_p() ? xnthread_name(xnpod_current_thread()) : 
NULL,
+                  xnpod_current_thread(),
+                  xnthread_name(xnpod_current_thread()),
                   muxid, muxop);
 
        /* Processing a Xenomai syscall. */
@@ -2115,7 +2072,7 @@ restart:
        __xn_status_return(regs, ret);
 
        sigs = 0;
-       if (xnpod_active_p() && !xnpod_root_p()) {
+       if (!xnpod_root_p()) {
                /*
                 * We may have gained a shadow TCB from the syscall we
                 * just invoked, so make sure to fetch it.
@@ -2209,9 +2166,6 @@ static int handle_schedule_event(struct task_struct 
*next_task)
        struct xnthread *prev, *next;
        sigset_t pending;
 
-       if (!xnpod_active_p())
-               return EVENT_PROPAGATE;
-
        prev_task = current;
        prev = xnshadow_thread(prev_task);
        next = xnshadow_thread(next_task);
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 07fb866..516d864 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -769,13 +769,10 @@ static int timer_vfile_show(struct 
xnvfile_regular_iterator *it, void *data)
 {
        const char *tm_status, *wd_status = "";
 
-       if (xnpod_active_p()) {
-               tm_status = (nkpod->status & XNCLKLK) ? "locked" : "on";
+       tm_status = (nkpod->status & XNCLKLK) ? "locked" : "on";
 #ifdef CONFIG_XENO_OPT_WATCHDOG
-               wd_status = "+watchdog";
+       wd_status = "+watchdog";
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
-       } else
-               tm_status = "off";
 
        xnvfile_printf(it,
                       
"status=%s%s:setup=%Lu:clock=%Lu:timerdev=%s:clockdev=%s\n",
diff --git a/kernel/cobalt/vfile.c b/kernel/cobalt/vfile.c
index 0bef0db..57c584c 100644
--- a/kernel/cobalt/vfile.c
+++ b/kernel/cobalt/vfile.c
@@ -155,14 +155,6 @@ static int vfile_snapshot_open(struct inode *inode, struct 
file *file)
        struct seq_file *seq;
        caddr_t data;
 
-       /*
-        * There is no point in reading/writing to v-files that must
-        * be connected to Xenomai resources if the system has not
-        * been initialized yet (i.e. xnpod_init() called).
-        */
-       if (!xnpod_active_p())
-               return -ESRCH;
-
        if ((file->f_mode & FMODE_WRITE) != 0 && ops->store == NULL)
                return -EACCES;
 


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

Reply via email to