Merge branch 'yritys' into feature/cws

This commit is contained in:
Michael Mueller
2024-07-30 16:07:16 +02:00
7 changed files with 64 additions and 3 deletions

View File

@@ -296,7 +296,7 @@ public:
} }
} }
for (const auto core_id : core_set) for (auto core_id = 0; core_id < system::topology::count_cores(); ++core_id)
{ {
const auto node_id = system::topology::node_id(core_id); const auto node_id = system::topology::node_id(core_id);
_core_heaps[core_id] = CoreHeap<S>{&_processor_heaps[node_id]}; _core_heaps[core_id] = CoreHeap<S>{&_processor_heaps[node_id]};

View File

@@ -0,0 +1,14 @@
#include "environment.h"
#include <mx/util/core_set.h>
using namespace mx::system;
void Environment::set_cores(mx::util::core_set *core_set)
{
system::Environment::get_instance()._coreset = core_set;
}
mx::util::core_set &Environment::cores()
{
return *Environment::get_instance()._coreset;
}

View File

@@ -6,6 +6,9 @@
#include <topo_session/node.h> #include <topo_session/node.h>
#include <cstdint> #include <cstdint>
namespace mx::util {
class core_set;
}
namespace mx::system { namespace mx::system {
/** /**
* Encapsulates functionality of the (Linux) system. * Encapsulates functionality of the (Linux) system.
@@ -18,6 +21,7 @@ private:
* @details The application's environment grants access to core services of EalánOS, such as thread creation and memory allocation. * @details The application's environment grants access to core services of EalánOS, such as thread creation and memory allocation.
*/ */
Libc::Env *_env; Libc::Env *_env;
util::core_set *_coreset;
public: public:
Environment() = default; Environment() = default;
@@ -36,6 +40,17 @@ public:
*/ */
void setenv(Libc::Env *env) { _env = env; } void setenv(Libc::Env *env) { _env = env; }
/**
* @brief Set core set to be used by memory allocators and scheduler
* @param core_set the core_set to use
*/
static void set_cores(util::core_set *core_set);
/**
* @brief returns the core set representing the physical environment MxTasking is running in
*/
static util::core_set &cores();
/** /**
* @brief Get the instance object * @brief Get the instance object
* *
@@ -90,7 +105,7 @@ public:
* @return Topology::Numa_region const& the corresponding node object * @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); } 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. * @return True, if NUMA balancing is enabled by the system.
*/ */

View File

@@ -73,7 +73,7 @@ public:
{ {
_task_allocator.reset(new ( _task_allocator.reset(new (
memory::GlobalHeap::allocate_cache_line_aligned(sizeof(memory::fixed::Allocator<config::task_size()>))) memory::GlobalHeap::allocate_cache_line_aligned(sizeof(memory::fixed::Allocator<config::task_size()>)))
memory::fixed::Allocator<config::task_size()>(core_set)); memory::fixed::Allocator<config::task_size()>(system::Environment::cores()));
} }
// Create a new scheduler. // Create a new scheduler.

14
src/mx/util/bits.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
namespace mx::util {
inline long int bit_scan_forward(std::uint64_t val)
{
if (!val)
return -1;
asm volatile("bsf %1, %0" : "=r"(val) : "rm"(val));
return val;
}
}

View File

@@ -43,6 +43,21 @@ core_set core_set::build(std::uint16_t cores, const Order order)
return core_set; return core_set;
} }
core_set core_set::build(std::uint64_t *core_mask, std::uint16_t count)
{
core_set core_set;
for (int c = 0; c < count; ++count)
{
std::bitset<tasking::config::max_cores()> mask{core_mask[c]};
long core = 0;
while ((core = util::bit_scan_forward(mask.to_ulong())) != -1) {
mask.reset(core);
core_set.emplace_back(core);
}
}
}
namespace mx::util { namespace mx::util {
std::ostream &operator<<(std::ostream &stream, const core_set &core_set) std::ostream &operator<<(std::ostream &stream, const core_set &core_set)
{ {

View File

@@ -8,6 +8,7 @@
#include <mx/system/topology.h> #include <mx/system/topology.h>
#include <mx/tasking/config.h> #include <mx/tasking/config.h>
#include <ostream> #include <ostream>
#include <mx/util/bits.h>
namespace mx::util { namespace mx::util {
/** /**
@@ -91,6 +92,8 @@ public:
*/ */
static core_set build(std::uint16_t cores, Order order = Ascending); static core_set build(std::uint16_t cores, Order order = Ascending);
static core_set build(std::uint64_t *core_mask, std::uint16_t count);
bool operator==(const core_set &other) const noexcept bool operator==(const core_set &other) const noexcept
{ {
return _core_identifier == other._core_identifier && _size == other._size && _numa_nodes == other._numa_nodes; return _core_identifier == other._core_identifier && _size == other._size && _numa_nodes == other._numa_nodes;