Yield for task when core affinity of a ready task is changed (#1123)

* The SMP scheduler should re-select a core to yield when the core
  affinity of a ready task is changed.
This commit is contained in:
chinglee-iot 2024-08-20 12:34:01 +08:00 committed by GitHub
parent 2faa8bc154
commit e43553af1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

25
tasks.c
View file

@ -2982,11 +2982,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
{ {
TCB_t * pxTCB; TCB_t * pxTCB;
BaseType_t xCoreID; BaseType_t xCoreID;
UBaseType_t uxPrevCoreAffinityMask;
#if ( configUSE_PREEMPTION == 1 )
UBaseType_t uxPrevNotAllowedCores;
#endif
traceENTER_vTaskCoreAffinitySet( xTask, uxCoreAffinityMask ); traceENTER_vTaskCoreAffinitySet( xTask, uxCoreAffinityMask );
@ -2994,7 +2989,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
{ {
pxTCB = prvGetTCBFromHandle( xTask ); pxTCB = prvGetTCBFromHandle( xTask );
uxPrevCoreAffinityMask = pxTCB->uxCoreAffinityMask;
pxTCB->uxCoreAffinityMask = uxCoreAffinityMask; pxTCB->uxCoreAffinityMask = uxCoreAffinityMask;
if( xSchedulerRunning != pdFALSE ) if( xSchedulerRunning != pdFALSE )
@ -3014,17 +3008,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
{ {
#if ( configUSE_PREEMPTION == 1 ) #if ( configUSE_PREEMPTION == 1 )
{ {
/* Calculate the cores on which this task was not allowed to /* The SMP scheduler requests a core to yield when a ready
* run previously. */ * task is able to run. It is possible that the core affinity
uxPrevNotAllowedCores = ( ~uxPrevCoreAffinityMask ) & ( ( 1U << configNUMBER_OF_CORES ) - 1U ); * of the ready task is changed before the requested core
* can select it to run. In that case, the task may not be
/* Does the new core mask enables this task to run on any of the * selected by the previously requested core due to core affinity
* previously not allowed cores? If yes, check if this task can be * constraint and the SMP scheduler must select a new core to
* scheduled on any of those cores. */ * yield for the task. */
if( ( uxPrevNotAllowedCores & uxCoreAffinityMask ) != 0U ) prvYieldForTask( xTask );
{
prvYieldForTask( pxTCB );
}
} }
#else /* #if( configUSE_PREEMPTION == 1 ) */ #else /* #if( configUSE_PREEMPTION == 1 ) */
{ {