From 17800007776ba2b20626e1a925c2916815635e4d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 18 Feb 2016 12:31:21 -0600 Subject: [PATCH] SMP: Setting bit for wrong CPU. Assertion has cause false alarm crashes.. --- arch | 2 +- include/nuttx/sched.h | 4 +++- sched/sched/sched_addreadytorun.c | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/arch b/arch index bd833ac25f..5a6306b76a 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit bd833ac25f0f982a372d8d9df5e1634a6eb21b32 +Subproject commit 5a6306b76aa6656c56f5c19cbf18757a295ee1bc diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 586c1a81e9..e7a8d5c26f 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -216,7 +216,9 @@ enum tstate_e }; typedef enum tstate_e tstate_t; -/* The following definitions are determined by tstate_t */ +/* The following definitions are determined by tstate_t. Ordering of values + * in the enumeration is important! + */ #define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN #define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2bcc3f9087..82b567856d 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -275,7 +275,7 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) switched = sched_addprioritized(btcb, tasklist); /* If the selected task was the g_assignedtasks[] list, then a context - * swith will occur. + * switch will occur. */ if (switched) @@ -304,12 +304,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (btcb->lockcount > 0) { - spin_setbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + spin_setbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock, &g_cpu_schedlock); } else { - spin_clrbit(&g_cpu_lockset, this_cpu(), &g_cpu_locksetlock, + spin_clrbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock, &g_cpu_schedlock); } @@ -319,12 +319,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) if (btcb->irqcount > 0) { - spin_setbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + spin_setbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock, &g_cpu_irqlock); } else { - spin_clrbit(&g_cpu_irqset, this_cpu(), &g_cpu_irqsetlock, + spin_clrbit(&g_cpu_irqset, cpu, &g_cpu_irqsetlock, &g_cpu_irqlock); } @@ -334,11 +334,12 @@ bool sched_addreadytorun(FAR struct tcb_s *btcb) * lifting machinery. */ + DEBUGASSERT(btcb->flink != NULL); next = (FAR struct tcb_s *)btcb->flink; - ASSERT(!spin_islocked(&g_cpu_schedlock) && next != NULL); if ((next->flags & TCB_FLAG_CPU_ASSIGNED) != 0) { + DEBUGASSERT(next->cpu == cpu); next->task_state = TSTATE_TASK_ASSIGNED; } else