diff --git a/Kconfig b/Kconfig index 95d0dc51f0..05e0a324bd 100644 --- a/Kconfig +++ b/Kconfig @@ -1758,6 +1758,18 @@ config STACK_COLORATION Only supported by a few architectures. +config STACK_USAGE_SAFE_PERCENT + int "Stack usage safe precent" + default 0 + range 0 100 + depends on STACK_COLORATION + ---help--- + Stack usage precent = up_check_tcbstack() * 100 / tcb->adj_stack_size, + this should lower then STACK_USAGE_SAFE_PERCENT. + Idle thread will timely check stack usage when this marco value > 0. + + N.B. This feature should not be used in production code. + config STACK_CANARIES bool "Compiler stack canaries" depends on ARCH_HAVE_STACKCHECK diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index 33573a1741..771522069d 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -800,7 +800,7 @@ void nx_start(void) sinfo("CPU0: Beginning Idle Loop\n"); for (; ; ) { -#if defined(CONFIG_STACK_COLORATION) && defined(CONFIG_DEBUG_MM) +#if defined(CONFIG_STACK_COLORATION) && CONFIG_STACK_USAGE_SAFE_PERCENT > 0 /* Check stack in idle thread */ @@ -812,7 +812,8 @@ void nx_start(void) flags = enter_critical_section(); tcb = g_pidhash[i].tcb; - if (tcb && up_check_tcbstack_remain(tcb) <= 0) + if (tcb && (up_check_tcbstack(tcb) * 100 / tcb->adj_stack_size + > CONFIG_STACK_USAGE_SAFE_PERCENT)) { _alert("Stack check failed, pid %d, name %s\n", tcb->pid, tcb->name);