Skip to content

Commit d3b074a

Browse files
authored
Add affinity to IDLE tasks in SMP systems (#1415)
1 parent a8c9d35 commit d3b074a

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

examples/template_configuration/FreeRTOSConfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,13 @@
558558
* tskNO_AFFINITY if left undefined. */
559559
#define configTIMER_SERVICE_TASK_CORE_AFFINITY tskNO_AFFINITY
560560

561+
/* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), set
562+
* configIDLE_AFFINITY to 1 to pin each Idle task to its corresponding
563+
* core. When set to 1, Idle task N will only run on core N, using an affinity
564+
* mask of (1 << N). Set to 0 to allow the scheduler to run Idle tasks on any
565+
* available core. Defaults to 0 if left undefined. */
566+
#define configIDLE_AFFINITY 0
567+
561568
/******************************************************************************/
562569
/* ARMv8-M secure side port related definitions. ******************************/
563570
/******************************************************************************/

include/FreeRTOS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@
377377
#define configIDLE_SHOULD_YIELD 1
378378
#endif
379379

380+
#ifndef configIDLE_AFFINITY
381+
#define configIDLE_AFFINITY 0
382+
#endif
383+
380384
#if configMAX_TASK_NAME_LEN < 1
381385
#error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h
382386
#endif

tasks.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3687,8 +3687,13 @@ static BaseType_t prvCreateIdleTasks( void )
36873687
/* Assign idle task to each core before SMP scheduler is running. */
36883688
xIdleTaskHandles[ xCoreID ]->xTaskRunState = xCoreID;
36893689
pxCurrentTCBs[ xCoreID ] = xIdleTaskHandles[ xCoreID ];
3690+
#if ( ( configIDLE_AFFINITY == 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
3691+
{
3692+
xIdleTaskHandles[ xCoreID ]->uxCoreAffinityMask = ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID );
3693+
}
3694+
#endif
36903695
}
3691-
#endif
3696+
#endif /* if ( configNUMBER_OF_CORES == 1 ) */
36923697
}
36933698
}
36943699

0 commit comments

Comments
 (0)