From 0a7e136a5a674fec18bb5ceeb4e4f588f99b2ea1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Feb 2016 08:01:09 -0600 Subject: [PATCH] SMP: Idle thread must be assigned to a CPU --- sched/init/os_smpstart.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sched/init/os_smpstart.c b/sched/init/os_smpstart.c index 0bd33ffb8e..bfbc49d509 100644 --- a/sched/init/os_smpstart.c +++ b/sched/init/os_smpstart.c @@ -46,14 +46,11 @@ #include #include +# include "sched/sched.h" # include "init/init.h" #ifdef CONFIG_SMP -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -75,6 +72,23 @@ int os_idletask(int argc, FAR char *argv[]) { + FAR struct tcb_s *rtcb = this_task(); + irqstate_t flags; + int cpu = this_cpu(); + + /* Make sure that this thread is assigned to the current CPU */ + + DEBUGASSERT(rtcb->cpu == cpu); + + /* REVISIT: disabling interrupts is not sufficient protection */ + + flags = irqsave(); + rtcb->flags |= TCB_FLAG_CPU_ASSIGNED; + rtcb->cpu = cpu; + irqrestore(flags); + + /* Then enter the IDLE loop */ + sdbg("CPU%d: Beginning Idle Loop\n"); for (; ; ) {