From 682d26c673d686115be2cdd0257b193b19514d22 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Mon, 27 Mar 2023 16:30:53 +0200 Subject: [PATCH] Added Genode::Env to MxTasking environment. --- src/mx/system/environment.h | 93 +++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/src/mx/system/environment.h b/src/mx/system/environment.h index f975a83..ce864ea 100644 --- a/src/mx/system/environment.h +++ b/src/mx/system/environment.h @@ -1,6 +1,10 @@ #pragma once - -#include +#include +#include +#include +#include +#include +#include namespace mx::system { /** @@ -8,20 +12,89 @@ namespace mx::system { */ class Environment { +private: + /** + * @brief Pointer to application's environment + * @details The application's environment grants access to core services of EalánOS, such as thread creation and memory allocation. + */ + Libc::Env *_env; + public: + Environment() = default; + + /** + * @brief Get Enviroment of current application + * + * @return Libc::Env& environment + */ + Libc::Env &getenv() { return *_env; } + + /** + * @brief Set libc environment for MxTasking + * @details + * @param env pointer to libc enviroment object + */ + void setenv(Libc::Env *env) { _env = env; } + + /** + * @brief Get the instance object + * + * @return Environment& singleton object of Environment + */ + static Environment &get_instance() + { + static Environment env; + return env; + } + + /** + * @brief Quick access to libc environment + * + * @return Libc::Env& + */ + static Libc::Env &env() { return Environment::get_instance().getenv(); } + + /** + * @brief Set the libc env object + * + * @details This method **must** be called before creating the MxTasking runtime, because the environment + * is vital for the initialization of the MxTasking runtime enviroment. + * @param env pointer to application's environment + */ + static void set_env(Libc::Env *env) { + Environment::get_instance().setenv(env); + } + + /* + * Access methods to core sessions of the libc enviroment, MxTasking is running in + */ + static Genode::Cpu_session &cpu() { return Environment::env().cpu(); } + static Genode::Ram_allocator &ram() { return Environment::env().ram(); } + static Genode::Region_map &rm() { return Environment::env().rm(); } + static Genode::Topo_session &topo() { return Environment::env().topo(); } + + /** + * @brief Convert integral core_id to location in the affinity space of the component + * + * @param core_id The core_id to convert + * @return Genode::Affinity::Location const& corresponding location in affinity space + */ + static Genode::Affinity::Location location(std::uint16_t core_id) { return cpu().affinity_space().location_of_index(core_id); } + + /** + * @brief Get NUMA node object for respective numa_id + * + * @param numa_id of Node to return + * @return Topology::Numa_region const& the corresponding node object + */ + static Topology::Numa_region node(std::uint8_t numa_id) { return topo().node_at_id(numa_id); } + /** * @return True, if NUMA balancing is enabled by the system. */ static bool is_numa_balancing_enabled() { - std::ifstream numa_balancing_file("/proc/sys/kernel/numa_balancing"); - auto is_enabled = std::int32_t{}; - if (numa_balancing_file >> is_enabled) - { - return !(is_enabled == 0); - } - - return true; + return false; } static constexpr auto is_sse2()