From 142ef47861aca97afa16b87fbf23bdf51101f2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Wed, 6 Jul 2022 15:32:47 +0200 Subject: [PATCH] Added port of MxTasking with sample application. --- repos/mml/lib/import/import-mxtasking.mk | 1 + repos/mml/lib/mk/mxtasking.mk | 17 +++++++ repos/mml/ports/mxtasking.port | 11 ++++ repos/mml/run/hello_mxtask.run | 43 ++++++++++++++++ repos/mml/src/app/hello_mxtask/main.cc | 64 ++++++++++++++++++++++++ repos/mml/src/app/hello_mxtask/target.mk | 4 ++ 6 files changed, 140 insertions(+) create mode 100644 repos/mml/lib/import/import-mxtasking.mk create mode 100644 repos/mml/lib/mk/mxtasking.mk create mode 100644 repos/mml/ports/mxtasking.port create mode 100644 repos/mml/run/hello_mxtask.run create mode 100644 repos/mml/src/app/hello_mxtask/main.cc create mode 100644 repos/mml/src/app/hello_mxtask/target.mk diff --git a/repos/mml/lib/import/import-mxtasking.mk b/repos/mml/lib/import/import-mxtasking.mk new file mode 100644 index 0000000000..5e23bf6b90 --- /dev/null +++ b/repos/mml/lib/import/import-mxtasking.mk @@ -0,0 +1 @@ +INC_DIR += $(call select_from_ports,mxtasking)/include/mxtasking \ No newline at end of file diff --git a/repos/mml/lib/mk/mxtasking.mk b/repos/mml/lib/mk/mxtasking.mk new file mode 100644 index 0000000000..7587beb175 --- /dev/null +++ b/repos/mml/lib/mk/mxtasking.mk @@ -0,0 +1,17 @@ +MXTASKING_DIR := $(call select_from_ports,mxtasking)/src/lib/mxtasking + +vpath %.cpp $(MXTASKING_DIR)/src/mx + +INC_DIR += $(MXTASKING_DIR)/src/mx $(MXTASKING_DIR)/lib +vpath %.h ${INC_DIR} + +CC_OPT += -pedantic -Wall -Wextra -Werror \ + -Wno-invalid-offsetof -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization \ + -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Woverloaded-virtual \ + -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef \ + -Wno-unused -Wold-style-cast -Wno-uninitialized -O1 -g3 + +CC_OPT += $(addprefix -I ,$(INC_DIR)) + +LIBS += libm libc stdcxx +SHARED_LIB = yes \ No newline at end of file diff --git a/repos/mml/ports/mxtasking.port b/repos/mml/ports/mxtasking.port new file mode 100644 index 0000000000..e7a3b1c46c --- /dev/null +++ b/repos/mml/ports/mxtasking.port @@ -0,0 +1,11 @@ +LICENSE := MIT +VERSION := 0.1 +DOWNLOADS := mxtasking.archive + +URL(mxtasking) := https://github.com/mmmueller41/mxtasking.git +SHA(mxtasking := +DIR(mxtasking) := src/lib/mxtasking +DIRS := include/mxtasking +DIR_CONTENT(include/mxtasking) := $(addprefix src/lib/mxtasking/,*.h) + +#PATCHES := \ No newline at end of file diff --git a/repos/mml/run/hello_mxtask.run b/repos/mml/run/hello_mxtask.run new file mode 100644 index 0000000000..6568a0c23f --- /dev/null +++ b/repos/mml/run/hello_mxtask.run @@ -0,0 +1,43 @@ +build "core init timer app/hello_mxtask" +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} +set boot_modules { + core init timer vfs.lib.so ld.lib.so libm.lib.so libc.lib.so stdcxx.lib.so mxtasking.lib.so hello_mxtask +} +build_boot_image $boot_modules +append qemu_args "-nographic -m 64" diff --git a/repos/mml/src/app/hello_mxtask/main.cc b/repos/mml/src/app/hello_mxtask/main.cc new file mode 100644 index 0000000000..4280a1d6af --- /dev/null +++ b/repos/mml/src/app/hello_mxtask/main.cc @@ -0,0 +1,64 @@ +/* Hello world appication from https://github.com/jmuehlig/mxtasking/src/application/hello_world */ +/* MIT License + +Copyright (c) 2021 Jan Mühlig +Modified by Michael Müller for use on Genode OS. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. */ + +#include +#include + +class HelloWorldTask : public mx::tasking::TaskInterface +{ +public: + constexpr HelloWorldTask() = default; + ~HelloWorldTask() override = default; + + mx::tasking::TaskResult execute(const std::uint16_t /*core_id*/, const std::uint16_t /*channel_id*/) override + { + std::cout << "Hello World" << std::endl; + + // Stop MxTasking runtime after this task. + return mx::tasking::TaskResult::make_stop(); + } +}; + +void Component::construct(Genode::Env &env) +{ + // Define which cores will be used (1 core here). + const auto cores = mx::util::core_set::build(1); + + mx::system::Environment::env = env; + { // Scope for the MxTasking runtime. + + // Create a runtime for the given cores. + mx::tasking::runtime_guard _{cores}; + + // 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(cores.front()); + + // Annotate the task to run on the first core. + hello_world_task->annotate(cores.front()); + + // Schedule the task. + mx::tasking::runtime::spawn(*hello_world_task); + } +} \ No newline at end of file diff --git a/repos/mml/src/app/hello_mxtask/target.mk b/repos/mml/src/app/hello_mxtask/target.mk new file mode 100644 index 0000000000..5c66b5719a --- /dev/null +++ b/repos/mml/src/app/hello_mxtask/target.mk @@ -0,0 +1,4 @@ +TARGET = hello_mxtask +SRC_CC = main.cc +LIBS += base libm libc stdcxx mxtasking +CXXFLAGS += -Wno-error \ No newline at end of file