Skip to content

Commit 631ae9e

Browse files
Add option to set the core affinity for the Timer Svc Task on SMP systems (#805)
This PR introduces the configTIMER_SERVICE_TASK_CORE_AFFINITY option which allows the system to configure the core affinity of the Timer Service Task on an SMP system. The default affinity of the Timer Service Task is set to tskNO_AFFINITY which is the current behavior on SMP systems. Signed-off-by: Sudeep Mohanty <[email protected]> Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
1 parent 1b2b090 commit 631ae9e

File tree

1 file changed

+72
-24
lines changed

1 file changed

+72
-24
lines changed

timers.c

+72-24
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,21 @@
6060
#define tmrNO_DELAY ( ( TickType_t ) 0U )
6161
#define tmrMAX_TIME_BEFORE_OVERFLOW ( ( TickType_t ) -1 )
6262

63-
/* The name assigned to the timer service task. This can be overridden by
64-
* defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
63+
/* The name assigned to the timer service task. This can be overridden by
64+
* defining configTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
6565
#ifndef configTIMER_SERVICE_TASK_NAME
6666
#define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
6767
#endif
6868

69+
#if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
70+
71+
/* The core affinity assigned to the timer service task on SMP systems.
72+
* This can be overridden by defining configTIMER_SERVICE_TASK_CORE_AFFINITY in FreeRTOSConfig.h. */
73+
#ifndef configTIMER_SERVICE_TASK_CORE_AFFINITY
74+
#define configTIMER_SERVICE_TASK_CORE_AFFINITY tskNO_AFFINITY
75+
#endif
76+
#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */
77+
6978
/* Bit definitions used in the ucStatus member of a timer structure. */
7079
#define tmrSTATUS_IS_ACTIVE ( 0x01U )
7180
#define tmrSTATUS_IS_STATICALLY_ALLOCATED ( 0x02U )
@@ -245,36 +254,75 @@
245254

246255
if( xTimerQueue != NULL )
247256
{
248-
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
257+
#if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
249258
{
250-
StaticTask_t * pxTimerTaskTCBBuffer = NULL;
251-
StackType_t * pxTimerTaskStackBuffer = NULL;
252-
uint32_t ulTimerTaskStackSize;
253-
254-
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
255-
xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
259+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
260+
{
261+
StaticTask_t * pxTimerTaskTCBBuffer = NULL;
262+
StackType_t * pxTimerTaskStackBuffer = NULL;
263+
uint32_t ulTimerTaskStackSize;
264+
265+
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
266+
xTimerTaskHandle = xTaskCreateStaticAffinitySet( prvTimerTask,
267+
configTIMER_SERVICE_TASK_NAME,
268+
ulTimerTaskStackSize,
269+
NULL,
270+
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
271+
pxTimerTaskStackBuffer,
272+
pxTimerTaskTCBBuffer,
273+
configTIMER_SERVICE_TASK_CORE_AFFINITY );
274+
275+
if( xTimerTaskHandle != NULL )
276+
{
277+
xReturn = pdPASS;
278+
}
279+
}
280+
#else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
281+
{
282+
xReturn = xTaskCreateAffinitySet( prvTimerTask,
256283
configTIMER_SERVICE_TASK_NAME,
257-
ulTimerTaskStackSize,
284+
configTIMER_TASK_STACK_DEPTH,
258285
NULL,
259286
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
260-
pxTimerTaskStackBuffer,
261-
pxTimerTaskTCBBuffer );
262-
263-
if( xTimerTaskHandle != NULL )
264-
{
265-
xReturn = pdPASS;
287+
configTIMER_SERVICE_TASK_CORE_AFFINITY,
288+
&xTimerTaskHandle );
266289
}
290+
#endif /* configSUPPORT_STATIC_ALLOCATION */
267291
}
268-
#else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
292+
#else /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */
269293
{
270-
xReturn = xTaskCreate( prvTimerTask,
271-
configTIMER_SERVICE_TASK_NAME,
272-
configTIMER_TASK_STACK_DEPTH,
273-
NULL,
274-
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
275-
&xTimerTaskHandle );
294+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
295+
{
296+
StaticTask_t * pxTimerTaskTCBBuffer = NULL;
297+
StackType_t * pxTimerTaskStackBuffer = NULL;
298+
uint32_t ulTimerTaskStackSize;
299+
300+
vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
301+
xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
302+
configTIMER_SERVICE_TASK_NAME,
303+
ulTimerTaskStackSize,
304+
NULL,
305+
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
306+
pxTimerTaskStackBuffer,
307+
pxTimerTaskTCBBuffer );
308+
309+
if( xTimerTaskHandle != NULL )
310+
{
311+
xReturn = pdPASS;
312+
}
313+
}
314+
#else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
315+
{
316+
xReturn = xTaskCreate( prvTimerTask,
317+
configTIMER_SERVICE_TASK_NAME,
318+
configTIMER_TASK_STACK_DEPTH,
319+
NULL,
320+
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
321+
&xTimerTaskHandle );
322+
}
323+
#endif /* configSUPPORT_STATIC_ALLOCATION */
276324
}
277-
#endif /* configSUPPORT_STATIC_ALLOCATION */
325+
#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) ) */
278326
}
279327
else
280328
{

0 commit comments

Comments
 (0)