Merge branch 'bugfix/freertos_nested_sched_suspension' into 'master'

freertos-idf: Fixed incorrect scheduler suspension check in xTaskRemoveFromEventList()

Closes IDF-7299

See merge request espressif/esp-idf!23537
This commit is contained in:
Zim Kalinowski
2023-05-09 18:07:47 +08:00

View File

@@ -280,11 +280,11 @@
* - Check the scheduler suspension state on core 0. The task can be scheduled if the scheduler is not suspended.
*/
#if ( configNUM_CORES > 1 )
#define taskCAN_BE_SCHEDULED( pxTCB ) \
( ( pxTCB->xCoreID != tskNO_AFFINITY ) ) ? ( uxSchedulerSuspended[ pxTCB->xCoreID ] == ( UBaseType_t ) pdFALSE ) : \
( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) pdFALSE ) || ( uxSchedulerSuspended[ 1 ] == ( UBaseType_t ) pdFALSE ) )
#define taskCAN_BE_SCHEDULED( pxTCB ) \
( ( pxTCB->xCoreID != tskNO_AFFINITY ) ) ? ( uxSchedulerSuspended[ pxTCB->xCoreID ] == ( UBaseType_t ) 0U ) : \
( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) 0U ) || ( uxSchedulerSuspended[ 1 ] == ( UBaseType_t ) 0U ) )
#else
#define taskCAN_BE_SCHEDULED( pxTCB ) ( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) pdFALSE ) )
#define taskCAN_BE_SCHEDULED( pxTCB ) ( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) 0U ) )
#endif /* configNUM_CORES > 1 */
/*
@@ -318,7 +318,7 @@
#if ( configNUM_CORES > 1 )
#define taskIS_SCHEDULER_SUSPENDED() ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED )
#else
#define taskIS_SCHEDULER_SUSPENDED() ( uxSchedulerSuspended[ 0 ] > 0 )
#define taskIS_SCHEDULER_SUSPENDED() ( ( uxSchedulerSuspended[ 0 ] != ( UBaseType_t ) 0U ) )
#endif /* configNUM_CORES > 1 */
/* The item value of the event list item is normally used to hold the priority
@@ -485,7 +485,7 @@ PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle[ configNUM_CORES ] = { NULL
* kernel to move the task from the pending ready list into the real ready list
* when the scheduler is unsuspended. The pending ready list itself can only be
* accessed from a critical section. */
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended[ configNUM_CORES ] = { ( UBaseType_t ) pdFALSE };
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended[ configNUM_CORES ] = { ( UBaseType_t ) 0U };
#if ( configGENERATE_RUN_TIME_STATS == 1 )
@@ -1384,7 +1384,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
/* If the target task can run on the current core, and has a higher priority than the current core, and the core has not suspended scheduling, then yield the current core */
if( ( ( xTaskCoreID == xCurCoreID ) || ( xTaskCoreID == tskNO_AFFINITY ) ) &&
( uxTaskPriority > pxCurrentTCB[ xCurCoreID ]->uxPriority ) &&
( uxSchedulerSuspended[ xCurCoreID ] == ( UBaseType_t ) pdFALSE ) )
( uxSchedulerSuspended[ xCurCoreID ] == ( UBaseType_t ) 0U ) )
{
/* Return true for the caller to yield the current core */
xYieldRequiredCurrentCore = pdTRUE;
@@ -1392,7 +1392,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
/* If the target task can run on the other core, and has a higher priority then the other core, and the other core has not suspended scheduling, then yield the other core */
else if( ( ( xTaskCoreID == !xCurCoreID ) || ( xTaskCoreID == tskNO_AFFINITY ) ) &&
( uxTaskPriority > pxCurrentTCB[ !xCurCoreID ]->uxPriority ) &&
( uxSchedulerSuspended[ !xCurCoreID ] == ( UBaseType_t ) pdFALSE ) )
( uxSchedulerSuspended[ !xCurCoreID ] == ( UBaseType_t ) 0U ) )
{
/* Signal the other core to yield */
vPortYieldOtherCore( !xCurCoreID );
@@ -1529,7 +1529,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
if( taskIS_CURRENTLY_RUNNING_ON_CORE( pxTCB, xPortGetCoreID() ) )
{
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == 0 );
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) 0U );
portYIELD_WITHIN_API();
}
else
@@ -2089,7 +2089,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
if( xSchedulerRunning != pdFALSE )
{
/* The current task has just been suspended. */
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == 0 );
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) 0U );
portYIELD_WITHIN_API();
}
else
@@ -2594,7 +2594,7 @@ BaseType_t xTaskResumeAll( void )
--uxSchedulerSuspended[ xCoreID ];
if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) 0U )
{
if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U )
{
@@ -3203,7 +3203,7 @@ BaseType_t xTaskIncrementTick( void )
taskENTER_CRITICAL_ISR( &xKernelLock );
#endif /* ( configNUM_CORES > 1 ) */
if( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) 0U )
{
/* Minor optimisation. The tick count cannot change in this
* block. */
@@ -3401,7 +3401,7 @@ BaseType_t xTaskIncrementTick( void )
* tasks to be unblocked. */
traceTASK_INCREMENT_TICK( xTickCount );
if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) 0U )
{
/* We need take the kernel lock here as we are about to access
* kernel data structures. */
@@ -3681,7 +3681,7 @@ void vTaskSwitchContext( void )
taskENTER_CRITICAL_ISR( &xKernelLock );
#endif /* ( configNUM_CORES > 1 ) */
if( uxSchedulerSuspended[ xPortGetCoreID() ] != ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xPortGetCoreID() ] != ( UBaseType_t ) 0U )
{
/* The scheduler is currently suspended - do not allow a context
* switch. */
@@ -3823,7 +3823,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by
* the event groups implementation. */
configASSERT( uxSchedulerSuspended[ 0 ] != 0 );
configASSERT( uxSchedulerSuspended[ 0 ] != ( UBaseType_t ) 0U );
#endif /* configNUM_CORES > 1 */
/* Store the item value in the event list item. It is safe to access the
@@ -3977,7 +3977,7 @@ BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList )
#else
xPendingListCore = 0;
#endif /* configNUM_CORES > 1 */
configASSERT( uxSchedulerSuspended[ xPendingListCore ] == pdTRUE );
configASSERT( uxSchedulerSuspended[ xPendingListCore ] != ( UBaseType_t ) 0U );
/* The delayed and ready lists cannot be accessed, so hold this task
* pending until the scheduler is resumed. */
@@ -4052,7 +4052,7 @@ void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by
* the event flags implementation. */
configASSERT( uxSchedulerSuspended[ 0 ] != pdFALSE );
configASSERT( uxSchedulerSuspended[ 0 ] != ( UBaseType_t ) 0U );
#endif /* configNUM_CORES > 1 */
/* Store the new item value in the event list. */
@@ -5050,7 +5050,7 @@ static void prvResetNextTaskUnblockTime( void )
}
else
{
if( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) 0U )
{
xReturn = taskSCHEDULER_RUNNING;
}