Skip to content

Commit

Permalink
core/thread: introduce THREAD_CREATE_NO_STACKTEST
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jul 18, 2024
1 parent b26de46 commit 992dfe5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
16 changes: 12 additions & 4 deletions core/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
* In addition to the priority, flags can be used when creating a thread to
* alter the thread's behavior after creation. The following flags are available:
*
* Flags | Description
* ----------------------------- | --------------------------------------------------
* @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
* Flags | Description
* ------------------------------ | --------------------------------------------------
* @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_NO_STACKTEST| measures the stack's memory usage
*
* Thread creation
* ===============
Expand Down Expand Up @@ -229,6 +230,13 @@ struct _thread {
*/
#define THREAD_CREATE_WOUT_YIELD (4)

/**
* @brief Never write markers into the thread's stack to measure stack usage
*
* This flag is ignored when DEVELHELP or SCHED_TEST_STACK is not enabled
*/
#define THREAD_CREATE_NO_STACKTEST (8)

/**
* @brief Legacy flag kept for compatibility.
*
Expand Down
23 changes: 15 additions & 8 deletions core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,21 @@ 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)
/* 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++;
if (flags & THREAD_CREATE_NO_STACKTEST) {
/* create stack guard. Alignment has been handled above, so silence
* -Wcast-align */
*(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack;
}
else {
/* 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 992dfe5

Please sign in to comment.