From 786a81c8465167f6c0726aeddd439b5276d356b0 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Thu, 1 Dec 2016 11:58:50 +0100 Subject: [PATCH] core: unify log() initialization between kernels * initialize the log environment implicitly for core * removing the redundant lock * unify between base-hw and all others Ref #2092 --- repos/base-fiasco/src/core/platform.cc | 2 - repos/base-foc/src/core/platform.cc | 2 - repos/base-hw/lib/mk/core-hw.inc | 1 + .../src/core/{default_log.cc => core_log.cc} | 30 +-------------- .../src/core/include/spec/x86_64/muen/board.h | 4 -- repos/base-hw/src/core/kernel/init.cc | 2 - .../src/core/spec/x86_64/kernel/cpu.cc | 5 --- repos/base-nova/src/core/platform.cc | 1 - repos/base-okl4/src/core/platform.cc | 2 - repos/base-pistachio/src/core/platform.cc | 2 - repos/base-sel4/src/core/platform.cc | 3 -- repos/base/src/core/default_log.cc | 38 ++++++------------- 12 files changed, 15 insertions(+), 77 deletions(-) rename repos/base-hw/src/core/{default_log.cc => core_log.cc} (63%) diff --git a/repos/base-fiasco/src/core/platform.cc b/repos/base-fiasco/src/core/platform.cc index 0fefac66e..6e01035cd 100644 --- a/repos/base-fiasco/src/core/platform.cc +++ b/repos/base-fiasco/src/core/platform.cc @@ -436,8 +436,6 @@ Platform::Platform() : if (initialized) panic("Platform constructed twice!"); initialized = true; - init_log(); - _setup_basics(); _setup_mem_alloc(); _setup_io_port_alloc(); diff --git a/repos/base-foc/src/core/platform.cc b/repos/base-foc/src/core/platform.cc index 7773c0d6a..8fb4d53f1 100644 --- a/repos/base-foc/src/core/platform.cc +++ b/repos/base-foc/src/core/platform.cc @@ -437,8 +437,6 @@ Platform::Platform() : if (initialized) panic("Platform constructed twice!"); initialized = true; - init_log(); - _setup_basics(); _setup_mem_alloc(); _setup_io_port_alloc(); diff --git a/repos/base-hw/lib/mk/core-hw.inc b/repos/base-hw/lib/mk/core-hw.inc index 5567aa83b..340ebd028 100644 --- a/repos/base-hw/lib/mk/core-hw.inc +++ b/repos/base-hw/lib/mk/core-hw.inc @@ -16,6 +16,7 @@ INC_DIR += $(BASE_DIR)/src/include SRC_CC += cpu_session_component.cc SRC_CC += cpu_session_support.cc SRC_CC += cpu_thread_component.cc +SRC_CC += core_log.cc SRC_CC += core_region_map.cc SRC_CC += core_mem_alloc.cc SRC_CC += core_rpc_cap_alloc.cc diff --git a/repos/base-hw/src/core/default_log.cc b/repos/base-hw/src/core/core_log.cc similarity index 63% rename from repos/base-hw/src/core/default_log.cc rename to repos/base-hw/src/core/core_log.cc index e2cb3617c..6db0596d1 100644 --- a/repos/base-hw/src/core/default_log.cc +++ b/repos/base-hw/src/core/core_log.cc @@ -16,7 +16,6 @@ #include /* base-internal includes */ -#include #include #include @@ -24,16 +23,11 @@ #include #include -using namespace Genode; - -static Log *log_ptr; - - -Log &Log::log() { return *log_ptr; } - static void out_char(char const c) { + using Genode::Serial; + enum { ASCII_LINE_FEED = 10, ASCII_CARRIAGE_RETURN = 13, @@ -49,24 +43,4 @@ static void out_char(char const c) void Genode::Core_log::out(char const c) { out_char(c); } -void Genode::init_log() -{ - /* ignore subsequent calls */ - if (log_ptr) return; - - struct Write_fn - { - Core_log log; - void operator () (char const *s) { log.output(s); } - }; - - typedef Buffered_output<512, Write_fn> Buffered_log_output; - - static Buffered_log_output *buffered_log_output = - unmanaged_singleton(Write_fn()); - - log_ptr = unmanaged_singleton(*buffered_log_output); -} - - void Kernel::log(char const c) { out_char(c); } diff --git a/repos/base-hw/src/core/include/spec/x86_64/muen/board.h b/repos/base-hw/src/core/include/spec/x86_64/muen/board.h index 1efb08902..5279b1c32 100644 --- a/repos/base-hw/src/core/include/spec/x86_64/muen/board.h +++ b/repos/base-hw/src/core/include/spec/x86_64/muen/board.h @@ -14,8 +14,6 @@ #ifndef _CORE__INCLUDE__SPEC__X86_64__MUEN__BOARD_H_ #define _CORE__INCLUDE__SPEC__X86_64__MUEN__BOARD_H_ -#include - namespace Genode { struct Board @@ -32,8 +30,6 @@ namespace Genode TIMER_VECTOR_KERNEL = 32, TIMER_VECTOR_USER = 50, }; - - void init() { Genode::init_log(); } }; } diff --git a/repos/base-hw/src/core/kernel/init.cc b/repos/base-hw/src/core/kernel/init.cc index 9eceb2a0a..3dec3d2b5 100644 --- a/repos/base-hw/src/core/kernel/init.cc +++ b/repos/base-hw/src/core/kernel/init.cc @@ -22,7 +22,6 @@ /* base includes */ #include -#include using namespace Kernel; @@ -60,7 +59,6 @@ extern "C" void init_kernel() Core_thread::singleton(); - Genode::init_log(); Genode::log(""); Genode::log("kernel initialized"); diff --git a/repos/base-hw/src/core/spec/x86_64/kernel/cpu.cc b/repos/base-hw/src/core/spec/x86_64/kernel/cpu.cc index e78e72314..9feaba734 100644 --- a/repos/base-hw/src/core/spec/x86_64/kernel/cpu.cc +++ b/repos/base-hw/src/core/spec/x86_64/kernel/cpu.cc @@ -15,9 +15,6 @@ /* Genode includes */ #include -/* base-internal includes */ -#include /* init_log() */ - /* core includes */ #include #include @@ -41,8 +38,6 @@ void Kernel::Cpu::init(Pic &pic, Kernel::Pd &core_pd, Genode::Board&) fpu().init(); - Genode::init_log(); - /* * Please do not remove the log(), because the serial constructor requires * access to the Bios Data Area, which is available in the initial diff --git a/repos/base-nova/src/core/platform.cc b/repos/base-nova/src/core/platform.cc index 1c6215db1..e63fc5940 100644 --- a/repos/base-nova/src/core/platform.cc +++ b/repos/base-nova/src/core/platform.cc @@ -304,7 +304,6 @@ Platform::Platform() : /* * Now that we can access the I/O ports for comport 0, printf works... */ - init_log(); /* * remap main utcb to default utcb address diff --git a/repos/base-okl4/src/core/platform.cc b/repos/base-okl4/src/core/platform.cc index e2578b103..4570fc17c 100644 --- a/repos/base-okl4/src/core/platform.cc +++ b/repos/base-okl4/src/core/platform.cc @@ -183,8 +183,6 @@ Platform::Platform() : _vm_start = 0x1000; _vm_size = 0xb0000000 - 0x1000; - init_log(); - log(":phys_alloc: ", *_core_mem_alloc.phys_alloc()); log(":virt_alloc: ", *_core_mem_alloc.virt_alloc()); log(":io_mem: ", _io_mem_alloc); diff --git a/repos/base-pistachio/src/core/platform.cc b/repos/base-pistachio/src/core/platform.cc index 1bdbced31..a07573e11 100644 --- a/repos/base-pistachio/src/core/platform.cc +++ b/repos/base-pistachio/src/core/platform.cc @@ -610,8 +610,6 @@ Platform::Platform() : if (initialized) panic("Platform constructed twice!"); initialized = true; - init_log(); - _setup_basics(); _setup_preemption(); _setup_mem_alloc(); diff --git a/repos/base-sel4/src/core/platform.cc b/repos/base-sel4/src/core/platform.cc index d2e7a4c2a..f2c295f80 100644 --- a/repos/base-sel4/src/core/platform.cc +++ b/repos/base-sel4/src/core/platform.cc @@ -74,9 +74,6 @@ bool Mapped_mem_allocator::_unmap_local(addr_t virt_addr, addr_t phys_addr, void Platform::_init_unused_phys_alloc() { - /* enable log support early */ - init_log(); - /* the lower physical ram is kept by the kernel and not usable to us */ _unused_phys_alloc.add_range(0x100000, 0UL - 0x100000); } diff --git a/repos/base/src/core/default_log.cc b/repos/base/src/core/default_log.cc index 7e0f37d6f..239cc301b 100644 --- a/repos/base/src/core/default_log.cc +++ b/repos/base/src/core/default_log.cc @@ -14,7 +14,6 @@ /* Genode includes */ #include -#include /* base-internal includes */ #include @@ -24,35 +23,22 @@ /* core includes */ #include -using namespace Genode; -static Log *log_ptr; - - -Log &Log::log() { return *log_ptr; } - - -void Genode::init_log() +Genode::Log &Genode::Log::log() { - /* ignore subsequent calls */ - if (log_ptr) return; - - struct Write_fn + struct Buffer { - Lock lock; - Core_log log; - - void operator () (char const *s) + struct Write_fn : Core_log { - Lock::Guard guard(lock); - log.output(s); - } + void operator () (char const *s) { output(s); } + } function; + + Buffered_output<512, Write_fn> buffer { function }; + Log log { buffer }; }; - typedef Buffered_output<512, Write_fn> Buffered_log_output; - - static Buffered_log_output *buffered_log_output = - unmanaged_singleton(Write_fn()); - - log_ptr = unmanaged_singleton(*buffered_log_output); + return unmanaged_singleton()->log; } + + +void Genode::init_log() { };