diff --git a/repos/ealanos/run/coreheap_test.run b/repos/ealanos/run/coreheap_test.run
new file mode 100644
index 0000000000..13642670f8
--- /dev/null
+++ b/repos/ealanos/run/coreheap_test.run
@@ -0,0 +1,52 @@
+set build_components {
+ core init hoitaja timer test/coreheap_test
+}
+
+build $build_components
+create_boot_directory
+
+install_config {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+build_boot_image [build_artifacts]
+
+append qemu_args " -nographic "
+run_genode_until forever
\ No newline at end of file
diff --git a/repos/ealanos/src/test/coreheap_test/main.cc b/repos/ealanos/src/test/coreheap_test/main.cc
index d6bbd9d57f..2c8e4f0f9b 100644
--- a/repos/ealanos/src/test/coreheap_test/main.cc
+++ b/repos/ealanos/src/test/coreheap_test/main.cc
@@ -13,6 +13,10 @@
#include
#include
#include
+#include
+#include
+
+#include
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 *_heap{nullptr};
+ Genode::Heap _genode_heap{_env.ram(), _env.rm()};
+ Genode::Tslab _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(_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 *_hamstraaja = new (_genode_heap) Hamstraaja(_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("");
+
+ 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);
+
}
\ No newline at end of file
diff --git a/repos/ealanos/src/test/coreheap_test/target.mk b/repos/ealanos/src/test/coreheap_test/target.mk
index 3470ac8c0f..dc312d5725 100644
--- a/repos/ealanos/src/test/coreheap_test/target.mk
+++ b/repos/ealanos/src/test/coreheap_test/target.mk
@@ -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++