From 372ca1815676ddbb6fa8f6b5bf1fcd6ce0e495e5 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Mon, 24 Feb 2025 15:24:06 +0100 Subject: [PATCH] Made cells into proper RPC objects. --- repos/base-tukija/include/cell/cell.h | 39 +++++++ repos/base-tukija/include/cell/client.h | 38 +++++++ repos/base-tukija/include/habitat/client.h | 4 +- .../base-tukija/include/habitat/connection.h | 4 +- repos/base-tukija/include/habitat/session.h | 5 +- .../src/core/include/cell_component.h | 103 ++++++++++++++++++ .../src/core/include/habitat_root.h | 8 +- .../core/include/habitat_session_component.h | 64 ++++++----- 8 files changed, 223 insertions(+), 42 deletions(-) create mode 100644 repos/base-tukija/include/cell/cell.h create mode 100644 repos/base-tukija/include/cell/client.h create mode 100644 repos/base-tukija/src/core/include/cell_component.h diff --git a/repos/base-tukija/include/cell/cell.h b/repos/base-tukija/include/cell/cell.h new file mode 100644 index 0000000000..371f295b98 --- /dev/null +++ b/repos/base-tukija/include/cell/cell.h @@ -0,0 +1,39 @@ +/* + * \brief Cell-session interface + * \author Michael Müller + * \date 2025-02-17 +*/ + +/* + * Copyright (C) 2025 Michael Müller, Osnabrück University + * + * This file is part of the EalánOS research operating system, which is distributed + * under the terms of the GNU Affero General Public License version 3. +*/ + +#ifndef _INCLUDE__CELL__SESSION_H_ +#define _INCLUDE__CELL__SESSION_H_ + +/* Genode includes */ +#include +#include +#include +#include + +namespace Ealan { struct Cell; + using Cell_capability = Genode::Capability; +} + +struct Ealan::Cell : Genode::Interface +{ + enum { CAP_QUOTA = 1 }; + + virtual void update(Genode::Affinity &affinity) = 0; + virtual bool is_brick() = 0; + + GENODE_RPC(Rpc_update, void, update, Genode::Affinity &); + GENODE_RPC(Rpc_is_brick, bool, is_brick); + + GENODE_RPC_INTERFACE(Rpc_update, Rpc_is_brick); +}; +#endif /* _INCLUDE__CELL__SESSION_H_ */ \ No newline at end of file diff --git a/repos/base-tukija/include/cell/client.h b/repos/base-tukija/include/cell/client.h new file mode 100644 index 0000000000..e24273b0ec --- /dev/null +++ b/repos/base-tukija/include/cell/client.h @@ -0,0 +1,38 @@ +/* + * \brief Client-side Cell interface + * \author Michael Müller + * \date 2025-02-24 + */ + +/* + * Copyright (C) 2025 Michael Müller , Osnabrück University + * + * This file is part of EalánOS based on the Genode OS framework, which are distributed + * under the terms of the GNU Affero General Public Lisense version 3. + */ + +#ifndef _INCLUDE__CELL__CLIENT_H_ +#define _INCLUDE__CELL__CLIENT_H_ + +#include +#include + +namespace Ealan { + struct Cell_client; +} + +struct Ealan::Cell_client : Genode::Rpc_client +{ + explicit Cell_client(Cell_capability cap) + : Rpc_client(cap) {} + + void update(Genode::Affinity &affinity) override { + call(affinity); + } + + bool is_brick() override { + return call(); + } +}; + +#endif /* _INCLUDE__CELL__CLIENT_H_ */ \ No newline at end of file diff --git a/repos/base-tukija/include/habitat/client.h b/repos/base-tukija/include/habitat/client.h index 06817de5f3..bba03336c2 100644 --- a/repos/base-tukija/include/habitat/client.h +++ b/repos/base-tukija/include/habitat/client.h @@ -27,8 +27,8 @@ struct Ealan::Habitat_client : Genode::Rpc_client { explicit Habitat_client(Habitat_capability session) : Rpc_client(session) {} - void create_cell(Genode::Capability pd, Genode::Affinity &affinity, Genode::uint16_t prio) override { - call(pd, affinity, prio); + Cell_capability create_cell(Genode::Capability pd, Genode::Affinity &affinity, Genode::uint16_t prio, Genode::Session_label const &label) override { + return call(pd, affinity, prio, label); } }; #endif \ No newline at end of file diff --git a/repos/base-tukija/include/habitat/connection.h b/repos/base-tukija/include/habitat/connection.h index c42a2632e0..d1620128ca 100644 --- a/repos/base-tukija/include/habitat/connection.h +++ b/repos/base-tukija/include/habitat/connection.h @@ -28,8 +28,8 @@ struct Ealan::Habitat_connection : Genode::Connection, H Habitat_connection(Genode::Env &env, Genode::Affinity &affinity, Label const &label = Label()) : Connection(env, label, Genode::Ram_quota { RAM_QUOTA }, affinity, Args("")), Habitat_client(cap()) {} - void create_cell(Genode::Capability pd_cap, Genode::Affinity &affinity, Genode::uint16_t prio) override { - Habitat_client::create_cell(pd_cap, affinity, prio); + Cell_capability create_cell(Genode::Capability pd_cap, Genode::Affinity &affinity, Genode::uint16_t prio, Genode::Session_label const &label) override { + return Habitat_client::create_cell(pd_cap, affinity, prio, label); } }; diff --git a/repos/base-tukija/include/habitat/session.h b/repos/base-tukija/include/habitat/session.h index 15e381a858..32afc91b25 100644 --- a/repos/base-tukija/include/habitat/session.h +++ b/repos/base-tukija/include/habitat/session.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace Ealan { struct Habitat_session; } @@ -30,9 +31,9 @@ struct Ealan::Habitat_session : Genode::Session /** * Attach cell info page to the cells virtual memory space */ - virtual void create_cell(Genode::Capability pd, Genode::Affinity &affinity, Genode::uint16_t prio) = 0; + virtual Cell_capability create_cell(Genode::Capability pd, Genode::Affinity &affinity, Genode::uint16_t prio, Genode::Session_label const &label) = 0; - GENODE_RPC(Rpc_create_cell, void, create_cell, Genode::Capability, Genode::Affinity&, Genode::uint16_t); + GENODE_RPC(Rpc_create_cell, Cell_capability, create_cell, Genode::Capability, Genode::Affinity &, Genode::uint16_t, Genode::Session_label const &); GENODE_RPC_INTERFACE(Rpc_create_cell); }; #endif \ No newline at end of file diff --git a/repos/base-tukija/src/core/include/cell_component.h b/repos/base-tukija/src/core/include/cell_component.h new file mode 100644 index 0000000000..e71e9782e9 --- /dev/null +++ b/repos/base-tukija/src/core/include/cell_component.h @@ -0,0 +1,103 @@ +/* + * \brief Core-specific instance of the Cell interface + * \author Michael Müller + * \date 2025-02-24 + */ + +/* + * Copyright (C) 2025 Michael Müller , Osnabrück University + * + * This file is part of EalánOS based on the Genode OS framework, which are distributed + * under the terms of the GNU Affero General Public Lisense version 3. + */ + +#ifndef _CORE__INCLUDE__CELL_COMPONENT_H_ +#define _CORE__INCLUDE__CELL_COMPONENT_H_ + +/* Genode includes */ +#include +#include +#include +#include +#include + +/* EalánOS includes */ +#include + +/* Tukija includes */ +#include +#include +#include + +namespace Ealan { + class Cell_component; +} + +class Ealan::Cell_component : public Genode::Rpc_object, + private Genode::List::Element +{ + private: + friend class Genode::List; + + Genode::Rpc_entrypoint &_ep; + Genode::Session_label const _session_label; + Genode::Region_map &_rm; + Genode::Pd_session_capability _pd_cap; + Genode::Pd_session_client _pd; + Genode::Tukija_native_pd_client _native_pd; + + Tukija::Cip *_cip{nullptr}; + + bool _is_brick{false}; + + void _calculate_mask_for_location(Tukija::Cpuset *coreset, const Genode::Affinity::Location &loc) + { + for (unsigned y = loc.ypos(); y < loc.ypos() + loc.height(); y++) + { + for (unsigned x = loc.xpos(); x < loc.xpos()+loc.width(); x++) + { + unsigned kernel_cpu = Core::platform_specific().kernel_cpu_id(Genode::Affinity::Location(x, y, loc.width(), loc.height())); + coreset->set(kernel_cpu); + } + } + } + + Cell_component(const Cell_component &); + + Cell_component& operator=(const Cell_component &); + + public: + + Cell_component(Genode::Pd_session_capability pd_cap, Genode::uint16_t prio, Genode::Affinity &affinity, Genode::Rpc_entrypoint &ep, Genode::Region_map &rm, Genode::Session_label const &label) : _ep(ep), _session_label(label), _rm(rm), _pd_cap(pd_cap), _pd(pd_cap), _native_pd(_pd.native_pd()) { + Tukija::mword_t cell_pd_sel = _native_pd.sel(); + Tukija::mword_t cip_phys = 0; + + Core::platform().region_alloc().alloc_aligned(4 * Tukija::PAGE_SIZE_BYTE, Tukija::PAGE_SIZE_LOG2).with_result( + [&](void *ptr) { _cip = static_cast(ptr); }, + [&](Genode::Range_allocator::Alloc_error) { throw Genode::Out_of_ram(); }); + + Tukija::mword_t cip_virt = reinterpret_cast(_cip); + + if (Tukija::create_cell(cell_pd_sel, static_cast(prio), cip_phys, cip_virt)) { + Genode::error("Failed to create cell at Tukija."); + } + + _calculate_mask_for_location(&_cip->cores_reserved, affinity.location()); + Genode::log("Cores for <", label, ">: ", _cip->cores_reserved); + } + + /******************** + ** Cell interface ** + ********************/ + + void update(Genode::Affinity &affinity) override { + /* TODO: implement */ + Genode::log("Changing cell's affinity to ", affinity); + } + + bool is_brick() override { + return _is_brick; + } +}; + +#endif \ No newline at end of file diff --git a/repos/base-tukija/src/core/include/habitat_root.h b/repos/base-tukija/src/core/include/habitat_root.h index 9afa09d86e..9756cbb5c0 100644 --- a/repos/base-tukija/src/core/include/habitat_root.h +++ b/repos/base-tukija/src/core/include/habitat_root.h @@ -14,16 +14,18 @@ namespace Core { Genode::Ram_allocator &_ram_alloc; Genode::Region_map &_local_rm; + Genode::Rpc_entrypoint &_session_ep; + protected: - Habitat_session_component *_create_session(char const *, Genode::Affinity const &affinity) override { + Habitat_session_component *_create_session(char const *args, Genode::Affinity const &affinity) override { if (!affinity.valid()) { Genode::error("Invalid affinity space: ", affinity); throw Genode::Service_denied(); } - return new (md_alloc()) Habitat_session_component(_local_rm, affinity.space()); + return new (md_alloc()) Habitat_session_component(session_label_from_args(args), _session_ep, _local_rm, _ram_alloc, affinity.space()); } void _upgrade_session(Habitat_session_component *, const char *) override @@ -37,7 +39,7 @@ namespace Core { Genode::Region_map &local_rm, Genode::Rpc_entrypoint &session_ep, Genode::Allocator &md_alloc) - : Root_component(&session_ep, &md_alloc), _ram_alloc(ram_alloc), _local_rm(local_rm) {} + : Root_component(&session_ep, &md_alloc), _ram_alloc(ram_alloc), _local_rm(local_rm), _session_ep(session_ep) {} }; } diff --git a/repos/base-tukija/src/core/include/habitat_session_component.h b/repos/base-tukija/src/core/include/habitat_session_component.h index 5cd080ce77..356dcd7b46 100644 --- a/repos/base-tukija/src/core/include/habitat_session_component.h +++ b/repos/base-tukija/src/core/include/habitat_session_component.h @@ -1,14 +1,29 @@ +/* + * \brief Core-specific instance of a Habitat session + * \author Michael Müller + * \date 2025-02-24 + */ + +/* + * Copyright (C) 2025 Michael Müller , Osnabrück University + * + * This file is part of EalánOS based on the Genode OS framework, which are distributed + * under the terms of the GNU Affero General Public Lisense version 3. + */ #ifndef _CORE__HABITAT_SESSION_COMPONENT_H_ #define _CORE__HABITAT_SESSION_COMPONENT_H_ #include #include #include +#include +#include #include #include #include #include +#include #include @@ -20,50 +35,33 @@ class Core::Habitat_session_component : public Genode::Rpc_object _managed_cells { }; - void _calculate_mask_for_location(Tukija::Cpuset *coreset, const Affinity::Location &loc) - { - for (unsigned y = loc.ypos(); y < loc.ypos() + loc.height(); y++) + void _calculate_mask_for_location(Tukija::Cpuset *coreset, const Affinity::Location &loc) { - for (unsigned x = loc.xpos(); x < loc.xpos()+loc.width(); x++) + for (unsigned y = loc.ypos(); y < loc.ypos() + loc.height(); y++) { - unsigned kernel_cpu = platform_specific().kernel_cpu_id(Affinity::Location(x, y, loc.width(), loc.height())); - coreset->set(kernel_cpu); + for (unsigned x = loc.xpos(); x < loc.xpos() + loc.width(); x++) + { + unsigned kernel_cpu = platform_specific().kernel_cpu_id(Affinity::Location(x, y, loc.width(), loc.height())); + coreset->set(kernel_cpu); + } } - } } public: - Habitat_session_component(Genode::Region_map &rm, Genode::Affinity::Space const &space) : _local_rm(rm), _space(space) {} + Habitat_session_component(Genode::Session_label const &label, Genode::Rpc_entrypoint &session_ep, Genode::Region_map &rm, Genode::Ram_allocator &alloc, Genode::Affinity::Space const &space) : _local_rm(rm), _space(space), _label(label), _md_alloc(alloc, rm), _ep(session_ep) {} - void create_cell(Genode::Capability pd_cap, [[maybe_unused]] Genode::Affinity &affinity, Genode::uint16_t prio) override { + Ealan::Cell_capability create_cell(Genode::Capability pd_cap, [[maybe_unused]] Genode::Affinity &affinity, Genode::uint16_t prio, Genode::Session_label const &label) override { - Genode::Pd_session_client pd(pd_cap); - - Genode::Tukija_native_pd_client cell_pd_client(pd.native_pd()); - Genode::log("Attempting to create cell object for ", pd_cap); - Tukija::mword_t cell_pd_sel = cell_pd_client.sel(); - - Tukija::mword_t cip_phys = 0; - - Tukija::mword_t cip_virt = 0; - platform().region_alloc().alloc_aligned(4 * Tukija::PAGE_SIZE_BYTE, Tukija::PAGE_SIZE_LOG2).with_result( - [&](void *ptr) { cip_virt = reinterpret_cast(ptr); }, - [&](Genode::Range_allocator::Alloc_error) {}); - - if (Tukija::create_cell(cell_pd_sel, static_cast(prio), cip_phys, cip_virt)) - { - Genode::error("Failed to create cell"); - } - - Genode::log("Mapped CIP from ", reinterpret_cast(cip_phys), " to ", cip_virt); - //*cip = 0xff; - Tukija::Cip *cip = reinterpret_cast(cip_virt); - - _calculate_mask_for_location(&cip->cores_reserved, affinity.location()); - Genode::log("Cores reserved: ", cip->cores_reserved); + Ealan::Cell_component *cell = new (_md_alloc) Ealan::Cell_component(pd_cap, prio, affinity, _ep, _local_rm, label); + _managed_cells.insert(cell); + return cell->cap(); } };