Add Alternative Log Buffer Support for printk Messages
RFC 1/1 Add Alternative Log Buffer Support for printk Messages
This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. In addition, this ports architecture support for this feature from arch/ppc to arch/powerpc.
When this option is enabled, an architecture- or machine-specific log buffer is used for all printk messages. This allows entities such as boot loaders (e.g. U-Boot) to place printk-compatible messages into this buffer and for the kernel to coalesce them with its normal messages.
---
The code has historically been used and proven to work on the LWMON5 platform under arch/ppc and is now used (by me) successfully on the AMCC Haleakala and Kilauea platforms.
As implemented for arch/powerpc, two suboptions for the alternative log buffer are supported. The buffer may be contiguous with the metadata and message data colocated or the metadata and message storage may be in discontiguous regions of memory (e.g. a set of scratch registers and an SRAM buffer). On Kilauea and Haleakala, I have used the former; whereas LWMON5 has traditionally used the latter.
The code here is, more or less, as-is from the DENX GIT tree. Comments welcome. Some prior discussion from the linuxppc-dev mailing list is at
http://ozlabs.org/pipermail/linuxppc-dev/2008-November/065589.html.
arch/powerpc/kernel/prom.c | 93 +++++++++++++++++++++++++++ include/linux/logbuff.h | 56 ++++++++++++++++ init/Kconfig | 25 +++++++ init/main.c | 4 + kernel/printk.c | 149 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 include/linux/logbuff.h
arch/powerpc/kernel/prom.c +93 -0
@@ -32,6 +32,7 @@#include <linux/debugfs.h> #include <linux/irq.h> #include <linux/lmb.h> +#include <linux/logbuff.h> #include <asm/prom.h> #include <asm/rtas.h>
@@ -61,6 +62,15 @@ #define DBG(fmt...)#endif +#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION +# if !defined(BOARD_ALT_LH_ADDR ) || !defined(BOARD_ALT_LB_ADDR ) +# error "Please specify BOARD_ALT_LH_ADDR & BOARD_ALT_LB_ADDR." +# endif +#else /* !CONFIG_ALT_LB_LOCATION */ +static phys_addr_t ext_logbuff; +#endif /* CONFIG_ALT_LB_LOCATION */ +#endif /* CONFIG_LOGBUFFER */ static int __initdata dt_root_addr_cells;static int __initdata dt_root_size_cells;
@@ -1018,6 +1028,85 @@ static int __init early_init_dt_scan_memory(unsigned long node,return 0 ; } +#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION +/* Alternative external log buffer mapping: log metadata header & the +* character buffer are separated and allocated not in RAM but in some +* other memory-mapped I/O region (e.g. log head in unused registers, +* and log buffer in OCM memory) +*/ +int __init setup_ext_logbuff_mem (volatile logbuff_t **lhead,char **lbuf) +{ +void *h, *b; + +if (unlikely (!lhead) ||unlikely (!lbuf)) +return -EINVAL ; + +/* map log head */ + h =ioremap (BOARD_ALT_LH_ADDR ,sizeof (logbuff_t)); +if (unlikely (!h)) +return -EFAULT ; + +/* map log buffer */ + b =ioremap (BOARD_ALT_LB_ADDR ,LOGBUFF_LEN ); +if (unlikely (!b)) { +iounmap (h); +return -EFAULT ; + } + + *lhead = h; + *lbuf = b; + +return 0 ; +} +#else /* !CONFIG_ALT_LB_LOCATION */ +/* Usual external log-buffer mapping: log metadata header & the character +* buffer are both contiguous in system RAM. +*/ +int __init setup_ext_logbuff_mem (logbuff_t **lhead,char **lbuf) +{ +void *p; + +if (unlikely (!lhead) ||unlikely (!lbuf)) +return -EINVAL ; + +if (unlikely (!ext_logbuff) || !lmb_is_reserved (ext_logbuff)) +return -EFAULT ; + + p =ioremap (ext_logbuff,LOGBUFF_RESERVE ); + +if (unlikely (!p)) +return -EFAULT ; + + *lhead = (logbuff_t *)(p +LOGBUFF_OVERHEAD - +sizeof (logbuff_t) + +sizeof (((logbuff_t *)0 )->buf)); + *lbuf = (*lhead)->buf; + +return 0 ; +} + +/* When the external log buffer configuration is used with the +* non-alternate location, the log head metadata and character buffer +* lie in the LOGBUFF_RESERVE bytes at the end of system RAM. Add this +* block of memory to the reserved memory pool so that it is not +* allocated for other purposes. +*/ +static void __init reserve_ext_logbuff_mem (void ) +{ +phys_addr_t top =lmb_end_of_DRAM (); +phys_addr_t size =LOGBUFF_RESERVE ; +phys_addr_t base = top - size; + +if (top > base) { + ext_logbuff = base; +DBG ("reserving: %x -> %x\n" , base, size); +lmb_reserve (base, size); + } +} +#endif /* CONFIG_ALT_LB_LOCATION */ +#endif /* CONFIG_LOGBUFFER */ +static void __init early_reserve_mem (void ) {u64 base, size;
@@ -1033,6 +1122,10 @@ static void __init early_reserve_mem(void) self_size = initial_boot_params->totalsize;lmb_reserve (self_base, self_size); +#if defined(CONFIG_LOGBUFFER ) && !defined(CONFIG_ALT_LB_LOCATION ) +reserve_ext_logbuff_mem (); +#endif /* defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_LOCATION) */ +#ifdef CONFIG_BLK_DEV_INITRD /* then reserve the initrd, if any */ if (initrd_start && (initrd_end > initrd_start))
include/linux/logbuff.h new file +56 -0
56 lines not on this page · raw message
init/Kconfig +25 -0
@@ -619,6 +619,31 @@ config PRINTK very difficult to diagnose system problems, saying N here is strongly discouraged. +config LOGBUFFER + bool "External logbuffer" if PRINTK + default n + help + This option enables support for an alternative, "external" + printk log buffer. When enabled, an architecture- or machine- + specific log buffer is used for all printk messages. This + allows entities such as boot loaders to place printk-compatible + messages into this buffer and for the kernel to coalesce them + with its normal messages. + +config ALT_LB_LOCATION + bool "Alternative logbuffer" if LOGBUFFER + default n + help + When using an alternative, "external" printk log buffer, an + architecture- or machine-specific log buffer with contiguous + metadata and message storage is used. This option enables + support for discontiguous metadata and message storage + memory (e.g. a set of scratch registers and an SRAM + buffer). By saying Y here, you must also ensure your + architecture- or machine-code specify BOARD_ALT_LH_ADDR and + BOARD_ALT_LB_ADDR, for the metadata and message memory, + respectively. + config BUG bool "BUG() support" if EMBEDDED default y
init/main.c +4 -0
@@ -61,6 +61,7 @@#include <linux/kthread.h> #include <linux/sched.h> #include <linux/signal.h> +#include <linux/logbuff.h> #include <linux/idr.h> #include <linux/ftrace.h>
@@ -563,6 +564,9 @@ asmlinkage void __init start_kernel(void)* Interrupts are still disabled. Do necessary setups, then * enable them */ +#ifdef CONFIG_LOGBUFFER +setup_ext_logbuff (); +#endif lock_kernel ();tick_init ();boot_cpu_init ();
kernel/printk.c +146 -3
198 lines not on this page · raw message
Signature · 1 line
1.6.0.4
From: Grant Erickson <[email protected]>
Date: Wed, 21 Jan 2009 09:39:46 -0800
Quoted 5 lines
This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. In addition, this ports architecture support for this feature from
arch/ppctoarch/powerpc.
Quoted 7 lines
When this option is enabled, an architecture- or machine-specific log buffer is used for all printk messages. This allows entities such as boot loaders (e.g. U-Boot) to place printk-compatible messages into this buffer and for the kernel to coalesce them with its normal messages.
Signed-off-by Grant Erickson <[email protected]>
Nice.
This would also be useful on Sparc where it is possible to tell the firmware to set aside a piece of physical memory which survives soft resets and thus can be inspected post reboot.
Hi,
[Sorry for the TOFU, I wanted to make sure people from the coreboot list can join in without having to dig through the archives. The coreboot list is moderated, but your mails will get through eventually.]
This is a feature which would benefit coreboot (formerly known as LinuxBIOS) as well. coreboot v3 keeps such a log buffer in RAM and we (coreboot developers) are interested in sharing that buffer with the kernel. There might be some differences in the buffer format, though.
I haven't yet read the patch completely, but from what I can see struct logbuff_t differs quite a bit between coreboot and U-Boot. There are some conceptually common struct members, but each of the projects has some info in there that's missing at the other project. It would be nice if we could work out some common data structure combining the best of both worlds.
Regards,
Carl-Daniel
Quoted 492 lines · Grant Erickson
This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. In addition, this ports architecture support for this feature from
arch/ppctoarch/powerpc.When this option is enabled, an architecture- or machine-specific log buffer is used for all printk messages. This allows entities such as boot loaders (e.g. U-Boot) to place printk-compatible messages into this buffer and for the kernel to coalesce them with its normal messages.
Signed-off-by Grant Erickson <[email protected]>---
The code has historically been used and proven to work on the LWMON5 platform under
arch/ppcand is now used (by me) successfully on the AMCC Haleakala and Kilauea platforms.As implemented for
arch/powerpc, two suboptions for the alternative log buffer are supported. The buffer may be contiguous with the metadata and message data colocated or the metadata and message storage may be in discontiguous regions of memory (e.g. a set of scratch registers and an SRAM buffer). On Kilauea and Haleakala, I have used the former; whereas LWMON5 has traditionally used the latter.The code here is, more or less, as-is from the DENX GIT tree. Comments welcome. Some prior discussion from the linuxppc-dev mailing list is at
http://ozlabs.org/pipermail/linuxppc-dev/2008-November/065589.html.arch/powerpc/kernel/prom.c | 93 +++++++++++++++++++++++++++ include/linux/logbuff.h | 56 ++++++++++++++++ init/Kconfig | 25 +++++++ init/main.c | 4 + kernel/printk.c | 149 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 include/linux/logbuff.harch/powerpc/kernel/prom.c +93
-0@@ -32,6 +32,7 @@#include <linux/debugfs.h> #include <linux/irq.h> #include <linux/lmb.h> +#include <linux/logbuff.h> #include <asm/prom.h> #include <asm/rtas.h> @@ -61,6 +62,15 @@ #define DBG(fmt...)#endif +#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION +# if !defined(BOARD_ALT_LH_ADDR ) || !defined(BOARD_ALT_LB_ADDR ) +# error "Please specify BOARD_ALT_LH_ADDR & BOARD_ALT_LB_ADDR." +# endif +#else /* !CONFIG_ALT_LB_LOCATION */ +static phys_addr_t ext_logbuff; +#endif /* CONFIG_ALT_LB_LOCATION */ +#endif /* CONFIG_LOGBUFFER */ static int __initdata dt_root_addr_cells;static int __initdata dt_root_size_cells;@@ -1018,6 +1028,85 @@ static int __init early_init_dt_scan_memory(unsigned long node,return 0 ; } +#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION +/* Alternative external log buffer mapping: log metadata header & the +* character buffer are separated and allocated not in RAM but in some +* other memory-mapped I/O region (e.g. log head in unused registers, +* and log buffer in OCM memory) +*/ +int __init setup_ext_logbuff_mem (volatile logbuff_t **lhead,char **lbuf) +{ +void *h, *b; + +if (unlikely (!lhead) ||unlikely (!lbuf)) +return -EINVAL ; + +/* map log head */ + h =ioremap (BOARD_ALT_LH_ADDR ,sizeof (logbuff_t)); +if (unlikely (!h)) +return -EFAULT ; + +/* map log buffer */ + b =ioremap (BOARD_ALT_LB_ADDR ,LOGBUFF_LEN ); +if (unlikely (!b)) { +iounmap (h); +return -EFAULT ; + } + + *lhead = h; + *lbuf = b; + +return 0 ; +} +#else /* !CONFIG_ALT_LB_LOCATION */ +/* Usual external log-buffer mapping: log metadata header & the character +* buffer are both contiguous in system RAM. +*/ +int __init setup_ext_logbuff_mem (logbuff_t **lhead,char **lbuf) +{ +void *p; + +if (unlikely (!lhead) ||unlikely (!lbuf)) +return -EINVAL ; + +if (unlikely (!ext_logbuff) || !lmb_is_reserved (ext_logbuff)) +return -EFAULT ; + + p =ioremap (ext_logbuff,LOGBUFF_RESERVE ); + +if (unlikely (!p)) +return -EFAULT ; + + *lhead = (logbuff_t *)(p +LOGBUFF_OVERHEAD - +sizeof (logbuff_t) + +sizeof (((logbuff_t *)0 )->buf)); + *lbuf = (*lhead)->buf; + +return 0 ; +} + +/* When the external log buffer configuration is used with the +* non-alternate location, the log head metadata and character buffer +* lie in the LOGBUFF_RESERVE bytes at the end of system RAM. Add this +* block of memory to the reserved memory pool so that it is not +* allocated for other purposes. +*/ +static void __init reserve_ext_logbuff_mem (void ) +{ +phys_addr_t top =lmb_end_of_DRAM (); +phys_addr_t size =LOGBUFF_RESERVE ; +phys_addr_t base = top - size; + +if (top > base) { + ext_logbuff = base; +DBG ("reserving: %x -> %x\n" , base, size); +lmb_reserve (base, size); + } +} +#endif /* CONFIG_ALT_LB_LOCATION */ +#endif /* CONFIG_LOGBUFFER */ +static void __init early_reserve_mem (void ) {u64 base, size;@@ -1033,6 +1122,10 @@ static void __init early_reserve_mem(void) self_size = initial_boot_params->totalsize;lmb_reserve (self_base, self_size); +#if defined(CONFIG_LOGBUFFER ) && !defined(CONFIG_ALT_LB_LOCATION ) +reserve_ext_logbuff_mem (); +#endif /* defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_LOCATION) */ +#ifdef CONFIG_BLK_DEV_INITRD /* then reserve the initrd, if any */ if (initrd_start && (initrd_end > initrd_start))include/linux/logbuff.h new file +56
-0@@ -0,0 +1,56 @@ +/* +* (C) Copyright 2007 +* Wolfgang Denk, DENX Software Engineering, [email protected]. +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ +#ifndef _LOGBUFF_H_ +#define _LOGBUFF_H_ + +#ifdef CONFIG_LOGBUFFER + +#define LOGBUFF_MAGIC 0xc0de4ced +#define LOGBUFF_LEN 16384 +#define LOGBUFF_OVERHEAD 4096 +#define LOGBUFF_RESERVE (LOGBUFF_LEN + LOGBUFF_OVERHEAD) + +/* The mapping used here has to be the same as in logbuff_init_ptrs () +in u-boot/common/cmd_log.c */ + +typedef struct { +unsigned long tag; +unsigned long start; +unsigned long con;/* next char to be sent to consoles */ +unsigned long end; +unsigned long chars; +unsigned char buf[0 ]; +}logbuff_t ; + +#ifdef CONFIG_ALT_LB_LOCATION +# define LOGBUFF_VOLATILE volatile +#else +# define LOGBUFF_VOLATILE +#endif /* defined(CONFIG_ALT_LB_LOCATION) */ + +extern void setup_ext_logbuff (void ); +/* arch specific */ +extern int setup_ext_logbuff_mem(LOGBUFF_VOLATILE logbuff_t **lhead, char **lbuf); + +#endif /* CONFIG_LOGBUFFER */ +#endif /* _LOGBUFF_H_ */ init/Kconfig +25
-0@@ -619,6 +619,31 @@ config PRINTK very difficult to diagnose system problems, saying N here is strongly discouraged. +config LOGBUFFER + bool "External logbuffer" if PRINTK + default n + help + This option enables support for an alternative, "external" + printk log buffer. When enabled, an architecture- or machine- + specific log buffer is used for all printk messages. This + allows entities such as boot loaders to place printk-compatible + messages into this buffer and for the kernel to coalesce them + with its normal messages. + +config ALT_LB_LOCATION + bool "Alternative logbuffer" if LOGBUFFER + default n + help + When using an alternative, "external" printk log buffer, an + architecture- or machine-specific log buffer with contiguous + metadata and message storage is used. This option enables + support for discontiguous metadata and message storage + memory (e.g. a set of scratch registers and an SRAM + buffer). By saying Y here, you must also ensure your + architecture- or machine-code specify BOARD_ALT_LH_ADDR and + BOARD_ALT_LB_ADDR, for the metadata and message memory, + respectively. + config BUG bool "BUG() support" if EMBEDDED default yinit/main.c +4
-0@@ -61,6 +61,7 @@#include <linux/kthread.h> #include <linux/sched.h> #include <linux/signal.h> +#include <linux/logbuff.h> #include <linux/idr.h> #include <linux/ftrace.h> @@ -563,6 +564,9 @@ asmlinkage void __init start_kernel(void)* Interrupts are still disabled. Do necessary setups, then * enable them */ +#ifdef CONFIG_LOGBUFFER +setup_ext_logbuff (); +#endif lock_kernel ();tick_init ();boot_cpu_init ();kernel/printk.c +146
-3@@ -32,6 +32,7 @@#include <linux/security.h> #include <linux/bootmem.h> #include <linux/syscalls.h> +#include <linux/logbuff.h> #include <asm/uaccess.h> @@ -101,9 +102,39 @@ static DEFINE_SPINLOCK(logbuf_lock);* The indices into log_buf are not constrained to log_buf_len - they * must be masked before subscripting */ +#ifdef CONFIG_LOGBUFFER +/* Indexes to the local log buffer */ +static unsigned long _log_start; +static unsigned long _con_start; +static unsigned long _log_end; +static unsigned long _logged_chars; +/* These will be switched to the external log buffer */ +#ifndef CONFIG_ALT_LB_LOCATION +/* usual logbuffer location */ +static unsigned long *ext_log_start = &_log_start; +static unsigned long *ext_con_start = &_con_start; +static unsigned long *ext_log_end = &_log_end; +static unsigned long *ext_logged_chars = &_logged_chars; +#define log_start (*ext_log_start) +#define con_start (*ext_con_start) +#define log_end (*ext_log_end) +#define logged_chars (*ext_logged_chars) +#else /* defined(CONFIG_ALT_LB_LOCATION) */ +/* alternative logbuffer location */ +static volatile unsigned long *ext_log_start = &_log_start; +static volatile unsigned long *ext_con_start = &_con_start; +static volatile unsigned long *ext_log_end = &_log_end; +static volatile unsigned long *ext_logged_chars = &_logged_chars; +#define log_start (*((volatile u32 *)ext_log_start)) +#define con_start (*((volatile u32 *)ext_con_start)) +#define log_end (*((volatile u32 *)ext_log_end)) +#define logged_chars (*((volatile u32 *)ext_logged_chars)) +#endif /* !defined(CONFIG_ALT_LB_LOCATION) */ +#else /* !defined(CONFIG_LOGBUFFER) */ static unsigned log_start;/* Index into log_buf: next char to be read by syslog() */ static unsigned con_start;/* Index into log_buf: next char to be sent to consoles */ static unsigned log_end;/* Index into log_buf: most-recently-written-char + 1 */ +#endif /* CONFIG_LOGBUFFER */ /* * Array of consoles built from command line options (console=) @@ -134,10 +165,121 @@ static int console_may_schedule;static char __log_buf[__LOG_BUF_LEN];static char *log_buf = __log_buf;static int log_buf_len = __LOG_BUF_LEN; +#ifndef CONFIG_LOGBUFFER static unsigned logged_chars;/* Number of chars produced since last read+clear operation */ +#endif /* !defined(CONFIG_LOGBUFFER) */ +#ifdef CONFIG_LOGBUFFER +/* Sanity check the external log buffer metadata. When an the external +* log buffer is enabled, the log metadata is effectively non-volatile +* in that the values are preserved from reboot to reboot (until/unless +* the system loses power). +*/ +static void __init logbuff_check_metadata(LOGBUFF_VOLATILE logbuff_t *log) +{ +unsigned long chars; + +/* Sanity check the producer and consumer indices. */ + +if (log->end - log->start >LOGBUFF_LEN ) + log->start = log->end -LOGBUFF_LEN ; + +if (log->end - log->con >LOGBUFF_LEN ) + log->con = log->end -LOGBUFF_LEN ; + +/* Occasionally, particularly following a reboot, the start +* consumer index is not properly caught up to the console +* consumer index. If this is the case, catch it up so that +* the log buffer doesn't start with, for example, +* "<0>Restarting system.\n" followed by the 'real' start of +* the log. +*/ + +if (log->con > log->start) + log->start = log->con; + +/* Ensure that the number of characters logged reflects the +* characters actually logged based on the producer and +* consumer indices rather than all characters cumulatively +* logged across all reboots since a power-loss event. +*/ + + chars = log->end - log->start; + +if (log->chars > chars) + log->chars = chars; +} + +/* Coalesce the current log bounded buffer and the external log +* bounded buffer by appending the former to the latter. Precedence is +* given to the external log buffer when there is more data to be +* appended than space exists, so the current log buffer is truncated +* instead of overwritting the external buffer. +*/ +static void __init logbuff_coalesce_buffers(LOGBUFF_VOLATILE logbuff_t *log) +{ +unsigned long dspace, ssize, len; + + dspace =LOGBUFF_LEN - (log->end - log->start); + ssize = log_end - log_start; + len =min (dspace, ssize); + +while (len-- >0 ) { + log->buf[log->end++ & (LOGBUFF_LEN -1 )] =LOG_BUF (log_start++); + log->chars++; + } +} +void __init setup_ext_logbuff (void ) +{ + LOGBUFF_VOLATILE logbuff_t *log; +char *ext_log_buf =NULL ; +unsigned long flags; + +if (setup_ext_logbuff_mem (&log, &ext_log_buf) <0 ) { +printk (KERN_WARNING +"Failed to setup external logbuffer - ignoring it\n" ); +return ; + } + +/* When no properly setup buffer is found, reset pointers */ +if (log->tag !=LOGBUFF_MAGIC ) { +printk (KERN_WARNING +"Unexpected external log buffer magic number. " +"Got %08lx, expected %08x. Resetting pointers and using " +"the buffer anyway.\n" , + log->tag,LOGBUFF_MAGIC ); + log->tag =LOGBUFF_MAGIC ; + log->start = log->end = log->con = log->chars =0 ; + } + +spin_lock_irqsave (&logbuf_lock, flags); + +logbuff_check_metadata (log); +logbuff_coalesce_buffers (log); + +/* Switch to the external log buffer */ + ext_log_start = &log->start; + ext_con_start = &log->con; + ext_log_end = &log->end; + ext_logged_chars = &log->chars; + + log_buf = ext_log_buf; + log_buf_len =LOGBUFF_LEN ; + +spin_unlock_irqrestore (&logbuf_lock, flags); + +printk (KERN_NOTICE "log_buf=%p\n" , log_buf); +} +#endif /* CONFIG_LOGBUFFER */ static int __init log_buf_len_setup (char *str) { +#ifdef CONFIG_LOGBUFFER +/* Log buffer size is LOGBUFF_LEN bytes */ +printk (KERN_NOTICE +"External log buffer configured; " +"ignoring log_buf_len param.\n" ); +return 1 ; +#else unsigned size =memparse (str, &str);unsigned long flags;@@ -173,6 +315,7 @@ static int __init log_buf_len_setup(char *str) } out:return 1 ; +#endif /* CONFIG_LOGBUFFER */ }__setup ("log_buf_len=" , log_buf_len_setup);@@ -230,7 +373,7 @@ static void boot_delay_msec(void)static inline void boot_delay_msec (void ) { } -#endif +#endif /* CONFIG_BOOT_PRINTK_DELAY */ /* * Commands to do_syslog: @@ -740,7 +883,7 @@ out_restore_irqs:EXPORT_SYMBOL (printk);EXPORT_SYMBOL (vprintk); -#else +#else /* !CONFIG_PRINTK */ asmlinkage long sys_syslog (int type,char __user *buf,int len) {@@ -751,7 +894,7 @@ static void call_console_drivers(unsigned start, unsigned end) { } -#endif +#endif /* CONFIG_PRINTK */ static int __add_preferred_console (char *name,int idx,char *options,char *brl_options)
Signature · 1 line
http://www.hailfinger.org/
Quoted 25 lines · On Wed, 21 Jan 2009 09:39:46 -0800 Grant Erickson <[email protected]>…
This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. In addition, this ports architecture support for this feature from
arch/ppctoarch/powerpc.When this option is enabled, an architecture- or machine-specific log buffer is used for all printk messages. This allows entities such as boot loaders (e.g. U-Boot) to place printk-compatible messages into this buffer and for the kernel to coalesce them with its normal messages.
Signed-off-by Grant Erickson <[email protected]>---
The code has historically been used and proven to work on the LWMON5 platform under
arch/ppcand is now used (by me) successfully on the AMCC Haleakala and Kilauea platforms.As implemented for
arch/powerpc, two suboptions for the alternative log buffer are supported. The buffer may be contiguous with the metadata and message data colocated or the metadata and message storage may be in discontiguous regions of memory (e.g. a set of scratch registers and an SRAM buffer). On Kilauea and Haleakala, I have used the former; whereas LWMON5 has traditionally used the latter.
Quoted 4 lines
The code here is, more or less, as-is from the DENX GIT tree. Comments welcome. Some prior discussion from the linuxppc-dev mailing list is at
http://ozlabs.org/pipermail/linuxppc-dev/2008-November/065589.html.
I'm not completely clear what all this exactly does. Let me try...
We have an external log buffer, into which stuff was written by (say) the boot prom code.
We want that to come out on the console during bootup.
So what we do is to divert the normal printk log buffer so that it starts writing at the tail of that existing external buffer. We emit the entire buffer some time during bootup. We henceforth continue to use that external buffer in the normal manner.
If so, why do it this way? Why not just copy the external buffer's contents into the normal buffer during bootup? ie: printk("%s", external_buffer).
I think a quite bad part of this feature is that it renders the kernel's log_buf_len boot parameter (and its Kconfig defult) ineffective. That's a pretty useful feature - people often set it to 1MB or more during problem diagnosis, and the new unalterable 16kbytes is very very small.
Quoted 13 lines
arch/powerpc/kernel/prom.c +1
-0@@ -32,6 +32,7 @@#include <linux/debugfs.h> #include <linux/irq.h> #include <linux/lmb.h> +#include <linux/logbuff.h> #include <asm/prom.h> #include <asm/rtas.h>
arch/powerpc/kernel/prom.c line 66
Quoted 5 lines
arch/powerpc/kernel/prom.c +2
-0@@ -61,6 +62,15 @@ #define DBG(fmt...)#endif +#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION
CONFIG_ALT_LB_LOCATION depends upon CONFIG_LOGBUFFER, so we only need
#ifdef CONFIG_ALT_LB_LOCATION
here. There are several instances of this in the patch.
Quoted 17 lines
arch/powerpc/kernel/prom.c +10
-0+# if !defined(BOARD_ALT_LH_ADDR ) || !defined(BOARD_ALT_LB_ADDR ) +# error "Please specify BOARD_ALT_LH_ADDR & BOARD_ALT_LB_ADDR." +# endif +#else /* !CONFIG_ALT_LB_LOCATION */ +static phys_addr_t ext_logbuff; +#endif /* CONFIG_ALT_LB_LOCATION */ +#endif /* CONFIG_LOGBUFFER */ static int __initdata dt_root_addr_cells;static int __initdata dt_root_size_cells;@@ -1018,6 +1028,85 @@ static int __init early_init_dt_scan_memory(unsigned long node,return 0 ; } +#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION +/* Alternative external log buffer mapping: log metadata header & the
arch/powerpc/kernel/prom.c static int __init early_init_dt_scan_memory(unsigned long node, · line 1043
Quoted 10 lines
arch/powerpc/kernel/prom.c +10
-0+* character buffer are separated and allocated not in RAM but in some +* other memory-mapped I/O region (e.g. log head in unused registers, +* and log buffer in OCM memory) +*/ +int __init setup_ext_logbuff_mem (volatile logbuff_t **lhead,char **lbuf) +{ +void *h, *b; + +if (unlikely (!lhead) ||unlikely (!lbuf)) +return -EINVAL ;
This test is unneeded.
Quoted 17 lines
arch/powerpc/kernel/prom.c +17
-0+/* map log head */ + h =ioremap (BOARD_ALT_LH_ADDR ,sizeof (logbuff_t)); +if (unlikely (!h)) +return -EFAULT ; + +/* map log buffer */ + b =ioremap (BOARD_ALT_LB_ADDR ,LOGBUFF_LEN ); +if (unlikely (!b)) { +iounmap (h); +return -EFAULT ; + } + + *lhead = h; + *lbuf = b; + +return 0 ; +}
arch/powerpc/kernel/prom.c static int __init early_init_dt_scan_memory(unsigned long node, · line 1071
Quoted 10 lines
arch/powerpc/kernel/prom.c +10
-0+#else /* !CONFIG_ALT_LB_LOCATION */ +/* Usual external log-buffer mapping: log metadata header & the character +* buffer are both contiguous in system RAM. +*/ +int __init setup_ext_logbuff_mem (logbuff_t **lhead,char **lbuf) +{ +void *p; + +if (unlikely (!lhead) ||unlikely (!lbuf)) +return -EINVAL ;
This test is unneeded.
arch/powerpc/kernel/prom.c static int __init early_init_dt_scan_memory(unsigned long node, · line 1072
Quoted 2 lines
arch/powerpc/kernel/prom.c +2
-0+if (unlikely (!ext_logbuff) || !lmb_is_reserved (ext_logbuff)) +return -EFAULT ;
Is this test needed?
arch/powerpc/kernel/prom.c static int __init early_init_dt_scan_memory(unsigned long node, · line 1083
Quoted 8 lines
arch/powerpc/kernel/prom.c +8
-0+ p =ioremap (ext_logbuff,LOGBUFF_RESERVE ); + +if (unlikely (!p)) +return -EFAULT ; + + *lhead = (logbuff_t *)(p +LOGBUFF_OVERHEAD - +sizeof (logbuff_t) + +sizeof (((logbuff_t *)0 )->buf));
The cast is unneeded.
Quoted 30 lines
arch/powerpc/kernel/prom.c +26
-0+ *lbuf = (*lhead)->buf; + +return 0 ; +} + +/* When the external log buffer configuration is used with the +* non-alternate location, the log head metadata and character buffer +* lie in the LOGBUFF_RESERVE bytes at the end of system RAM. Add this +* block of memory to the reserved memory pool so that it is not +* allocated for other purposes. +*/ +static void __init reserve_ext_logbuff_mem (void ) +{ +phys_addr_t top =lmb_end_of_DRAM (); +phys_addr_t size =LOGBUFF_RESERVE ; +phys_addr_t base = top - size; + +if (top > base) { + ext_logbuff = base; +DBG ("reserving: %x -> %x\n" , base, size); +lmb_reserve (base, size); + } +} +#endif /* CONFIG_ALT_LB_LOCATION */ +#endif /* CONFIG_LOGBUFFER */ +static void __init early_reserve_mem (void ) {u64 base, size;
arch/powerpc/kernel/prom.c static void __init early_reserve_mem(void) · line 1127
Quoted 6 lines
arch/powerpc/kernel/prom.c +3
-0@@ -1033,6 +1122,10 @@ static void __init early_reserve_mem(void) self_size = initial_boot_params->totalsize;lmb_reserve (self_base, self_size); +#if defined(CONFIG_LOGBUFFER ) && !defined(CONFIG_ALT_LB_LOCATION ) +reserve_ext_logbuff_mem (); +#endif /* defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_LOCATION) */
It would be cleaner and more maintainable to do
#else
static inline void reserve_ext_logbuff_mem(void)
{
}
#endif
above, then remove the ifdefs here.
Quoted 28 lines
arch/powerpc/kernel/prom.c +1
-0+#ifdef CONFIG_BLK_DEV_INITRD /* then reserve the initrd, if any */ if (initrd_start && (initrd_end > initrd_start))include/linux/logbuff.h new file +18
-0@@ -0,0 +1,56 @@ +/* +* (C) Copyright 2007 +* Wolfgang Denk, DENX Software Engineering, [email protected]. +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License
include/linux/logbuff.h line 28
Quoted 10 lines
include/linux/logbuff.h new file +10
-0+* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ +#ifndef _LOGBUFF_H_ +#define _LOGBUFF_H_ + +#ifdef CONFIG_LOGBUFFER + +#define LOGBUFF_MAGIC 0xc0de4ced
What is the meaning of this value? Is it random, or does it correspond to some powerpc firmware thing, or??
Do we actually need this magic number? All it appears to do is to cause a warning.
The magic number could/should be placed in magic.h.
include/linux/logbuff.h line 31
Quoted 3 lines
include/linux/logbuff.h new file +3
-0+#define LOGBUFF_LEN 16384 +#define LOGBUFF_OVERHEAD 4096 +#define LOGBUFF_RESERVE (LOGBUFF_LEN + LOGBUFF_OVERHEAD)
What is LOGBUFF_OVERHEAD supposed to do?
afacit both LOGBUFF_OVERHEAD and LOGBUFF_RESERVE are unused and could/should be removed.
include/linux/logbuff.h line 34
Quoted 2 lines
include/linux/logbuff.h new file +2
-0+/* The mapping used here has to be the same as in logbuff_init_ptrs () +in u-boot/common/cmd_log.c */
Please prefer to format comments as
/*
* The mapping used here has to be the same as in logbuff_init_ptrs ()
* in u-boot/common/cmd_log.c
*/
include/linux/logbuff.h line 43
Quoted 8 lines
include/linux/logbuff.h new file +8
-0+typedef struct { +unsigned long tag; +unsigned long start; +unsigned long con;/* next char to be sent to consoles */ +unsigned long end; +unsigned long chars; +unsigned char buf[0 ]; +}logbuff_t ;
Please avoid adding typedefs like this. Just use `struct ext_log_buffer' (or whatever) everywhere.
include/linux/logbuff.h line 49
Quoted 5 lines
include/linux/logbuff.h new file +5
-0+#ifdef CONFIG_ALT_LB_LOCATION +# define LOGBUFF_VOLATILE volatile +#else +# define LOGBUFF_VOLATILE +#endif /* defined(CONFIG_ALT_LB_LOCATION) */
Why does this code use volatiles? Please seeDocumentation/volatile-considered-harmful.txt
Quoted 55 lines
include/linux/logbuff.h new file +6
-0+extern void setup_ext_logbuff (void ); +/* arch specific */ +extern int setup_ext_logbuff_mem(LOGBUFF_VOLATILE logbuff_t **lhead, char **lbuf); + +#endif /* CONFIG_LOGBUFFER */ +#endif /* _LOGBUFF_H_ */ init/Kconfig +25
-0@@ -619,6 +619,31 @@ config PRINTK very difficult to diagnose system problems, saying N here is strongly discouraged. +config LOGBUFFER + bool "External logbuffer" if PRINTK + default n + help + This option enables support for an alternative, "external" + printk log buffer. When enabled, an architecture- or machine- + specific log buffer is used for all printk messages. This + allows entities such as boot loaders to place printk-compatible + messages into this buffer and for the kernel to coalesce them + with its normal messages. + +config ALT_LB_LOCATION + bool "Alternative logbuffer" if LOGBUFFER + default n + help + When using an alternative, "external" printk log buffer, an + architecture- or machine-specific log buffer with contiguous + metadata and message storage is used. This option enables + support for discontiguous metadata and message storage + memory (e.g. a set of scratch registers and an SRAM + buffer). By saying Y here, you must also ensure your + architecture- or machine-code specify BOARD_ALT_LH_ADDR and + BOARD_ALT_LB_ADDR, for the metadata and message memory, + respectively. + config BUG bool "BUG() support" if EMBEDDED default yinit/main.c +1
-0@@ -61,6 +61,7 @@#include <linux/kthread.h> #include <linux/sched.h> #include <linux/signal.h> +#include <linux/logbuff.h> #include <linux/idr.h> #include <linux/ftrace.h>
init/main.c asmlinkage void __init start_kernel(void) · line 569
Quoted 6 lines
init/main.c +3
-0@@ -563,6 +564,9 @@ asmlinkage void __init start_kernel(void)* Interrupts are still disabled. Do necessary setups, then * enable them */ +#ifdef CONFIG_LOGBUFFER +setup_ext_logbuff (); +#endif
Do
#else
static inline void setup_ext_logbuff(void)
{
}
#endif /* CONFIG_whatever */
in a header file, then remove these ifdefs.
Quoted 42 lines
init/main.c +0
-0lock_kernel ();tick_init ();boot_cpu_init ();kernel/printk.c +24
-0@@ -32,6 +32,7 @@#include <linux/security.h> #include <linux/bootmem.h> #include <linux/syscalls.h> +#include <linux/logbuff.h> #include <asm/uaccess.h> @@ -101,9 +102,39 @@ static DEFINE_SPINLOCK(logbuf_lock);* The indices into log_buf are not constrained to log_buf_len - they * must be masked before subscripting */ +#ifdef CONFIG_LOGBUFFER +/* Indexes to the local log buffer */ +static unsigned long _log_start; +static unsigned long _con_start; +static unsigned long _log_end; +static unsigned long _logged_chars; +/* These will be switched to the external log buffer */ +#ifndef CONFIG_ALT_LB_LOCATION +/* usual logbuffer location */ +static unsigned long *ext_log_start = &_log_start; +static unsigned long *ext_con_start = &_con_start; +static unsigned long *ext_log_end = &_log_end; +static unsigned long *ext_logged_chars = &_logged_chars; +#define log_start (*ext_log_start) +#define con_start (*ext_con_start) +#define log_end (*ext_log_end) +#define logged_chars (*ext_logged_chars) +#else /* defined(CONFIG_ALT_LB_LOCATION) */ +/* alternative logbuffer location */ +static volatile unsigned long *ext_log_start = &_log_start; +static volatile unsigned long *ext_con_start = &_con_start; +static volatile unsigned long *ext_log_end = &_log_end; +static volatile unsigned long *ext_logged_chars = &_logged_chars;
kernel/printk.c static DEFINE_SPINLOCK(logbuf_lock); · line 137
Quoted 10 lines
kernel/printk.c +7
-0+#define log_start (*((volatile u32 *)ext_log_start)) +#define con_start (*((volatile u32 *)ext_con_start)) +#define log_end (*((volatile u32 *)ext_log_end)) +#define logged_chars (*((volatile u32 *)ext_logged_chars)) +#endif /* !defined(CONFIG_ALT_LB_LOCATION) */ +#else /* !defined(CONFIG_LOGBUFFER) */ static unsigned log_start;/* Index into log_buf: next char to be read by syslog() */ static unsigned con_start;/* Index into log_buf: next char to be sent to consoles */ static unsigned log_end;/* Index into log_buf: most-recently-written-char + 1 */ +#endif /* CONFIG_LOGBUFFER */
ick.
Quoted 73 lines
kernel/printk.c +65
-0/* * Array of consoles built from command line options (console=) @@ -134,10 +165,121 @@ static int console_may_schedule;static char __log_buf[__LOG_BUF_LEN];static char *log_buf = __log_buf;static int log_buf_len = __LOG_BUF_LEN; +#ifndef CONFIG_LOGBUFFER static unsigned logged_chars;/* Number of chars produced since last read+clear operation */ +#endif /* !defined(CONFIG_LOGBUFFER) */ +#ifdef CONFIG_LOGBUFFER +/* Sanity check the external log buffer metadata. When an the external +* log buffer is enabled, the log metadata is effectively non-volatile +* in that the values are preserved from reboot to reboot (until/unless +* the system loses power). +*/ +static void __init logbuff_check_metadata(LOGBUFF_VOLATILE logbuff_t *log) +{ +unsigned long chars; + +/* Sanity check the producer and consumer indices. */ + +if (log->end - log->start >LOGBUFF_LEN ) + log->start = log->end -LOGBUFF_LEN ; + +if (log->end - log->con >LOGBUFF_LEN ) + log->con = log->end -LOGBUFF_LEN ; + +/* Occasionally, particularly following a reboot, the start +* consumer index is not properly caught up to the console +* consumer index. If this is the case, catch it up so that +* the log buffer doesn't start with, for example, +* "<0>Restarting system.\n" followed by the 'real' start of +* the log. +*/ + +if (log->con > log->start) + log->start = log->con; + +/* Ensure that the number of characters logged reflects the +* characters actually logged based on the producer and +* consumer indices rather than all characters cumulatively +* logged across all reboots since a power-loss event. +*/ + + chars = log->end - log->start; + +if (log->chars > chars) + log->chars = chars; +} + +/* Coalesce the current log bounded buffer and the external log +* bounded buffer by appending the former to the latter. Precedence is +* given to the external log buffer when there is more data to be +* appended than space exists, so the current log buffer is truncated +* instead of overwritting the external buffer. +*/ +static void __init logbuff_coalesce_buffers(LOGBUFF_VOLATILE logbuff_t *log) +{ +unsigned long dspace, ssize, len; + + dspace =LOGBUFF_LEN - (log->end - log->start); + ssize = log_end - log_start; + len =min (dspace, ssize); + +while (len-- >0 ) { + log->buf[log->end++ & (LOGBUFF_LEN -1 )] =LOG_BUF (log_start++); + log->chars++; + } +} +void __init setup_ext_logbuff (void ) +{ + LOGBUFF_VOLATILE logbuff_t *log;
kernel/printk.c static int console_may_schedule; · line 244
Quoted 10 lines
kernel/printk.c +10
-0+char *ext_log_buf =NULL ; +unsigned long flags; + +if (setup_ext_logbuff_mem (&log, &ext_log_buf) <0 ) { +printk (KERN_WARNING +"Failed to setup external logbuffer - ignoring it\n" ); +return ; + } + +/* When no properly setup buffer is found, reset pointers */
"set up"
Quoted 28 lines
kernel/printk.c +28
-0+if (log->tag !=LOGBUFF_MAGIC ) { +printk (KERN_WARNING +"Unexpected external log buffer magic number. " +"Got %08lx, expected %08x. Resetting pointers and using " +"the buffer anyway.\n" , + log->tag,LOGBUFF_MAGIC ); + log->tag =LOGBUFF_MAGIC ; + log->start = log->end = log->con = log->chars =0 ; + } + +spin_lock_irqsave (&logbuf_lock, flags); + +logbuff_check_metadata (log); +logbuff_coalesce_buffers (log); + +/* Switch to the external log buffer */ + ext_log_start = &log->start; + ext_con_start = &log->con; + ext_log_end = &log->end; + ext_logged_chars = &log->chars; + + log_buf = ext_log_buf; + log_buf_len =LOGBUFF_LEN ; + +spin_unlock_irqrestore (&logbuf_lock, flags); + +printk (KERN_NOTICE "log_buf=%p\n" , log_buf); +}
kernel/printk.c static int console_may_schedule; · line 282
Quoted 10 lines
kernel/printk.c +8
-0+#endif /* CONFIG_LOGBUFFER */ static int __init log_buf_len_setup (char *str) { +#ifdef CONFIG_LOGBUFFER +/* Log buffer size is LOGBUFF_LEN bytes */ +printk (KERN_NOTICE +"External log buffer configured; " +"ignoring log_buf_len param.\n" ); +return 1 ; +#else
:(
Quoted 38 lines
kernel/printk.c +4
-3unsigned size =memparse (str, &str);unsigned long flags;@@ -173,6 +315,7 @@ static int __init log_buf_len_setup(char *str) } out:return 1 ; +#endif /* CONFIG_LOGBUFFER */ }__setup ("log_buf_len=" , log_buf_len_setup);@@ -230,7 +373,7 @@ static void boot_delay_msec(void)static inline void boot_delay_msec (void ) { } -#endif +#endif /* CONFIG_BOOT_PRINTK_DELAY */ /* * Commands to do_syslog: @@ -740,7 +883,7 @@ out_restore_irqs:EXPORT_SYMBOL (printk);EXPORT_SYMBOL (vprintk); -#else +#else /* !CONFIG_PRINTK */ asmlinkage long sys_syslog (int type,char __user *buf,int len) {@@ -751,7 +894,7 @@ static void call_console_drivers(unsigned start, unsigned end) { } -#endif +#endif /* CONFIG_PRINTK */ static int __add_preferred_console (char *name,int idx,char *options,char *brl_options)
Quoted 37 lines · Andrew Morton
Quoted 25 lines · On Wed, 21 Jan 2009 09:39:46 -0800 Grant Erickson <[email protected]>…
This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. In addition, this ports architecture support for this feature from
arch/ppctoarch/powerpc.When this option is enabled, an architecture- or machine-specific log buffer is used for all printk messages. This allows entities such as boot loaders (e.g. U-Boot) to place printk-compatible messages into this buffer and for the kernel to coalesce them with its normal messages.
Signed-off-by Grant Erickson <[email protected]>---
The code has historically been used and proven to work on the LWMON5 platform under
arch/ppcand is now used (by me) successfully on the AMCC Haleakala and Kilauea platforms.As implemented for
arch/powerpc, two suboptions for the alternative log buffer are supported. The buffer may be contiguous with the metadata and message data colocated or the metadata and message storage may be in discontiguous regions of memory (e.g. a set of scratch registers and an SRAM buffer). On Kilauea and Haleakala, I have used the former; whereas LWMON5 has traditionally used the latter.Quoted 4 lines
The code here is, more or less, as-is from the DENX GIT tree. Comments welcome. Some prior discussion from the linuxppc-dev mailing list is at
http://ozlabs.org/pipermail/linuxppc-dev/2008-November/065589.html.I'm not completely clear what all this exactly does. Let me try...
We have an external log buffer, into which stuff was written by (say) the boot prom code.
Quoted 6 lines
We want that to come out on the console during bootup.
So what we do is to divert the normal printk log buffer so that it starts writing at the tail of that existing external buffer. We emit the entire buffer some time during bootup. We henceforth continue to use that external buffer in the normal manner. If so, why do it this way?
Andrew,
Thanks for your feedback. Your summary is precisely the intent. As I mentioned in check-in notice, this isn't my work per se, but a fix of prior unsubmitted work. Consequently, I can only speculate on the original implementation choices of the primary authors (Yuri Tikhonov <[email protected]> on behalf of Denx from what I can ascertain from GIT logs). I've added Wolfgang in the event he can add background where appropriate.
I believe this to be a useful feature for the embedded system space; however, I am not wedded in any way to the current implementation and am happy to evolve it as needed to meet the needs of key stakeholders.
Quoted 2 lines
Why not just copy the external buffer's contents into the normal buffer during bootup? ie:
printk("%s", external_buffer).
Again, conjecturing, I suspect the goal was to ensure that the boot messages appear on the console or in the syslog before kernel messages of that particular boot cycle. Depending on the board and architecture in question, the kernel log buffer may have several messages in it by the time the log coalescing code runs. For example, on the board I tested this on:
# dmesg
U-Boot 1.3.3 (Jan 9 2009 - 10:24:45)
POST memory PASSED
POST ecc PASSED
POST cache PASSED
POST ethernet PASSED
Using Kilauea machine description
log_buf=fdffc000
Linux version 2.6.27.7 (gerickson@ubuntu-fusion) (gcc version 4.0.0
(DENX ELDK 4.1 4.0.0)) #1 Fri Jan 9 10:30:30 PST 2009"Using Kilauea..." is already in the kernel buffer when the time comes around to coalesce the buffer.
In the case of u-boot, it uses logging code nearly identical to Linux, so employing the straightforward approach of 'printk("%s", external_buffer)' would result in:
# dmesg
U-Boot 1.3.3 (Jan 9 2009 - 10:24:45)
<4>POST memory PASSED
<4>POST ecc PASSED
<4>POST cache PASSED
<4>POST ethernet PASSED
Using Kilauea machine descriptionNot the end of the world, but not ideal either.
Quoted 5 lines
I think a quite bad part of this feature is that it renders the kernel's
log_buf_lenboot parameter (and itsKconfigdefult) ineffective. That's a pretty useful feature - people often set it to 1MB or more during problem diagnosis, and the new unalterable 16kbytes is very very small.
Agreed; however, I'm not sure how often this technique is employed in embedded systems versus desktop systems.
I'd be happy to keep the existing log buffer and perform a prepend from the boot buffer to it rather than an append of the kernel buffer to the boot buffer. Thoughts?
Quoted 16 lines
Quoted 16 lines
arch/powerpc/kernel/prom.c +1
-0@@ -32,6 +32,7 @@#include <linux/debugfs.h> #include <linux/irq.h> #include <linux/lmb.h> +#include <linux/logbuff.h> #include <asm/prom.h> #include <asm/rtas.h> @@ -61,6 +62,15 @@ #define DBG(fmt...)#endif
Quoted 8 lines
arch/powerpc/kernel/prom.c line 66
Quoted 2 lines
arch/powerpc/kernel/prom.c +2
-0+#ifdef CONFIG_LOGBUFFER +#ifdef CONFIG_ALT_LB_LOCATION
CONFIG_ALT_LB_LOCATIONdepends uponCONFIG_LOGBUFFER, so we only need#ifdef
CONFIG_ALT_LB_LOCATIONhere. There are several instances of this in the patch.
On the PPC mailing list, there were some solid proposals using the device tree that would make the configuration a bit cleaner. In those cases, there's simply a board/architecture method/probe enabled by Kconfig that would perform the aforementioned prepend operation.
Thoughts?
Quoted 9 lines
arch/powerpc/kernel/prom.c line 72
Quoted 6 lines
arch/powerpc/kernel/prom.c +6
-0+#ifndef _LOGBUFF_H_ +#define _LOGBUFF_H_ + +#ifdef CONFIG_LOGBUFFER + +#define LOGBUFF_MAGIC 0xc0de4cedWhat is the meaning of this value? Is it random, or does it correspond to some powerpc firmware thing, or??
It's defined by u-boot and used by u-boot in relation to how it manages POST status and its log buffer.
Quoted 4 lines
Do we actually need this magic number? All it appears to do is to cause a warning.
The magic number could/should be placed in
magic.h.
Wolfgang?
Quoted 9 lines
arch/powerpc/kernel/prom.c line 75
Quoted 4 lines
arch/powerpc/kernel/prom.c +3
-0+#define LOGBUFF_LEN 16384 +#define LOGBUFF_OVERHEAD 4096 +#define LOGBUFF_RESERVE (LOGBUFF_LEN + LOGBUFF_OVERHEAD)What is
LOGBUFF_OVERHEADsupposed to do?afacit both
LOGBUFF_OVERHEADandLOGBUFF_RESERVEare unused and could/should be removed.
Again, I am simply conjecturing here; however, I would guess that for the case of the co-located boot log metadata and buffer data, there was a desire to provide a buffer of the same page-aligned size as the default kernel buffer (16 KiB) and then a desire to use 5 words of metadata but, again, keep things "easy" by just stealing/reserving a whole, additional page.
Wolfgang?
Quoted 8 lines
arch/powerpc/kernel/prom.c
Quoted 5 lines
arch/powerpc/kernel/prom.c +5
-0+#ifdef CONFIG_ALT_LB_LOCATION +# define LOGBUFF_VOLATILE volatile +#else +# define LOGBUFF_VOLATILE +#endif /* defined(CONFIG_ALT_LB_LOCATION) */ Why does this code use volatiles? Please see
Documentation/volatile-considered-harmful.txt
I've definitely read and understand it. Again, conjecturing here, but I would guess that for the non-colocated buffer/metadata case, the original author(s) were perhaps trying to avoid placing xe32_to_cpu or such in the generic kernel logging code.
If we take the prepend-and-preserve-the-kernel-buffer tack, I think this would all largely get cleaned-up and disappear. Prepend I/O would then be relegated to architecture- or board-specific code.
Thoughts? Wolfgang?
Quoted 49 lines
Quoted 49 lines
lock_kernel();tick_init();boot_cpu_init();kernel/printk.c +30
-0@@ -32,6 +32,7 @@#include <linux/security.h> #include <linux/bootmem.h> #include <linux/syscalls.h> +#include <linux/logbuff.h> #include <asm/uaccess.h> @@ -101,9 +102,39 @@ static DEFINE_SPINLOCK(logbuf_lock);* The indices into log_buf are not constrained to log_buf_len - they * must be masked before subscripting */ +#ifdef CONFIG_LOGBUFFER +/* Indexes to the local log buffer */ +static unsigned long _log_start; +static unsigned long _con_start; +static unsigned long _log_end; +static unsigned long _logged_chars; +/* These will be switched to the external log buffer */ +#ifndef CONFIG_ALT_LB_LOCATION +/* usual logbuffer location */ +static unsigned long *ext_log_start = &_log_start; +static unsigned long *ext_con_start = &_con_start; +static unsigned long *ext_log_end = &_log_end; +static unsigned long *ext_logged_chars = &_logged_chars; +#define log_start (*ext_log_start) +#define con_start (*ext_con_start) +#define log_end (*ext_log_end) +#define logged_chars (*ext_logged_chars) +#else /* defined(CONFIG_ALT_LB_LOCATION) */ +/* alternative logbuffer location */ +static volatile unsigned long *ext_log_start = &_log_start; +static volatile unsigned long *ext_con_start = &_con_start; +static volatile unsigned long *ext_log_end = &_log_end; +static volatile unsigned long *ext_logged_chars = &_logged_chars; +#define log_start (*((volatile u32 *)ext_log_start)) +#define con_start (*((volatile u32 *)ext_con_start)) +#define log_end (*((volatile u32 *)ext_log_end)) +#define logged_chars (*((volatile u32 *)ext_logged_chars)) +#endif /* !defined(CONFIG_ALT_LB_LOCATION) */ +#else /* !defined(CONFIG_LOGBUFFER) */ static unsigned log_start;/* Index into log_buf: next char to be read by
Quoted 8 lines
Quoted 6 lines
syslog()*/
static unsignedcon_start; /* Index intolog_buf: next char to be sent to
consoles */
static unsignedlog_end; /* Index intolog_buf: most-recently-written-char +
1 */
+#endif /*CONFIG_LOGBUFFER*/ick.
See comments above.
If you and Wolfgang are supportive of the prepend and preserve approach, I think I can take another pass at this and eliminate a good measure of the implementation concerns.
I welcome your further feedback.
Regards,
Grant
Quoted 21 lines · On Fri, 30 Jan 2009 14:01:49 -0800 Grant Erickson <[email protected]>…
Your summary is precisely the intent. As I
mentioned in check-in notice, this isn't my work per se, but a fix of prior unsubmitted work. Consequently, I can only speculate on the original implementation choices of the primary authors (Yuri Tikhonov <[email protected]> on behalf of Denx from what I can ascertain from GIT logs). I've added Wolfgang in the event he can add background where appropriate.I believe this to be a useful feature for the embedded system space; however, I am not wedded in any way to the current implementation and am happy to evolve it as needed to meet the needs of key stakeholders.
Quoted 2 lines
Why not just copy the external buffer's contents into the normal buffer during bootup? ie:
printk("%s", external_buffer).Again, conjecturing, I suspect the goal was to ensure that the boot messages appear on the console or in the syslog before kernel messages of that particular boot cycle. Depending on the board and architecture in question, the kernel log buffer may have several messages in it by the time the log coalescing code runs. For example, on the board I tested this on:
Quoted 10 lines
# dmesg
U-Boot 1.3.3 (Jan 9 2009 - 10:24:45)
POST memory PASSED
POST ecc PASSED
POST cache PASSED
POST ethernet PASSED
Using Kilauea machine description
log_buf=fdffc000
Linux version 2.6.27.7 (gerickson@ubuntu-fusion) (gcc version 4.0.0
(DENX ELDK 4.1 4.0.0)) #1 Fri Jan 9 10:30:30 PST 2009It shouldn't be too hard to cook up some way of copying some data into th log buffer before the kernel itself has put anything in there, if that's all which is needed.
something similar to this?
include/linux/kernel.h | 2 ++ init/main.c | 6 ++++++ kernel/printk.c | 8 ++++++++ 3 files changed, 16 insertions(+)
init/main.c renamed from init/main.c~a +6 -0
@@ -535,11 +535,17 @@ void __init __weak thread_info_cache_ini { } +void __init __weak arch_copy_boot_messages (void ) +{ +} + asmlinkage void __init start_kernel(void) {char * command_line;extern struct kernel_param __start___param[], __stop___param[]; +arch_copy_boot_messages (); +smp_setup_processor_id ();/*
kernel/printk.c renamed from kernel/printk.c~a +8 -0
@@ -493,6 +493,14 @@ static void emit_log_char(char c) logged_chars++; } +void emit_log_string (const char *s) +{ +spin_lock_irqsave (&logbuf_lock); +while (*s) +emit_log_char (*s++); +spin_unlock_irqsave (&logbuf_lock); +} +/* * Zap console related locks when oopsing. Only zap at most once * every 10 seconds, to leave time for slow consoles to print a
include/linux/kernel.h renamed from include/linux/kernel.h~a +2 -0
@@ -257,6 +257,8 @@ static inline bool printk_timed_ratelimiextern int printk_needs_cpu (int cpu);extern void printk_tick (void ); +extern void __init arch_copy_boot_messages (void ); +extern void emit_log_string (const char *s); extern void asmlinkage __attribute__((format(printf, 1, 2))) early_printk(const char *fmt, ...);
_
Dear Andrew,
Quoted 4 lines · In message <[email protected]> you wrote:
It shouldn't be too hard to cook up some way of copying some data into th log buffer before the kernel itself has put anything in there, if that's all which is needed.
Agreed, but we also want to get the data back into the shared log buffer when the system crashes someone presses the reset button. The log buffer shall survive reboots -that's the basic requirment of the implementation, and this is what makes it a bit more complicated.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] Microsoft Multitasking: several applications can crash at the same time.
Dear Grant & Andrew,
Quoted 3 lines · In message <C5A8B8CD.143B5%[email protected]> you wrote:
Quoted 3 lines
We have an external log buffer, into which stuff was written by (say) the boot prom code.
Correct. Typically we use this in U-Boot to pass Power-On Self Test results to applications running under Linux, using the standard syslog tools.
Another are of use is to save the log buffer over a reset (crash) of the system, so that it can be read either rom the boot loader or, after a reboot, from Linux.
Quoted 1 line
Quoted 1 line
We want that to come out on the console during bootup.
Not necessarily. The main function is to feed it into the syslog processing.
Quoted 4 lines
Quoted 4 lines
So what we do is to divert the normal printk log buffer so that it starts writing at the tail of that existing external buffer. We emit the entire buffer some time during bootup. We henceforth continue to use that external buffer in the normal manner. If so, why do it this way?
Do you have a better approach how to share the log buffer between Linux and a boot loader in such a way that the content will survive crahses and reboots?
Quoted 3 lines
I believe this to be a useful feature for the embedded system space; however, I am not wedded in any way to the current implementation and am happy to evolve it as needed to meet the needs of key stakeholders.
Indeed we use this heavily in embedded systems, mainly to process POST results under Linux (for example, to disable certain functions when the POST results indicate hardware issues, etc.).
Quoted 2 lines
Quoted 2 lines
Why not just copy the external buffer's contents into the normal buffer during bootup? ie:
printk("%s", external_buffer).
For two reasons:
1) Additional copy operation (ok, that's cheap).
2) We would lose the capability that the buffer content even survives a reset / crash / reboot.
This is a feature can be very useful in embedded systems where there is (at least normally) nobody looking at any console messages; being able to see the kernel's crash messages after a reboot in the normal syslog messages can be really helpful.
Quoted 5 lines
Quoted 5 lines
I think a quite bad part of this feature is that it renders the kernel's
log_buf_lenboot parameter (and itsKconfigdefult) ineffective. That's a pretty useful feature - people often set it to 1MB or more during problem diagnosis, and the new unalterable 16kbytes is very very small.
Yes, we are aware of this, but it's a compromise. Basicly it depends on hardware capabilities. In most cases, it is sufficient to keep the syslog buffer in RAM. But if you really have to guarantee that the content of the buffer remains stable, this cannot be used because during a processor reset there will be usually a too long pause until the memory controller gets re-initialized and RAM refresh continues - we might lose data in this time. In most cases it just works fine, but it's out of spec. In such situations, when such a guarantee is needed, we can use any SRAM that may be available on the board, or we can use some on-chip-memory (OCM, basicly also SRAM) that might be on the processor.
The OCM on the processors in question is 16 kB, hence the limitation there.
But note that the code is general enough to support the other options (other, bigger SRAM, or arbitrarily sized buffer in RAM), too.
Quoted 2 lines
Agreed; however, I'm not sure how often this technique is employed in embedded systems versus desktop systems.
I haven't seen this ever used in desktop systems yet. And I doubt if there is any x86 with a boot loader that supports somehting like this.
But there is for example a pretty large number of mobile cranes all ove rthe workd which are using this feature :-)
Quoted 3 lines
I'd be happy to keep the existing log buffer and perform a prepend from the boot buffer to it rather than an append of the kernel buffer to the boot buffer. Thoughts?
Please don't - this would implement only the way to pass the buffer from the boot loader too Linux, but not the way back.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] What we anticipate seldom occurs; what we least expect generally happens. - Bengamin Disraeli
Quoted 8 lines · Wolfgang Denk
Dear Grant & Andrew,
Quoted 3 lines · In message <C5A8B8CD.143B5%[email protected]> you wrote:
Quoted 3 lines
We have an external log buffer, into which stuff was written by (say) the boot prom code.
Quoted 8 lines
Correct. Typically we use this in U-Boot to pass Power-On Self Test results to applications running under Linux, using the standard syslog tools.
Another are of use is to save the log buffer over a reset (crash) of the system, so that it can be read either rom the boot loader or, after a reboot, from Linux.
That part is not yet implemented in coreboot, but it certainly is useful.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
We want that to come out on the console during bootup.
Not necessarily. The main function is to feed it into the syslog processing.
Indeed.
Quoted 12 lines
Quoted 5 lines
Quoted 5 lines
So what we do is to divert the normal printk log buffer so that it starts writing at the tail of that existing external buffer. We emit the entire buffer some time during bootup. We henceforth continue to use that external buffer in the normal manner. If so, why do it this way?
Do you have a better approach how to share the log buffer between Linux and a boot loader in such a way that the content will survive crahses and reboots?
Quoted 9 lines
Quoted 4 lines
I believe this to be a useful feature for the embedded system space; however, I am not wedded in any way to the current implementation and am happy to evolve it as needed to meet the needs of key stakeholders.
Indeed we use this heavily in embedded systems, mainly to process POST results under Linux (for example, to disable certain functions when the POST results indicate hardware issues, etc.).
For coreboot, the feature is used to avoid long delays for serial output and to make the coreboot POST logs available on machines where you don't want to or can't store the POST logs. Coreboot POST logs at maximum verbosity are roughly 61kB large on my machine and may be bigger on others. Default verbosity still has a few dozen lines in the log.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Why not just copy the external buffer's contents into the normal buffer during bootup? ie:
printk("%s", external_buffer).For two reasons:
1) Additional copy operation (ok, that's cheap).
Indeed. It probably won't take more than a few microseconds if the external buffer is already in DRAM.
Quoted 8 lines
2) We would lose the capability that the buffer content even survives a reset / crash / reboot.
This is a feature can be very useful in embedded systems where there is (at least normally) nobody looking at any console messages; being able to see the kernel's crash messages after a reboot in the normal syslog messages can be really helpful.
This benefit is a bit debatable on x86 due to the lack of non-volatile fast memory with decent sizes. (Yes, you can store the log in the flash ROM, but it will wear out.)
Coreboot can try to preserve RAM contents, but depending on the particular hardware all bets are off.
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
I think a quite bad part of this feature is that it renders the kernel's
log_buf_lenboot parameter (and itsKconfigdefult) ineffective. That's a pretty useful feature - people often set it to 1MB or more during problem diagnosis, and the new unalterable 16kbytes is very very small.Yes, we are aware of this, but it's a compromise. Basicly it depends on hardware capabilities. In most cases, it is sufficient to keep the syslog buffer in RAM. But if you really have to guarantee that the content of the buffer remains stable, this cannot be used because during a processor reset there will be usually a too long pause until the memory controller gets re-initialized and RAM refresh continues - we might lose data in this time. In most cases it just works fine, but it's out of spec. In such situations, when such a guarantee is needed, we can use any SRAM that may be available on the board, or we can use some on-chip-memory (OCM, basicly also SRAM) that might be on the processor.
Quoted 3 lines
The OCM on the processors in question is 16 kB, hence the limitation there.
I'd like to have the buffer location at least configurable to use that feature on regular desktop and server x86 machines.
Quoted 3 lines
But note that the code is general enough to support the other options (other, bigger SRAM, or arbitrarily sized buffer in RAM), too.
Good.
Quoted 7 lines
Quoted 3 lines
Agreed; however, I'm not sure how often this technique is employed in embedded systems versus desktop systems.
I haven't seen this ever used in desktop systems yet. And I doubt if there is any x86 with a boot loader that supports somehting like this.
Coreboot v3 (free x86 firmware, formerly known as LinuxBIOS) does this.
Quoted 4 lines
But there is for example a pretty large number of mobile cranes all over the world which are using this feature :-)
Quoted 8 lines
Quoted 4 lines
I'd be happy to keep the existing log buffer and perform a prepend from the boot buffer to it rather than an append of the kernel buffer to the boot buffer. Thoughts?
Please don't - this would implement only the way to pass the buffer from the boot loader too Linux, but not the way back.
It would be great if the location of that buffer could be retrieved either via ACPI or e820 tables on x86. Hardcoded locations do not make sense for x86 because coreboot tries to keep memory as unfragmented as possible and stores the buffer at the top of memory (well, you can hardcode the buffer location in coreboot but that is just a hack).
Unless I misread the code, it assumes no wraparound has occured in the firmware log buffer. With full verbosity in coreboot, such wraparounds can happen.
The coreboot log buffer struct is really simple:
struct printk_buffer {
int len;
int readoffset;
int writeoffset;
char buffer[];
};The buffer is implemented as a ring buffer with variable size. The size is determined from a few runtime variables for minimum RAM waste, so hardcoding it to some fixed value would be suboptimal.
Can we coordinate to make sure both U-Boot and coreboot can use the feature?
Regards,
Carl-Daniel
Signature · 1 line
http://www.hailfinger.org/