FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.71k stars 1.11k forks source link

[BUG] vTaskDelay raises configASSERT when SMP is on #1068

Closed NikJen26 closed 4 months ago

NikJen26 commented 4 months ago

Describe the bug Assume a Multicore System using the SMP Version of FreeRTOS. Whenever a Tasks calls xQueueSend (xQueueGenericSend) the scheduler gets suspended for a brief moment (vTaskSuspendAll). This results in the variable uxSchedulerSuspended to be incremented. Now, the second core might execute another Tasks that calls vTaskDelay which in turn calls vTasksSuspendAll (which increments uxSchedulerSuspended). The check afterwards configASSERT( uxSchedulerSuspended == 1U );` will fail in that scenario.

Target

Host

To Reproduce see description

Expected behavior This check should only be valid for non SMP configurations.

Additional context

Stack Trace:

APU 
    Cortex-A53 #0 (External Debug Request), EL3(S)/A64  
        0x00000000ffff2048 GateSmp_tryLock(): portASM.S, line 473   
        0x000000000004b3a8 vPortRecursiveLock(): port.c, line 229   
        0x0000000000048714 vTaskEnterCritical(): tasks.c, line 6966 
        0x00000000000428f0 xQueueGenericSend(): queue.c, line 1108  
        0x000000000004ca94 prvTestAbortingQueueSend(): AbortDelay.c, line 621   
        0x000000000004c40c prvBlockingTask(): AbortDelay.c, line 257    
        0x0000000000000000  
    Cortex-A53 #1 (External Debug Request), EL3(S)/A64  
        0x000000000004abf0 vMainAssertCalled(): main.c, line 261    
        0x00000000000456fc vTaskDelay(): tasks.c, line 2446 
        0x00000000000508c4 prvTest6_CheckAutoReloadResetBehaviour(): TimerDemo.c, line 598  
        0x000000000004fd24 prvTimerTestTask(): TimerDemo.c, line 214    
        0x0000000000000000  
aggarg commented 4 months ago

vTaskSuspendAll acquires task lock here, so the 2nd task running on other core cannot pass this point and increment uxSchedulerSuspended until the task lock is released in xTaskResumeAll here.

NikJen26 commented 4 months ago

So the issue seem to be the recursive Spinlock implementation of my port. Thanks for your help.