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 1/4] 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 ) */ { From 18a168bcd2603354bcc5f8a408b2562d86709dd1 Mon Sep 17 00:00:00 2001 From: Saiiijchan <49641410+Saiiijchan@users.noreply.github.com> Date: Tue, 20 Aug 2024 21:04:43 +0800 Subject: [PATCH 2/4] Add heap protector to allocted heap blocks (#1125) When validate those allocated heap block structure, the canary is not used. Do xor with canary when allocating a new block. Signed-off-by: wangfei_chen Co-authored-by: wangfei_chen --- portable/MemMang/heap_4.c | 6 +++--- portable/MemMang/heap_5.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/portable/MemMang/heap_4.c b/portable/MemMang/heap_4.c index d1021ea09..f3cab000d 100644 --- a/portable/MemMang/heap_4.c +++ b/portable/MemMang/heap_4.c @@ -308,7 +308,7 @@ void * pvPortMalloc( size_t xWantedSize ) /* The block is being returned - it is allocated and owned * by the application and has no "next" block. */ heapALLOCATE_BLOCK( pxBlock ); - pxBlock->pxNextFreeBlock = NULL; + pxBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL ); xNumberOfSuccessfulAllocations++; } else @@ -367,11 +367,11 @@ void vPortFree( void * pv ) heapVALIDATE_BLOCK_POINTER( pxLink ); configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 ); - configASSERT( pxLink->pxNextFreeBlock == NULL ); + configASSERT( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) ); if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 ) { - if( pxLink->pxNextFreeBlock == NULL ) + if( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) ) { /* The block is being returned to the heap - it is no longer * allocated. */ diff --git a/portable/MemMang/heap_5.c b/portable/MemMang/heap_5.c index e0c566640..fccf79825 100644 --- a/portable/MemMang/heap_5.c +++ b/portable/MemMang/heap_5.c @@ -336,7 +336,7 @@ void * pvPortMalloc( size_t xWantedSize ) /* The block is being returned - it is allocated and owned * by the application and has no "next" block. */ heapALLOCATE_BLOCK( pxBlock ); - pxBlock->pxNextFreeBlock = NULL; + pxBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL ); xNumberOfSuccessfulAllocations++; } else @@ -395,11 +395,11 @@ void vPortFree( void * pv ) heapVALIDATE_BLOCK_POINTER( pxLink ); configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 ); - configASSERT( pxLink->pxNextFreeBlock == NULL ); + configASSERT( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) ); if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 ) { - if( pxLink->pxNextFreeBlock == NULL ) + if( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) ) { /* The block is being returned to the heap - it is no longer * allocated. */ From 0b904a553adc5f4fdbe0d1df168358579e8788b4 Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Wed, 21 Aug 2024 09:54:46 +0000 Subject: [PATCH 3/4] Remove access check from ISR function (#1127) --- portable/Common/mpu_wrappers_v2.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/portable/Common/mpu_wrappers_v2.c b/portable/Common/mpu_wrappers_v2.c index 2dc36b33b..96f7734f1 100644 --- a/portable/Common/mpu_wrappers_v2.c +++ b/portable/Common/mpu_wrappers_v2.c @@ -3838,27 +3838,16 @@ BaseType_t xReturn = pdFALSE; TimerHandle_t xInternalTimerHandle = NULL; int32_t lIndex; - BaseType_t xIsHigherPriorityTaskWokenWriteable = pdFALSE; - if( pxHigherPriorityTaskWoken != NULL ) + lIndex = ( int32_t ) xTimer; + + if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE ) { - xIsHigherPriorityTaskWokenWriteable = xPortIsAuthorizedToAccessBuffer( pxHigherPriorityTaskWoken, - sizeof( BaseType_t ), - tskMPU_WRITE_PERMISSION ); - } + xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) ); - if( ( pxHigherPriorityTaskWoken == NULL ) || ( xIsHigherPriorityTaskWokenWriteable == pdTRUE ) ) - { - lIndex = ( int32_t ) xTimer; - - if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE ) + if( xInternalTimerHandle != NULL ) { - xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) ); - - if( xInternalTimerHandle != NULL ) - { - xReturn = xTimerGenericCommandFromISR( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); - } + xReturn = xTimerGenericCommandFromISR( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ); } } From 23cfd114d314b0e2dc5e53a3540b0647fc0a1b5b Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Thu, 22 Aug 2024 04:33:58 +0000 Subject: [PATCH 4/4] Update CMakeLists.txt to proper name for the ports (#1129) --- portable/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/portable/CMakeLists.txt b/portable/CMakeLists.txt index 819e2c116..553397589 100644 --- a/portable/CMakeLists.txt +++ b/portable/CMakeLists.txt @@ -798,8 +798,8 @@ target_include_directories(freertos_kernel_port_headers INTERFACE $<$:${CMAKE_CURRENT_LIST_DIR}/GCC/ARM_CA9> # ARMv8-A ports for GCC - $<$:${CMAKE_CURRENT_LIST_DIR}/GCC/Arm_AARCH64> - $<$:${CMAKE_CURRENT_LIST_DIR}/GCC/Arm_AARCH64_SRE> + $<$:${CMAKE_CURRENT_LIST_DIR}/GCC/ARM_AARCH64> + $<$:${CMAKE_CURRENT_LIST_DIR}/GCC/ARM_AARCH64_SRE> # ARMv6-M port for GCC $<$:${CMAKE_CURRENT_LIST_DIR}/GCC/ARM_CM0>