Skip to content

Commit 7b9edd4

Browse files
authored
Merge pull request #2 from chinglee-iot/merge-main-misra-SMP-rebase20221130
Merge main misra smp rebase20221130
2 parents 435c44a + c4be682 commit 7b9edd4

File tree

1 file changed

+70
-73
lines changed

1 file changed

+70
-73
lines changed

tasks.c

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t
474474

475475
#endif
476476

477+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configNUMBER_OF_CORES > 1 )
478+
static StaticTask_t xIdleTCBBuffers[ configNUMBER_OF_CORES - 1 ];
479+
static StackType_t xIdleTaskStackBuffers[ configNUMBER_OF_CORES - 1 ][ configMINIMAL_STACK_SIZE ];
480+
#endif /* #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configNUMBER_OF_CORES > 1 ) */
481+
477482
/*lint -restore */
478483

479484
/*-----------------------------------------------------------*/
@@ -1049,106 +1054,101 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
10491054

10501055
/* There are configNUMBER_OF_CORES Idle tasks created when scheduler started.
10511056
* The scheduler should be able to select a task to run when uxCurrentPriority
1052-
* is tskIDLE_PRIORITY. */
1053-
configASSERT( ( uxCurrentPriority > tskIDLE_PRIORITY ) || ( xTaskScheduled == pdTRUE ) );
1057+
* is tskIDLE_PRIORITY. uxCurrentPriority is never decreased to value blow
1058+
* tskIDLE_PRIORITY. */
10541059
uxCurrentPriority--;
10551060
}
10561061

1057-
if( xTaskScheduled == pdTRUE )
1062+
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
10581063
{
1059-
configASSERT( taskTASK_IS_RUNNING( pxCurrentTCBs[ xCoreID ] ) == pdTRUE );
1060-
1061-
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
1064+
if( xPriorityDropped != pdFALSE )
10621065
{
1063-
if( xPriorityDropped != pdFALSE )
1064-
{
1065-
/* There may be several ready tasks that were being prevented from running because there was
1066-
* a higher priority task running. Now that the last of the higher priority tasks is no longer
1067-
* running, make sure all the other idle tasks yield. */
1068-
BaseType_t x;
1066+
/* There may be several ready tasks that were being prevented from running because there was
1067+
* a higher priority task running. Now that the last of the higher priority tasks is no longer
1068+
* running, make sure all the other idle tasks yield. */
1069+
BaseType_t x;
10691070

1070-
for( x = ( BaseType_t ) 0; x < ( BaseType_t ) configNUMBER_OF_CORES; x++ )
1071+
for( x = ( BaseType_t ) 0; x < ( BaseType_t ) configNUMBER_OF_CORES; x++ )
1072+
{
1073+
if( ( pxCurrentTCBs[ x ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0 )
10711074
{
1072-
if( ( pxCurrentTCBs[ x ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0 )
1073-
{
1074-
prvYieldCore( x );
1075-
}
1075+
prvYieldCore( x );
10761076
}
10771077
}
10781078
}
1079-
#endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */
1079+
}
1080+
#endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */
10801081

1081-
#if ( configUSE_CORE_AFFINITY == 1 )
1082+
#if ( configUSE_CORE_AFFINITY == 1 )
1083+
{
1084+
if( ( pxPreviousTCB != NULL ) && ( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxPreviousTCB->uxPriority ] ), &( pxPreviousTCB->xStateListItem ) ) != pdFALSE ) )
10821085
{
1083-
if( ( pxPreviousTCB != NULL ) && ( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxPreviousTCB->uxPriority ] ), &( pxPreviousTCB->xStateListItem ) ) != pdFALSE ) )
1086+
/* A ready task was just evicted from this core. See if it can be
1087+
* scheduled on any other core. */
1088+
UBaseType_t uxCoreMap = pxPreviousTCB->uxCoreAffinityMask;
1089+
BaseType_t xLowestPriority = ( BaseType_t ) pxPreviousTCB->uxPriority;
1090+
BaseType_t xLowestPriorityCore = -1;
1091+
BaseType_t x;
1092+
1093+
if( ( pxPreviousTCB->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0U )
10841094
{
1085-
/* A ready task was just evicted from this core. See if it can be
1086-
* scheduled on any other core. */
1087-
UBaseType_t uxCoreMap = pxPreviousTCB->uxCoreAffinityMask;
1088-
BaseType_t xLowestPriority = ( BaseType_t ) pxPreviousTCB->uxPriority;
1089-
BaseType_t xLowestPriorityCore = -1;
1090-
BaseType_t x;
1095+
xLowestPriority = xLowestPriority - 1;
1096+
}
10911097

1092-
if( ( pxPreviousTCB->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0U )
1093-
{
1094-
xLowestPriority = xLowestPriority - 1;
1095-
}
1098+
if( ( uxCoreMap & ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID ) ) != 0U )
1099+
{
1100+
/* The ready task that was removed from this core is not excluded from it.
1101+
* Only look at the intersection of the cores the removed task is allowed to run
1102+
* on with the cores that the new task is excluded from. It is possible that the
1103+
* new task was only placed onto this core because it is excluded from another.
1104+
* Check to see if the previous task could run on one of those cores. */
1105+
uxCoreMap &= ~( pxCurrentTCBs[ xCoreID ]->uxCoreAffinityMask );
1106+
}
1107+
else
1108+
{
1109+
/* The ready task that was removed from this core is excluded from it. */
1110+
}
10961111

1097-
if( ( uxCoreMap & ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID ) ) != 0U )
1098-
{
1099-
/* The ready task that was removed from this core is not excluded from it.
1100-
* Only look at the intersection of the cores the removed task is allowed to run
1101-
* on with the cores that the new task is excluded from. It is possible that the
1102-
* new task was only placed onto this core because it is excluded from another.
1103-
* Check to see if the previous task could run on one of those cores. */
1104-
uxCoreMap &= ~( pxCurrentTCBs[ xCoreID ]->uxCoreAffinityMask );
1105-
}
1106-
else
1107-
{
1108-
/* The ready task that was removed from this core is excluded from it. */
1109-
}
1112+
uxCoreMap &= ( ( 1U << configNUMBER_OF_CORES ) - 1U );
11101113

1111-
uxCoreMap &= ( ( 1U << configNUMBER_OF_CORES ) - 1U );
1114+
for( x = ( ( BaseType_t ) configNUMBER_OF_CORES - 1 ); x >= ( BaseType_t ) 0; x-- )
1115+
{
1116+
UBaseType_t uxCore = ( UBaseType_t ) x;
1117+
BaseType_t xTaskPriority;
11121118

1113-
for( x = ( ( BaseType_t ) configNUMBER_OF_CORES - 1 ); x >= ( BaseType_t ) 0; x-- )
1119+
if( ( uxCoreMap & ( 1 << uxCore ) ) != 0 )
11141120
{
1115-
UBaseType_t uxCore = ( UBaseType_t ) x;
1116-
BaseType_t xTaskPriority;
1121+
xTaskPriority = ( BaseType_t ) pxCurrentTCBs[ uxCore ]->uxPriority;
11171122

1118-
if( ( uxCoreMap & ( 1 << uxCore ) ) != 0 )
1123+
if( ( pxCurrentTCBs[ uxCore ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0U )
11191124
{
1120-
xTaskPriority = ( BaseType_t ) pxCurrentTCBs[ uxCore ]->uxPriority;
1121-
1122-
if( ( pxCurrentTCBs[ uxCore ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0U )
1123-
{
1124-
xTaskPriority = xTaskPriority - ( BaseType_t ) 1;
1125-
}
1125+
xTaskPriority = xTaskPriority - ( BaseType_t ) 1;
1126+
}
11261127

1127-
uxCoreMap &= ~( ( UBaseType_t ) 1U << uxCore );
1128+
uxCoreMap &= ~( ( UBaseType_t ) 1U << uxCore );
11281129

1129-
if( ( xTaskPriority < xLowestPriority ) &&
1130-
( taskTASK_IS_RUNNING( pxCurrentTCBs[ uxCore ] ) != pdFALSE ) &&
1131-
( xYieldPendings[ uxCore ] == pdFALSE ) )
1130+
if( ( xTaskPriority < xLowestPriority ) &&
1131+
( taskTASK_IS_RUNNING( pxCurrentTCBs[ uxCore ] ) != pdFALSE ) &&
1132+
( xYieldPendings[ uxCore ] == pdFALSE ) )
1133+
{
1134+
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
1135+
if( pxCurrentTCBs[ uxCore ]->xPreemptionDisable == pdFALSE )
1136+
#endif
11321137
{
1133-
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
1134-
if( pxCurrentTCBs[ uxCore ]->xPreemptionDisable == pdFALSE )
1135-
#endif
1136-
{
1137-
xLowestPriority = xTaskPriority;
1138-
xLowestPriorityCore = ( BaseType_t ) uxCore;
1139-
}
1138+
xLowestPriority = xTaskPriority;
1139+
xLowestPriorityCore = ( BaseType_t ) uxCore;
11401140
}
11411141
}
11421142
}
1143+
}
11431144

1144-
if( taskVALID_CORE_ID( xLowestPriorityCore ) == pdTRUE )
1145-
{
1146-
prvYieldCore( xLowestPriorityCore );
1147-
}
1145+
if( xLowestPriorityCore >= 0 )
1146+
{
1147+
prvYieldCore( xLowestPriorityCore );
11481148
}
11491149
}
1150-
#endif /* #if ( configUSE_CORE_AFFINITY == 1 ) */
11511150
}
1151+
#endif /* #if ( configUSE_CORE_AFFINITY == 1 ) */
11521152
}
11531153

11541154
#endif /* ( configNUMBER_OF_CORES > 1 ) */
@@ -3214,9 +3214,6 @@ static BaseType_t prvCreateIdleTasks( void )
32143214
}
32153215
else
32163216
{
3217-
static StaticTask_t xIdleTCBBuffers[ configNUMBER_OF_CORES - 1 ];
3218-
static StackType_t xIdleTaskStackBuffers[ configNUMBER_OF_CORES - 1 ][ configMINIMAL_STACK_SIZE ];
3219-
32203217
xIdleTaskHandles[ xCoreID ] = xTaskCreateStatic( prvMinimalIdleTask,
32213218
cIdleName,
32223219
configMINIMAL_STACK_SIZE,

0 commit comments

Comments
 (0)