From 3824ad47566fe4331453585ed3db03fa0706cf9f Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 13 Sep 2018 16:53:57 +0200 Subject: [PATCH] nova: define kernel memory based on system memory Switch to kernel branch, that determines the available system memory during boot time. The overall kernel memory is still static, but during boot time dynamically the amount can be chosen. Following 3 config option exists: CONFIG_MEMORY_BOOT is the amount of kernel memory allocated in the BSS statically - effectively chosen during link time - see linker script. CONFIG_MEMORY_DYN_MIN && CONFIG_MEMORY_DYN_PER_MILL configures the dynamic part of the kernel memory allocation applied during early kernel boot time. CONFIG_MEMORY_DYN_MIN is the amount of memory which should be allocated at least. CONFIG_MEMORY_DYN_PER_MILL defines the amount of the system memory in per mill which should be allocated at most. The overall maximum kernel memory is restricted to ~1G (64bit), due to the chosen internal virtual memory layout. Fixes #2985 --- repos/base-nova/ports/nova.hash | 2 +- repos/base-nova/ports/nova.port | 2 +- repos/base-nova/src/core/platform.cc | 8 +++++++- repos/base-nova/src/kernel/nova/target.mk | 7 +++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/repos/base-nova/ports/nova.hash b/repos/base-nova/ports/nova.hash index ef975a03db..8ec34e1b61 100644 --- a/repos/base-nova/ports/nova.hash +++ b/repos/base-nova/ports/nova.hash @@ -1 +1 @@ -96a3ed33cf48798847b43f6023ae92a002224875 +95f7056d34c5d48ef9dfbf67f5053fd0486e47b8 diff --git a/repos/base-nova/ports/nova.port b/repos/base-nova/ports/nova.port index 9008ad4924..bee0799c25 100644 --- a/repos/base-nova/ports/nova.port +++ b/repos/base-nova/ports/nova.port @@ -4,7 +4,7 @@ DOWNLOADS := nova.git # r10 branch URL(nova) := https://github.com/alex-ab/NOVA.git -REV(nova) := b44329a8601ff3936aa77336752d85cff95f1a94 +REV(nova) := b156131007c928e2968fc5e551cea402c1886919 DIR(nova) := src/kernel/nova PATCHES := $(sort $(wildcard $(REP_DIR)/patches/*.patch)) diff --git a/repos/base-nova/src/core/platform.cc b/repos/base-nova/src/core/platform.cc index 40083c2173..abe73428e6 100644 --- a/repos/base-nova/src/core/platform.cc +++ b/repos/base-nova/src/core/platform.cc @@ -489,6 +489,7 @@ Platform::Platform() : Hip::Mem_desc *boot_fb = nullptr; bool efi_boot = false; + addr_t kernel_memory = 0; /* * All "available" ram must be added to our physical allocator before all @@ -501,6 +502,9 @@ Platform::Platform() : if (mem_desc->type == Hip::Mem_desc::FRAMEBUFFER) boot_fb = mem_desc; + if (mem_desc->type == Hip::Mem_desc::MICROHYPERVISOR) + kernel_memory += mem_desc->size; + if (mem_desc->type != Hip::Mem_desc::AVAILABLE_MEMORY) continue; if (verbose_boot_info) { @@ -731,7 +735,7 @@ Platform::Platform() : /* core log as ROM module */ { void * phys_ptr = nullptr; - unsigned const pages = 1; + unsigned const pages = 4; size_t const log_size = pages << get_page_size_log2(); ram_alloc()->alloc_aligned(log_size, &phys_ptr, get_page_size_log2()); @@ -760,6 +764,8 @@ Platform::Platform() : log(_rom_fs); + log(Number_of_bytes(kernel_memory), " kernel memory"); log(""); + /* add capability selector ranges to map */ unsigned const first_index = 0x2000; unsigned index = first_index; diff --git a/repos/base-nova/src/kernel/nova/target.mk b/repos/base-nova/src/kernel/nova/target.mk index 04aec00f5f..7bb27c1cd5 100644 --- a/repos/base-nova/src/kernel/nova/target.mk +++ b/repos/base-nova/src/kernel/nova/target.mk @@ -20,7 +20,10 @@ CC_OPT += -pipe \ -fdata-sections -fomit-frame-pointer -freg-struct-return \ -freorder-blocks -funit-at-a-time -fno-exceptions -fno-rtti \ -fno-stack-protector -fvisibility-inlines-hidden \ - -fno-asynchronous-unwind-tables -std=gnu++0x + -fno-asynchronous-unwind-tables -std=gnu++0x +# kernel memory: 28M minimum dynamic or 10 pro mill of the system memory +CC_OPT += -DCONFIG_MEMORY_DYN_MIN=0x1c00000 \ + -DCONFIG_MEMORY_DYN_PER_MILL=10 CC_OPT_PIC := ifeq ($(filter-out $(SPECS),32bit),) override CC_MARCH = -m32 @@ -44,7 +47,7 @@ LD_SCRIPT_STATIC = hypervisor.o $(TARGET): hypervisor.o hypervisor.o: $(NOVA_SRC_DIR)/src/hypervisor.ld target.mk - $(VERBOSE)$(CC) $(INCLUDES) -DCONFIG_KERNEL_MEMORY=32M -MP -MMD -pipe $(CC_MARCH) -xc -E -P $< -o $@ + $(VERBOSE)$(CC) $(INCLUDES) -DCONFIG_MEMORY_BOOT=4M -MP -MMD -pipe $(CC_MARCH) -xc -E -P $< -o $@ clean cleanall: $(VERBOSE)rm -rf $(NOVA_BUILD_DIR)