From 39bdd2a52ba1a77690da54c17b7cb4c51ea9182d Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Mon, 4 Sep 2023 17:44:49 +0800 Subject: [PATCH 1/6] Add core affinity bits check --- include/FreeRTOS.h | 4 ++++ tasks.c | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index ca5818eae4..079475fd8c 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -1165,6 +1165,10 @@ #error configUSE_TASK_PREEMPTION_DISABLE is not supported in single core FreeRTOS #endif +#if ( ( configNUMBER_OF_CORES == 1 ) && ( configUSE_CORE_AFFINITY != 0 ) ) + #error configUSE_CORE_AFFINITY is not supported in single core FreeRTOS +#endif + #ifndef configINITIAL_TICK_COUNT #define configINITIAL_TICK_COUNT 0 #endif diff --git a/tasks.c b/tasks.c index 2786c5ab0e..0ce8d58273 100644 --- a/tasks.c +++ b/tasks.c @@ -305,7 +305,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to #endif #if ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) - UBaseType_t uxCoreAffinityMask; /*< Used to link the task to certain cores. UBaseType_t must have greater than or equal to the number of bits as confNUM_CORES. */ + UBaseType_t uxCoreAffinityMask; /**< Used to link the task to certain cores. UBaseType_t must have greater than or equal to the number of bits as configNUMBER_OF_CORES. */ #endif ListItem_t xStateListItem; /**< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */ @@ -3257,6 +3257,13 @@ void vTaskStartScheduler( void ) { BaseType_t xReturn; + #if ( configUSE_CORE_AFFINITY == 1 ) + { + /* UBaseType_t must have greater than or equal to the number of bits as confNUMBER_OF_CORES. */ + configASSERT( configNUMBER_OF_CORES <= ( sizeof( UBaseType_t ) * 8 ) ); + } + #endif + xReturn = prvCreateIdleTasks(); #if ( configUSE_TIMERS == 1 ) From 02f05f364e965d730b5194e936264969ee3add1c Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 10:46:16 +0800 Subject: [PATCH 2/6] Add taskBITS_PER_BYTES --- tasks.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index 0ce8d58273..10545dc061 100644 --- a/tasks.c +++ b/tasks.c @@ -291,6 +291,8 @@ typedef BaseType_t TaskRunning_t; #define INFINITE_LOOP() 1 #endif +#define taskBITS_PER_TYPE ( ( size_t ) 8 ) + /* * Task control block. A task control block (TCB) is allocated for each task, * and stores task state information, including a pointer to the task's context @@ -3260,7 +3262,7 @@ void vTaskStartScheduler( void ) #if ( configUSE_CORE_AFFINITY == 1 ) { /* UBaseType_t must have greater than or equal to the number of bits as confNUMBER_OF_CORES. */ - configASSERT( configNUMBER_OF_CORES <= ( sizeof( UBaseType_t ) * 8 ) ); + configASSERT( configNUMBER_OF_CORES <= ( sizeof( UBaseType_t ) * taskBITS_PER_TYPE ) ); } #endif From 692d238ee3aabc7edbc86d2660410317e4344301 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 10:48:51 +0800 Subject: [PATCH 3/6] Update comment --- tasks.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index b2299a151c..4bce06f1af 100644 --- a/tasks.c +++ b/tasks.c @@ -3261,7 +3261,8 @@ void vTaskStartScheduler( void ) #if ( configUSE_CORE_AFFINITY == 1 ) { - /* UBaseType_t must have greater than or equal to the number of bits as confNUMBER_OF_CORES. */ + /* Sanity check that the UBaseType_t must have greater than or equal to + * the number of bits as confNUMBER_OF_CORES. */ configASSERT( configNUMBER_OF_CORES <= ( sizeof( UBaseType_t ) * taskBITS_PER_TYPE ) ); } #endif From 499dee26fcb1d43d265a839d2a350872a72b033b Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 10:49:52 +0800 Subject: [PATCH 4/6] Reverse condition order --- tasks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index 4bce06f1af..40e42ecbed 100644 --- a/tasks.c +++ b/tasks.c @@ -3263,7 +3263,7 @@ void vTaskStartScheduler( void ) { /* Sanity check that the UBaseType_t must have greater than or equal to * the number of bits as confNUMBER_OF_CORES. */ - configASSERT( configNUMBER_OF_CORES <= ( sizeof( UBaseType_t ) * taskBITS_PER_TYPE ) ); + configASSERT( ( sizeof( UBaseType_t ) * taskBITS_PER_TYPE ) >= configNUMBER_OF_CORES ); } #endif From eb9ec69cdffe15fdcaecb0e9aa19e0801059737b Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 17:07:23 +0800 Subject: [PATCH 5/6] Add number of cores check --- tasks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks.c b/tasks.c index 40e42ecbed..79d026e9eb 100644 --- a/tasks.c +++ b/tasks.c @@ -3259,13 +3259,13 @@ void vTaskStartScheduler( void ) { BaseType_t xReturn; - #if ( configUSE_CORE_AFFINITY == 1 ) + #if ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) { /* Sanity check that the UBaseType_t must have greater than or equal to * the number of bits as confNUMBER_OF_CORES. */ configASSERT( ( sizeof( UBaseType_t ) * taskBITS_PER_TYPE ) >= configNUMBER_OF_CORES ); } - #endif + #endif /* #if ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) */ xReturn = prvCreateIdleTasks(); From 60f7acd59537251d165cc4ff03303918f8065ae1 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 17:21:57 +0800 Subject: [PATCH 6/6] Fix typo --- tasks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks.c b/tasks.c index 79d026e9eb..e813f6606d 100644 --- a/tasks.c +++ b/tasks.c @@ -291,7 +291,7 @@ typedef BaseType_t TaskRunning_t; #define INFINITE_LOOP() 1 #endif -#define taskBITS_PER_TYPE ( ( size_t ) 8 ) +#define taskBITS_PER_BYTE ( ( size_t ) 8 ) /* * Task control block. A task control block (TCB) is allocated for each task, @@ -3263,7 +3263,7 @@ void vTaskStartScheduler( void ) { /* Sanity check that the UBaseType_t must have greater than or equal to * the number of bits as confNUMBER_OF_CORES. */ - configASSERT( ( sizeof( UBaseType_t ) * taskBITS_PER_TYPE ) >= configNUMBER_OF_CORES ); + configASSERT( ( sizeof( UBaseType_t ) * taskBITS_PER_BYTE ) >= configNUMBER_OF_CORES ); } #endif /* #if ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) */