From 5a3a1c704b984e6bdc3bac93006cf7bdbf28fc2a Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 11 May 2017 19:39:46 +0200 Subject: [PATCH] base: use 'Ram_allocator' as stack-area back end The 'Stack_area_ram_session' is now a 'Stack_area_ram_allocator', which simplifies the code and remove a dependency from the 'Ram_session' interface, which we want to remove after all. Issue #2407 --- repos/base-linux/src/core/stack_area.cc | 18 +++++---------- repos/base-linux/src/lib/base/platform_env.cc | 4 ++-- repos/base-sel4/src/core/stack_area.cc | 22 +++++-------------- repos/base/lib/symbols/ld | 4 ++-- repos/base/src/core/stack_area.cc | 18 +++++---------- .../base/src/include/base/internal/globals.h | 4 ++-- .../src/include/base/internal/platform_env.h | 4 ++-- repos/base/src/lib/base/stack_area.cc | 6 ++--- repos/base/src/lib/base/thread.cc | 18 ++++----------- 9 files changed, 32 insertions(+), 66 deletions(-) diff --git a/repos/base-linux/src/core/stack_area.cc b/repos/base-linux/src/core/stack_area.cc index a77cb13f54..d1a30ed53b 100644 --- a/repos/base-linux/src/core/stack_area.cc +++ b/repos/base-linux/src/core/stack_area.cc @@ -78,7 +78,7 @@ class Stack_area_region_map : public Genode::Region_map }; -struct Stack_area_ram_session : Genode::Ram_session +struct Stack_area_ram_allocator : Genode::Ram_allocator { Genode::Ram_dataspace_capability alloc(Genode::size_t size, Genode::Cache_attribute) override { @@ -87,14 +87,6 @@ struct Stack_area_ram_session : Genode::Ram_session void free(Genode::Ram_dataspace_capability) override { } Genode::size_t dataspace_size(Genode::Ram_dataspace_capability) const override { return 0; } - - void ref_account(Genode::Ram_session_capability) override { } - - void transfer_quota(Genode::Ram_session_capability, Genode::Ram_quota) override { } - - Genode::Ram_quota ram_quota() const override { return { 0 }; } - - Genode::Ram_quota used_ram() const override { return { 0 }; } }; @@ -103,16 +95,16 @@ struct Stack_area_ram_session : Genode::Ram_session */ namespace Genode { - Region_map *env_stack_area_region_map; - Ram_session *env_stack_area_ram_session; + Region_map *env_stack_area_region_map; + Ram_allocator *env_stack_area_ram_allocator; void init_stack_area() { static Stack_area_region_map rm_inst; env_stack_area_region_map = &rm_inst; - static Stack_area_ram_session ram_inst; - env_stack_area_ram_session = &ram_inst; + static Stack_area_ram_allocator ram_inst; + env_stack_area_ram_allocator = &ram_inst; } } diff --git a/repos/base-linux/src/lib/base/platform_env.cc b/repos/base-linux/src/lib/base/platform_env.cc index 61079d89f9..8f3fe9c949 100644 --- a/repos/base-linux/src/lib/base/platform_env.cc +++ b/repos/base-linux/src/lib/base/platform_env.cc @@ -163,8 +163,8 @@ Platform_env::Platform_env() { _attach_stack_area(); - env_stack_area_region_map = &_local_pd_session._stack_area; - env_stack_area_ram_session = ram_session(); + env_stack_area_region_map = &_local_pd_session._stack_area; + env_stack_area_ram_allocator = ram_session(); /* register TID and PID of the main thread at core */ Linux_native_cpu_client native_cpu(cpu_session()->native_cpu()); diff --git a/repos/base-sel4/src/core/stack_area.cc b/repos/base-sel4/src/core/stack_area.cc index 4d7eeb6513..53448634c1 100644 --- a/repos/base-sel4/src/core/stack_area.cc +++ b/repos/base-sel4/src/core/stack_area.cc @@ -14,7 +14,7 @@ /* Genode includes */ #include -#include +#include #include #include #include @@ -108,8 +108,6 @@ class Stack_area_region_map : public Region_map /* XXX missing XXX */ warning(__PRETTY_FUNCTION__, ": not implemented"); - // Untyped_memory::convert_to_untyped_frames(phys_addr, phys_size) - // Untyped_memory::free_pages(phys_alloc, num_pages); } void fault_handler(Signal_context_capability) override { } @@ -120,7 +118,7 @@ class Stack_area_region_map : public Region_map }; -struct Stack_area_ram_session : Ram_session +struct Stack_area_ram_allocator : Ram_allocator { Ram_dataspace_capability alloc(size_t, Cache_attribute) override { return reinterpret_cap_cast(Native_capability()); } @@ -129,28 +127,20 @@ struct Stack_area_ram_session : Ram_session warning(__func__, " not implemented"); } size_t dataspace_size(Ram_dataspace_capability) const override { return 0; } - - void ref_account(Ram_session_capability) override { } - - void transfer_quota(Ram_session_capability, Ram_quota) override { } - - Ram_quota ram_quota() const override { return { 0 }; } - - Ram_quota used_ram() const override { return { 0 }; } }; namespace Genode { - Region_map *env_stack_area_region_map; - Ram_session *env_stack_area_ram_session; + Region_map *env_stack_area_region_map; + Ram_allocator *env_stack_area_ram_allocator; void init_stack_area() { static Stack_area_region_map rm_inst; env_stack_area_region_map = &rm_inst; - static Stack_area_ram_session ram_inst; - env_stack_area_ram_session = &ram_inst; + static Stack_area_ram_allocator ram_inst; + env_stack_area_ram_allocator = &ram_inst; } } diff --git a/repos/base/lib/symbols/ld b/repos/base/lib/symbols/ld index dcc7872186..d00f01e1d3 100644 --- a/repos/base/lib/symbols/ld +++ b/repos/base/lib/symbols/ld @@ -202,8 +202,8 @@ _ZN6Genode23Alarm_timeout_scheduler18_schedule_periodicERNS_7TimeoutENS_12Micros _ZN6Genode23Alarm_timeout_scheduler7_enableEv T _ZN6Genode23Alarm_timeout_schedulerC1ERNS_11Time_sourceE T _ZN6Genode23Alarm_timeout_schedulerC2ERNS_11Time_sourceE T -_ZN6Genode25env_stack_area_region_mapE B 4 -_ZN6Genode26env_stack_area_ram_sessionE B 4 +_ZN6Genode25env_stack_area_region_mapE B 8 +_ZN6Genode28env_stack_area_ram_allocatorE B 8 _ZN6Genode29upgrade_pd_quota_non_blockingENS_9Ram_quotaENS_9Cap_quotaE T _ZN6Genode3Log3logEv T _ZN6Genode3Log8_acquireENS0_4TypeE T diff --git a/repos/base/src/core/stack_area.cc b/repos/base/src/core/stack_area.cc index 6cbde04896..7bd24db83a 100644 --- a/repos/base/src/core/stack_area.cc +++ b/repos/base/src/core/stack_area.cc @@ -14,7 +14,7 @@ /* Genode includes */ #include -#include +#include #include #include #include @@ -30,8 +30,8 @@ namespace Genode { - Region_map *env_stack_area_region_map; - Ram_session *env_stack_area_ram_session; + Region_map *env_stack_area_region_map; + Ram_allocator *env_stack_area_ram_allocator; void init_stack_area(); } @@ -125,7 +125,7 @@ class Stack_area_region_map : public Region_map }; -struct Stack_area_ram_session : Ram_session +struct Stack_area_ram_allocator : Ram_allocator { Ram_dataspace_capability alloc(size_t, Cache_attribute) override { return reinterpret_cap_cast(Native_capability()); } @@ -133,12 +133,6 @@ struct Stack_area_ram_session : Ram_session void free(Ram_dataspace_capability) override { } size_t dataspace_size(Ram_dataspace_capability) const override { return 0; } - - void ref_account (Ram_session_capability) override { } - void transfer_quota (Ram_session_capability, Ram_quota) override { } - - Ram_quota ram_quota () const override { return { 0 }; } - Ram_quota used_ram () const override { return { 0 }; } }; @@ -147,6 +141,6 @@ void Genode::init_stack_area() static Stack_area_region_map rm; env_stack_area_region_map = &rm; - static Stack_area_ram_session ram; - env_stack_area_ram_session = &ram; + static Stack_area_ram_allocator ram; + env_stack_area_ram_allocator = &ram; } diff --git a/repos/base/src/include/base/internal/globals.h b/repos/base/src/include/base/internal/globals.h index ec354b7353..789eefe72a 100644 --- a/repos/base/src/include/base/internal/globals.h +++ b/repos/base/src/include/base/internal/globals.h @@ -23,8 +23,8 @@ namespace Genode { class Env; class Local_session_id_space; - extern Region_map *env_stack_area_region_map; - extern Ram_session *env_stack_area_ram_session; + extern Region_map *env_stack_area_region_map; + extern Ram_allocator *env_stack_area_ram_allocator; Thread_capability main_thread_cap(); diff --git a/repos/base/src/include/base/internal/platform_env.h b/repos/base/src/include/base/internal/platform_env.h index f8c30b2e24..9ca476fe05 100644 --- a/repos/base/src/include/base/internal/platform_env.h +++ b/repos/base/src/include/base/internal/platform_env.h @@ -100,8 +100,8 @@ class Genode::Platform_env : public Env_deprecated, _heap(&_resources.ram, &_resources.rm, Heap::UNLIMITED), _emergency_ram_ds(_resources.ram.alloc(_emergency_ram_size())) { - env_stack_area_ram_session = &_resources.ram; - env_stack_area_region_map = &_stack_area; + env_stack_area_ram_allocator = &_resources.ram; + env_stack_area_region_map = &_stack_area; } /* diff --git a/repos/base/src/lib/base/stack_area.cc b/repos/base/src/lib/base/stack_area.cc index e476ada16d..13db9fba92 100644 --- a/repos/base/src/lib/base/stack_area.cc +++ b/repos/base/src/lib/base/stack_area.cc @@ -13,13 +13,13 @@ /* Genode includes */ #include -#include +#include /* base-internal includes */ #include namespace Genode { - Region_map *env_stack_area_region_map; - Ram_session *env_stack_area_ram_session; + Region_map *env_stack_area_region_map; + Ram_allocator *env_stack_area_ram_allocator; } diff --git a/repos/base/src/lib/base/thread.cc b/repos/base/src/lib/base/thread.cc index ba810465ae..167bded2f3 100644 --- a/repos/base/src/lib/base/thread.cc +++ b/repos/base/src/lib/base/thread.cc @@ -22,21 +22,11 @@ /* base-internal includes */ #include +#include using namespace Genode; -/** - * Return the managed dataspace holding the stack area - * - * This function is provided by the process environment. - */ -namespace Genode { - extern Region_map * const env_stack_area_region_map; - extern Ram_session * const env_stack_area_ram_session; -} - - void Stack::size(size_t const size) { /* check if the stack needs to be enhanced */ @@ -57,7 +47,7 @@ void Stack::size(size_t const size) /* allocate and attach backing store for the stack enhancement */ addr_t const ds_addr = _base - ds_size - stack_area_virtual_base(); try { - Ram_session * const ram = env_stack_area_ram_session; + Ram_allocator * const ram = env_stack_area_ram_allocator; Ram_dataspace_capability const ds_cap = ram->alloc(ds_size); Region_map * const rm = env_stack_area_region_map; void * const attach_addr = rm->attach_at(ds_cap, ds_addr, ds_size); @@ -103,7 +93,7 @@ Thread::_alloc_stack(size_t stack_size, char const *name, bool main_thread) /* allocate and attach backing store for the stack */ Ram_dataspace_capability ds_cap; try { - ds_cap = env_stack_area_ram_session->alloc(ds_size); + ds_cap = env_stack_area_ram_allocator->alloc(ds_size); addr_t attach_addr = ds_addr - stack_area_virtual_base(); if (attach_addr != (addr_t)env_stack_area_region_map->attach_at(ds_cap, attach_addr, ds_size)) throw Stack_alloc_failed(); @@ -133,7 +123,7 @@ void Thread::_free_stack(Stack *stack) stack->~Stack(); Genode::env_stack_area_region_map->detach((void *)ds_addr); - Genode::env_stack_area_ram_session->free(ds_cap); + Genode::env_stack_area_ram_allocator->free(ds_cap); /* stack ready for reuse */ Stack_allocator::stack_allocator().free(stack);