mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
core: Extended Ram_allocator by NUMA-specfic allocation and deallocation.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
/* core includes */
|
||||
#include <ram_dataspace_factory.h>
|
||||
#include <platform_generic.h>
|
||||
#include <platform.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
@@ -144,6 +146,26 @@ Ram_dataspace_factory::try_alloc(size_t ds_size, Cache cache)
|
||||
return static_cap_cast<Ram_dataspace>(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<void*>(_phys_range.start), "-", reinterpret_cast<void*>(_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<void*>(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<void*>(_phys_range.start), "-", reinterpret_cast<void*>(_phys_range.end));
|
||||
return result;
|
||||
}
|
||||
|
||||
void Ram_dataspace_factory::free(Ram_dataspace_capability ds_cap)
|
||||
{
|
||||
|
||||
@@ -132,6 +132,10 @@ struct Stack_area_ram_allocator : Ram_allocator
|
||||
Alloc_result try_alloc(size_t, Cache) override {
|
||||
return reinterpret_cap_cast<Ram_dataspace>(Native_capability()); }
|
||||
|
||||
Alloc_result try_alloc(size_t, Ram_allocator::Numa_id, Cache) override {
|
||||
return reinterpret_cap_cast<Ram_dataspace>(Native_capability()); }
|
||||
|
||||
|
||||
void free(Ram_dataspace_capability) override { }
|
||||
|
||||
size_t dataspace_size(Ram_dataspace_capability) const override { return 0; }
|
||||
|
||||
@@ -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<Alloc_result>(
|
||||
|
||||
[&] (Ram_dataspace_capability cap) {
|
||||
new (_md_alloc) Registered<Dataspace>(_dataspaces, cap);
|
||||
return cap; },
|
||||
|
||||
[&] (Alloc_error error) {
|
||||
return error; });
|
||||
}
|
||||
|
||||
void free(Ram_dataspace_capability ds_cap) override
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user