[Xenomai-git] Philippe Gerum : cobalt/pod: drop PEXEC and FATAL condition bits

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 53b3bc6d6c0299beda34d4488cb97caf1fadd16a
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=53b3bc6d6c0299beda34d4488cb97caf1fadd16a

Author: Philippe Gerum 
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 
 
 /* Pod status flags */
-#define XNFATAL  0x0001/* Fatal error in progress */
-#define XNPEXEC  0x0002/* Pod is active (a skin is attached) */
-#define XNCLKLK  0x0004/* All clocks locked */
+#define XNCLKLK  0x0001/* 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 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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;
-
-

[Xenomai-git] Philippe Gerum : cobalt/pod: drop PEXEC and FATAL condition bits

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 53b3bc6d6c0299beda34d4488cb97caf1fadd16a
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=53b3bc6d6c0299beda34d4488cb97caf1fadd16a

Author: Philippe Gerum 
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 
 
 /* Pod status flags */
-#define XNFATAL  0x0001/* Fatal error in progress */
-#define XNPEXEC  0x0002/* Pod is active (a skin is attached) */
-#define XNCLKLK  0x0004/* All clocks locked */
+#define XNCLKLK  0x0001/* 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 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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;
-
-  

[Xenomai-git] Philippe Gerum : cobalt/pod: drop PEXEC and FATAL condition bits

2013-07-31 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: b78c14c033ca12e976bd188c3f782c578b35e320
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b78c14c033ca12e976bd188c3f782c578b35e320

Author: Philippe Gerum 
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 
 
 /* Pod status flags */
-#define XNFATAL  0x0001/* Fatal error in progress */
-#define XNPEXEC  0x0002/* Pod is active (a skin is attached) */
-#define XNCLKLK  0x0004/* All clocks locked */
+#define XNCLKLK  0x0001/* 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 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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;
-
-