diff --git a/src/mx/system/topology.h b/src/mx/system/topology.h index 43c155f..ecd84ff 100644 --- a/src/mx/system/topology.h +++ b/src/mx/system/topology.h @@ -1,10 +1,13 @@ #pragma once +#include +#include +#include + #include #include -#include -#include -#include +#include "environment.h" + namespace mx::system { /** @@ -17,7 +20,13 @@ public: /** * @return Core where the caller is running. */ - static std::uint16_t core_id() { return std::uint16_t(sched_getcpu()); } + static std::uint16_t core_id() + { + Genode::Affinity::Location loc = Genode::Thread::myself()->affinity(); + unsigned width = Environment::cpu().affinity_space().width(); + + return std::uint16_t(loc.xpos() + loc.ypos() * width); + } /** * Reads the NUMA region identifier of the given core. @@ -25,16 +34,16 @@ public: * @param core_id Id of the core. * @return Id of the NUMA region the core stays in. */ - static std::uint8_t node_id(const std::uint16_t core_id) { return std::max(numa_node_of_cpu(core_id), 0); } + static std::uint8_t node_id(const std::uint16_t core_id) { return std::uint8_t(Environment::topo().node_affinity_of(Environment::location(core_id)).id()); } /** * @return The greatest NUMA region identifier. */ - static std::uint8_t max_node_id() { return std::uint8_t(numa_max_node()); } + static std::uint8_t max_node_id() { return std::uint8_t(Environment::topo().node_count()-1); } /** * @return Number of available cores. */ - static std::uint16_t count_cores() { return std::uint16_t(std::thread::hardware_concurrency()); } + static std::uint16_t count_cores() { return std::uint16_t(Environment::cpu().affinity_space().total()); } }; } // namespace mx::system \ No newline at end of file