diff --git a/repos/base/include/base/ram_allocator.h b/repos/base/include/base/ram_allocator.h index 46225e4592..e857959f89 100644 --- a/repos/base/include/base/ram_allocator.h +++ b/repos/base/include/base/ram_allocator.h @@ -40,6 +40,8 @@ struct Genode::Ram_allocator : Interface struct Denied : Exception { }; + typedef unsigned Numa_id; + /** * Allocate RAM dataspace * @@ -50,6 +52,7 @@ struct Genode::Ram_allocator : Interface * \return capability to RAM dataspace, or error code of type 'Alloc_error' */ virtual Alloc_result try_alloc(size_t size, Cache cache = CACHED) = 0; + virtual Alloc_result try_alloc(size_t size, Numa_id numa_id, Cache cache = CACHED) = 0; /** * Allocate RAM dataspace @@ -154,6 +157,10 @@ class Genode::Constrained_ram_allocator : public Ram_allocator ); } + Alloc_result try_alloc(size_t size, Numa_id, Cache cache = CACHED) override { + return this->Constrained_ram_allocator::try_alloc(size, cache); /* overriden in platform specific code */ + } + void free(Ram_dataspace_capability ds) override { size_t const size = _ram_alloc.dataspace_size(ds); diff --git a/repos/base/src/core/include/ram_dataspace_factory.h b/repos/base/src/core/include/ram_dataspace_factory.h index 747372b01b..01defb4302 100644 --- a/repos/base/src/core/include/ram_dataspace_factory.h +++ b/repos/base/src/core/include/ram_dataspace_factory.h @@ -45,7 +45,7 @@ class Genode::Ram_dataspace_factory : public Ram_allocator, Rpc_entrypoint &_ep; Range_allocator &_phys_alloc; - Phys_range const _phys_range; + Phys_range _phys_range; /* @@ -109,6 +109,7 @@ class Genode::Ram_dataspace_factory : public Ram_allocator, *****************************/ Alloc_result try_alloc(size_t, Cache) override; + Alloc_result try_alloc(size_t, Ram_allocator::Numa_id, Cache) override; void free(Ram_dataspace_capability) override; size_t dataspace_size(Ram_dataspace_capability ds) const override; }; diff --git a/repos/base/src/core/include/synced_ram_allocator.h b/repos/base/src/core/include/synced_ram_allocator.h index a7cd605fc6..139f812f27 100644 --- a/repos/base/src/core/include/synced_ram_allocator.h +++ b/repos/base/src/core/include/synced_ram_allocator.h @@ -38,6 +38,12 @@ class Genode::Synced_ram_allocator : public Ram_allocator Mutex::Guard mutex_guard(_mutex); return _alloc.try_alloc(size, cache); } + + Alloc_result try_alloc(size_t size, Ram_allocator::Numa_id numa_id, Cache cache) override + { + Mutex::Guard mutex_guard(_mutex); + return _alloc.try_alloc(size, numa_id, cache); + } void free(Ram_dataspace_capability ds) override { diff --git a/repos/base/src/core/ram_dataspace_factory.cc b/repos/base/src/core/ram_dataspace_factory.cc index 04911289a0..ac37478547 100644 --- a/repos/base/src/core/ram_dataspace_factory.cc +++ b/repos/base/src/core/ram_dataspace_factory.cc @@ -16,6 +16,8 @@ /* core includes */ #include +#include +#include using namespace Genode; @@ -144,6 +146,26 @@ Ram_dataspace_factory::try_alloc(size_t ds_size, Cache cache) return static_cap_cast(ds_cap); } +Ram_allocator::Alloc_result Ram_dataspace_factory::try_alloc(size_t size, Ram_allocator::Numa_id numa_id, Cache cached=CACHED) +{ + Ram_dataspace_factory::Phys_range old = {_phys_range.start, _phys_range.end}; + _phys_range = {platform_specific().mem_range(numa_id).start, platform_specific().mem_range(numa_id).end}; + log("Using Mem range for NUMA node ", numa_id, " ", reinterpret_cast(_phys_range.start), "-", reinterpret_cast(_phys_range.end)); + Ram_allocator::Alloc_result result = Ram_dataspace_factory::try_alloc(size, cached); + result.with_result( + [&](Genode::Ram_dataspace_capability cap) + { + _ep.apply(cap, [&](Dataspace_component *c) + { log("Allocated memory at ", reinterpret_cast(c->phys_addr()), " on Node ", numa_id); }); + }, + [&](Ram_allocator::Alloc_error) + { + log("Error at allocation"); + }); + _phys_range = {old.start, old.end}; + log("Restored original range to ", reinterpret_cast(_phys_range.start), "-", reinterpret_cast(_phys_range.end)); + return result; +} void Ram_dataspace_factory::free(Ram_dataspace_capability ds_cap) { diff --git a/repos/base/src/core/stack_area.cc b/repos/base/src/core/stack_area.cc index c981eb54e5..e39e01676d 100644 --- a/repos/base/src/core/stack_area.cc +++ b/repos/base/src/core/stack_area.cc @@ -132,6 +132,10 @@ struct Stack_area_ram_allocator : Ram_allocator Alloc_result try_alloc(size_t, Cache) override { return reinterpret_cap_cast(Native_capability()); } + Alloc_result try_alloc(size_t, Ram_allocator::Numa_id, Cache) override { + return reinterpret_cap_cast(Native_capability()); } + + void free(Ram_dataspace_capability) override { } size_t dataspace_size(Ram_dataspace_capability) const override { return 0; } diff --git a/repos/libports/src/lib/libc/internal/malloc_ram_allocator.h b/repos/libports/src/lib/libc/internal/malloc_ram_allocator.h index d2ee44c7c4..40e0a6babb 100644 --- a/repos/libports/src/lib/libc/internal/malloc_ram_allocator.h +++ b/repos/libports/src/lib/libc/internal/malloc_ram_allocator.h @@ -64,6 +64,18 @@ struct Libc::Malloc_ram_allocator : Ram_allocator [&] (Alloc_error error) { return error; }); } + + Alloc_result try_alloc(size_t size, Ram_allocator::Numa_id numa_id, Cache cache) override + { + return _ram.try_alloc(size, numa_id, cache).convert( + + [&] (Ram_dataspace_capability cap) { + new (_md_alloc) Registered(_dataspaces, cap); + return cap; }, + + [&] (Alloc_error error) { + return error; }); + } void free(Ram_dataspace_capability ds_cap) override {