From 08205492235ee3eff5c0a82cc210eb1f511171c1 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 15 Oct 2020 09:43:27 +0900 Subject: [PATCH] sched: Fix DEBUGASSERT() in sched_unlock() for SMP Summary: - I noticed DEBUGASSERT() happens in sched_unlock() - The test was Wi-Fi audio streaming stress test with spresense 3cores - Actually, g_cpu_schedlock was locked but g_cpu_lockset was incorrect - Finally, I found that cpu was obtained before enter_critical_section() - And the task was moved from one cpu to another cpu - However, that call should be done within the critical section - This commit fixes this issue Impact: - Affects SMP only Testing: - Tested with spresense:wifi_smp (both NCPUS=2 and 3) - Tested with lc823450-xgevk:rndis - Tested with maix-bit:smp (QEMU) - Tested with esp32-core:smp (QEMU) - Tested with sabre-6quad:smp (QEMU) Signed-off-by: Masayuki Ishikawa --- sched/sched/sched_unlock.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 857c682101..3991b16f52 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -54,14 +54,12 @@ int sched_unlock(void) { FAR struct tcb_s *rtcb; - int cpu; /* This operation is safe because the scheduler is locked and no context * switch may occur. */ - cpu = this_cpu(); - rtcb = current_task(cpu); + rtcb = this_task(); /* Check for some special cases: (1) rtcb may be NULL only during * early boot-up phases, and (2) sched_unlock() should have no @@ -73,6 +71,7 @@ int sched_unlock(void) /* Prevent context switches throughout the following. */ irqstate_t flags = enter_critical_section(); + int cpu = this_cpu(); /* Decrement the preemption lock counter */