From 3b1fa40de3d1a2f4ea87ec6e372a71b3455c5367 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 3 Jun 2025 15:31:23 +0200 Subject: [PATCH] ealanos: Some test for Hamstraaja. --- repos/ealanos/run/hamstraaja.run | 52 +++++++++ .../ealanos/src/test/hamstraaja_test/main.cc | 101 ++++++++++++++++++ .../src/test/hamstraaja_test/target.mk | 9 ++ 3 files changed, 162 insertions(+) create mode 100644 repos/ealanos/run/hamstraaja.run create mode 100644 repos/ealanos/src/test/hamstraaja_test/main.cc create mode 100644 repos/ealanos/src/test/hamstraaja_test/target.mk diff --git a/repos/ealanos/run/hamstraaja.run b/repos/ealanos/run/hamstraaja.run new file mode 100644 index 0000000000..d41754d242 --- /dev/null +++ b/repos/ealanos/run/hamstraaja.run @@ -0,0 +1,52 @@ +set build_components { + core init hoitaja timer test/hamstraaja_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/hamstraaja_test/main.cc b/repos/ealanos/src/test/hamstraaja_test/main.cc new file mode 100644 index 0000000000..e72e690587 --- /dev/null +++ b/repos/ealanos/src/test/hamstraaja_test/main.cc @@ -0,0 +1,101 @@ +/** + * @file main.cc + * @author your name (you@domain.com) + * @brief Component for testing CPU core-local heaps + * @version 0.1 + * @date 2025-04-23 + * + * @copyright Copyright (c) 2025 + * + */ + +#include "base/affinity.h" +#include "base/stdint.h" +#include "base/thread.h" +#include "trace/timestamp.h" +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace Ealan::Memory { + class CoreheapTest; + using namespace Genode; +} + +class Ealan::Memory::CoreheapTest +{ + private: + static constexpr const size_t MAX = 1024*64; + static constexpr const size_t MIN = 64; + static constexpr const size_t num_size_classes = MAX / MIN; + + Genode::Xoroshiro_128_plus random{42}; + + Env &_env; + Core_heap *_heap{nullptr}; + Genode::Heap _genode_heap{_env.ram(), _env.rm()}; + Genode::Tslab _tslab{_genode_heap}; + + public: + + CoreheapTest(Env &env) : _env(env) + { + [[maybe_unused]] void *ptrs[4 * MAX / MIN]; + Genode::log("-------- Testing Hamstraaja --------"); + Hamstraaja *_hamstraaja = new (_genode_heap) Hamstraaja(_env.pd(), _env.rm()); + + Genode::Affinity::Location loc = Genode::Thread::myself()->affinity(); + for (unsigned node_id = 0; node_id < Tukija::Tip::tip()->num_domains(); node_id++) { + _hamstraaja->reserve_superblocks_for_location(loc, 32, 192, node_id); + } + //_hamstraaja->reserve_superblocks(32, MIN, 2); + + for (int j = 0; j < 3; j++) { + Genode::Trace::Timestamp start = Genode::Trace::timestamp(); + for (unsigned i = 0; i < 500; i++) + { + ptrs[i] = _hamstraaja->aligned_alloc(128, 0); + if (reinterpret_cast(ptrs[i]) % 64 != 0) { + Genode::error("Alignment error: ", ptrs[i]); + } + } + Genode::Trace::Timestamp end = Genode::Trace::timestamp(); + + Genode::log("Took ", (end - start), " cycles to allocate ", 500, " blocks from Hamstraaja"); + + start = Genode::Trace::timestamp(); + for (unsigned i = 0; i < 500; i++) { + _hamstraaja->free(ptrs[i], 0); + } + end = Genode::Trace::timestamp(); + Genode::log("Took ", (end - start), " cycles to free ", 500, " blocks from Hamstraaja"); + } + + Genode::log("Trying to get memory from each NUMA region"); + Tukija::Tip::tip()->for_each([&](Tukija::Tip::Domain &dom) { + void *ptr = _hamstraaja->aligned_alloc(64, 0, dom.id); + Genode::log("[node ", dom.id, "] ", ptr); + }); + + 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 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/hamstraaja_test/target.mk b/repos/ealanos/src/test/hamstraaja_test/target.mk new file mode 100644 index 0000000000..525860ad79 --- /dev/null +++ b/repos/ealanos/src/test/hamstraaja_test/target.mk @@ -0,0 +1,9 @@ +TARGET = hamstraaja_test +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++ +