From 0bea0a00372ca337e4fbabc302c99e3e65e225b7 Mon Sep 17 00:00:00 2001 From: buxiasen Date: Sat, 20 Jul 2024 17:30:07 +0800 Subject: [PATCH] sched_backtrace: fix when dump running thread in other-core Signed-off-by: buxiasen --- sched/sched/sched_backtrace.c | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/sched/sched/sched_backtrace.c b/sched/sched/sched_backtrace.c index 4e8c69547559b..6e95b45b51a21 100644 --- a/sched/sched/sched_backtrace.c +++ b/sched/sched/sched_backtrace.c @@ -25,6 +25,8 @@ ****************************************************************************/ #include +#include +#include #include "sched.h" @@ -45,16 +47,36 @@ #ifdef CONFIG_ARCH_HAVE_BACKTRACE int sched_backtrace(pid_t tid, FAR void **buffer, int size, int skip) { - FAR struct tcb_s *rtcb; - irqstate_t flags; + FAR struct tcb_s *tcb = this_task(); int ret = 0; - if (tid >= 0) + + if (tcb->pid == tid) + { + ret = up_backtrace(tcb, buffer, size, skip); + } + else { - flags = enter_critical_section(); - rtcb = nxsched_get_tcb(tid); - if (rtcb != NULL) + irqstate_t flags = enter_critical_section(); + + tcb = nxsched_get_tcb(tid); + if (tcb != NULL) { - ret = up_backtrace(rtcb, buffer, size, skip); +#ifdef CONFIG_SMP + if (tcb->task_state == TSTATE_TASK_RUNNING && + g_nx_initstate != OSINIT_PANIC) + { + up_cpu_pause(tcb->cpu); + } +#endif + + ret = up_backtrace(tcb, buffer, size, skip); +#ifdef CONFIG_SMP + if (tcb->task_state == TSTATE_TASK_RUNNING && + g_nx_initstate != OSINIT_PANIC) + { + up_cpu_resume(tcb->cpu); + } +#endif } leave_critical_section(flags);