Skip to contentSkip to conversation

kernel, logbuf: add support for external log buffer

RFC In review Heiko Schocher 2 participants 3 messages Jun 11, 2012 – Jul 24, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

RFC 1/1 kernel, logbuf: add support for external log buffer

This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. This patch is based on DENX-only kernel commit:

commit 212f61c7fd3b952a81d1459dd32a86a32ddfd4ce

Author: Igor Lisitsin <[email protected]>
Date:   Wed Apr 18 14:55:19 2007 +0400

Add support for external log buffer.

Add support for external log buffer, for example passed by U-Boot, which may already contain messages (from the boot loader and/or POST).

see:
http://git.denx.de/?p=linux-denx.git;a=commit;h=212f61c7fd3b952a81d1459dd32a86a32ddfd4ce

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. This patch support this feature for arch/arm based boards.

Cc Wolfgang Denk <[email protected]>
Cc Igor Lisitsin <[email protected]>
Cc Grant Erickson <[email protected]>
Cc linux-kernel at vger.kernel.org
Cc Tim Bird <[email protected]>
Cc CE Linux Developers List <[email protected]>
Cc Kay Sievers <[email protected]>

---
restage prior discussion from lkml:

https://lkml.org/lkml/2009/1/21/250

Discussion stopped, and I want to reanimate it, also there is a Project Proposal on the "CE Linux Developers List" for such a feature, see here:

http://www.mail-archive.com/celinux-dev at lists.celinuxforum.org/msg00103.html

Maybe it is now the time to discuss this again?

Is it worth to try to get this old code in current kernel, or should we investigate Kay Sievers proposal for a structured logging system, which will alter the format of the messages as they are stored in the log buffer, and discuss for this a "logbuffer support"?

See this discussion here:

http://thread.gmane.org/gmane.linux.kernel/1277619

 arch/arm/mm/init.c      |   25 ++++++++++
 include/linux/logbuff.h |   51 ++++++++++++++++++++
 init/Kconfig            |   12 +++++
 init/main.c             |    5 ++
 kernel/printk.c         |  117 +++++++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 206 insertions(+), 4 deletions(-)
 create mode 100644 include/linux/logbuff.h
arch/arm/mm/init.c +25 -0
index 8f5813b..9609a8e 100644
@@ -20,6 +20,7 @@
 #include <linux/highmem.h>
 #include <linux/gfp.h>
 #include <linux/memblock.h>
+#include <linux/logbuff.h>
 
 #include <asm/mach-types.h>
 #include <asm/memblock.h>
@@ -38,6 +39,10 @@
 static unsigned long phys_initrd_start __initdata = 0;
 static unsigned long phys_initrd_size __initdata = 0;
 
+#ifdef CONFIG_LOGBUFFER
+static unsigned long ext_logbuff __initdata;
+#endif
+
 static int __init early_initrd(char *p)
 {
 	unsigned long start, size;
@@ -325,6 +330,9 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
 void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
 {
 	int i;
+#ifdef CONFIG_LOGBUFFER
+	unsigned long	log_buf_base;
+#endif
 
 	for (i = 0; i < mi->nr_banks; i++)
 		memblock_add(mi->bank[i].start, mi->bank[i].size);
@@ -356,6 +364,16 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
 		initrd_end = initrd_start + phys_initrd_size;
 	}
 #endif
+#ifdef CONFIG_LOGBUFFER
+	log_buf_base = memblock_end_of_DRAM() - LOGBUFF_RESERVE;
+	if (memblock_is_region_reserved(log_buf_base, LOGBUFF_RESERVE)) {
+		pr_err("LOGBUF: could not use addr: %lx for logbuf support -" \
+			" disabling logbuf support\n", log_buf_base);
+	} else {
+		memblock_reserve(log_buf_base, LOGBUFF_RESERVE);
+		ext_logbuff = __phys_to_virt(log_buf_base);
+	}
+#endif
 
 	arm_mm_memblock_reserve();
 	arm_dt_memblock_reserve();
@@ -409,6 +427,13 @@ void __init bootmem_init(void)
 	max_pfn = max_high - PHYS_PFN_OFFSET;
 }
 
+#ifdef CONFIG_LOGBUFFER
+void * __init setup_ext_logbuff_mem(void)
+{
+	return (void *)ext_logbuff;
+}
+#endif
+
 static inline int free_area(unsigned long pfn, unsigned long end, char *s)
 {
 	unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
include/linux/logbuff.h new file +51 -0

51 lines not on this page · raw message

init/Kconfig +12 -0
index 6cfd71d..0badc3c 100644
@@ -1031,6 +1031,18 @@ config PRINTK
 	  very difficult to diagnose system problems, saying N here is
 	  strongly discouraged.
 
+config LOGBUFFER
+	bool "External logbuffer" if PRINTK
+	default n
+	depends on ARM
+	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 BUG
 	bool "BUG() support" if EXPERT
 	default y
init/main.c +5 -0
index 44b2433..608e0b2 100644
@@ -68,6 +68,7 @@
 #include <linux/shmem_fs.h>
 #include <linux/slab.h>
 #include <linux/perf_event.h>
+#include <linux/logbuff.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -492,6 +493,7 @@ asmlinkage void __init start_kernel(void)
 	tick_init();
 	boot_cpu_init();
 	page_address_init();
+
 	printk(KERN_NOTICE "%s", linux_banner);
 	setup_arch(&command_line);
 	mm_init_owner(&init_mm, &init_task);
@@ -522,6 +524,9 @@ asmlinkage void __init start_kernel(void)
 	sort_main_extable();
 	trap_init();
 	mm_init();
+#ifdef CONFIG_LOGBUFFER
+	setup_ext_logbuff();
+#endif
 
 	/*
 	 * Set up the scheduler prior starting any interrupts (such as the
kernel/printk.c +113 -4

148 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#1 lore raw

Hello,

Quoted 57 lines · Heiko Schocher

This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. This patch is based on DENX-only kernel commit:

commit 212f61c7fd3b952a81d1459dd32a86a32ddfd4ce

Author: Igor Lisitsin<[email protected]>
Date:   Wed Apr 18 14:55:19 2007 +0400

Add support for external log buffer.

Add support for external log buffer, for example passed by U-Boot, which may already contain messages (from the boot loader and/or POST).

see:
http://git.denx.de/?p=linux-denx.git;a=commit;h=212f61c7fd3b952a81d1459dd32a86a32ddfd4ce

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. This patch support this feature for arch/arm based boards.

Cc Wolfgang Denk<[email protected]>
Cc Igor Lisitsin<[email protected]>
Cc Grant Erickson<[email protected]>
Cc linux-kernel at vger.kernel.org
Cc Tim Bird<[email protected]>
Cc CE Linux Developers List<[email protected]>
Cc Kay Sievers<[email protected]>

---
restage prior discussion from lkml:

https://lkml.org/lkml/2009/1/21/250

Discussion stopped, and I want to reanimate it, also there is a Project Proposal on the "CE Linux Developers List" for such a feature, see here:

http://www.mail-archive.com/celinux-dev at lists.celinuxforum.org/msg00103.html

Maybe it is now the time to discuss this again?

Is it worth to try to get this old code in current kernel, or should we investigate Kay Sievers proposal for a structured logging system, which will alter the format of the messages as they are stored in the log buffer, and discuss for this a "logbuffer support"?

See this discussion here:

http://thread.gmane.org/gmane.linux.kernel/1277619

Quoted 7 lines
  arch/arm/mm/init.c      |   25 ++++++++++
  include/linux/logbuff.h |   51 ++++++++++++++++++++
  init/Kconfig            |   12 +++++
  init/main.c             |    5 ++
  kernel/printk.c         |  117 +++++++++++++++++++++++++++++++++++++++++++++--
  5 files changed, 206 insertions(+), 4 deletions(-)

create mode 100644 include/linux/logbuff.h

ping? I got no respond to this RFC ... no chance to get this to mainline?

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#2 lore raw
In reply to Heiko Schocher
Quoted 19 lines · On Mon, 11 Jun 2012 08:13:08 +0200 Heiko Schocher <[email protected]> wrote:

This merges support for the previously DENX-only kernel feature of specifying an alternative, "external" buffer for kernel printk messages and their associated metadata. This patch is based on DENX-only kernel commit:

commit 212f61c7fd3b952a81d1459dd32a86a32ddfd4ce

Author: Igor Lisitsin <[email protected]>
Date:   Wed Apr 18 14:55:19 2007 +0400

Add support for external log buffer.

Add support for external log buffer, for example passed by U-Boot, which may already contain messages (from the boot loader and/or POST).

see:
http://git.denx.de/?p=linux-denx.git;a=commit;h=212f61c7fd3b952a81d1459dd32a86a32ddfd4ce

Quoted 6 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. This patch support this feature for arch/arm based boards.

Why was it done this way, rather than adding a hook to permit architectures to insert data into the head of the existing kernel buffer?

The latter approach would be quite simple, wouldn't it? A single line added to printk.c which calls an arch function which locates the boot loader buffer and prints it, with printk. And this is more flexible - for example, there might be more than one external message stream which we wish to capture.