From 316f12855afd0acd596fdae6afabdb3c6ea8f92d Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Mon, 7 Aug 2023 17:45:54 +0200 Subject: [PATCH] base: Added RPC to allow to change affinity of CPU and TOPO session after creation. This is necessary, as a cell might be pushed out of its original CPU region by Hoitaja. --- repos/base/include/cpu_session/client.h | 4 ++++ repos/base/include/cpu_session/connection.h | 2 +- repos/base/include/cpu_session/cpu_session.h | 9 ++++++++- repos/base/include/topo_session/client.h | 5 +++++ repos/base/include/topo_session/topo_session.h | 4 +++- repos/base/src/core/cpu_session_component.cc | 4 ++++ .../src/core/include/cpu_session_component.h | 1 + repos/base/src/core/include/topo_root.h | 6 +++++- .../src/core/include/topo_session_component.h | 13 ++++++++++--- repos/base/src/core/topo_session_component.cc | 18 ++++++++++++------ 10 files changed, 53 insertions(+), 13 deletions(-) diff --git a/repos/base/include/cpu_session/client.h b/repos/base/include/cpu_session/client.h index 60e65f801b..50b929c580 100644 --- a/repos/base/include/cpu_session/client.h +++ b/repos/base/include/cpu_session/client.h @@ -42,6 +42,10 @@ struct Genode::Cpu_session_client : Rpc_client Affinity::Space affinity_space() const override { return call(); } + void move(const Affinity::Location loc) override { + call(loc); + } + Dataspace_capability trace_control() override { return call(); } diff --git a/repos/base/include/cpu_session/connection.h b/repos/base/include/cpu_session/connection.h index ac0368abfd..865eb5c973 100644 --- a/repos/base/include/cpu_session/connection.h +++ b/repos/base/include/cpu_session/connection.h @@ -22,7 +22,7 @@ namespace Genode { struct Cpu_connection; } struct Genode::Cpu_connection : Connection, Cpu_session_client { - enum { RAM_QUOTA = 36*1024 }; + enum { RAM_QUOTA = 72*1024 }; /** * Constructor diff --git a/repos/base/include/cpu_session/cpu_session.h b/repos/base/include/cpu_session/cpu_session.h index 6297d5eadf..6a5b11c016 100644 --- a/repos/base/include/cpu_session/cpu_session.h +++ b/repos/base/include/cpu_session/cpu_session.h @@ -138,6 +138,12 @@ struct Genode::Cpu_session : Session */ virtual Affinity::Space affinity_space() const = 0; + /** + * @brief Update affinity location of this CPU session + * + */ + virtual void move(const Genode::Affinity::Location ) = 0; + /** * Translate generic priority value to kernel-specific priority levels * @@ -249,6 +255,7 @@ struct Genode::Cpu_session : Session GENODE_RPC(Rpc_migrate_thread, void, migrate_thread, Thread_capability, Affinity::Location); GENODE_RPC(Rpc_exception_sigh, void, exception_sigh, Signal_context_capability); GENODE_RPC(Rpc_affinity_space, Affinity::Space, affinity_space); + GENODE_RPC(Rpc_move, void, move, Affinity::Location); GENODE_RPC(Rpc_trace_control, Dataspace_capability, trace_control); GENODE_RPC(Rpc_ref_account, int, ref_account, Cpu_session_capability); GENODE_RPC(Rpc_transfer_quota, int, transfer_quota, Cpu_session_capability, size_t); @@ -257,7 +264,7 @@ struct Genode::Cpu_session : Session GENODE_RPC_INTERFACE(Rpc_create_thread, Rpc_kill_thread, Rpc_exception_sigh, Rpc_affinity_space, Rpc_trace_control, Rpc_ref_account, - Rpc_transfer_quota, Rpc_quota, Rpc_native_cpu, Rpc_migrate_thread); + Rpc_transfer_quota, Rpc_quota, Rpc_native_cpu, Rpc_migrate_thread, Rpc_move); }; diff --git a/repos/base/include/topo_session/client.h b/repos/base/include/topo_session/client.h index 35d00fcbb8..a092597310 100644 --- a/repos/base/include/topo_session/client.h +++ b/repos/base/include/topo_session/client.h @@ -41,4 +41,9 @@ struct Genode::Topo_session_client : Rpc_client unsigned node_count() override { return call(); } + + void reconstruct(const Affinity affinity) override + { + call(affinity); + } }; \ No newline at end of file diff --git a/repos/base/include/topo_session/topo_session.h b/repos/base/include/topo_session/topo_session.h index d6f90b9d06..8030df45c1 100644 --- a/repos/base/include/topo_session/topo_session.h +++ b/repos/base/include/topo_session/topo_session.h @@ -49,10 +49,12 @@ struct Genode::Topo_session : Session virtual Topology::Numa_region node_affinity_of(Affinity::Location const &) = 0; virtual Topology::Numa_region node_at_id(unsigned node_id) = 0; virtual unsigned node_count() = 0; + virtual void reconstruct(const Affinity) = 0; GENODE_RPC(Rpc_node_affinity, Topology::Numa_region, node_affinity_of, Affinity::Location const &); GENODE_RPC(Rpc_node_id, Topology::Numa_region, node_at_id, unsigned); GENODE_RPC(Rpc_node_count, unsigned, node_count); + GENODE_RPC(Rpc_reconstruct, void, reconstruct, Affinity); - GENODE_RPC_INTERFACE(Rpc_node_affinity, Rpc_node_id, Rpc_node_count); + GENODE_RPC_INTERFACE(Rpc_node_affinity, Rpc_node_id, Rpc_node_count, Rpc_reconstruct); }; \ No newline at end of file diff --git a/repos/base/src/core/cpu_session_component.cc b/repos/base/src/core/cpu_session_component.cc index 760cacbb87..49e7177aec 100644 --- a/repos/base/src/core/cpu_session_component.cc +++ b/repos/base/src/core/cpu_session_component.cc @@ -171,6 +171,10 @@ Affinity::Space Cpu_session_component::affinity_space() const return Affinity::Space(_location.width(), _location.height()); } +void Cpu_session_component::move(const Affinity::Location destination) +{ + _location = destination; +} Dataspace_capability Cpu_session_component::trace_control() { diff --git a/repos/base/src/core/include/cpu_session_component.h b/repos/base/src/core/include/cpu_session_component.h index 1b904ab3bf..44cdd1421c 100644 --- a/repos/base/src/core/include/cpu_session_component.h +++ b/repos/base/src/core/include/cpu_session_component.h @@ -172,6 +172,7 @@ class Genode::Cpu_session_component : public Session_object, void migrate_thread(Thread_capability, Affinity::Location) override; void exception_sigh(Signal_context_capability) override; Affinity::Space affinity_space() const override; + void move(const Affinity::Location) override; Dataspace_capability trace_control() override; int ref_account(Cpu_session_capability c) override; int transfer_quota(Cpu_session_capability, size_t) override; diff --git a/repos/base/src/core/include/topo_root.h b/repos/base/src/core/include/topo_root.h index 9c7c5978b7..52e369d8eb 100644 --- a/repos/base/src/core/include/topo_root.h +++ b/repos/base/src/core/include/topo_root.h @@ -19,6 +19,8 @@ #include +#include + namespace Genode { class Topo_root : public Root_component @@ -35,8 +37,10 @@ namespace Genode { if (ram_quota < Trace::Control_area::SIZE) throw Insufficient_ram_quota(); - if (!affinity.valid()) + if (!affinity.valid()) { + log("Location ", affinity.location(), " not within space ", affinity.space()); throw Service_denied(); + } return new (md_alloc()) Topo_session_component(*this->ep(), diff --git a/repos/base/src/core/include/topo_session_component.h b/repos/base/src/core/include/topo_session_component.h index e86ffd7665..20699f7193 100644 --- a/repos/base/src/core/include/topo_session_component.h +++ b/repos/base/src/core/include/topo_session_component.h @@ -30,7 +30,7 @@ namespace Genode { class Genode::Topo_session_component : public Session_object { private: - Genode::Affinity &_affinity; + Genode::Affinity _affinity; Sliced_heap _md_alloc; Topology::Numa_region _node_affinities[Genode::Platform::MAX_SUPPORTED_CPUS][Genode::Platform::MAX_SUPPORTED_CPUS]; @@ -44,9 +44,10 @@ class Genode::Topo_session_component : public Session_object Diag const &diag, Ram_allocator &ram_alloc, Region_map &local_rm, - Affinity &affinity + Affinity affinity ); + void construct(); /** * @brief Topology session interface @@ -65,5 +66,11 @@ class Genode::Topo_session_component : public Session_object unsigned node_count() override { return _node_count; - } + } + + void reconstruct(Affinity affinity) override + { + _affinity = affinity; + construct(); + } }; diff --git a/repos/base/src/core/topo_session_component.cc b/repos/base/src/core/topo_session_component.cc index f4caaf3fd4..42102eb3bd 100644 --- a/repos/base/src/core/topo_session_component.cc +++ b/repos/base/src/core/topo_session_component.cc @@ -25,19 +25,24 @@ Topo_session_component::Topo_session_component(Rpc_entrypoint &session_ep, Diag const &diag, Ram_allocator &ram_alloc, Region_map &local_rm, - Affinity &affinity) + Affinity affinity) : Session_object(session_ep, resources, label, diag), _affinity(affinity), _md_alloc(ram_alloc, local_rm), _node_count(0) { - Affinity::Location location = affinity.location(); + construct(); +} + +void Topo_session_component::construct() +{ + Affinity::Location location = _affinity.location(); const unsigned height = location.height(); unsigned width = location.width(); unsigned curr_node_id = 0; Topology::Numa_region *node_created = new (_md_alloc) Topology::Numa_region[64](); - Genode::log("[", label, "] Creating new topology model of size ", width, "x", height); + Genode::log("[", label(), "] Creating new topology model of size ", width, "x", height); for (unsigned x = 0; x < width; x++) { @@ -53,14 +58,14 @@ Topo_session_component::Topo_session_component(Rpc_entrypoint &session_ep, unsigned cpu_id = platform_specific().kernel_cpu_id(loc); unsigned native_id = platform_specific().domain_of_cpu(cpu_id); - log("[", label, "] CPU (", x, "x", y, ") is native CPU ", cpu_id, " on node ", native_id); + log("[", label(), "] CPU (", x, "x", y, ") is native CPU ", cpu_id, " on node ", native_id); if (node_created[native_id].core_count() == 0) { _nodes[curr_node_id] = _node_affinities[x][y] = Topology::Numa_region(curr_node_id, native_id); _node_affinities[x][y].increment_core_count(); node_created[native_id] = _node_affinities[x][y]; - log("[", label, "] Found new native NUMA region ", native_id, " for CPU (", x, "x", y, ")"); + log("[", label(), "] Found new native NUMA region ", native_id, " for CPU (", x, "x", y, ")"); _node_count++; curr_node_id++; } @@ -71,4 +76,5 @@ Topo_session_component::Topo_session_component(Rpc_entrypoint &session_ep, } } } -} + +} \ No newline at end of file