Module: xenomai-jki
Branch: for-upstream
Commit: cbc284165fbb3ad2135ca923d74c8466866c21c8
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=cbc284165fbb3ad2135ca923d74c8466866c21c8

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Jun 28 16:52:50 2011 +0200

nucleus: Drop panic message buffering

The kernel only takes up to 1K per printk, so buffering up to 16K is
already pointless. If we happen to write out more (or enter an endless
loop), we trigger a secondary WARN_ON in vsnprintf first. Finally, and
that's worst, if we crash or lock up while filling nkmsgbuf, nothing is
printed at all.

So let's drop this buffering and write out the panic message line-wise.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/asm-generic/system.h |   11 +++++++--
 include/asm-sim/system.h     |    9 ++++++-
 include/nucleus/pod.h        |    2 -
 include/nucleus/types.h      |   10 ++++----
 ksrc/nucleus/module.c        |    9 --------
 ksrc/nucleus/pod.c           |   45 ++++++++++++++++-------------------------
 6 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/include/asm-generic/system.h b/include/asm-generic/system.h
index dd2282f..fe378ef 100644
--- a/include/asm-generic/system.h
+++ b/include/asm-generic/system.h
@@ -240,6 +240,7 @@ static inline int xnlock_dbg_release(xnlock_t *lock)
 #define xnarch_loginfo(fmt, args...)   printk(KERN_INFO XNARCH_PROMPT fmt, 
##args)
 #define xnarch_logwarn(fmt, args...)   printk(KERN_WARNING XNARCH_PROMPT fmt, 
##args)
 #define xnarch_logerr(fmt, args...)    printk(KERN_ERR XNARCH_PROMPT fmt, 
##args)
+#define xnarch_logerr_noprompt(fmt, args...)   printk(KERN_ERR fmt, ##args)
 #define xnarch_printf(fmt, args...)    printk(KERN_INFO XNARCH_PROMPT fmt, 
##args)
 
 #ifndef RTHAL_SHARED_HEAP_FLAGS
@@ -298,10 +299,14 @@ static inline unsigned long long 
xnarch_get_clock_freq(void)
 
 #define xnarch_get_cpu_tsc                     rthal_rdtsc
 
-#define xnarch_halt(emsg)                              \
+static inline void xnarch_begin_panic(void)
+{
+       xnarch_trace_panic_freeze();
+       rthal_emergency_console();
+}
+
+#define xnarch_halt()                                  \
        do {                                            \
-               rthal_emergency_console();              \
-               xnarch_logerr("fatal: %s\n", emsg);     \
                show_stack(NULL,NULL);                  \
                xnarch_trace_panic_dump();              \
                for (;;)                                \
diff --git a/include/asm-sim/system.h b/include/asm-sim/system.h
index 71036e7..c5a06df 100644
--- a/include/asm-sim/system.h
+++ b/include/asm-sim/system.h
@@ -104,6 +104,7 @@ typedef unsigned long xnlock_t;
 #define xnarch_loginfo(fmt,args...)  fprintf(stdout, XNARCH_PROMPT fmt , 
##args)
 #define xnarch_logwarn(fmt,args...)  fprintf(stderr, XNARCH_PROMPT fmt , 
##args)
 #define xnarch_logerr(fmt,args...)   fprintf(stderr, XNARCH_PROMPT fmt , 
##args)
+#define xnarch_logerr_noprompt(fmt,args...) fprintf(stderr, fmt , ##args)
 #define xnarch_printf(fmt,args...)   fprintf(stdout, fmt , ##args)
 #define printk(fmt,args...)          xnarch_loginfo(fmt , ##args)
 
@@ -443,9 +444,13 @@ static inline unsigned long xnarch_get_cpu_freq (void)
     return mvm_get_cpu_freq();
 }
 
-static inline void xnarch_halt (const char *emsg)
+static inline void xnarch_begin_panic (void)
 {
-    __mvm_breakable(mvm_fatal)("%s",emsg);
+}
+
+static inline void xnarch_halt (void)
+{
+    __mvm_breakable(mvm_fatal)("");
 }
 
 static inline void *xnarch_alloc_host_mem (u_long bytes)
diff --git a/include/nucleus/pod.h b/include/nucleus/pod.h
index d683003..24ec49f 100644
--- a/include/nucleus/pod.h
+++ b/include/nucleus/pod.h
@@ -98,8 +98,6 @@ extern u_long nklatency;
 
 extern u_long nktimerlat;
 
-extern char *nkmsgbuf;
-
 extern xnarch_cpumask_t nkaffinity;
 
 extern xnpod_t nkpod_struct;
diff --git a/include/nucleus/types.h b/include/nucleus/types.h
index 1f028d4..a2bd01f 100644
--- a/include/nucleus/types.h
+++ b/include/nucleus/types.h
@@ -120,7 +120,7 @@ typedef atomic_flags_t xnflags_t;
 extern "C" {
 #endif
 
-const char *xnpod_fatal_helper(const char *format, ...);
+void xnpod_fatal_helper(const char *format, ...);
 
 int __xeno_user_init(void);
 
@@ -134,13 +134,13 @@ void __xeno_user_exit(void);
 #define xnloginfo(fmt,args...) xnarch_loginfo(fmt , ##args)
 #define xnlogwarn(fmt,args...) xnarch_logwarn(fmt , ##args)
 #define xnlogerr(fmt,args...)  xnarch_logerr(fmt , ##args)
+#define xnlogerr_noprompt(fmt,args...) xnarch_logerr_noprompt(fmt , ##args)
 
 #define xnpod_fatal(format,args...) \
 do { \
-    const char *panic; \
-    xnarch_trace_panic_freeze(); \
-    panic = xnpod_fatal_helper(format,##args); \
-    xnarch_halt(panic); \
+       xnarch_begin_panic(); \
+       xnpod_fatal_helper(format,##args); \
+       xnarch_halt(); \
 } while (0)
 
 #ifdef __XENO_SIM__
diff --git a/ksrc/nucleus/module.c b/ksrc/nucleus/module.c
index 234a82a..5eb7c52 100644
--- a/ksrc/nucleus/module.c
+++ b/ksrc/nucleus/module.c
@@ -148,12 +148,6 @@ int __init __xeno_sys_init(void)
 
        xnmod_sysheap_size = module_param_value(sysheap_size_arg) * 1024;
 
-       nkmsgbuf = xnarch_alloc_host_mem(XNPOD_FATAL_BUFSZ);
-       if (nkmsgbuf == NULL) {
-               ret = -ENOMEM;
-               goto fail;
-       }
-
        ret = xnarch_init();
        if (ret)
                goto fail;
@@ -283,9 +277,6 @@ void __exit __xeno_sys_exit(void)
        xnheap_destroy_mapped(&__xnsys_global_ppd.sem_heap, NULL, NULL);
 #endif
 
-       if (nkmsgbuf)
-               xnarch_free_host_mem(nkmsgbuf, XNPOD_FATAL_BUFSZ);
-
        xnloginfo("real-time nucleus unloaded.\n");
 }
 
diff --git a/ksrc/nucleus/pod.c b/ksrc/nucleus/pod.c
index d25120f..9a02e80 100644
--- a/ksrc/nucleus/pod.c
+++ b/ksrc/nucleus/pod.c
@@ -64,8 +64,6 @@ EXPORT_SYMBOL_GPL(nklatency);
 /* Already accounted for in nklatency, kept separately for user information. */
 u_long nktimerlat = 0;
 
-char *nkmsgbuf = NULL;
-
 xnarch_cpumask_t nkaffinity = XNPOD_ALL_CPUS;
 
 xnticks_t nkvtick = CONFIG_XENO_OPT_TIMING_VIRTICK * 1000;
@@ -193,11 +191,11 @@ static inline int __xnpod_fault_init_fpu(struct xnthread 
*thread)
 
 #endif /* !CONFIG_XENO_HW_FPU */
 
-const char *xnpod_fatal_helper(const char *format, ...)
+void xnpod_fatal_helper(const char *format, ...)
 {
+       static char msg_buf[1024];
        const unsigned nr_cpus = xnarch_num_online_cpus();
        xnholder_t *holder;
-       char *p = nkmsgbuf;
        xnticks_t now;
        unsigned cpu;
        va_list ap;
@@ -206,7 +204,8 @@ const char *xnpod_fatal_helper(const char *format, ...)
        xnlock_get_irqsave(&nklock, s);
 
        va_start(ap, format);
-       p += vsnprintf(p, XNPOD_FATAL_BUFSZ, format, ap);
+       vsnprintf(msg_buf, sizeof(msg_buf), format, ap);
+       xnlogerr("%s", msg_buf);
        va_end(ap);
 
        if (!xnpod_active_p() || xnpod_fatal_p())
@@ -215,9 +214,8 @@ const char *xnpod_fatal_helper(const char *format, ...)
        __setbits(nkpod->status, XNFATAL);
        now = xntbase_get_jiffies(&nktbase);
 
-       p += snprintf(p, XNPOD_FATAL_BUFSZ - (p - nkmsgbuf),
-                     "\n %-3s  %-6s %-8s %-8s %-8s  %s\n",
-                     "CPU", "PID", "PRI", "TIMEOUT", "STAT", "NAME");
+       xnlogerr_noprompt("\n %-3s  %-6s %-8s %-8s %-8s  %s\n",
+                         "CPU", "PID", "PRI", "TIMEOUT", "STAT", "NAME");
 
        for (cpu = 0; cpu < nr_cpus; ++cpu) {
                xnsched_t *sched = xnpod_sched_slot(cpu);
@@ -243,34 +241,27 @@ const char *xnpod_fatal_helper(const char *format, ...)
                        else
                                snprintf(pbuf, sizeof(pbuf), "%3d", dnprio);
 
-                       p += snprintf(p, XNPOD_FATAL_BUFSZ - (p - nkmsgbuf),
-                                     "%c%3u  %-6d %-8s %-8Lu %.8lx  %s\n",
-                                     thread == sched->curr ? '>' : ' ',
-                                     cpu,
-                                     xnthread_user_pid(thread),
-                                     pbuf,
-                                     xnthread_get_timeout(thread, now),
-                                     xnthread_state_flags(thread),
-                                     xnthread_name(thread));
+                       xnlogerr_noprompt("%c%3u  %-6d %-8s %-8Lu %.8lx  %s\n",
+                                         thread == sched->curr ? '>' : ' ',
+                                         cpu,
+                                         xnthread_user_pid(thread),
+                                         pbuf,
+                                         xnthread_get_timeout(thread, now),
+                                         xnthread_state_flags(thread),
+                                         xnthread_name(thread));
                }
        }
 
        if (xntbase_enabled_p(&nktbase))
-               p += snprintf(p, XNPOD_FATAL_BUFSZ - (p - nkmsgbuf),
-                             "Master time base: clock=%Lu\n",
-                             xntbase_get_rawclock(&nktbase));
+               xnlogerr_noprompt("Master time base: clock=%Lu\n",
+                                 xntbase_get_rawclock(&nktbase));
        else
-               p += snprintf(p, XNPOD_FATAL_BUFSZ - (p - nkmsgbuf),
-                             "Master time base: disabled\n");
+               xnlogerr_noprompt("Master time base: disabled\n");
 #ifdef CONFIG_SMP
-               p += snprintf(p, XNPOD_FATAL_BUFSZ - (p - nkmsgbuf),
-                             "Current CPU: #%d\n", xnarch_current_cpu());
+       xnlogerr_noprompt("Current CPU: #%d\n", xnarch_current_cpu());
 #endif
       out:
-
        xnlock_put_irqrestore(&nklock, s);
-
-       return nkmsgbuf;
 }
 EXPORT_SYMBOL_GPL(xnpod_fatal_helper);
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to