From e68975fcf75c26363ded33de9b98f2a1ccf65b03 Mon Sep 17 00:00:00 2001 From: Christoph Seitz Date: Fri, 16 Feb 2024 06:42:18 +0100 Subject: [PATCH] Add default core affinity config value. (#996) * Add default core affinity config value. --------- Co-authored-by: Anubhav Rawal --- examples/template_configuration/FreeRTOSConfig.h | 9 +++++++++ include/FreeRTOS.h | 6 ++++++ tasks.c | 8 ++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/template_configuration/FreeRTOSConfig.h b/examples/template_configuration/FreeRTOSConfig.h index 14aa3b24be..2c807142c6 100644 --- a/examples/template_configuration/FreeRTOSConfig.h +++ b/examples/template_configuration/FreeRTOSConfig.h @@ -496,6 +496,15 @@ * run any task on any available core. */ #define configUSE_CORE_AFFINITY 0 +/* When using SMP with core affinity feature enabled, set + * configTASK_DEFAULT_CORE_AFFINITY to change the default core affinity mask for + * tasks created without an affinity mask specified. Setting the define to 1 would + * make such tasks run on core 0 and setting it to (1 << portGET_CORE_ID()) would + * make such tasks run on the current core. This config value is useful, if + * swapping tasks between cores is not supported (e.g. Tricore) or if legacy code + * should be controlled. Defaults to tskNO_AFFINITY if left undefined. */ +#define configTASK_DEFAULT_CORE_AFFINITY tskNO_AFFINITY + /* When using SMP (i.e. configNUMBER_OF_CORES is greater than one), if * configUSE_TASK_PREEMPTION_DISABLE is set to 1, individual tasks can be set to * either pre-emptive or co-operative mode using the vTaskPreemptionDisable and diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index 9ef6217cfb..0c386cc4d2 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -484,6 +484,12 @@ #define configUSE_CORE_AFFINITY 0 #endif /* configUSE_CORE_AFFINITY */ +#if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) + #ifndef configTASK_DEFAULT_CORE_AFFINITY + #define configTASK_DEFAULT_CORE_AFFINITY tskNO_AFFINITY + #endif +#endif + #ifndef configUSE_PASSIVE_IDLE_HOOK #define configUSE_PASSIVE_IDLE_HOOK 0 #endif /* configUSE_PASSIVE_IDLE_HOOK */ diff --git a/tasks.c b/tasks.c index c51c155a7f..6c399dbf5c 100644 --- a/tasks.c +++ b/tasks.c @@ -1325,7 +1325,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) { /* Set the task's affinity before scheduling it. */ - pxNewTCB->uxCoreAffinityMask = tskNO_AFFINITY; + pxNewTCB->uxCoreAffinityMask = configTASK_DEFAULT_CORE_AFFINITY; } #endif @@ -1442,7 +1442,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) { /* Set the task's affinity before scheduling it. */ - pxNewTCB->uxCoreAffinityMask = tskNO_AFFINITY; + pxNewTCB->uxCoreAffinityMask = configTASK_DEFAULT_CORE_AFFINITY; } #endif @@ -1560,7 +1560,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) { /* Set the task's affinity before scheduling it. */ - pxNewTCB->uxCoreAffinityMask = tskNO_AFFINITY; + pxNewTCB->uxCoreAffinityMask = configTASK_DEFAULT_CORE_AFFINITY; } #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */ @@ -1733,7 +1733,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) { /* Set the task's affinity before scheduling it. */ - pxNewTCB->uxCoreAffinityMask = tskNO_AFFINITY; + pxNewTCB->uxCoreAffinityMask = configTASK_DEFAULT_CORE_AFFINITY; } #endif