From e43553af1e3d19a1eec27593c332f97e986cbd1c Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:34:01 +0800 Subject: [PATCH] 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. --- tasks.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tasks.c b/tasks.c index cb3c190b9..8002d316a 100644 --- a/tasks.c +++ b/tasks.c @@ -2982,11 +2982,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, { TCB_t * pxTCB; BaseType_t xCoreID; - UBaseType_t uxPrevCoreAffinityMask; - - #if ( configUSE_PREEMPTION == 1 ) - UBaseType_t uxPrevNotAllowedCores; - #endif traceENTER_vTaskCoreAffinitySet( xTask, uxCoreAffinityMask ); @@ -2994,7 +2989,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, { pxTCB = prvGetTCBFromHandle( xTask ); - uxPrevCoreAffinityMask = pxTCB->uxCoreAffinityMask; pxTCB->uxCoreAffinityMask = uxCoreAffinityMask; if( xSchedulerRunning != pdFALSE ) @@ -3014,17 +3008,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, { #if ( configUSE_PREEMPTION == 1 ) { - /* Calculate the cores on which this task was not allowed to - * run previously. */ - uxPrevNotAllowedCores = ( ~uxPrevCoreAffinityMask ) & ( ( 1U << configNUMBER_OF_CORES ) - 1U ); - - /* Does the new core mask enables this task to run on any of the - * previously not allowed cores? If yes, check if this task can be - * scheduled on any of those cores. */ - if( ( uxPrevNotAllowedCores & uxCoreAffinityMask ) != 0U ) - { - prvYieldForTask( pxTCB ); - } + /* The SMP scheduler requests a core to yield when a ready + * task is able to run. It is possible that the core affinity + * of the ready task is changed before the requested core + * can select it to run. In that case, the task may not be + * selected by the previously requested core due to core affinity + * constraint and the SMP scheduler must select a new core to + * yield for the task. */ + prvYieldForTask( xTask ); } #else /* #if( configUSE_PREEMPTION == 1 ) */ {