Skip to content

Commit d59bfca

Browse files
committed
converted exclusion to affinity
1 parent b9a1747 commit d59bfca

File tree

4 files changed

+55
-44
lines changed

4 files changed

+55
-44
lines changed

.github/lexicon.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,8 @@ uxbitstoset
24002400
uxbitstowait
24012401
uxbitstowaitfor
24022402
uxcontrolbits
2403-
uxcoreexclude
2403+
uxcoreaffinitymask
2404+
uxcoreaffinityinheritancemask
24042405
uxcriticalnesting
24052406
uxcurrenteventbits
24062407
uxcurrentnumberoftasks

include/FreeRTOS.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@
240240
#define configUSE_TASK_PREEMPTION_DISABLE 0
241241
#endif
242242

243-
#ifndef configUSE_CORE_EXCLUSION
244-
#define configUSE_CORE_EXCLUSION 0
243+
#ifndef configUSE_CORE_AFFINITY
244+
#define configUSE_CORE_AFFINITY 0
245245
#endif
246246

247247
#ifndef configUSE_ALTERNATIVE_API
@@ -948,7 +948,7 @@
948948
#error configUSE_MUTEXES must be set to 1 to use recursive mutexes
949949
#endif
950950

951-
#if( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configUSE_CORE_EXCLUSION != 0 ) )
951+
#if( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configUSE_CORE_AFFINITY != 0 ) )
952952
#error configRUN_MULTIPLE_PRIORITIES must be set to 1 to use core exclusion
953953
#endif
954954

@@ -1209,8 +1209,9 @@ typedef struct xSTATIC_TCB
12091209
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
12101210
BaseType_t xDummy24;
12111211
#endif
1212-
#if ( configUSE_CORE_EXCLUSION == 1 )
1212+
#if ( configUSE_CORE_AFFINITY == 1 && configNUM_CORES > 1 )
12131213
UBaseType_t uxDummy25;
1214+
UBaseType_t uxDummy26;
12141215
#endif
12151216
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
12161217
void * pxDummy8;

include/task.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ typedef enum
170170
*/
171171
#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
172172

173+
/**
174+
* Defines affinity to all available cores.
175+
*
176+
*/
177+
#define tskNO_AFFINITY ( ( UBaseType_t ) -1U )
178+
179+
180+
173181
/**
174182
* task. h
175183
*
@@ -1235,8 +1243,10 @@ void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
12351243
*/
12361244
BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
12371245

1238-
void vTaskCoreExclusionSet( const TaskHandle_t xTask, UBaseType_t uxCoreExclude );
1239-
UBaseType_t vTaskCoreExclusionGet( const TaskHandle_t xTask );
1246+
#if ( configUSE_CORE_AFFINITY == 1)
1247+
void vTaskCoreAffinitySet( const TaskHandle_t xTask, UBaseType_t uxCoreAffinityMask );
1248+
UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask );
1249+
#endif
12401250

12411251
void vTaskPreemptionDisable( const TaskHandle_t xTask );
12421252
void vTaskPreemptionEnable( const TaskHandle_t xTask );

tasks.c

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
254254
BaseType_t xPreemptionDisable; /*< Used to prevent the task from being preempted */
255255
#endif
256256

257-
#if ( configUSE_CORE_EXCLUSION == 1 )
258-
UBaseType_t uxCoreExclude; /*< Used to exclude the task from certain cores */
257+
#if ( configUSE_CORE_AFFINITY == 1 && configNUM_CORES > 1 )
258+
UBaseType_t uxCoreAffinityMask; /*< Used to link the task to certain cores. UBaseType_t must have >= the same number of bits as SMP confNUM_CORES */
259+
UBaseType_t uxCoreAffinityInheritanceMask; /*< Used to allow a task to inherit the affinity of its parent */
259260
#endif
260261

261262
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
@@ -321,7 +322,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
321322
#if ( configUSE_POSIX_ERRNO == 1 )
322323
int iTaskErrno;
323324
#endif
324-
} tskTCB;
325+
} tskTCB;
325326

326327
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name
327328
* below to enable the use of older kernel aware debuggers. */
@@ -760,8 +761,8 @@ static void prvYieldForTask( TCB_t * pxTCB,
760761
{
761762
if( xTaskPriority <= xLowestPriority )
762763
{
763-
#if ( configUSE_CORE_EXCLUSION == 1 )
764-
if( ( pxTCB->uxCoreExclude & ( 1 << x ) ) == 0 )
764+
#if ( configUSE_CORE_AFFINITY == 1 )
765+
if( ( pxTCB->uxCoreAffinityMask & ( 1 << x ) ) == 1 )
765766
#endif
766767
{
767768
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@@ -824,7 +825,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
824825
BaseType_t xTaskScheduled = pdFALSE;
825826
BaseType_t xDecrementTopPriority = pdTRUE;
826827

827-
#if ( configUSE_CORE_EXCLUSION == 1 )
828+
#if ( configUSE_CORE_AFFINITY == 1 )
828829
TCB_t * pxPreviousTCB = NULL;
829830
#endif
830831
#if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) )
@@ -892,13 +893,13 @@ static void prvYieldForTask( TCB_t * pxTCB,
892893

893894
if( pxTCB->xTaskRunState == taskTASK_NOT_RUNNING )
894895
{
895-
#if ( configUSE_CORE_EXCLUSION == 1 )
896-
if( ( pxTCB->uxCoreExclude & ( 1 << xCoreID ) ) == 0 )
896+
#if ( configUSE_CORE_AFFINITY == 1 )
897+
if( ( pxTCB->uxCoreAffinityMask & ( 1 << xCoreID ) ) == 1 )
897898
#endif
898899
{
899900
/* If the task is not being executed by any core swap it in */
900901
pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_NOT_RUNNING;
901-
#if ( configUSE_CORE_EXCLUSION == 1 )
902+
#if ( configUSE_CORE_AFFINITY == 1 )
902903
pxPreviousTCB = pxCurrentTCBs[ xCoreID ];
903904
#endif
904905
pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID;
@@ -909,8 +910,8 @@ static void prvYieldForTask( TCB_t * pxTCB,
909910
else if( pxTCB == pxCurrentTCBs[ xCoreID ] )
910911
{
911912
configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_YIELDING ) );
912-
#if ( configUSE_CORE_EXCLUSION == 1 )
913-
if( ( pxTCB->uxCoreExclude & ( 1 << xCoreID ) ) == 0 )
913+
#if ( configUSE_CORE_AFFINITY == 1 )
914+
if( ( pxTCB->uxCoreAffinityMask & ( 1 << xCoreID ) ) == 1 )
914915
#endif
915916
{
916917
/* The task is already running on this core, mark it as scheduled */
@@ -974,12 +975,12 @@ static void prvYieldForTask( TCB_t * pxTCB,
974975
}
975976
#endif /* if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) ) */
976977

977-
#if ( configUSE_CORE_EXCLUSION == 1 )
978+
#if ( configUSE_CORE_AFFINITY == 1 )
978979
if( ( pxPreviousTCB != NULL ) && ( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxPreviousTCB->uxPriority ] ), &( pxPreviousTCB->xStateListItem ) ) != pdFALSE ) )
979980
{
980-
/* A ready task was just bumped off this core. Look at the cores it is not excluded
981+
/* A ready task was just bumped off this core. Look at the cores it can run from
981982
* from to see if it is able to run on any of them */
982-
UBaseType_t uxCoreMap = ~( pxPreviousTCB->uxCoreExclude );
983+
UBaseType_t uxCoreMap = pxPreviousTCB->uxCoreAffinityMask;
983984
BaseType_t xLowestPriority = pxPreviousTCB->uxPriority - pxPreviousTCB->xIsIdle;
984985
BaseType_t xLowestPriorityCore = -1;
985986

@@ -990,12 +991,12 @@ static void prvYieldForTask( TCB_t * pxTCB,
990991
* on with the cores that the new task is excluded from. It is possible that the
991992
* new task was only placed onto this core because it is excluded from another.
992993
* Check to see if the previous task could run on one of those cores. */
993-
uxCoreMap &= pxCurrentTCBs[ xCoreID ]->uxCoreExclude;
994+
uxCoreMap &= ~( pxCurrentTCBs[ xCoreID ]->uxCoreAffinityMask );
994995
}
995996
else
996997
{
997998
/* The ready task that was removed from this core is excluded from it.
998-
* See if we can schedule it on any of the cores where it is not excluded from. */
999+
* @todo See if we can schedule it on any of the cores where it is not excluded from. */
9991000
}
10001001

10011002
uxCoreMap &= ( ( 1 << configNUM_CORES ) - 1 );
@@ -1027,7 +1028,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
10271028
prvYieldCore( xLowestPriorityCore );
10281029
}
10291030
}
1030-
#endif /* if ( configUSE_CORE_EXCLUSION == 1 ) */
1031+
#endif /* if ( configUSE_CORE_AFFINITY == 1 ) */
10311032

10321033
return pdTRUE;
10331034
}
@@ -1047,8 +1048,6 @@ static void prvYieldForTask( TCB_t * pxTCB,
10471048
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
10481049
/*-----------------------------------------------------------*/
10491050

1050-
1051-
10521051
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
10531052

10541053
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
@@ -1078,6 +1077,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
10781077

10791078
if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) )
10801079
{
1080+
prvTaskCreator( pxTaskCode, ulStack)
10811081
/* The memory used for the task's TCB and stack are passed into this
10821082
* function - use them. */
10831083
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,
14811481
}
14821482
#endif
14831483

1484-
#if ( configUSE_CORE_EXCLUSION == 1 )
1484+
#if ( configUSE_CORE_AFFINITY == 1 )
14851485
{
1486-
pxNewTCB->uxCoreExclude = 0;
1486+
pxNewTCB->uxCoreAffinityMask = tskNO_AFFINITY;
14871487
}
14881488
#endif
14891489
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@@ -1608,9 +1608,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
16081608
if( pxCurrentTCBs[ xCoreID ] == NULL )
16091609
{
16101610
pxNewTCB->xTaskRunState = xCoreID;
1611-
#if ( configUSE_CORE_EXCLUSION == 1 )
1611+
#if ( configUSE_CORE_AFFINITY == 1 )
16121612
{
1613-
pxNewTCB->uxCoreExclude = ~( 1 << xCoreID );
1613+
pxNewTCB->uxCoreAffinityMask = ( 1 << xCoreID );
16141614
}
16151615
#endif
16161616
pxCurrentTCBs[ xCoreID ] = pxNewTCB;
@@ -2220,10 +2220,10 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
22202220
#endif /* INCLUDE_vTaskPrioritySet */
22212221
/*-----------------------------------------------------------*/
22222222

2223-
#if ( configUSE_CORE_EXCLUSION == 1 )
2223+
#if ( configUSE_CORE_AFFINITY == 1 )
22242224

2225-
void vTaskCoreExclusionSet( const TaskHandle_t xTask,
2226-
UBaseType_t uxCoreExclude )
2225+
void vTaskCoreAffinitySet( const TaskHandle_t xTask,
2226+
UBaseType_t uxCoreAffinityMask )
22272227
{
22282228
TCB_t * pxTCB;
22292229
BaseType_t xCoreID;
@@ -2232,15 +2232,15 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
22322232
{
22332233
pxTCB = prvGetTCBFromHandle( xTask );
22342234

2235-
pxTCB->uxCoreExclude = uxCoreExclude;
2235+
pxTCB->uxCoreAffinityMask = uxCoreAffinityMask;
22362236

22372237
if( xSchedulerRunning != pdFALSE )
22382238
{
22392239
if( taskTASK_IS_RUNNING( pxTCB->xTaskRunState ) )
22402240
{
22412241
xCoreID = ( BaseType_t ) pxTCB->xTaskRunState;
22422242

2243-
if( ( uxCoreExclude & ( 1 << xCoreID ) ) != 0 )
2243+
if( ( uxCoreAffinityMask & ( 1 << xCoreID ) ) != 1 )
22442244
{
22452245
prvYieldCore( xCoreID );
22462246
}
@@ -2250,27 +2250,27 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
22502250
taskEXIT_CRITICAL();
22512251
}
22522252

2253-
#endif /* configUSE_CORE_EXCLUSION */
2253+
#endif /* configUSE_CORE_AFFINITY */
22542254
/*-----------------------------------------------------------*/
22552255

2256-
#if ( configUSE_CORE_EXCLUSION == 1 )
2256+
#if ( configUSE_CORE_AFFINITY == 1 )
22572257

2258-
UBaseType_t vTaskCoreExclusionGet( const TaskHandle_t xTask )
2258+
UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask )
22592259
{
22602260
TCB_t * pxTCB;
2261-
UBaseType_t uxCoreExclude;
2261+
UBaseType_t uxCoreAffinityMask;
22622262

22632263
taskENTER_CRITICAL();
22642264
{
22652265
pxTCB = prvGetTCBFromHandle( xTask );
2266-
uxCoreExclude = pxTCB->uxCoreExclude;
2266+
uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
22672267
}
22682268
taskEXIT_CRITICAL();
22692269

2270-
return uxCoreExclude;
2270+
return uxCoreAffinityMask;
22712271
}
22722272

2273-
#endif /* configUSE_CORE_EXCLUSION */
2273+
#endif /* configUSE_CORE_AFFINITY */
22742274
/*-----------------------------------------------------------*/
22752275

22762276
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
@@ -2451,8 +2451,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
24512451
BaseType_t xReturn = pdFALSE;
24522452
const TCB_t * const pxTCB = xTask;
24532453

2454-
/* Accesses xPendingReadyList so must be called from a critical
2455-
* section. */
2454+
/* Accesses xPendingReadyList so must be called from a critical section. */
24562455

24572456
/* It does not make sense to check if the calling task is suspended. */
24582457
configASSERT( xTask );

0 commit comments

Comments
 (0)