forked from espressif/esp-idf
freertos: Add multi-core OS startup race condition workaround
FreeRTOS uses a single "xSchedulerRunning" variable to tack whether the scheduler has started, and this variable is set to "pdTRUE" by core 0 via calling vTaskStartScheduler(). However, with SMP FreeRTOS, there is a race condition where core 0 has already started the scheduler and another core has not called xPortStartScheduler() yet and calls some FreeRTOS API. Thus the resultant FreeRTOS API can cause errors as it thinks the scheduler has started. This commit adds a temporary workaround (by having each core maintain their own "xSchedulerRunning" variable.
This commit is contained in:
@@ -3279,6 +3279,15 @@ void vTaskYieldWithinAPI( void );
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#if ( configNUM_CORES > 1 )
|
||||
/*
|
||||
Workaround for non-thread safe multi-core OS startup (see IDF-4524)
|
||||
This function must be called with interrupts disabled on all cores other than
|
||||
core 0 during startup.
|
||||
*/
|
||||
void vTaskStartSchedulerOtherCores( void );
|
||||
#endif // configNUM_CORES > 1
|
||||
|
||||
#include "idf_additions.h"
|
||||
|
||||
#endif //ESP_PLATFORM
|
||||
|
@@ -448,6 +448,13 @@ BaseType_t xPortStartScheduler( void )
|
||||
|
||||
port_xSchedulerRunning[xPortGetCoreID()] = 1;
|
||||
|
||||
#if configNUM_CORES > 1
|
||||
// Workaround for non-thread safe multi-core OS startup (see IDF-4524)
|
||||
if (xPortGetCoreID() != 0) {
|
||||
vTaskStartSchedulerOtherCores();
|
||||
}
|
||||
#endif // configNUM_CORES > 1
|
||||
|
||||
// Cannot be directly called from C; never returns
|
||||
__asm__ volatile ("call0 _frxt_dispatch\n");
|
||||
|
||||
|
@@ -369,7 +369,15 @@ PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tas
|
||||
PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
|
||||
PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
|
||||
PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
|
||||
#if ( ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 ) )
|
||||
/*
|
||||
Workaround for non-thread safe multi-core OS startup (see IDF-4524)
|
||||
*/
|
||||
PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunningPerCore[ configNUM_CORES ] = { pdFALSE };
|
||||
#define xSchedulerRunning xSchedulerRunningPerCore[ portGET_CORE_ID() ]
|
||||
#else // ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 )
|
||||
PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;
|
||||
#endif // ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 )
|
||||
PRIVILEGED_DATA static volatile TickType_t xPendedTicks = ( TickType_t ) 0U;
|
||||
PRIVILEGED_DATA static volatile BaseType_t xYieldPendings[ configNUM_CORES ] = { pdFALSE };
|
||||
PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;
|
||||
@@ -6443,3 +6451,14 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
|
||||
#endif
|
||||
|
||||
#endif /* if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) */
|
||||
|
||||
#if ( ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1 ) )
|
||||
/*
|
||||
Workaround for non-thread safe multi-core OS startup (see IDF-4524)
|
||||
*/
|
||||
void vTaskStartSchedulerOtherCores( void )
|
||||
{
|
||||
/* This function is always called with interrupts disabled*/
|
||||
xSchedulerRunning = pdTRUE;
|
||||
}
|
||||
#endif // ( ESP_PLATFORM == 1 ) && ( configNUM_CORES > 1
|
||||
|
Reference in New Issue
Block a user