Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fiber] Adds a fiber processing library #439

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Erik Henriksson
* Copyright (c) 2021, Christopher Durand
*
* This file is part of the modm project.
*
Expand All @@ -14,7 +15,7 @@
modm_extern_c int
main(void);

modm::fiber::Stack<2048> main_stack;
modm::fiber::Stack<{{ main_fiber_stack_size }}> main_stack;
modm::Fiber main_fiber(main_stack, &main);

modm_extern_c void
Expand Down
12 changes: 11 additions & 1 deletion src/modm/processing/fiber/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020, Erik Henriksson
# Copyright (c) 2021, Christopher Durand
#
# This file is part of the modm project.
#
Expand All @@ -20,19 +21,28 @@ def prepare(module, options):
# module.depends(":architecture:assert")
# if options[":target"].identifier["platform"] in ["sam", "stm32"]:
# module.depends(":cmsis:device")

module.add_option(
NumericOption(
name="main_fiber_stack_size",
description="Stack size of fiber running main()",
minimum=2 ** 8,
maximum=2 ** 16,
default=2048))
return True

def build(env):
core = env[":target"].get_driver("core")["type"]

env.substitutions["main_fiber_stack_size"] = env["main_fiber_stack_size"]
env.outbasepath = "modm/src/modm/processing/fiber"
env.copy("../fiber.hpp")
env.copy("fiber.hpp")
env.copy("fiber.cpp")
env.copy("fiber_impl.hpp")
env.copy("context.hpp")
env.copy("context.cpp")
env.copy("fiber_main.cpp")
env.template("fiber_main.cpp.in")

if core.startswith("cortex-m0"):
env.copy("context_cortex_m0.cpp")
Expand Down
2 changes: 1 addition & 1 deletion test/all/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def run(self):
lbuild_command += ["avr.xml"]
shutil.copyfile("avr.cpp", os.path.join(tempdir, "main.cpp"))
else:
lbuild_command += ["cortex-m.xml", "-D:::main_stack_size=512"]
lbuild_command += ["cortex-m.xml", "-D:::main_stack_size=512", "-D:::main_fiber_stack_size=512"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was kinda intended to reuse the main_stack_size, since that is now ignored (since there is no more non-fiber main()).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's ignored. Isn't there still a main stack where the ISRs execute and all code before fibers run?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at least on Cortex-M, AVRs don't have that option…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only thought about cortex-m. There is hosted as well and potential other platforms we might support in the future, so this has to go to some platform specific setting. It is still useful to be able to configure both stack sizes on cortex-m. What do you suggest?

Copy link
Member

@salkinium salkinium Jul 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm uncertain about this feature, since we cannot make AVR and hosted main a fiber, since we don't control how their main() is called. It would be inconsistent and confusing if the main function is a fiber only on Cortex-M. The only issue is when modm::yield() is called before the scheduler is initialized, but perhaps we can just spin in that case or modm_assert on it. I would remove the main fiber and make everything explicit, even if it will require refactoring some examples in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure as well and would opt for consistency and removing the main fiber. That would also have the benefit of improved backwards compatibility for existing code with tiny 2-4kB RAM devices where splitting the stack to main + main fiber stack could be problematic.

docs generation is still broken: Error generating documentation for device at90can64-16mu: 'NoneType' object is not subscriptable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens when lbuild has an error, usually when module dependencies are not satifed. I need to improve error reporting here…

shutil.copyfile("cortex-m.cpp", os.path.join(tempdir, "main.cpp"))

if self.cache_dir:
Expand Down