Update pxCurrentTCBs[ portGET_CORE_ID() ] optimization

This commit is contained in:
Ching-Hsin,Lee 2024-07-08 10:14:45 +08:00
parent f4dad5e7c1
commit 67b6574633

31
tasks.c
View file

@ -86,8 +86,7 @@
#define taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ) \ #define taskYIELD_ANY_CORE_IF_USING_PREEMPTION( pxTCB ) \
do { \ do { \
TCB_t * const pxConstCurrentTCB = prvGetCurrentTaskTCB(); \ if( ( prvGetCurrentTaskTCBUnsafe()->uxPriority ) < ( pxTCB )->uxPriority ) \
if( pxConstCurrentTCB->uxPriority < ( pxTCB )->uxPriority ) \
{ \ { \
portYIELD_WITHIN_API(); \ portYIELD_WITHIN_API(); \
} \ } \
@ -318,10 +317,10 @@
#define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U ) #define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U )
#if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) )
#define portGET_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting ) #define portGET_CRITICAL_NESTING_COUNT() ( prvGetCurrentTaskTCBUnsafe()->uxCriticalNesting )
#define portSET_CRITICAL_NESTING_COUNT( x ) ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting = ( x ) ) #define portSET_CRITICAL_NESTING_COUNT( x ) ( prvGetCurrentTaskTCBUnsafe()->uxCriticalNesting = ( x ) )
#define portINCREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting++ ) #define portINCREMENT_CRITICAL_NESTING_COUNT() ( prvGetCurrentTaskTCBUnsafe()->uxCriticalNesting++ )
#define portDECREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting-- ) #define portDECREMENT_CRITICAL_NESTING_COUNT() ( prvGetCurrentTaskTCBUnsafe()->uxCriticalNesting-- )
#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */ #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */
#define taskBITS_PER_BYTE ( ( size_t ) 8 ) #define taskBITS_PER_BYTE ( ( size_t ) 8 )
@ -833,7 +832,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
uxSavedInterruptStatus = portSET_INTERRUPT_MASK(); uxSavedInterruptStatus = portSET_INTERRUPT_MASK();
{ {
pxTCB = pxCurrentTCBs[ portGET_CORE_ID() ]; pxTCB = prvGetCurrentTaskTCBUnsafe();
} }
portCLEAR_INTERRUPT_MASK( uxSavedInterruptStatus ); portCLEAR_INTERRUPT_MASK( uxSavedInterruptStatus );
@ -854,7 +853,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
/* This function is always called with interrupts disabled /* This function is always called with interrupts disabled
* so this is safe. */ * so this is safe. */
pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ]; pxThisTCB = prvGetCurrentTaskTCBUnsafe();
while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD ) while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
{ {
@ -918,13 +917,13 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
#if ( configRUN_MULTIPLE_PRIORITIES == 0 ) #if ( configRUN_MULTIPLE_PRIORITIES == 0 )
BaseType_t xYieldCount = 0; BaseType_t xYieldCount = 0;
TCB_t * const pxConstCurrentTCB = prvGetCurrentTaskTCBUnsafe();
#endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */ #endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */
/* This must be called from a critical section. */ /* This must be called from a critical section. */
configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U );
#if ( configRUN_MULTIPLE_PRIORITIES == 0 ) #if ( configRUN_MULTIPLE_PRIORITIES == 0 )
/* No task should yield for this one if it is a lower priority /* No task should yield for this one if it is a lower priority
* than priority level of currently ready tasks. */ * than priority level of currently ready tasks. */
if( pxTCB->uxPriority >= uxTopReadyPriority ) if( pxTCB->uxPriority >= uxTopReadyPriority )
@ -1010,11 +1009,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
#if ( configRUN_MULTIPLE_PRIORITIES == 0 ) #if ( configRUN_MULTIPLE_PRIORITIES == 0 )
/* Verify that the calling core always yields to higher priority tasks. */ /* Verify that the calling core always yields to higher priority tasks. */
if( ( ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) && if( ( ( pxConstCurrentTCB->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) &&
( pxTCB->uxPriority > pxCurrentTCBs[ portGET_CORE_ID() ]->uxPriority ) ) ( pxTCB->uxPriority > pxConstCurrentTCB->uxPriority ) )
{ {
configASSERT( ( xYieldPendings[ portGET_CORE_ID() ] == pdTRUE ) || configASSERT( ( xYieldPendings[ portGET_CORE_ID() ] == pdTRUE ) ||
( taskTASK_IS_RUNNING( pxCurrentTCBs[ portGET_CORE_ID() ] ) == pdFALSE ) ); ( taskTASK_IS_RUNNING( pxConstCurrentTCB ) == pdFALSE ) );
} }
#endif #endif
} }
@ -2121,8 +2120,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
prvAddTaskToReadyList( pxNewTCB ); prvAddTaskToReadyList( pxNewTCB );
portSETUP_TCB( pxNewTCB ); portSETUP_TCB( pxNewTCB );
}
taskEXIT_CRITICAL();
if( xSchedulerRunning != pdFALSE ) if( xSchedulerRunning != pdFALSE )
{ {
@ -2135,6 +2132,8 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
mtCOVERAGE_TEST_MARKER(); mtCOVERAGE_TEST_MARKER();
} }
} }
taskEXIT_CRITICAL();
}
#else /* #if ( configNUMBER_OF_CORES == 1 ) */ #else /* #if ( configNUMBER_OF_CORES == 1 ) */
@ -3406,12 +3405,10 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
configASSERT( xTaskToResume ); configASSERT( xTaskToResume );
#if ( configNUMBER_OF_CORES == 1 ) #if ( configNUMBER_OF_CORES == 1 )
/* The parameter cannot be NULL as it is impossible to resume the /* The parameter cannot be NULL as it is impossible to resume the
* currently executing task. */ * currently executing task. */
if( ( taskTASK_IS_RUNNING( pxTCB ) == pdFALSE ) && ( pxTCB != NULL ) ) if( ( taskTASK_IS_RUNNING( pxTCB ) == pdFALSE ) && ( pxTCB != NULL ) )
#else #else
/* The parameter cannot be NULL as it is impossible to resume the /* The parameter cannot be NULL as it is impossible to resume the
* currently executing task. It is also impossible to resume a task * currently executing task. It is also impossible to resume a task
* that is actively running on another core but it is not safe * that is actively running on another core but it is not safe
@ -5260,7 +5257,7 @@ BaseType_t xTaskIncrementTick( void )
/* Macro to inject port specific behaviour immediately after /* Macro to inject port specific behaviour immediately after
* switching tasks, such as setting an end of stack watchpoint * switching tasks, such as setting an end of stack watchpoint
* or reconfiguring the MPU. */ * or reconfiguring the MPU. */
portTASK_SWITCH_HOOK( pxCurrentTCBs[ portGET_CORE_ID() ] ); portTASK_SWITCH_HOOK( prvGetCurrentTaskTCBUnsafe() );
/* After the new task is switched in, update the global errno. */ /* After the new task is switched in, update the global errno. */
#if ( configUSE_POSIX_ERRNO == 1 ) #if ( configUSE_POSIX_ERRNO == 1 )