ealanos: Changed hello world example for MxTasking after downgrade.

This commit is contained in:
Michael Mueller
2025-06-03 15:34:08 +02:00
parent a69c53bfc9
commit 4308a3091b

View File

@@ -2,6 +2,7 @@
#include <cstddef>
#include <iostream>
#include <mx/tasking/runtime.h>
#include <mx/system/topology.h>
#include <libc/component.h>
@@ -11,12 +12,12 @@ public:
constexpr HelloWorldTask() = default;
~HelloWorldTask() override = default;
mx::tasking::TaskResult execute(const std::uint16_t core_id) override
mx::tasking::TaskResult execute(const std::uint16_t core_id, const std::uint16_t) override
{
std::cout << "Hello World" << std::endl;
//std::cout << "Hello World from worker " << core_id << std::endl;
Genode::log("Hello world from worker ", core_id, " on CPU ", mx::system::topology::core_id());
// Stop MxTasking runtime after this task.
return mx::tasking::TaskResult::make_stop(core_id);
return mx::tasking::TaskResult::make_null();
}
};
@@ -24,26 +25,31 @@ int mx_main(Libc::Env &env)
{
unsigned num_cores = env.cpu().affinity_space().total();
// Define which cores will be used (1 core here).
std::cout << "Creating coreset with " << num_cores << " cores" << std::endl;
const auto cores = mx::util::core_set::build(num_cores, mx::util::core_set::NUMAAware);
std::cout << "Created coreset" << std::endl;
{ // Scope for the MxTasking runtime.
std::size_t qouta = env.pd().avail_ram().value;
std::cout << "Remaining memory quota " << qouta << std::endl;
// Create a runtime for the given cores.
mx::tasking::runtime_guard _{env, true,cores};
mx::tasking::runtime_guard _{env, false,cores};
std::cout << "MxTasking initialized." << std::endl;
// Create an instance of the HelloWorldTask with the current core as first
// parameter. The core is required for memory allocation.
auto *hello_world_task = mx::tasking::runtime::new_task<HelloWorldTask>(cores.front());
for (const auto core : cores) {
auto *hello_world_task = mx::tasking::runtime::new_task<HelloWorldTask>(core);
std::cout << "task object is at " << static_cast<void*>(hello_world_task) << std::endl;
// Annotate the task to run on the first core.
hello_world_task->annotate(cores.front());
hello_world_task->annotate(core);
// Schedule the task.
mx::tasking::runtime::spawn(*hello_world_task);
}
std::cout << "Remaining memory quota " << env.pd().avail_ram().value << std::endl;
std::cout << "Consumed RAM qouta " << (qouta - env.pd().avail_ram().value) << std::endl;
}