Skip to content

sys/event: manage event thread size via build system#21941

Merged
benpicco merged 3 commits intoRIOT-OS:masterfrom
maribu:sys/event/thread-stack-size-build-system-integration
Dec 9, 2025
Merged

sys/event: manage event thread size via build system#21941
benpicco merged 3 commits intoRIOT-OS:masterfrom
maribu:sys/event/thread-stack-size-build-system-integration

Conversation

@maribu
Copy link
Copy Markdown
Member

@maribu maribu commented Dec 8, 2025

Contribution description

This adds a mechanism for modules to declare requirements on the thread stack size in their Makefile.dep and let the build system then override the default stack size, if any requirements are declared.

The motivation is to allow multiple modules to have special requirements without causing conflicts, as just adding the following to their Makefile.include would do:

CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE=<MAGIC_NUMBER>

Instead, the new mechanism would work by having them both declare in their Makefile.dep:

EVENT_THREAD_MEDIUM_STACKSIZE_MIN +=

The build system then picks the maximum number in EVENT_THREAD_MEDIUM_STACKSIZE_MIN and exposes this as stack size, if any module did declare a minimum requirement.

Testing procedure

The test in tests/sys/event_thread_shared has been extended to test correct passing of the stack size value at compile time. So a green CI would be sufficient.

Issues/PRs references

None

This can be used to get the highest value out of a list of numeric
numbers in a Makefile variable separated by whitespace.
@maribu maribu requested a review from benpicco December 8, 2025 14:54
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 8, 2025
@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: build system Area: Build system Area: sys Area: System labels Dec 8, 2025
@mguetschow mguetschow changed the title makefiles: add $(call max_number, <NUMS>) shell function sys/event: manage event thread size via build system Dec 8, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Dec 8, 2025

Murdock results

✔️ PASSED

37eb213 tests/sys/event_thread_shared: test stack size handling

Success Failures Total Runtime
10947 0 10949 08m:52s

Artifacts

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Dec 8, 2025

I defused the footgun with potential confusion of event thread names and event queue names.

E.g. if event_thread is in use, we only have the lowest prio event thread handling all three event queues (but handling the event queues in the order of their priorities).

I think a module posting to EVENT_PRIO_MEDIUM rightfully may expect that EVENT_THREAD_MEDIUM_STACKSIZE_MIN += 1024 would ensure that the thread handling EVENT_PRIO_MEDIUM has a stack size of at least 1024. With new change this is the case, even when the medium queue is handled by the same thread as EVENT_PRIO_LOWEST.

Copy link
Copy Markdown
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

That is a really nice addition!

maribu and others added 2 commits December 9, 2025 13:50
This adds a mechanism for modules to declare requirements on the thread
stack size in their `Makefile.dep` and let the build system then
override the default stack size, if any requirements are declared.

The motivation is to allow multiple modules to have special requirements
without causing conflicts, as just adding the following to their
`Makefile.include` would do:

```Makefile
CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE=<MAGIC_NUMBER>
```

Instead, the new mechanism would work by having them both declare in
their `Makefile.dep`:

```Makefile
EVENT_THREAD_MEDIUM_STACKSIZE_MIN +=
```

The build system then picks the maximum number in
`EVENT_THREAD_MEDIUM_STACKSIZE_MIN` and exposes this as stack size, if
any module did declare a minimum requirement.

Co-authored-by: benpicco <[email protected]>
This adds a simple integration test for declaring the stack size
requirements in modules.
@maribu maribu force-pushed the sys/event/thread-stack-size-build-system-integration branch from 2db5023 to 37eb213 Compare December 9, 2025 12:51
@maribu maribu enabled auto-merge December 9, 2025 12:51
@maribu maribu added this pull request to the merge queue Dec 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 9, 2025
@benpicco benpicco added this pull request to the merge queue Dec 9, 2025
Merged via the queue into RIOT-OS:master with commit b1611ae Dec 9, 2025
25 checks passed
@maribu maribu deleted the sys/event/thread-stack-size-build-system-integration branch December 15, 2025 07:53
@leandrolanzieri leandrolanzieri added this to the Release 2026.01 milestone Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants