Implemented system interface for Genode in MxTasking.

This commit is contained in:
Michael Mueller
2023-03-27 16:31:54 +02:00
parent 682d26c673
commit 137b914bb1

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <topo_session/topo_session.h>
#include <base/affinity.h>
#include <base/thread.h>
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <numa.h> #include "environment.h"
#include <sched.h>
#include <thread>
namespace mx::system { namespace mx::system {
/** /**
@@ -17,7 +20,13 @@ public:
/** /**
* @return Core where the caller is running. * @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. * Reads the NUMA region identifier of the given core.
@@ -25,16 +34,16 @@ public:
* @param core_id Id of the core. * @param core_id Id of the core.
* @return Id of the NUMA region the core stays in. * @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. * @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. * @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 } // namespace mx::system