converted exclusion to affinity

This commit is contained in:
Joseph Julicher 2021-05-13 17:20:41 -07:00
parent b9a17479a0
commit d59bfca4f9
4 changed files with 55 additions and 44 deletions

3
.github/lexicon.txt vendored
View file

@ -2400,7 +2400,8 @@ uxbitstoset
uxbitstowait uxbitstowait
uxbitstowaitfor uxbitstowaitfor
uxcontrolbits uxcontrolbits
uxcoreexclude uxcoreaffinitymask
uxcoreaffinityinheritancemask
uxcriticalnesting uxcriticalnesting
uxcurrenteventbits uxcurrenteventbits
uxcurrentnumberoftasks uxcurrentnumberoftasks

View file

@ -240,8 +240,8 @@
#define configUSE_TASK_PREEMPTION_DISABLE 0 #define configUSE_TASK_PREEMPTION_DISABLE 0
#endif #endif
#ifndef configUSE_CORE_EXCLUSION #ifndef configUSE_CORE_AFFINITY
#define configUSE_CORE_EXCLUSION 0 #define configUSE_CORE_AFFINITY 0
#endif #endif
#ifndef configUSE_ALTERNATIVE_API #ifndef configUSE_ALTERNATIVE_API
@ -948,7 +948,7 @@
#error configUSE_MUTEXES must be set to 1 to use recursive mutexes #error configUSE_MUTEXES must be set to 1 to use recursive mutexes
#endif #endif
#if( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configUSE_CORE_EXCLUSION != 0 ) ) #if( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configUSE_CORE_AFFINITY != 0 ) )
#error configRUN_MULTIPLE_PRIORITIES must be set to 1 to use core exclusion #error configRUN_MULTIPLE_PRIORITIES must be set to 1 to use core exclusion
#endif #endif
@ -1209,8 +1209,9 @@ typedef struct xSTATIC_TCB
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 ) #if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
BaseType_t xDummy24; BaseType_t xDummy24;
#endif #endif
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 && configNUM_CORES > 1 )
UBaseType_t uxDummy25; UBaseType_t uxDummy25;
UBaseType_t uxDummy26;
#endif #endif
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
void * pxDummy8; void * pxDummy8;

View file

@ -170,6 +170,14 @@ typedef enum
*/ */
#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U ) #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
/**
* Defines affinity to all available cores.
*
*/
#define tskNO_AFFINITY ( ( UBaseType_t ) -1U )
/** /**
* task. h * task. h
* *
@ -1235,8 +1243,10 @@ void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
*/ */
BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
void vTaskCoreExclusionSet( const TaskHandle_t xTask, UBaseType_t uxCoreExclude ); #if ( configUSE_CORE_AFFINITY == 1)
UBaseType_t vTaskCoreExclusionGet( const TaskHandle_t xTask ); void vTaskCoreAffinitySet( const TaskHandle_t xTask, UBaseType_t uxCoreAffinityMask );
UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask );
#endif
void vTaskPreemptionDisable( const TaskHandle_t xTask ); void vTaskPreemptionDisable( const TaskHandle_t xTask );
void vTaskPreemptionEnable( const TaskHandle_t xTask ); void vTaskPreemptionEnable( const TaskHandle_t xTask );

73
tasks.c
View file

@ -254,8 +254,9 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
BaseType_t xPreemptionDisable; /*< Used to prevent the task from being preempted */ BaseType_t xPreemptionDisable; /*< Used to prevent the task from being preempted */
#endif #endif
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 && configNUM_CORES > 1 )
UBaseType_t uxCoreExclude; /*< Used to exclude the task from certain cores */ UBaseType_t uxCoreAffinityMask; /*< Used to link the task to certain cores. UBaseType_t must have >= the same number of bits as SMP confNUM_CORES */
UBaseType_t uxCoreAffinityInheritanceMask; /*< Used to allow a task to inherit the affinity of its parent */
#endif #endif
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
@ -321,7 +322,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
#if ( configUSE_POSIX_ERRNO == 1 ) #if ( configUSE_POSIX_ERRNO == 1 )
int iTaskErrno; int iTaskErrno;
#endif #endif
} tskTCB; } tskTCB;
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name /* The old tskTCB name is maintained above then typedefed to the new TCB_t name
* below to enable the use of older kernel aware debuggers. */ * below to enable the use of older kernel aware debuggers. */
@ -760,8 +761,8 @@ static void prvYieldForTask( TCB_t * pxTCB,
{ {
if( xTaskPriority <= xLowestPriority ) if( xTaskPriority <= xLowestPriority )
{ {
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
if( ( pxTCB->uxCoreExclude & ( 1 << x ) ) == 0 ) if( ( pxTCB->uxCoreAffinityMask & ( 1 << x ) ) == 1 )
#endif #endif
{ {
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 ) #if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@ -824,7 +825,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
BaseType_t xTaskScheduled = pdFALSE; BaseType_t xTaskScheduled = pdFALSE;
BaseType_t xDecrementTopPriority = pdTRUE; BaseType_t xDecrementTopPriority = pdTRUE;
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
TCB_t * pxPreviousTCB = NULL; TCB_t * pxPreviousTCB = NULL;
#endif #endif
#if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) ) #if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) )
@ -892,13 +893,13 @@ static void prvYieldForTask( TCB_t * pxTCB,
if( pxTCB->xTaskRunState == taskTASK_NOT_RUNNING ) if( pxTCB->xTaskRunState == taskTASK_NOT_RUNNING )
{ {
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
if( ( pxTCB->uxCoreExclude & ( 1 << xCoreID ) ) == 0 ) if( ( pxTCB->uxCoreAffinityMask & ( 1 << xCoreID ) ) == 1 )
#endif #endif
{ {
/* If the task is not being executed by any core swap it in */ /* If the task is not being executed by any core swap it in */
pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_NOT_RUNNING; pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_NOT_RUNNING;
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
pxPreviousTCB = pxCurrentTCBs[ xCoreID ]; pxPreviousTCB = pxCurrentTCBs[ xCoreID ];
#endif #endif
pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID; pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID;
@ -909,8 +910,8 @@ static void prvYieldForTask( TCB_t * pxTCB,
else if( pxTCB == pxCurrentTCBs[ xCoreID ] ) else if( pxTCB == pxCurrentTCBs[ xCoreID ] )
{ {
configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_YIELDING ) ); configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_YIELDING ) );
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
if( ( pxTCB->uxCoreExclude & ( 1 << xCoreID ) ) == 0 ) if( ( pxTCB->uxCoreAffinityMask & ( 1 << xCoreID ) ) == 1 )
#endif #endif
{ {
/* The task is already running on this core, mark it as scheduled */ /* The task is already running on this core, mark it as scheduled */
@ -974,12 +975,12 @@ static void prvYieldForTask( TCB_t * pxTCB,
} }
#endif /* if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) ) */ #endif /* if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) ) */
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
if( ( pxPreviousTCB != NULL ) && ( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxPreviousTCB->uxPriority ] ), &( pxPreviousTCB->xStateListItem ) ) != pdFALSE ) ) if( ( pxPreviousTCB != NULL ) && ( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxPreviousTCB->uxPriority ] ), &( pxPreviousTCB->xStateListItem ) ) != pdFALSE ) )
{ {
/* A ready task was just bumped off this core. Look at the cores it is not excluded /* A ready task was just bumped off this core. Look at the cores it can run from
* from to see if it is able to run on any of them */ * from to see if it is able to run on any of them */
UBaseType_t uxCoreMap = ~( pxPreviousTCB->uxCoreExclude ); UBaseType_t uxCoreMap = pxPreviousTCB->uxCoreAffinityMask;
BaseType_t xLowestPriority = pxPreviousTCB->uxPriority - pxPreviousTCB->xIsIdle; BaseType_t xLowestPriority = pxPreviousTCB->uxPriority - pxPreviousTCB->xIsIdle;
BaseType_t xLowestPriorityCore = -1; BaseType_t xLowestPriorityCore = -1;
@ -990,12 +991,12 @@ static void prvYieldForTask( TCB_t * pxTCB,
* on with the cores that the new task is excluded from. It is possible that the * on with the cores that the new task is excluded from. It is possible that the
* new task was only placed onto this core because it is excluded from another. * new task was only placed onto this core because it is excluded from another.
* Check to see if the previous task could run on one of those cores. */ * Check to see if the previous task could run on one of those cores. */
uxCoreMap &= pxCurrentTCBs[ xCoreID ]->uxCoreExclude; uxCoreMap &= ~( pxCurrentTCBs[ xCoreID ]->uxCoreAffinityMask );
} }
else else
{ {
/* The ready task that was removed from this core is excluded from it. /* The ready task that was removed from this core is excluded from it.
* See if we can schedule it on any of the cores where it is not excluded from. */ * @todo See if we can schedule it on any of the cores where it is not excluded from. */
} }
uxCoreMap &= ( ( 1 << configNUM_CORES ) - 1 ); uxCoreMap &= ( ( 1 << configNUM_CORES ) - 1 );
@ -1027,7 +1028,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
prvYieldCore( xLowestPriorityCore ); prvYieldCore( xLowestPriorityCore );
} }
} }
#endif /* if ( configUSE_CORE_EXCLUSION == 1 ) */ #endif /* if ( configUSE_CORE_AFFINITY == 1 ) */
return pdTRUE; return pdTRUE;
} }
@ -1047,8 +1048,6 @@ static void prvYieldForTask( TCB_t * pxTCB,
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
@ -1078,6 +1077,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) ) if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) )
{ {
prvTaskCreator( pxTaskCode, ulStack)
/* The memory used for the task's TCB and stack are passed into this /* The memory used for the task's TCB and stack are passed into this
* function - use them. */ * function - use them. */
pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */ pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */
@ -1481,9 +1481,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
} }
#endif #endif
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
{ {
pxNewTCB->uxCoreExclude = 0; pxNewTCB->uxCoreAffinityMask = tskNO_AFFINITY;
} }
#endif #endif
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 ) #if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@ -1608,9 +1608,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
if( pxCurrentTCBs[ xCoreID ] == NULL ) if( pxCurrentTCBs[ xCoreID ] == NULL )
{ {
pxNewTCB->xTaskRunState = xCoreID; pxNewTCB->xTaskRunState = xCoreID;
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
{ {
pxNewTCB->uxCoreExclude = ~( 1 << xCoreID ); pxNewTCB->uxCoreAffinityMask = ( 1 << xCoreID );
} }
#endif #endif
pxCurrentTCBs[ xCoreID ] = pxNewTCB; pxCurrentTCBs[ xCoreID ] = pxNewTCB;
@ -2220,10 +2220,10 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
#endif /* INCLUDE_vTaskPrioritySet */ #endif /* INCLUDE_vTaskPrioritySet */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
void vTaskCoreExclusionSet( const TaskHandle_t xTask, void vTaskCoreAffinitySet( const TaskHandle_t xTask,
UBaseType_t uxCoreExclude ) UBaseType_t uxCoreAffinityMask )
{ {
TCB_t * pxTCB; TCB_t * pxTCB;
BaseType_t xCoreID; BaseType_t xCoreID;
@ -2232,7 +2232,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
{ {
pxTCB = prvGetTCBFromHandle( xTask ); pxTCB = prvGetTCBFromHandle( xTask );
pxTCB->uxCoreExclude = uxCoreExclude; pxTCB->uxCoreAffinityMask = uxCoreAffinityMask;
if( xSchedulerRunning != pdFALSE ) if( xSchedulerRunning != pdFALSE )
{ {
@ -2240,7 +2240,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
{ {
xCoreID = ( BaseType_t ) pxTCB->xTaskRunState; xCoreID = ( BaseType_t ) pxTCB->xTaskRunState;
if( ( uxCoreExclude & ( 1 << xCoreID ) ) != 0 ) if( ( uxCoreAffinityMask & ( 1 << xCoreID ) ) != 1 )
{ {
prvYieldCore( xCoreID ); prvYieldCore( xCoreID );
} }
@ -2250,27 +2250,27 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
taskEXIT_CRITICAL(); taskEXIT_CRITICAL();
} }
#endif /* configUSE_CORE_EXCLUSION */ #endif /* configUSE_CORE_AFFINITY */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( configUSE_CORE_EXCLUSION == 1 ) #if ( configUSE_CORE_AFFINITY == 1 )
UBaseType_t vTaskCoreExclusionGet( const TaskHandle_t xTask ) UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask )
{ {
TCB_t * pxTCB; TCB_t * pxTCB;
UBaseType_t uxCoreExclude; UBaseType_t uxCoreAffinityMask;
taskENTER_CRITICAL(); taskENTER_CRITICAL();
{ {
pxTCB = prvGetTCBFromHandle( xTask ); pxTCB = prvGetTCBFromHandle( xTask );
uxCoreExclude = pxTCB->uxCoreExclude; uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
} }
taskEXIT_CRITICAL(); taskEXIT_CRITICAL();
return uxCoreExclude; return uxCoreAffinityMask;
} }
#endif /* configUSE_CORE_EXCLUSION */ #endif /* configUSE_CORE_AFFINITY */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 ) #if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@ -2451,8 +2451,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
BaseType_t xReturn = pdFALSE; BaseType_t xReturn = pdFALSE;
const TCB_t * const pxTCB = xTask; const TCB_t * const pxTCB = xTask;
/* Accesses xPendingReadyList so must be called from a critical /* Accesses xPendingReadyList so must be called from a critical section. */
* section. */
/* It does not make sense to check if the calling task is suspended. */ /* It does not make sense to check if the calling task is suspended. */
configASSERT( xTask ); configASSERT( xTask );