change(freertos/idf): Remove xCoreID TCB member for single-core

This commit does the following:

- removes the xCoreID member from the TCB when building for single-core
- xCoreID is no longer hard set to 0 when calling "PinnedToCore" task creation
functions in single-core
- Tidy up or add missing xCoreID asserts for functions that take xCoreID as an
argument:
    - Functions that set/query a variable of a particular core will call
      taskVALID_CORE_ID() to ensure ) 0 <= xCoreID < configNUMBER_OF_CORES
    - Task creation functions that accept xCoreID also call taskVALID_CORE_ID()
      but also allow tskNO_AFFINITY.
- Fix TaskStatus_t
    - Remove xCoreID from TaskStatus_t if configTASKLIST_INCLUDE_COREID is not
      defined.
    - Set xCoreID to 0 when calling vTaskGetInfo() in single-core builds
This commit is contained in:
Darian Leung 2023-11-16 19:41:24 +08:00
parent 63fee6c23a
commit ee0ee4887f
10 changed files with 99 additions and 41 deletions

View File

@ -1289,8 +1289,9 @@ typedef struct xSTATIC_TCB
UBaseType_t uxDummy5;
void * pxDummy6;
uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ];
/* Todo: Remove xCoreID for single core builds (IDF-7894) */
BaseType_t xDummyCoreID;
#if ( configNUMBER_OF_CORES > 1 )
BaseType_t xDummyCoreID;
#endif /* configNUMBER_OF_CORES > 1 */
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
void * pxDummy8;
#endif

View File

@ -176,7 +176,9 @@ typedef struct xTASK_STATUS
StackType_t * pxEndOfStack; /**< Points to the end address of the task's stack area. */
#endif
configSTACK_DEPTH_TYPE usStackHighWaterMark; /**< The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
BaseType_t xCoreID; /**< Core this task is pinned to (0, 1, or tskNO_AFFINITY). If configNUMBER_OF_CORES == 1, this will always be 0. */
#if ( configTASKLIST_INCLUDE_COREID == 1 )
BaseType_t xCoreID; /**< Core this task is pinned to (0, 1, or tskNO_AFFINITY). If configNUMBER_OF_CORES == 1, this will always be 0. */
#endif
} TaskStatus_t;
/** Possible return values for eTaskConfirmSleepModeStatus(). */
@ -211,7 +213,7 @@ typedef enum
*
* \ingroup Tasks
*/
#define taskVALID_CORE_ID( xCoreID ) ( ( ( ( ( BaseType_t ) xCoreID ) >= 0 && ( ( BaseType_t ) xCoreID ) < configNUMBER_OF_CORES ) || ( ( ( BaseType_t ) xCoreID ) == tskNO_AFFINITY ) ) ? pdTRUE : pdFALSE )
#define taskVALID_CORE_ID( xCoreID ) ( ( ( ( BaseType_t ) xCoreID ) >= 0 && ( ( BaseType_t ) xCoreID ) < configNUMBER_OF_CORES ) ? pdTRUE : pdFALSE )
/**
*

View File

@ -38,10 +38,19 @@
/* Macros used instead ofsetoff() for better performance of interrupt handler */
#define PORT_OFFSET_PX_STACK 0x30
#define PORT_OFFSET_PX_END_OF_STACK (PORT_OFFSET_PX_STACK + \
/* void * pxDummy6 */ 4 + \
/* uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ] */ CONFIG_FREERTOS_MAX_TASK_NAME_LEN + \
/* BaseType_t xDummyCoreID */ 4)
#if CONFIG_FREERTOS_UNICORE
#define CORE_ID_SIZE 0
#else
#define CORE_ID_SIZE 4
#endif
#define PORT_OFFSET_PX_END_OF_STACK ( \
PORT_OFFSET_PX_STACK \
+ 4 /* void * pxDummy6 */ \
+ CONFIG_FREERTOS_MAX_TASK_NAME_LEN /* uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ] */ \
+ CORE_ID_SIZE /* BaseType_t xDummyCoreID */ \
)
#ifndef __ASSEMBLER__

View File

@ -301,7 +301,11 @@ static void vPortCleanUpCoprocArea(void *pvTCB)
* If yes, reset the owner. */
if (sa->sa_enable != 0) {
/* Get the core the task is pinned on */
const BaseType_t coreID = task->xDummyCoreID;
#if ( configNUM_CORES > 1 )
const BaseType_t coreID = task->xDummyCoreID;
#else /* configNUM_CORES > 1 */
const BaseType_t coreID = 0;
#endif /* configNUM_CORES > 1 */
for (int i = 0; i < SOC_CPU_COPROC_NUM; i++) {
StaticTask_t** owner = &port_uxCoprocOwner[coreID][i];
@ -767,11 +771,12 @@ void vPortTCBPreDeleteHook( void *pxTCB )
* are saved lazily, as soon as a task starts using one, it must always be scheduled on the core
* it is currently executing on.
*/
#if ( configNUM_CORES > 1 )
void vPortTaskPinToCore(StaticTask_t* task, int coreid)
{
task->xDummyCoreID = coreid;
}
#endif /* configNUM_CORES > 1 */
/**
* @brief Get coprocessor save area out of the given task. If the coprocessor area is not created,

View File

@ -185,10 +185,12 @@ rtos_save_fpu_coproc:
csrr a1, fcsr
sw a1, RV_FPU_FCSR(a0)
rtos_save_fpu_coproc_nosave:
#if ( configNUM_CORES > 1 )
/* Pin current task to current core */
mv a0, s1
csrr a1, mhartid
call vPortTaskPinToCore
#endif /* configNUM_CORES > 1 */
/* Check if we have to restore a previous FPU context from the current TCB */
mv a0, s1
call pxPortGetCoprocArea

View File

@ -618,8 +618,12 @@ static void vPortCleanUpCoprocArea(void *pvTCB)
uxCoprocArea = ( UBaseType_t ) ( ( ( StaticTask_t * ) pvTCB )->pxDummy8 ); /* Get TCB_t.pxEndOfStack */
uxCoprocArea = STACKPTR_ALIGN_DOWN(16, uxCoprocArea - XT_CP_SIZE);
/* Get xTargetCoreID from the TCB.xCoreID */
xTargetCoreID = ( ( StaticTask_t * ) pvTCB )->xDummyCoreID;
#if ( configNUMBER_OF_CORES > 1 )
/* Get xTargetCoreID from the TCB.xCoreID */
xTargetCoreID = ( ( StaticTask_t * ) pvTCB )->xDummyCoreID;
#else /* configNUMBER_OF_CORES > 1 */
xTargetCoreID = 0;
#endif /* configNUMBER_OF_CORES > 1 */
/* If task has live floating point registers somewhere, release them */
void _xt_coproc_release(volatile void *coproc_sa_base, BaseType_t xTargetCoreID);

View File

@ -390,8 +390,9 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
StackType_t * pxStack; /*< Points to the start of the stack. */
char pcTaskName[ configMAX_TASK_NAME_LEN ]; /*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
/* Todo: Remove xCoreID for single core builds (IDF-7894) */
BaseType_t xCoreID; /*< The core that this task is pinned to */
#if ( configNUMBER_OF_CORES > 1 )
BaseType_t xCoreID; /*< The core that this task is pinned to */
#endif /* configNUMBER_OF_CORES > 1 */
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
StackType_t * pxEndOfStack; /*< Points to the highest valid address for the stack. */
@ -971,14 +972,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
StackType_t * pxTopOfStack;
UBaseType_t x;
#if ( configNUMBER_OF_CORES > 1 )
/* Check that xCoreID is valid */
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
#else
/* Hard code xCoreID to 0 */
xCoreID = 0;
#endif
#if ( portUSING_MPU_WRAPPERS == 1 )
/* Should the task be created in privileged mode? */
BaseType_t xRunPrivileged;
@ -1077,7 +1070,16 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
}
pxNewTCB->uxPriority = uxPriority;
pxNewTCB->xCoreID = xCoreID; /* Todo: Remove xCoreID for single core builds (IDF-7894) */
#if ( configNUMBER_OF_CORES > 1 )
{
pxNewTCB->xCoreID = xCoreID;
}
#else /* configNUMBER_OF_CORES > 1 */
{
/* Avoid compiler warning about unreferenced parameter. */
( void ) xCoreID;
}
#endif /* configNUMBER_OF_CORES > 1 */
#if ( configUSE_MUTEXES == 1 )
{
pxNewTCB->uxBasePriority = uxPriority;
@ -4573,8 +4575,19 @@ static void prvCheckTasksWaitingTermination( void )
pxTaskStatus->pxEndOfStack = pxTCB->pxEndOfStack;
#endif
pxTaskStatus->xTaskNumber = pxTCB->uxTCBNumber;
/* Todo: Remove xCoreID for single core builds (IDF-7894) */
pxTaskStatus->xCoreID = pxTCB->xCoreID;
#if ( configTASKLIST_INCLUDE_COREID == 1 )
{
#if ( configNUMBER_OF_CORES > 1 )
{
pxTaskStatus->xCoreID = pxTCB->xCoreID;
}
#else /* configNUMBER_OF_CORES > 1 */
{
pxTaskStatus->xCoreID = 0;
}
#endif /* configNUMBER_OF_CORES > 1 */
}
#endif /* configTASKLIST_INCLUDE_COREID == 1 */
#if ( configUSE_MUTEXES == 1 )
{
@ -5425,8 +5438,16 @@ static void prvResetNextTaskUnblockTime( void )
pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );
/* Write the rest of the string. */
sprintf( pcWriteBuffer, "\t%c\t%u\t%d\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, pxTaskStatusArray[ x ].xCoreID, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */
#if ( configTASKLIST_INCLUDE_COREID == 1 )
{
sprintf( pcWriteBuffer, "\t%c\t%u\t%d\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].xCoreID, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
}
#else /* configTASKLIST_INCLUDE_COREID == 1 */
{
sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */
}
#endif /* configTASKLIST_INCLUDE_COREID == 1 */
pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */
}
/* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION

View File

@ -175,6 +175,8 @@ _Static_assert( tskNO_AFFINITY == ( BaseType_t ) CONFIG_FREERTOS_NO_AFFINITY, "C
{
BaseType_t xReturn;
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE || xCoreID == tskNO_AFFINITY );
#if CONFIG_FREERTOS_SMP
{
/* If using Amazon SMP FreeRTOS. This function is just a wrapper around
@ -309,6 +311,10 @@ _Static_assert( tskNO_AFFINITY == ( BaseType_t ) CONFIG_FREERTOS_NO_AFFINITY, "C
{
TaskHandle_t xReturn;
configASSERT( portVALID_STACK_MEM( puxStackBuffer ) );
configASSERT( portVALID_TCB_MEM( pxTaskBuffer ) );
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE || xCoreID == tskNO_AFFINITY );
#if CONFIG_FREERTOS_SMP
{
/* If using Amazon SMP FreeRTOS. This function is just a wrapper around
@ -318,6 +324,10 @@ _Static_assert( tskNO_AFFINITY == ( BaseType_t ) CONFIG_FREERTOS_NO_AFFINITY, "C
/* Convert xCoreID into an affinity mask */
UBaseType_t uxCoreAffinityMask;
/* Bit shifting << xCoreID is only valid if we have less than
* 32 cores. */
ESP_STATIC_ASSERT( configNUM_CORES < 32 );
if( xCoreID == tskNO_AFFINITY )
{
uxCoreAffinityMask = tskNO_AFFINITY;
@ -339,10 +349,6 @@ _Static_assert( tskNO_AFFINITY == ( BaseType_t ) CONFIG_FREERTOS_NO_AFFINITY, "C
{
TCB_t * pxNewTCB;
configASSERT( portVALID_STACK_MEM( puxStackBuffer ) );
configASSERT( portVALID_TCB_MEM( pxTaskBuffer ) );
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
#if ( configASSERT_DEFINED == 1 )
{
/* Sanity check that the size of the structure used to declare a
@ -458,7 +464,7 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask )
{
/* If xTaskGetIdleTaskHandle() is called before the scheduler has been
* started, then xIdleTaskHandle will be NULL. */
configASSERT( ( xCoreID < configNUMBER_OF_CORES ) && ( xCoreID != tskNO_AFFINITY ) );
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
configASSERT( ( xIdleTaskHandle[ xCoreID ] != NULL ) );
return xIdleTaskHandle[ xCoreID ];
}
@ -472,14 +478,14 @@ BaseType_t xTaskGetCoreID( TaskHandle_t xTask )
{
TaskHandle_t xReturn;
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
#if ( CONFIG_FREERTOS_SMP )
{
xReturn = xTaskGetCurrentTaskHandleCPU( ( UBaseType_t ) xCoreID );
}
#else /* CONFIG_FREERTOS_SMP */
{
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
/* A critical section is not required as this function does not
* guarantee that the TCB will still be valid when this function
* returns. */
@ -1109,7 +1115,8 @@ void * pvTaskGetCurrentTCBForCore( BaseType_t xCoreID )
{
void * pvRet;
configASSERT( ( xCoreID >= 0 ) && ( xCoreID < configNUM_CORES ) );
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
#if CONFIG_FREERTOS_SMP
/* SMP FreeRTOS defines pxCurrentTCB as a macro function call */
pvRet = ( void * ) pxCurrentTCB;
@ -1187,6 +1194,11 @@ void * pvTaskGetCurrentTCBForCore( BaseType_t xCoreID )
configASSERT( uxStackMemoryCaps & ( MALLOC_CAP_8BIT ) );
configASSERT( ( uxStackMemoryCaps & MALLOC_CAP_SPIRAM ) ||
( uxStackMemoryCaps & MALLOC_CAP_INTERNAL ) );
#if ( !CONFIG_FREERTOS_SMP )
{
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE || xCoreID == tskNO_AFFINITY );
}
#endif /* !CONFIG_FREERTOS_SMP */
/* Allocate space for the stack used by the task being created. */
pxStack = heap_caps_malloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), uxStackMemoryCaps );

View File

@ -314,8 +314,8 @@
* should be set to ( 2 | portPRIVILEGE_BIT ).
*
* @param xCoreID (only IDF SMP FreeRTOS)
* The core to which the task is pinned to, or tskNO_AFFINITY if
* the task can run on any core.
* The core to which the task is pinned to, or tskNO_AFFINITY if the task has no
* core affinity.
*
* @param uxCoreAffinityMask (only Amazon SMP FreeRTOS)
* A bitwise value that indicates the cores on which the task can run.

View File

@ -43,7 +43,8 @@
* task. The task's pinned core is specified by the xCoreID argument. If xCoreID
* is set to tskNO_AFFINITY, then the task is unpinned and can run on any core.
*
* @note If ( configNUM_CORES == 1 ), xCoreID is ignored.
* @note If ( configNUMBER_OF_CORES == 1 ), setting xCoreID to tskNO_AFFINITY will be
* be treated as 0.
*
* @param pxTaskCode Pointer to the task entry function.
* @param pcName A descriptive name for the task.
@ -55,7 +56,7 @@
* @param pxCreatedTask Used to pass back a handle by which the created task can
* be referenced.
* @param xCoreID The core to which the task is pinned to, or tskNO_AFFINITY if
* the task has no core affinity
* the task has no core affinity.
* @return pdPASS if the task was successfully created and added to a ready
* list, otherwise an error code defined in the file projdefs.h
*/
@ -79,7 +80,8 @@
* xCoreID is set to tskNO_AFFINITY, then the task is unpinned and can run on any
* core.
*
* @note If ( configNUM_CORES == 1 ), xCoreID is ignored.
* @note If ( configNUMBER_OF_CORES == 1 ), setting xCoreID to tskNO_AFFINITY will be
* be treated as 0.
*
* @param pxTaskCode Pointer to the task entry function.
* @param pcName A descriptive name for the task.
@ -93,7 +95,7 @@
* @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
* then be used to hold the task's data structures,
* @param xCoreID The core to which the task is pinned to, or tskNO_AFFINITY if
* the task has no core affinity
* the task has no core affinity.
* @return The task handle if the task was created, NULL otherwise.
*/
TaskHandle_t xTaskCreateStaticPinnedToCore( TaskFunction_t pxTaskCode,