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 ae2bd61054
commit 439c7c4261
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

@@ -42,10 +42,19 @@
#else
#define PORT_OFFSET_PX_STACK 0x30
#endif /* #if CONFIG_FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES */
#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