diff --git a/repos/os/src/hoitaja/cell_controller.h b/repos/os/src/hoitaja/cell_controller.h new file mode 100644 index 0000000000..94127a2d7d --- /dev/null +++ b/repos/os/src/hoitaja/cell_controller.h @@ -0,0 +1,46 @@ +/* + * \brief Hoitaja — Cell Controller + * \author Michael Müller, Norman Feske (Init) + * \date 2023-04-20 + */ + +/* + * Copyright (C) 2010-2017 Genode Labs GmbH + * Copyright (C) 2023 Michael Müller, Osnabrück University + * + * This file is part of EalánOS, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include + +namespace Hoitaja +{ + class Cell_controller; +} + +class Hoitaja::Cell_controller +{ + public: + void create_cell(); + void destroy_cell(); + + /** + * @brief Determine which cells shall be shrinked down + * + * @return Sandbox::Child* List of cells to shrink + */ + Sandbox::Child *cells_to_shrink(); + /** + * @brief Determine which cell shall be grown up + * + * @return Sandbox::Child* List of cells to grow + */ + Sandbox::Child *cells_to_grow(); + + /** + * @brief Regather performance metrics for next adaptation cycle + * + */ + void update_metrics(); +}; \ No newline at end of file diff --git a/repos/os/src/hoitaja/config.xsd b/repos/os/src/hoitaja/config.xsd new file mode 100644 index 0000000000..727b5b91e6 --- /dev/null +++ b/repos/os/src/hoitaja/config.xsd @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repos/os/src/hoitaja/core_allocator.h b/repos/os/src/hoitaja/core_allocator.h new file mode 100644 index 0000000000..6b8dcb58c3 --- /dev/null +++ b/repos/os/src/hoitaja/core_allocator.h @@ -0,0 +1,40 @@ +/* + * \brief Hoitaja — Core Allocator + * \author Michael Müller, Norman Feske (Init) + * \date 2023-04-20 + */ + +/* + * Copyright (C) 2010-2017 Genode Labs GmbH + * Copyright (C) 2023 Michael Müller, Osnabrück University + * + * This file is part of EalánOS, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Genode includes */ +#include +#include + +/** Hoitaja includes **/ +#include "load_controller.h" +#include "cell_controller.h" + +namespace Hoitaja +{ + class Core_allocator; +} + +class Hoitaja::Core_allocator +{ + private: + Sandbox::Child *_cells_to_grow; + Sandbox::Child *_cells_to_shrink; + + public: + /** + * @brief Update core allocations for cells reported by Cell controller + * + */ + void update(); +}; \ No newline at end of file diff --git a/repos/os/src/hoitaja/habitat.h b/repos/os/src/hoitaja/habitat.h new file mode 100644 index 0000000000..09f1996bae --- /dev/null +++ b/repos/os/src/hoitaja/habitat.h @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Hoitaja { + class Habitat; + using namespace Genode; +} +class Hoitaja::Habitat : Sandbox::Library +{ + + private: + friend class Genode::Sandbox::Local_service_base; + + Heap _heap; + + Registry + _local_services{}; + + public: + void apply_config(Xml_node const &config) override { + log("Hoitaja is applying new config."); + Sandbox::Library::apply_config(config); + } + + void generate_state_report(Xml_generator &xml) const override { + log("Generating new state report for Hoitaja."); + Sandbox::Library::generate_state_report(xml); + } + + void maintain_cells(); + + Habitat(Env &env, Genode::Sandbox::State_handler &handler) + : Sandbox::Library(env, _heap, _local_services, handler), _heap(env.ram(), env.rm()) + { + } +}; \ No newline at end of file diff --git a/repos/os/src/hoitaja/hyperthread_controller.h b/repos/os/src/hoitaja/hyperthread_controller.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/repos/os/src/hoitaja/load_controller.h b/repos/os/src/hoitaja/load_controller.h new file mode 100644 index 0000000000..801f29a26f --- /dev/null +++ b/repos/os/src/hoitaja/load_controller.h @@ -0,0 +1,27 @@ +/* + * \brief Hoitaja — Load Controller + * \author Michael Müller, Norman Feske (Init) + * \date 2023-04-20 + */ + +/* + * Copyright (C) 2010-2017 Genode Labs GmbH + * Copyright (C) 2023 Michael Müller, Osnabrück University + * + * This file is part of EalánOS, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include +#include + +namespace Hoitaja { + class Load_controller; +} + +class Hoitaja::Load_controller +{ + public: + unsigned short *cpu_loads(); + Genode::Affinity::Location *idle_cores(); +}; \ No newline at end of file diff --git a/repos/os/src/hoitaja/main.cc b/repos/os/src/hoitaja/main.cc new file mode 100644 index 0000000000..26839672d6 --- /dev/null +++ b/repos/os/src/hoitaja/main.cc @@ -0,0 +1,144 @@ +/* + * \brief Hoitaja — Cell Management Component based on Init + * \author Michael Müller, Norman Feske (Init) + * \date 2023-04-20 + */ + +/* + * Copyright (C) 2010-2017 Genode Labs GmbH + * Copyright (C) 2023 Michael Müller, Osnabrück University + * + * This file is part of EalánOS, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Genode includes */ +#include +#include +#include +#include +#include + +/** Hoitaja components **/ +/* Filtering components */ +#include "load_controller.h" +#include "cell_controller.h" +#include "hyperthread_controller.h" +#include "memory_controller.h" +#include "numa_controller.h" +/* Core Allocator */ +#include "core_allocator.h" + +namespace Hoitaja { + + using namespace Genode; + + struct Main; +} + + +struct Hoitaja::Main : Genode::Sandbox::State_handler +{ + Env &_env; + + Habitat _sandbox { _env, *this }; + + Timer::Connection _timer{_env}; + + Attached_rom_dataspace _config { _env, "config" }; + + void _handle_resource_avail() { } + + Signal_handler
_resource_avail_handler { + _env.ep(), *this, &Main::_handle_resource_avail }; + + Constructible _reporter { }; + + size_t _report_buffer_size = 0; + + void _handle_config() + { + _config.update(); + + Xml_node const config = _config.xml(); + + bool reporter_enabled = false; + config.with_optional_sub_node("report", [&] (Xml_node report) { + + reporter_enabled = true; + + /* (re-)construct reporter whenever the buffer size is changed */ + Number_of_bytes const buffer_size = + report.attribute_value("buffer", Number_of_bytes(4096)); + + if (buffer_size != _report_buffer_size || !_reporter.constructed()) { + _report_buffer_size = buffer_size; + _reporter.construct(_env, "state", "state", _report_buffer_size); + } + }); + + if (_reporter.constructed()) + _reporter->enabled(reporter_enabled); + + _sandbox.apply_config(config); + } + + Signal_handler
_config_handler { + _env.ep(), *this, &Main::_handle_config }; + + void _handle_timeout() + { + //log("Hoitaja's entering its maintance cycle"); + // For now just print all cells created by Hoitaja + //_sandbox.maintain_cells(); + _timer.trigger_once(1000 * 1000); + } + + Signal_handler
_timeout_handler{ + _env.ep(), *this, &Main::_handle_timeout}; + + /** + * Sandbox::State_handler interface + */ + void handle_sandbox_state() override + { + + try { + Reporter::Xml_generator xml(*_reporter, [&] () { + _sandbox.generate_state_report(xml); }); + } + catch (Xml_generator::Buffer_exceeded) { + + error("state report exceeds maximum size"); + + /* try to reflect the error condition as state report */ + try { + Reporter::Xml_generator xml(*_reporter, [&] () { + xml.attribute("error", "report buffer exceeded"); }); + } + catch (...) { } + } + } + + Main(Env &env) : _env(env) + { + _config.sigh(_config_handler); + _timer.sigh(_timeout_handler); + + /* prevent init to block for resource upgrades (never satisfied by core) */ + _env.parent().resource_avail_sigh(_resource_avail_handler); + + _timer.trigger_once(1000 * 1000); + _handle_config(); + } +}; + +void Hoitaja::Habitat::maintain_cells() +{ + log("My current children are:"); + _children.for_each_child([&](Child &child) + { log(child.name(), " ram: ", child.ram_quota()); }); +} + +void Component::construct(Genode::Env &env) { static Hoitaja::Main main(env); } + diff --git a/repos/os/src/hoitaja/memory_controller.h b/repos/os/src/hoitaja/memory_controller.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/repos/os/src/hoitaja/numa_controller.h b/repos/os/src/hoitaja/numa_controller.h new file mode 100644 index 0000000000..e69de29bb2