From d77a3709d2747d9742354161af051b411a78b3f9 Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Wed, 11 Dec 2024 23:29:00 -0500 Subject: [PATCH 1/6] Pass core ID to CRITICAL_NESTING_COUNT macros --- tasks.c | 74 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/tasks.c b/tasks.c index 22e11f0fb21..69124cf5184 100644 --- a/tasks.c +++ b/tasks.c @@ -317,10 +317,10 @@ #define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U ) #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) - #define portGET_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting ) - #define portSET_CRITICAL_NESTING_COUNT( x ) ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting = ( x ) ) - #define portINCREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting++ ) - #define portDECREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting-- ) + #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting ) + #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting = ( x ) ) + #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting++ ) + #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting-- ) #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */ #define taskBITS_PER_BYTE ( ( size_t ) 8 ) @@ -807,13 +807,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; { UBaseType_t uxPrevCriticalNesting; const TCB_t * pxThisTCB; + const UBaseType_t xCoreID = portGET_CORE_ID(); /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); /* This function is always called with interrupts disabled * so this is safe. */ - pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ]; + pxThisTCB = pxCurrentTCBs[ xCoreID ]; while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD ) { @@ -825,11 +826,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; * the suspension and critical nesting counts, as well as release * and reacquire the correct locks. And then, do it all over again * if our state changed again during the reacquisition. */ - uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT(); + uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT( xCoreID ); if( uxPrevCriticalNesting > 0U ) { - portSET_CRITICAL_NESTING_COUNT( 0U ); + portSET_CRITICAL_NESTING_COUNT( xCoreID, 0U ); portRELEASE_ISR_LOCK(); } else @@ -855,7 +856,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; portGET_TASK_LOCK(); portGET_ISR_LOCK(); - portSET_CRITICAL_NESTING_COUNT( uxPrevCriticalNesting ); + portSET_CRITICAL_NESTING_COUNT( xCoreID, uxPrevCriticalNesting ); if( uxPrevCriticalNesting == 0U ) { @@ -874,13 +875,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; BaseType_t xCurrentCoreTaskPriority; BaseType_t xLowestPriorityCore = ( BaseType_t ) -1; BaseType_t xCoreID; + const BaseType_t xCurrentCoreID = portGET_CORE_ID(); #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) BaseType_t xYieldCount = 0; #endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */ /* This must be called from a critical section. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCurrentCoreID ) > 0U ); #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) @@ -969,11 +971,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) /* Verify that the calling core always yields to higher priority tasks. */ - if( ( ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) && - ( pxTCB->uxPriority > pxCurrentTCBs[ portGET_CORE_ID() ]->uxPriority ) ) + if( ( ( pxCurrentTCBs[ xCurrentCoreID ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) && + ( pxTCB->uxPriority > pxCurrentTCBs[ xCurrentCoreID ]->uxPriority ) ) { - configASSERT( ( xYieldPendings[ portGET_CORE_ID() ] == pdTRUE ) || - ( taskTASK_IS_RUNNING( pxCurrentTCBs[ portGET_CORE_ID() ] ) == pdFALSE ) ); + configASSERT( ( xYieldPendings[ xCurrentCoreID ] == pdTRUE ) || + ( taskTASK_IS_RUNNING( pxCurrentTCBs[ xCurrentCoreID ] ) == pdFALSE ) ); } #endif } @@ -3866,6 +3868,7 @@ void vTaskSuspendAll( void ) #else /* #if ( configNUMBER_OF_CORES == 1 ) */ { UBaseType_t ulState; + const UBaseType_t xCoreID = portGET_CORE_ID(); /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -3880,7 +3883,7 @@ void vTaskSuspendAll( void ) ulState = portSET_INTERRUPT_MASK(); /* This must never be called from inside a critical section. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 ); /* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that * do not otherwise exhibit real time behaviour. */ @@ -5187,7 +5190,7 @@ BaseType_t xTaskIncrementTick( void ) /* vTaskSwitchContext() must never be called from within a critical section. * This is not necessarily true for single core FreeRTOS, but it is for this * SMP port. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 ); if( uxSchedulerSuspended != ( UBaseType_t ) 0U ) { @@ -6937,15 +6940,17 @@ static void prvResetNextTaskUnblockTime( void ) */ void vTaskYieldWithinAPI( void ) { + const UBaseType_t xCoreID = portGET_CORE_ID(); + traceENTER_vTaskYieldWithinAPI(); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { portYIELD(); } else { - xYieldPendings[ portGET_CORE_ID() ] = pdTRUE; + xYieldPendings[ xCoreID ] = pdTRUE; } traceRETURN_vTaskYieldWithinAPI(); @@ -6992,19 +6997,21 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskEnterCritical( void ) { + const UBaseType_t xCoreID = portGET_CORE_ID(); + traceENTER_vTaskEnterCritical(); portDISABLE_INTERRUPTS(); if( xSchedulerRunning != pdFALSE ) { - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { portGET_TASK_LOCK(); portGET_ISR_LOCK(); } - portINCREMENT_CRITICAL_NESTING_COUNT(); + portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); /* This is not the interrupt safe version of the enter critical * function so assert() if it is being called from an interrupt @@ -7012,7 +7019,7 @@ static void prvResetNextTaskUnblockTime( void ) * interrupt. Only assert if the critical nesting count is 1 to * protect against recursive calls if the assert function also uses a * critical section. */ - if( portGET_CRITICAL_NESTING_COUNT() == 1U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U ) { portASSERT_IF_IN_ISR(); @@ -7043,6 +7050,7 @@ static void prvResetNextTaskUnblockTime( void ) UBaseType_t vTaskEnterCriticalFromISR( void ) { UBaseType_t uxSavedInterruptStatus = 0; + const UBaseType_t xCoreID = portGET_CORE_ID(); traceENTER_vTaskEnterCriticalFromISR(); @@ -7050,12 +7058,12 @@ static void prvResetNextTaskUnblockTime( void ) { uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { portGET_ISR_LOCK(); } - portINCREMENT_CRITICAL_NESTING_COUNT(); + portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); } else { @@ -7119,28 +7127,30 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCritical( void ) { + const UBaseType_t xCoreID = portGET_CORE_ID(); + traceENTER_vTaskExitCritical(); if( xSchedulerRunning != pdFALSE ) { /* If critical nesting count is zero then this function * does not match a previous call to vTaskEnterCritical(). */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ); /* This function should not be called in ISR. Use vTaskExitCriticalFromISR * to exit critical section from ISR. */ portASSERT_IF_IN_ISR(); - if( portGET_CRITICAL_NESTING_COUNT() > 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ) { - portDECREMENT_CRITICAL_NESTING_COUNT(); + portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { BaseType_t xYieldCurrentTask; /* Get the xYieldPending stats inside the critical section. */ - xYieldCurrentTask = xYieldPendings[ portGET_CORE_ID() ]; + xYieldCurrentTask = xYieldPendings[ xCoreID ]; portRELEASE_ISR_LOCK(); portRELEASE_TASK_LOCK(); @@ -7180,19 +7190,21 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus ) { + const UBaseType_t xCoreID = portGET_CORE_ID(); + traceENTER_vTaskExitCriticalFromISR( uxSavedInterruptStatus ); if( xSchedulerRunning != pdFALSE ) { /* If critical nesting count is zero then this function * does not match a previous call to vTaskEnterCritical(). */ - configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ); - if( portGET_CRITICAL_NESTING_COUNT() > 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ) { - portDECREMENT_CRITICAL_NESTING_COUNT(); + portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ); - if( portGET_CRITICAL_NESTING_COUNT() == 0U ) + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { portRELEASE_ISR_LOCK(); portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); From bc1c6079d72097cc82877aeceb4188d746fc7948 Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Wed, 11 Dec 2024 23:38:14 -0500 Subject: [PATCH 2/6] Match existing data type for xCoreID --- tasks.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tasks.c b/tasks.c index 69124cf5184..26561ddb7f0 100644 --- a/tasks.c +++ b/tasks.c @@ -807,7 +807,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; { UBaseType_t uxPrevCriticalNesting; const TCB_t * pxThisTCB; - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -3868,7 +3868,7 @@ void vTaskSuspendAll( void ) #else /* #if ( configNUMBER_OF_CORES == 1 ) */ { UBaseType_t ulState; - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -4006,8 +4006,7 @@ BaseType_t xTaskResumeAll( void ) * tasks from this list into their appropriate ready list. */ taskENTER_CRITICAL(); { - BaseType_t xCoreID; - xCoreID = ( BaseType_t ) portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* If uxSchedulerSuspended is zero then this function does not match a * previous call to vTaskSuspendAll(). */ @@ -6940,7 +6939,7 @@ static void prvResetNextTaskUnblockTime( void ) */ void vTaskYieldWithinAPI( void ) { - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskYieldWithinAPI(); @@ -6997,7 +6996,7 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskEnterCritical( void ) { - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskEnterCritical(); @@ -7050,7 +7049,7 @@ static void prvResetNextTaskUnblockTime( void ) UBaseType_t vTaskEnterCriticalFromISR( void ) { UBaseType_t uxSavedInterruptStatus = 0; - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskEnterCriticalFromISR(); @@ -7127,7 +7126,7 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCritical( void ) { - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskExitCritical(); @@ -7190,7 +7189,7 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus ) { - const UBaseType_t xCoreID = portGET_CORE_ID(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskExitCriticalFromISR( uxSavedInterruptStatus ); From b6382df843e1056587d6083a254099b6b8f7a80f Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Thu, 12 Dec 2024 23:07:51 -0500 Subject: [PATCH 3/6] Get core ID when interrupts are disabled --- tasks.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tasks.c b/tasks.c index 26561ddb7f0..c20583ceeeb 100644 --- a/tasks.c +++ b/tasks.c @@ -807,7 +807,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; { UBaseType_t uxPrevCriticalNesting; const TCB_t * pxThisTCB; - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -855,6 +855,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; portDISABLE_INTERRUPTS(); portGET_TASK_LOCK(); portGET_ISR_LOCK(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); portSET_CRITICAL_NESTING_COUNT( xCoreID, uxPrevCriticalNesting ); @@ -3868,7 +3869,7 @@ void vTaskSuspendAll( void ) #else /* #if ( configNUMBER_OF_CORES == 1 ) */ { UBaseType_t ulState; - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + BaseType_t xCoreID; /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -3881,6 +3882,7 @@ void vTaskSuspendAll( void ) * It is safe to re-enable interrupts after releasing the ISR lock and incrementing * uxSchedulerSuspended since that will prevent context switches. */ ulState = portSET_INTERRUPT_MASK(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* This must never be called from inside a critical section. */ configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 ); @@ -6996,12 +6998,12 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskEnterCritical( void ) { - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); - traceENTER_vTaskEnterCritical(); portDISABLE_INTERRUPTS(); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + if( xSchedulerRunning != pdFALSE ) { if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) @@ -7049,13 +7051,14 @@ static void prvResetNextTaskUnblockTime( void ) UBaseType_t vTaskEnterCriticalFromISR( void ) { UBaseType_t uxSavedInterruptStatus = 0; - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + BaseType_t xCoreID; traceENTER_vTaskEnterCriticalFromISR(); if( xSchedulerRunning != pdFALSE ) { uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + xCoreID = ( BaseType_t ) portGET_CORE_ID(); if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { From 23daad03f6c99479ac5b3fe3b7cadf6eb1bc54c3 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Sat, 14 Dec 2024 11:21:04 +0800 Subject: [PATCH 4/6] Implement get core ID with interrupt disabled --- .../ThirdParty/GCC/RP2040/include/portmacro.h | 8 +- tasks.c | 90 ++++++++++--------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/portable/ThirdParty/GCC/RP2040/include/portmacro.h b/portable/ThirdParty/GCC/RP2040/include/portmacro.h index 14f58940c69..ed9dbade09e 100644 --- a/portable/ThirdParty/GCC/RP2040/include/portmacro.h +++ b/portable/ThirdParty/GCC/RP2040/include/portmacro.h @@ -158,10 +158,10 @@ void vYieldCore( int xCoreID ); #define portCRITICAL_NESTING_IN_TCB 0 extern UBaseType_t uxCriticalNestings[ configNUMBER_OF_CORES ]; -#define portGET_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ] ) -#define portSET_CRITICAL_NESTING_COUNT( x ) ( uxCriticalNestings[ portGET_CORE_ID() ] = ( x ) ) -#define portINCREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]++ ) -#define portDECREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]-- ) +#define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ] ) +#define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( uxCriticalNestings[ ( xCoreID ) ] = ( x ) ) +#define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]++ ) +#define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]-- ) /*-----------------------------------------------------------*/ diff --git a/tasks.c b/tasks.c index c20583ceeeb..c86b076ee8b 100644 --- a/tasks.c +++ b/tasks.c @@ -317,10 +317,10 @@ #define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U ) #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) - #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting ) - #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting = ( x ) ) - #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting++ ) - #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting-- ) + #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting ) + #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting = ( x ) ) + #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting++ ) + #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting-- ) #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */ #define taskBITS_PER_BYTE ( ( size_t ) 8 ) @@ -6941,18 +6941,24 @@ static void prvResetNextTaskUnblockTime( void ) */ void vTaskYieldWithinAPI( void ) { - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + UBaseType_t ulState; traceENTER_vTaskYieldWithinAPI(); - if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) + ulState = portSET_INTERRUPT_MASK(); { - portYIELD(); - } - else - { - xYieldPendings[ xCoreID ] = pdTRUE; + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) + { + portYIELD(); + } + else + { + xYieldPendings[ xCoreID ] = pdTRUE; + } } + portCLEAR_INTERRUPT_MASK( ulState ); traceRETURN_vTaskYieldWithinAPI(); } @@ -7001,42 +7007,43 @@ static void prvResetNextTaskUnblockTime( void ) traceENTER_vTaskEnterCritical(); portDISABLE_INTERRUPTS(); - - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); - - if( xSchedulerRunning != pdFALSE ) { - if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) - { - portGET_TASK_LOCK(); - portGET_ISR_LOCK(); - } - - portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); - /* This is not the interrupt safe version of the enter critical - * function so assert() if it is being called from an interrupt - * context. Only API functions that end in "FromISR" can be used in an - * interrupt. Only assert if the critical nesting count is 1 to - * protect against recursive calls if the assert function also uses a - * critical section. */ - if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U ) + if( xSchedulerRunning != pdFALSE ) { - portASSERT_IF_IN_ISR(); + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) + { + portGET_TASK_LOCK(); + portGET_ISR_LOCK(); + } - if( uxSchedulerSuspended == 0U ) + portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ); + + /* This is not the interrupt safe version of the enter critical + * function so assert() if it is being called from an interrupt + * context. Only API functions that end in "FromISR" can be used in an + * interrupt. Only assert if the critical nesting count is 1 to + * protect against recursive calls if the assert function also uses a + * critical section. */ + if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U ) { - /* The only time there would be a problem is if this is called - * before a context switch and vTaskExitCritical() is called - * after pxCurrentTCB changes. Therefore this should not be - * used within vTaskSwitchContext(). */ - prvCheckForRunStateChange(); + portASSERT_IF_IN_ISR(); + + if( uxSchedulerSuspended == 0U ) + { + /* The only time there would be a problem is if this is called + * before a context switch and vTaskExitCritical() is called + * after pxCurrentTCB changes. Therefore this should not be + * used within vTaskSwitchContext(). */ + prvCheckForRunStateChange(); + } } } - } - else - { - mtCOVERAGE_TEST_MARKER(); + else + { + mtCOVERAGE_TEST_MARKER(); + } } traceRETURN_vTaskEnterCritical(); @@ -7051,14 +7058,13 @@ static void prvResetNextTaskUnblockTime( void ) UBaseType_t vTaskEnterCriticalFromISR( void ) { UBaseType_t uxSavedInterruptStatus = 0; - BaseType_t xCoreID; + const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); traceENTER_vTaskEnterCriticalFromISR(); if( xSchedulerRunning != pdFALSE ) { uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); - xCoreID = ( BaseType_t ) portGET_CORE_ID(); if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) { From 942fa51fb4e2cd8cd0b4c086af2a0436a810efcb Mon Sep 17 00:00:00 2001 From: Felix van Oost Date: Mon, 16 Dec 2024 22:56:59 -0500 Subject: [PATCH 5/6] Get core ID inline within vTaskSuspendAll() to resolve compiler warning --- tasks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks.c b/tasks.c index c86b076ee8b..104d0376de4 100644 --- a/tasks.c +++ b/tasks.c @@ -3869,7 +3869,6 @@ void vTaskSuspendAll( void ) #else /* #if ( configNUMBER_OF_CORES == 1 ) */ { UBaseType_t ulState; - BaseType_t xCoreID; /* This must only be called from within a task. */ portASSERT_IF_IN_ISR(); @@ -3882,10 +3881,9 @@ void vTaskSuspendAll( void ) * It is safe to re-enable interrupts after releasing the ISR lock and incrementing * uxSchedulerSuspended since that will prevent context switches. */ ulState = portSET_INTERRUPT_MASK(); - xCoreID = ( BaseType_t ) portGET_CORE_ID(); /* This must never be called from inside a critical section. */ - configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 ); + configASSERT( portGET_CRITICAL_NESTING_COUNT( portGET_CORE_ID() ) == 0 ); /* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that * do not otherwise exhibit real time behaviour. */ @@ -7198,12 +7196,14 @@ static void prvResetNextTaskUnblockTime( void ) void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus ) { - const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); + BaseType_t xCoreID; traceENTER_vTaskExitCriticalFromISR( uxSavedInterruptStatus ); if( xSchedulerRunning != pdFALSE ) { + xCoreID = ( BaseType_t ) portGET_CORE_ID(); + /* If critical nesting count is zero then this function * does not match a previous call to vTaskEnterCritical(). */ configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U ); From adb6578eef0c6147dd649e6600af9f1100d6aa13 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Tue, 17 Dec 2024 11:07:47 +0000 Subject: [PATCH 6/6] Fix formatting check Signed-off-by: Gaurav Aggarwal --- tasks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index 104d0376de4..7d9c8758520 100644 --- a/tasks.c +++ b/tasks.c @@ -7203,7 +7203,7 @@ static void prvResetNextTaskUnblockTime( void ) if( xSchedulerRunning != pdFALSE ) { xCoreID = ( BaseType_t ) portGET_CORE_ID(); - + /* If critical nesting count is zero then this function * does not match a previous call to vTaskEnterCritical(). */ configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U );