Defined method prototypes for the internal interfaces of Hoitaja.

This commit is contained in:
Michael Mueller
2023-06-13 18:51:25 +02:00
parent aa183af6a4
commit a72727fd45
9 changed files with 517 additions and 0 deletions

View File

@@ -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 <sandbox/child.h>
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();
};

View File

@@ -0,0 +1,214 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="base_types.xsd"/>
<xs:complexType name="template_service">
<xs:choice minOccurs="1" maxOccurs="3">
<xs:element name="parent"/>
<xs:element name="any-child"/>
<xs:element name="child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="Session_label" />
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="Session_label" />
<xs:attribute name="label_prefix" type="Session_label" />
<xs:attribute name="label_suffix" type="Session_label" />
<xs:attribute name="label_last" type="Session_label" />
<xs:attribute name="unscoped_label" type="Session_label" />
</xs:complexType>
<xs:complexType name="template_route">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="service" type="template_service"/>
<xs:element name="any-service" type="template_service"/>
</xs:choice>
</xs:complexType>
<xs:element name="config">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="service">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="default-policy">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="Session_label" />
</xs:complexType>
</xs:element><!-- child -->
</xs:choice>
</xs:complexType>
</xs:element><!-- default-policy -->
<xs:element name="policy">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="Session_label" />
</xs:complexType>
</xs:element><!-- child -->
</xs:choice>
<xs:attribute name="label" type="Session_label" />
<xs:attribute name="label_prefix" type="Session_label" />
<xs:attribute name="label_suffix" type="Session_label" />
<xs:attribute name="label_last" type="Session_label" />
<xs:attribute name="unscoped_label" type="Session_label" />
</xs:complexType>
</xs:element><!-- policy -->
</xs:choice>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element><!-- "service" -->
<xs:element name="affinity-space">
<xs:complexType>
<xs:attribute name="width" type="xs:int" />
<xs:attribute name="height" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "affinity-space" -->
<xs:element name="parent-provides">
<xs:complexType>
<xs:sequence>
<xs:element name="service" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element> <!-- "parent-provides" -->
<xs:element name="alias">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="child" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "alias" -->
<xs:element name="default-route" type="template_route"/>
<xs:element name="default">
<xs:complexType>
<xs:attribute name="caps" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "default" -->
<xs:element name="report">
<xs:complexType>
<xs:attribute name="ids" type="Boolean" />
<xs:attribute name="requested" type="Boolean" />
<xs:attribute name="provided" type="Boolean" />
<xs:attribute name="session_args" type="Boolean" />
<xs:attribute name="child_caps" type="Boolean" />
<xs:attribute name="child_ram" type="Boolean" />
<xs:attribute name="init_caps" type="Boolean" />
<xs:attribute name="init_ram" type="Boolean" />
<xs:attribute name="delay_ms" type="xs:int" />
<xs:attribute name="buffer" type="Number_of_bytes" />
</xs:complexType>
</xs:element> <!-- "report" -->
<xs:element name="heartbeat">
<xs:complexType>
<xs:attribute name="rate_ms" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "heartbeat" -->
<xs:element name="resource">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="preserve" type="Number_of_bytes" />
</xs:complexType>
</xs:element> <!-- "resource" -->
<xs:element name="start" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="binary">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element> <!-- "binary" -->
<xs:element name="heartbeat" />
<xs:element name="affinity">
<xs:complexType>
<xs:attribute name="xpos" type="xs:int" />
<xs:attribute name="ypos" type="xs:int" />
<xs:attribute name="width" type="xs:int" />
<xs:attribute name="height" type="xs:int" />
</xs:complexType>
</xs:element> <!-- "affinity" -->
<xs:element name="resource">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="quantum" type="Number_of_bytes" />
</xs:complexType>
</xs:element> <!-- "resource" -->
<xs:element name="exit">
<xs:complexType>
<xs:attribute name="propagate" type="Boolean" />
</xs:complexType>
</xs:element> <!-- "exit" -->
<xs:element name="provides">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="service">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element> <!-- "provides" -->
<xs:element name="route" type="template_route"/>
<xs:element name="config">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip" />
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element> <!-- "config" -->
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="ld" type="Boolean" />
<xs:attribute name="caps" type="xs:int" />
<xs:attribute name="priority" type="xs:int" />
<xs:attribute name="managing_system" type="Boolean" />
</xs:complexType>
</xs:element> <!-- "start" -->
</xs:choice>
<xs:attribute name="prio_levels" type="xs:int" />
<xs:attribute name="verbose" type="Boolean" />
<xs:attribute name="ld_verbose" type="Boolean" />
</xs:complexType>
</xs:element> <!-- "config" -->
</xs:schema>

View File

@@ -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 <sandbox/child.h>
#include <sandbox/library.h>
/** 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();
};

View File

@@ -0,0 +1,46 @@
#include <sandbox/child.h>
#include <sandbox/alias.h>
#include <sandbox/server.h>
#include <sandbox/heartbeat.h>
#include <sandbox/config_model.h>
#include <sandbox/library.h>
#include <sandbox/sandbox.h>
#include <base/log.h>
#include <base/registry.h>
#include <base/service.h>
#include <base/heap.h>
namespace Hoitaja {
class Habitat;
using namespace Genode;
}
class Hoitaja::Habitat : Sandbox::Library
{
private:
friend class Genode::Sandbox::Local_service_base;
Heap _heap;
Registry<Genode::Sandbox::Local_service_base>
_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())
{
}
};

View File

@@ -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 <trace_session/connection.h>
#include <base/affinity.h>
namespace Hoitaja {
class Load_controller;
}
class Hoitaja::Load_controller
{
public:
unsigned short *cpu_loads();
Genode::Affinity::Location *idle_cores();
};

View File

@@ -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 <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <habitat.h>
#include <os/reporter.h>
#include <timer_session/connection.h>
/** 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<Main> _resource_avail_handler {
_env.ep(), *this, &Main::_handle_resource_avail };
Constructible<Reporter> _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<Main> _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<Main> _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); }

View File

View File