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 <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
Masayuki Ishikawa 2020-10-15 09:43:27 +09:00 committed by Brennan Ashton
parent 2b9282d5ee
commit 0820549223

View File

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