Skip to content

Conversation

@peter-mitsis
Copy link
Contributor

This set of commits adds support for thread runtime stack safety. It has been divided into two parts--kernel support and thread analyzer integration.

On the kernel side, this extends the idea of the existing k_thread_stack_space_get() to invoke a caller defined handler/callback if the amount of unused stack space is less than a configured threshold. Two new stack checking routines have been added: k_thread_runtime_stack_safety_full_check() and k_thread_runtime_stack_safety_threshold_check(). The latter performs an abbreviated check on the stack that is limited to the configured threshold.

On the thread analyzer integration side, when enabled it replaces the stack check with the full stack safety check. The default handler can be replaced at runtime by calling thread_analyzer_stack_safety_handler_set(). This allows a developer to leverage the existing analyzer to periodically scan stack usages and act upon them accordingly if their configured thresholds have been crossed (log the incident, suspend a thread, abort a thread, reboot the system, ...).

@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: Kernel area: Debugging labels Oct 24, 2025
Adds support for thread runtime stack safety. This kernel feature
allows a developer to run enhanced stack usage checks on threads
such that if the amount of unused stack space drops below a thread's
configured threshold, it will invoke a custom handler/callback.

This can be used by monitoring software to log warnings, suspend
or abort threads, or even reboot the system.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This updates the thread analyzer to optionally leverage the kernel's
thread runtime stack safety infrastructure to act upon threads whose
unused stack space has fallen below their configured thresholds.

By default, the thread analyzer merely reports what it has found.
However, a developer can override this behavior with a custom handler
using thread_analyzer_stack_safety_handler_set().

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Adds stack safety to thread analyzer test case.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
@peter-mitsis peter-mitsis force-pushed the pmitsis-runtime-stack-safety branch from 5605720 to 2d02110 Compare October 27, 2025 20:16
@sonarqubecloud
Copy link

@fabiobaltieri fabiobaltieri merged commit 599e3bb into zephyrproject-rtos:main Nov 25, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Debugging area: Kernel area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants