sched: add STACK_USAGE_SAFE_PERCENT for stack overflow check

Change-Id: Ia70e243b36401e28c31fcd7e1b480b79374c27ef
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2021-06-18 16:55:46 +08:00 committed by Xiang Xiao
parent 940c80f7b3
commit 8d2615f78d
2 changed files with 15 additions and 2 deletions

12
Kconfig
View File

@ -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

View File

@ -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);