1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

core: add support for test_utils_print_stack_usage

- activate THREAD_CREATE_STACKTEST also if test_utils_print_stack_usage
  is used

- make thread_measure_stack_free() available unconditionally

- if DEVELHELP is active, call test_utils_print_stack_usage() on any
  thread exit

- if DEVELHELP is active, call test_utils_print_stack_usage() after main
  for the idle thread, if that is used
This commit is contained in:
Kaspar Schleiser 2020-08-06 13:24:06 +02:00
parent fbe57de85e
commit 2ba85c1bc8
4 changed files with 18 additions and 8 deletions

View File

@ -438,7 +438,6 @@ void thread_add_to_list(list_node_t *list, thread_t *thread);
*/
const char *thread_getname(kernel_pid_t pid);
#ifdef DEVELHELP
/**
* @brief Measures the stack usage of a stack
*
@ -449,7 +448,6 @@ const char *thread_getname(kernel_pid_t pid);
* @return the amount of unused space of the thread's stack
*/
uintptr_t thread_measure_stack_free(const char *stack);
#endif /* DEVELHELP */
/**
* @brief Get the number of bytes used on the ISR stack

View File

@ -40,6 +40,9 @@
extern int main(void);
static char main_stack[THREAD_STACKSIZE_MAIN];
static char idle_stack[THREAD_STACKSIZE_IDLE];
static void *main_trampoline(void *arg)
{
(void)arg;
@ -54,12 +57,16 @@ static void *main_trampoline(void *arg)
main();
#ifdef MODULE_TEST_UTILS_PRINT_STACK_USAGE
void print_stack_usage_metric(const char *name, void *stack, unsigned max_size);
if (IS_USED(MODULE_CORE_IDLE_THREAD)) {
print_stack_usage_metric("idle", idle_stack, THREAD_STACKSIZE_IDLE);
}
#endif
return NULL;
}
static char main_stack[THREAD_STACKSIZE_MAIN];
static char idle_stack[THREAD_STACKSIZE_IDLE];
static void *idle_thread(void *arg)
{
(void)arg;

View File

@ -304,6 +304,12 @@ NORETURN void sched_task_exit(void)
DEBUG("sched_task_exit: ending thread %" PRIkernel_pid "...\n",
thread_getpid());
#if defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE) && defined(DEVELHELP)
void print_stack_usage_metric(const char *name, void *stack, unsigned max_size);
thread_t *me = thread_get_active();
print_stack_usage_metric(me->name, me->stack_start, me->stack_size);
#endif
(void)irq_disable();
sched_threads[thread_getpid()] = NULL;
sched_num_threads--;

View File

@ -171,7 +171,6 @@ void thread_add_to_list(list_node_t *list, thread_t *thread)
list->next = new_node;
}
#ifdef DEVELHELP
uintptr_t thread_measure_stack_free(const char *stack)
{
/* Alignment of stack has been fixed (if needed) by thread_create(), so
@ -188,7 +187,6 @@ uintptr_t thread_measure_stack_free(const char *stack)
return space_free;
}
#endif
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
int flags, thread_task_func_t function, void *arg,
@ -234,7 +232,8 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
_init_tls(thread->tls);
#endif
#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK)
#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 */