mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
ealanos: Expanded test for Core_heap to include tests for Hamstraaja.
This commit is contained in:
52
repos/ealanos/run/coreheap_test.run
Normal file
52
repos/ealanos/run/coreheap_test.run
Normal file
@@ -0,0 +1,52 @@
|
||||
set build_components {
|
||||
core init hoitaja timer test/coreheap_test
|
||||
}
|
||||
|
||||
build $build_components
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
<config prio_levels="32" verbose="true">
|
||||
<parent-provides>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="CPU"/>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="RM"/>
|
||||
<service name="SIGNAL"/>
|
||||
<service name="TRACE"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</default-route>
|
||||
<default caps="2000"/>
|
||||
<affinity-space width="32" height="1"/>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="3M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
<route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="cell1" priority="-1">
|
||||
<binary name="coreheap_test"/>
|
||||
<resource name="RAM" quantum="2G"/>
|
||||
</start>
|
||||
<!--
|
||||
<start name="cell2" priority="-2">
|
||||
<binary name="empty_cell"/>
|
||||
<resource name="RAM" quantum="3M"/>
|
||||
</start>
|
||||
-->
|
||||
</config>
|
||||
}
|
||||
|
||||
build_boot_image [build_artifacts]
|
||||
|
||||
append qemu_args " -nographic "
|
||||
run_genode_until forever
|
||||
@@ -13,6 +13,10 @@
|
||||
#include <base/env.h>
|
||||
#include <base/heap.h>
|
||||
#include <ealanos/memory/coreheap.h>
|
||||
#include <base/internal/xoroshiro.h>
|
||||
#include <base/tslab.h>
|
||||
|
||||
#include <ealanos/memory/hamstraaja.h>
|
||||
|
||||
namespace Ealan::Memory {
|
||||
class CoreheapTest;
|
||||
@@ -22,8 +26,16 @@ namespace Ealan::Memory {
|
||||
class Ealan::Memory::CoreheapTest
|
||||
{
|
||||
private:
|
||||
static constexpr const size_t MAX = 1024*1680;
|
||||
static constexpr const size_t MIN = 1680;
|
||||
static constexpr const size_t num_size_classes = MAX / MIN;
|
||||
|
||||
Genode::Xoroshiro_128_plus random{42};
|
||||
|
||||
Env &_env;
|
||||
Core_heap<64, 2048> _heap{_env.pd(), _env.rm()};
|
||||
Core_heap<MIN, MAX> *_heap{nullptr};
|
||||
Genode::Heap _genode_heap{_env.ram(), _env.rm()};
|
||||
Genode::Tslab<void*, 1024*1600> _tslab{_genode_heap};
|
||||
|
||||
public:
|
||||
|
||||
@@ -31,12 +43,126 @@ class Ealan::Memory::CoreheapTest
|
||||
{
|
||||
log("Starting tests for Core_heap");
|
||||
|
||||
void *p = _heap.aligned_alloc(42, 16);
|
||||
log("Allocated memory at ", p);
|
||||
_heap = new (_genode_heap) Core_heap<MIN, MAX>(_env.pd(), _env.rm());
|
||||
/*Genode::log("Trying to allocate from all possible size classes");
|
||||
for (size_t sz = MIN; sz < num_size_classes*MIN; sz+=MIN) {
|
||||
size_t size = random.value() % sz;
|
||||
Genode::log("Allocating ", size, " bytes.");
|
||||
void *ptr = _heap->aligned_alloc(size, 1, 16);
|
||||
Genode::log("Allocated ", size, " bytes of sizeclass ", sz, " at ", ptr);
|
||||
}*/
|
||||
|
||||
Genode::log("Exhausting super block of size class ", MIN);
|
||||
|
||||
_heap->reserve_superblocks(32, 1, MIN);
|
||||
|
||||
[[maybe_unused]] void *ptrs[2 * MAX / MIN];
|
||||
Genode::Trace::Timestamp start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++)
|
||||
{
|
||||
ptrs[i] = _heap->aligned_alloc(1600, 1, 0);
|
||||
}
|
||||
Genode::Trace::Timestamp end = Genode::Trace::timestamp();
|
||||
|
||||
Genode::log("Took ", (end - start), " cycles to allocate ", 2*MAX / MIN, " blocks from same superblock");
|
||||
|
||||
[[maybe_unused]] void *gen_ptr = _genode_heap.alloc(MIN);
|
||||
[[maybe_unused]] void *genode_ptrs[2 * MAX / MIN];
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++)
|
||||
{
|
||||
genode_ptrs[i] = _genode_heap.alloc(1600);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
Genode::log("Took ", (end - start), " cycles to allocate ", 2*MAX / MIN, " blocks from Genode::Heap");
|
||||
|
||||
Genode::log("Freeing all blocks");
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++) {
|
||||
_heap->free(ptrs[i], 0);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
Genode::log("Took ", (end - start), " cycles to free ", 2*MAX / MIN, " blocks from Core_heap");
|
||||
|
||||
Genode::log("Freeing all blocks");
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++) {
|
||||
_genode_heap.free(genode_ptrs[i], 1600);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
Genode::log("Took ", (end - start), " cycles to free ", 2*MAX / MIN, " blocks from Genode::Heap");
|
||||
|
||||
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++)
|
||||
{
|
||||
ptrs[i] = _heap->aligned_alloc(1600, 1, 0);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
|
||||
Genode::log("Took ", (end - start), " cycles to allocate ", 2*MAX / MIN, " blocks from same superblock");
|
||||
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++)
|
||||
{
|
||||
genode_ptrs[i] = _tslab.alloc(1);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
Genode::log("Took ", (end - start), " cycles to allocate ", 2*MAX / MIN, " blocks from Genode::Tslab");
|
||||
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++) {
|
||||
_tslab.free(genode_ptrs[i], 1);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
Genode::log("Took ", (end - start), " cycles to free ", 2*MAX / MIN, " blocks from Genode::Tslab");
|
||||
|
||||
|
||||
Genode::log("Now, trying to allocate of size class 64, again");
|
||||
[[maybe_unused]] void *ptr = _heap->aligned_alloc(32, 1, 16);
|
||||
Genode::log("New block was allocated at ", ptr);
|
||||
_heap->free(ptr, 16);
|
||||
|
||||
Genode::log("Allocating a hyperblock");
|
||||
ptr = _heap->aligned_alloc(3198, 2, 0);
|
||||
Genode::log("Hyperblock is at ", ptr);
|
||||
|
||||
Genode::log("Freeing hyperblock");
|
||||
_heap->free(ptr);
|
||||
|
||||
Genode::log("-------- Testing Hamstraaja --------");
|
||||
Hamstraaja<MIN, MAX> *_hamstraaja = new (_genode_heap) Hamstraaja<MIN, MAX>(_env.pd(), _env.rm());
|
||||
|
||||
_hamstraaja->reserve_superblocks(32, MIN, 2);
|
||||
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++)
|
||||
{
|
||||
ptrs[i] = _hamstraaja->aligned_alloc(1600, 0, 2);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
|
||||
Genode::log("Took ", (end - start), " cycles to allocate ", 2*MAX / MIN, " blocks from Hamstraaja");
|
||||
|
||||
start = Genode::Trace::timestamp();
|
||||
for (unsigned i = 0; i < 2*MAX / MIN; i++) {
|
||||
_hamstraaja->free(ptrs[i], 0);
|
||||
}
|
||||
end = Genode::Trace::timestamp();
|
||||
Genode::log("Took ", (end - start), " cycles to free ", 2*MAX / MIN, " blocks from Core_heap");
|
||||
Genode::log("Testing Hamstraaja as drop-in replacement for Genode::Heap");
|
||||
|
||||
Genode::Xml_node *xml_node = new (_hamstraaja) Xml_node("<test/>");
|
||||
|
||||
Genode::log("Allocated XML node is at ", xml_node);
|
||||
|
||||
Genode::destroy(_hamstraaja, xml_node);
|
||||
}
|
||||
};
|
||||
|
||||
void Component::construct(Genode::Env &env)
|
||||
{
|
||||
static Ealan::Memory::CoreheapTest test(env);
|
||||
static Genode::Heap heap{env.ram(), env.rm()};
|
||||
[[maybe_unused]] Ealan::Memory::CoreheapTest *test = new (heap) Ealan::Memory::CoreheapTest(env);
|
||||
|
||||
}
|
||||
@@ -3,4 +3,7 @@ SRC_CC = main.cc
|
||||
LIBS = base
|
||||
INC_DIR = $(PRG_DIR)
|
||||
INC_DIR += $(REP_DIR)/include
|
||||
INC_DIR += $(BASE_DIR)/src/include/
|
||||
|
||||
CC_OPT += -Wno-error=effc++
|
||||
|
||||
|
||||
Reference in New Issue
Block a user