Skip to content

Commit f7f7b9d

Browse files
authored
Add ipconfigIP_TASK_AFFINITY (#1288)
* Quick change to set ip task affinity * Add ipconfigIP_TASK_AFFINITY * Formatting * Add check that configUSE_CORE_AFFINITY is enabled * Add documentation * Fix format and fix typo * use > 0
1 parent 8492a50 commit f7f7b9d

File tree

2 files changed

+82
-13
lines changed

2 files changed

+82
-13
lines changed

source/FreeRTOS_IP.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,13 +1016,28 @@ BaseType_t FreeRTOS_IPInit_Multi( void )
10161016
{
10171017
static StaticTask_t xIPTaskBuffer;
10181018
static StackType_t xIPTaskStack[ ipconfigIP_TASK_STACK_SIZE_WORDS ];
1019-
xIPTaskHandle = xTaskCreateStatic( &prvIPTask,
1020-
"IP-Task",
1021-
ipconfigIP_TASK_STACK_SIZE_WORDS,
1022-
NULL,
1023-
ipconfigIP_TASK_PRIORITY,
1024-
xIPTaskStack,
1025-
&xIPTaskBuffer );
1019+
#if ( ipconfigIP_TASK_AFFINITY > 0 )
1020+
{
1021+
xIPTaskHandle = xTaskCreateStaticAffinitySet( &prvIPTask,
1022+
"IP-Task",
1023+
ipconfigIP_TASK_STACK_SIZE_WORDS,
1024+
NULL,
1025+
ipconfigIP_TASK_PRIORITY,
1026+
xIPTaskStack,
1027+
&xIPTaskBuffer,
1028+
ipconfigIP_TASK_AFFINITY );
1029+
}
1030+
#else /* if ( ipconfigIP_TASK_AFFINITY ) */
1031+
{
1032+
xIPTaskHandle = xTaskCreateStatic( &prvIPTask,
1033+
"IP-Task",
1034+
ipconfigIP_TASK_STACK_SIZE_WORDS,
1035+
NULL,
1036+
ipconfigIP_TASK_PRIORITY,
1037+
xIPTaskStack,
1038+
&xIPTaskBuffer );
1039+
}
1040+
#endif /* ipconfigIP_TASK_AFFINITY */
10261041

10271042
if( xIPTaskHandle != NULL )
10281043
{
@@ -1031,12 +1046,26 @@ BaseType_t FreeRTOS_IPInit_Multi( void )
10311046
}
10321047
#else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
10331048
{
1034-
xReturn = xTaskCreate( &prvIPTask,
1035-
"IP-task",
1036-
ipconfigIP_TASK_STACK_SIZE_WORDS,
1037-
NULL,
1038-
ipconfigIP_TASK_PRIORITY,
1039-
&( xIPTaskHandle ) );
1049+
#if ( ipconfigIP_TASK_AFFINITY > 0 )
1050+
{
1051+
xReturn = xTaskCreateAffinitySet( &prvIPTask,
1052+
"IP-task",
1053+
ipconfigIP_TASK_STACK_SIZE_WORDS,
1054+
NULL,
1055+
ipconfigIP_TASK_PRIORITY,
1056+
ipconfigIP_TASK_AFFINITY,
1057+
&( xIPTaskHandle ) );
1058+
}
1059+
#else /* if ( ipconfigIP_TASK_AFFINITY ) */
1060+
{
1061+
xReturn = xTaskCreate( &prvIPTask,
1062+
"IP-task",
1063+
ipconfigIP_TASK_STACK_SIZE_WORDS,
1064+
NULL,
1065+
ipconfigIP_TASK_PRIORITY,
1066+
&( xIPTaskHandle ) );
1067+
}
1068+
#endif /* ipconfigIP_TASK_AFFINITY */
10401069
}
10411070
#endif /* configSUPPORT_STATIC_ALLOCATION */
10421071
}

source/include/FreeRTOSIPConfigDefaults.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,46 @@ STATIC_ASSERT( pdMS_TO_TICKS( ipconfigPHY_LS_LOW_CHECK_TIME_MS ) <= portMAX_DELA
11391139

11401140
/*---------------------------------------------------------------------------*/
11411141

1142+
/*
1143+
* ipconfigIP_TASK_AFFINITY
1144+
*
1145+
* https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html#ipconfigIP_TASK_AFFINITY
1146+
*
1147+
* Type: UBaseType_t
1148+
* Unit: task affinity
1149+
* Minimum: 0
1150+
* Maximum: (2 ^ configNUMBER_OF_CORES) - 1
1151+
*
1152+
* When running using a SMP kernel, task affinity can be used to prevent
1153+
* concurrent execution of code that does not fully support SMP. Until
1154+
* the TCP library and ports fully supports SMP, it is necessary to set
1155+
* the affinity of all tasks which use TCP functions to the same core in
1156+
* order to prevent concurrent execution.
1157+
*
1158+
* An alternative to setting task affinity is to set configRUN_MULTIPLE_PRIORITIES
1159+
* to 0.
1160+
*
1161+
* Task affinity is defined as shifting a bit by the core number.
1162+
*
1163+
* Example:
1164+
* (1U << 0U) //run only on core 0
1165+
* (1U << 1U) //run only on core 1
1166+
*/
1167+
1168+
#ifndef ipconfigIP_TASK_AFFINITY
1169+
#define ipconfigIP_TASK_AFFINITY ( 0 )
1170+
#endif
1171+
1172+
#if ( ipconfigIP_TASK_AFFINITY < 0 )
1173+
#error ipconfigIP_TASK_AFFINITY must be at least 0
1174+
#endif
1175+
1176+
#if ( ipconfigIP_TASK_AFFINITY > 0 && configUSE_CORE_AFFINITY == 0 )
1177+
#error configUSE_CORE_AFFINITY must be 1 in order to use ipconfigIP_TASK_AFFINITY
1178+
#endif
1179+
1180+
/*---------------------------------------------------------------------------*/
1181+
11421182
/*
11431183
* ipconfigIP_TASK_STACK_SIZE_WORDS
11441184
*

0 commit comments

Comments
 (0)