mirror of
https://github.com/mmueller41/mxtasking.git
synced 2026-01-21 12:42:57 +01:00
Implemented system interface for Genode in MxTasking.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <topo_session/topo_session.h>
|
||||
#include <base/affinity.h>
|
||||
#include <base/thread.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <numa.h>
|
||||
#include <sched.h>
|
||||
#include <thread>
|
||||
#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
|
||||
Reference in New Issue
Block a user