Skip to content

Commit

Permalink
Update SMP get idle task memory for static allocation (FreeRTOS#784)
Browse files Browse the repository at this point in the history
* Add static idle task memory support for SMP
* Rename vApplicationMinimalIdleTask to vApplicationPassiveIdleTask
* Rename the macro configUSE_MINIMAL_IDLE_HOOK to configUSE_PASSIVE_IDLE_HOOK
* Update xTaskGetIdleTaskHandle for SMP
* Add more check in xTaskGetIdleTaskHandle
* Support configKERNEL_PROVIDED_STATIC_MEMORY for SMP

---------

Signed-off-by: Gaurav Aggarwal <[email protected]>
Co-authored-by: Gaurav Aggarwal <[email protected]>
Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2023
1 parent 92a4d17 commit 4bfb9b2
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 190 deletions.
20 changes: 13 additions & 7 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
#endif

#if ( configNUMBER_OF_CORES > 1 )
#ifndef configUSE_MINIMAL_IDLE_HOOK
#error Missing definition: configUSE_MINIMAL_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
#ifndef configUSE_PASSIVE_IDLE_HOOK
#error Missing definition: configUSE_PASSIVE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
#endif
#endif

Expand Down Expand Up @@ -473,9 +473,9 @@
#define configUSE_CORE_AFFINITY 0
#endif /* configUSE_CORE_AFFINITY */

#ifndef configUSE_MINIMAL_IDLE_HOOK
#define configUSE_MINIMAL_IDLE_HOOK 0
#endif /* configUSE_MINIMAL_IDLE_HOOK */
#ifndef configUSE_PASSIVE_IDLE_HOOK
#define configUSE_PASSIVE_IDLE_HOOK 0
#endif /* configUSE_PASSIVE_IDLE_HOOK */

/* The timers module relies on xTaskGetSchedulerState(). */
#if configUSE_TIMERS == 1
Expand Down Expand Up @@ -1834,8 +1834,14 @@
#define traceRETURN_uxTaskGetSystemState( uxTask )
#endif

#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle()
#if ( configNUMBER_OF_CORES == 1 )
#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle()
#endif
#else
#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle( xCoreID )
#endif
#endif

#ifndef traceRETURN_xTaskGetIdleTaskHandle
Expand Down
57 changes: 52 additions & 5 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,8 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL

#if ( configSUPPORT_STATIC_ALLOCATION == 1 )

#if ( configNUMBER_OF_CORES == 1 )

/**
* task.h
* @code{c}
Expand All @@ -1943,10 +1945,41 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL
* @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
* @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
*/
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
#endif
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
#else /* #if ( configNUMBER_OF_CORES == 1 ) */

/**
* task.h
* @code{c}
* void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize, BaseType_t xCoreID )
* @endcode
*
* This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Tasks TCB. This function is required when
* configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
*
* In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
* 1. 1 Active idle task which does all the housekeeping.
* 2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
* These idle tasks are created to ensure that each core has an idle task to run when
* no other task is available to run.
*
* The function vApplicationGetIdleTaskMemory is called with xCoreID 0 to get the
* memory for Active idle task. It is called with xCoreID 1, 2 ... ( configNUMBER_OF_CORES - 1 )
* to get memory for passive idle tasks.
*
* @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
* @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
* @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
* @param xCoreId The core index of the idle task buffer
*/
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize, /*lint !e526 Symbol not defined as it is an application callback. */
BaseType_t xCoreID );
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */

/**
* task.h
Expand All @@ -1970,8 +2003,22 @@ BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
*
* Simply returns the handle of the idle task. It is not valid to call
* xTaskGetIdleTaskHandle() before the scheduler has been started.
*
* In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
* 1. 1 Active idle task which does all the housekeeping.
* 2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
* These idle tasks are created to ensure that each core has an idle task to run when
* no other task is available to run.
*
* Set xCoreID to 0 to get the Active idle task handle. Set xCoreID to
* 1,2 ... ( configNUMBER_OF_CORES - 1 ) to get the Passive idle task
* handles.
*/
TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
#if ( configNUMBER_OF_CORES == 1 )
TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
TaskHandle_t xTaskGetIdleTaskHandle( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */

/**
* configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
Expand Down
Loading

0 comments on commit 4bfb9b2

Please sign in to comment.