Skip to content

Commit

Permalink
core/thread: always use THREAD_CREATE_STACKTEST with DEVELHELP
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jul 29, 2024
1 parent 9ca9696 commit b1d3825
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
13 changes: 8 additions & 5 deletions core/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
* ----------------------------- | --------------------------------------------------
* @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually
* @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation
* @ref THREAD_CREATE_STACKTEST | measures the stack's memory usage
*
* Thread creation
* ===============
Expand Down Expand Up @@ -83,7 +82,7 @@
* int main(void)
* {
* thread_create(rcv_thread_stack, sizeof(rcv_thread_stack),
* THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
* THREAD_PRIORITY_MAIN - 1, 0,
* rcv_thread, NULL, "rcv_thread");
* }
* ~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -231,10 +230,13 @@ struct _thread {
#define THREAD_CREATE_WOUT_YIELD (4)

/**
* @brief Write markers into the thread's stack to measure stack usage (for
* debugging and profiling purposes)
* @brief Legacy flag kept for compatibility.
*
* @deprecated will be removed after 2025.07 release
*
* This is always enabled with `DEVELHELP=1` or `SCHED_TEST_STACK`.
*/
#define THREAD_CREATE_STACKTEST (8)
#define THREAD_CREATE_STACKTEST (0)
/** @} */

/**
Expand Down Expand Up @@ -456,6 +458,7 @@ static inline const char *thread_getname(kernel_pid_t pid)
* Only works if the stack is filled with canaries
* (`*((uintptr_t *)ptr) == (uintptr_t)ptr` for naturally aligned `ptr` within
* the stack).
* This is enabled if `DEVELHELP` or `SCHED_TEST_STACK` is set.
*
* @param[in] stack the stack you want to measure. Try
* `thread_get_stackstart(thread_get_active())`
Expand Down
23 changes: 8 additions & 15 deletions core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,14 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,

#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
|| defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE)
if (flags & THREAD_CREATE_STACKTEST) {
/* assign each int of the stack the value of it's address. Alignment
* has been handled above, so silence -Wcast-align */
uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize);
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;

while (stackp < stackmax) {
*stackp = (uintptr_t)stackp;
stackp++;
}
}
else {
/* create stack guard. Alignment has been handled above, so silence
* -Wcast-align */
*(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack;
/* assign each int of the stack the value of it's address. Alignment
* has been handled above, so silence -Wcast-align */
uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize);
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;

while (stackp < stackmax) {
*stackp = (uintptr_t)stackp;
stackp++;
}
#endif

Expand Down

0 comments on commit b1d3825

Please sign in to comment.