Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions makefiles/app_dirs.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ tests/pkg/tflite-micro/external_modules/
tests/pkg/utensor/external_modules/
tests/pkg/wolfcrypt-ed25519-verify/
tests/sys/suit_manifest/native_flashpage/
tests/sys/event_thread_shared/external_modules/
tests/unittests/
5 changes: 5 additions & 0 deletions makefiles/utils/strings.mk
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ _is_equal = $(if $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))),1,)
version_is_greater_or_equal = $(or \
$(call _is_greater,$(call _padded_version,$1),$(call _padded_version,$2)),\
$(call _is_equal,$(call _padded_version,$1),$(call _padded_version,$2)))

# Get the maximum number of the natural numbers given as $1
# $1: A list of natural numbers separated by white space
# Return: The value of the highest natural number in $1
max_number = $(shell echo $1 | awk 'BEGIN{max=0} {for(i=1;i<=NF;i++){x=$$i; if (x > max){max = x}}} END{print max}')
8 changes: 8 additions & 0 deletions makefiles/utils/test-strings.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ test-version_is_greater_or_equal:
$(Q)test 1 = "$(call version_is_greater_or_equal,$(TEST_VERSION_4),$(TEST_VERSION_3))" || { echo ERROR: "$(TEST_VERSION_3)" \< "$(TEST_VERSION_4)"; exit 1; }
$(Q)test "" = "$(call version_is_greater_or_equal,$(TEST_VERSION_3),$(TEST_VERSION_4))" || { echo ERROR: Test should fail, "$(TEST_VERSION_4)" is not \< "$(TEST_VERSION_3)"; exit 1; }
$(Q)test "" = "$(call version_is_greater_or_equal,$(TEST_VERSION_1),$(TEST_VERSION_4))" || { echo ERROR: Test should fail, "$(TEST_VERSION_1)" is not \< "$(TEST_VERSION_4)"; exit 1; }

test-max_number:
$(Q)test "8" = "$(call max_number, 7 4 8 0 1 3)"
$(Q)test "42" = "$(call max_number, 42 4 8 0 1 3)"
$(Q)test "1337" = "$(call max_number, 42 4 8 0 1 1337)"
$(Q)test "0" = "$(call max_number, 0 0 0 0 0)"
$(Q)test "13" = "$(call max_number, 13)"
$(Q)test "0" = "$(call max_number,)"
4 changes: 4 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,7 @@ endif
ifneq (,$(filter unicoap,$(USEMODULE)))
include $(RIOTBASE)/sys/net/application_layer/unicoap/Makefile.include
endif

ifneq (,$(filter event,$(USEMODULE)))
include $(RIOTBASE)/sys/event/Makefile.include
endif
35 changes: 35 additions & 0 deletions sys/event/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
include $(RIOTMAKE)/utils/strings.mk

# This applies to all thread stacks
ifneq (, $(EVENT_THREAD_STACKSIZE_MIN))
EVENT_THREAD_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_STACKSIZE_MIN))
endif

ifeq (,$(filter event_thread_highest, $(USEMODULE)))
# No highest priority event thread, so the highest prio queue is handled by
# the same thread handling the medium priority queue. So we "trickle down"
# the requirements here
EVENT_THREAD_MEDIUM_STACKSIZE_MIN += $(EVENT_THREAD_HIGHEST_STACKSIZE_MIN)
else
ifneq (, $(EVENT_THREAD_HIGHEST_STACKSIZE_MIN))
EVENT_THREAD_HIGHEST_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_HIGHEST_STACKSIZE_MIN) $(EVENT_THREAD_STACKSIZE_MIN))
CFLAGS += -DEVENT_THREAD_HIGHEST_STACKSIZE=$(EVENT_THREAD_HIGHEST_STACKSIZE_MIN)
endif
endif

ifeq (,$(filter event_thread_medium, $(USEMODULE)))
# No medium priority event thread, so the medium prio queue is handled by
# the same thread handling the lowest priority queue. So we "trickle down"
# the requirements here
EVENT_THREAD_LOWEST_STACKSIZE_MIN += $(EVENT_THREAD_MEDIUM_STACKSIZE_MIN)
else
ifneq (, $(EVENT_THREAD_MEDIUM_STACKSIZE_MIN))
EVENT_THREAD_MEDIUM_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_MEDIUM_STACKSIZE_MIN) $(EVENT_THREAD_STACKSIZE_MIN))
CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE=$(EVENT_THREAD_MEDIUM_STACKSIZE_MIN)
endif
endif

ifneq (, $(EVENT_THREAD_LOWEST_STACKSIZE_MIN))
EVENT_THREAD_LOWEST_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_LOWEST_STACKSIZE_MIN) $(EVENT_THREAD_STACKSIZE_MIN))
CFLAGS += -DEVENT_THREAD_LOWEST_STACKSIZE=$(EVENT_THREAD_LOWEST_STACKSIZE_MIN)
endif
26 changes: 26 additions & 0 deletions sys/include/event/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@
* event queue gets its own thread. So higher priority events will always
* preempt events of lower priority in this case.
*
* Managing Stack Size Requirements
* --------------------------------
*
* A module using the medium priority event queue might require a certain
* minimum stack size, say 1024, to operate correctly. Instead of just adding
* `CFLAGS += -DDEVENT_THREAD_MEDIUM_STACKSIZE=1024`, it can instead add the
* following to its `Makefile.dep`:
*
* ```Makefile
* EVENT_THREAD_MEDIUM_STACKSIZE_MIN += 1024
* ```
*
* In the `Makefile.include` of `sys/event` the highest value of the minimum
* requirements declared by any module will be picked and added to the
* `CFLAGS`.
*
* @note `EVENT_THREAD_MEDIUM_STACKSIZE_MIN` and
* `EVENT_THREAD_HIGHEST_STACKSIZE_MIN` always apply to the thread
* managing the medium priority queue.
* @details E.g. without the module `event_thread_medium` the lowest priority
* and medium priority queues are both handled by the lowest priority
* even thread. In that case, `EVENT_THREAD_MEDIUM_STACKSIZE_MIN` would
* ensure a minimum thread statck size on the lowest priority even
* thread. With `event_thread_medium` in use, it would instead apply
* to the stack of the dedicated medium event queue thread.
*
* @{
*
* @file
Expand Down
4 changes: 4 additions & 0 deletions tests/build_system/utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ COMPILE_TESTS += test-uppercase
COMPILE_TESTS += test-uppercase_and_underscore
COMPILE_TESTS += test-version_is_greater
COMPILE_TESTS += test-version_is_greater_or_equal
COMPILE_TESTS += test-max_number

# Tests will be run both in the host machine and in `docker`
all: build-system-utils-tests
Expand Down Expand Up @@ -59,3 +60,6 @@ test-version_is_greater:

test-version_is_greater_or_equal:
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-version_is_greater_or_equal)

test-max_number:
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-max_number)
8 changes: 8 additions & 0 deletions tests/sys/event_thread_shared/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ include ../Makefile.sys_common

USEMODULE += event_thread

# Test that selecting event thread size works from the modules `Makefile.dep`
# work as expected by including a bunch of empty test module
EXTERNAL_MODULE_DIRS += external_modules
USEMODULE += test_module_a
USEMODULE += test_module_b
USEMODULE += test_module_c
USEMODULE += test_module_d

include $(RIOTBASE)/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EVENT_THREAD_HIGHEST_STACKSIZE_MIN += 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EVENT_THREAD_HIGHEST_STACKSIZE_MIN += 300
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EVENT_THREAD_HIGHEST_STACKSIZE_MIN += 567
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EVENT_THREAD_HIGHEST_STACKSIZE_MIN += 256
6 changes: 6 additions & 0 deletions tests/sys/event_thread_shared/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
* @}
*/

#include <assert.h>
#include <stdio.h>

#include "thread.h"
#include "event/thread.h"

static_assert(EVENT_THREAD_LOWEST_STACKSIZE == 567,
"Selecting highest of the minimum stack size requirements "
"declared via `EVENT_THREAD_HIGHEST_STACKSIZE_MIN += <num>` "
"must work correctly");

static void _handler_high(event_t *event) {
(void)event;
puts("high");
Expand Down
Loading