mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
ealanos: Changed hello world example for MxTasking after downgrade.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mx/tasking/runtime.h>
|
#include <mx/tasking/runtime.h>
|
||||||
|
#include <mx/system/topology.h>
|
||||||
|
|
||||||
#include <libc/component.h>
|
#include <libc/component.h>
|
||||||
|
|
||||||
@@ -11,39 +12,44 @@ public:
|
|||||||
constexpr HelloWorldTask() = default;
|
constexpr HelloWorldTask() = default;
|
||||||
~HelloWorldTask() override = 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.
|
// Stop MxTasking runtime after this task.
|
||||||
return mx::tasking::TaskResult::make_stop(core_id);
|
return mx::tasking::TaskResult::make_null();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int mx_main(Libc::Env &env)
|
int mx_main(Libc::Env &env)
|
||||||
{
|
{
|
||||||
unsigned num_cores = env.cpu().affinity_space().total();
|
unsigned num_cores = env.cpu().affinity_space().total();
|
||||||
// Define which cores will be used (1 core here).
|
// 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);
|
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.
|
{ // Scope for the MxTasking runtime.
|
||||||
|
|
||||||
std::size_t qouta = env.pd().avail_ram().value;
|
std::size_t qouta = env.pd().avail_ram().value;
|
||||||
std::cout << "Remaining memory quota " << qouta << std::endl;
|
std::cout << "Remaining memory quota " << qouta << std::endl;
|
||||||
// Create a runtime for the given cores.
|
// 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;
|
std::cout << "MxTasking initialized." << std::endl;
|
||||||
// Create an instance of the HelloWorldTask with the current core as first
|
// Create an instance of the HelloWorldTask with the current core as first
|
||||||
// parameter. The core is required for memory allocation.
|
// 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;
|
std::cout << "task object is at " << static_cast<void*>(hello_world_task) << std::endl;
|
||||||
// Annotate the task to run on the first core.
|
// Annotate the task to run on the first core.
|
||||||
hello_world_task->annotate(cores.front());
|
hello_world_task->annotate(core);
|
||||||
|
|
||||||
// Schedule the task.
|
// Schedule the task.
|
||||||
mx::tasking::runtime::spawn(*hello_world_task);
|
mx::tasking::runtime::spawn(*hello_world_task);
|
||||||
|
}
|
||||||
std::cout << "Remaining memory quota " << env.pd().avail_ram().value << std::endl;
|
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;
|
std::cout << "Consumed RAM qouta " << (qouta - env.pd().avail_ram().value) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user