From b90464f4c2fcab74e15ecd4727559b12f1b7ffd5 Mon Sep 17 00:00:00 2001 From: rus084 Date: Tue, 12 May 2026 12:41:36 +0300 Subject: [PATCH] Add affinity to IDLE tasks in SMP systems --- include/FreeRTOS.h | 4 ++++ tasks.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index 63e2feb51..83fd430bd 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -377,6 +377,10 @@ #define configIDLE_SHOULD_YIELD 1 #endif +#ifndef configIDLE_AFFINITY + #define configIDLE_AFFINITY 0 +#endif + #if configMAX_TASK_NAME_LEN < 1 #error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h #endif diff --git a/tasks.c b/tasks.c index c596c475f..ca8189863 100644 --- a/tasks.c +++ b/tasks.c @@ -3687,6 +3687,11 @@ static BaseType_t prvCreateIdleTasks( void ) /* Assign idle task to each core before SMP scheduler is running. */ xIdleTaskHandles[ xCoreID ]->xTaskRunState = xCoreID; pxCurrentTCBs[ xCoreID ] = xIdleTaskHandles[ xCoreID ]; + #if ( ( configIDLE_AFFINITY == 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) + { + xIdleTaskHandles[ xCoreID ]->uxCoreAffinityMask = ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID ); + } + #endif } #endif }