Skip to content

Commit

Permalink
Update xTaskGetIdleTaskHandle() For SMP (#868)
Browse files Browse the repository at this point in the history
* Update xTaskGetIdleTaskHandle() in SMP

This commit updates xTaskGetIdleTaskHandle() for SMP in the following ways:

- xTaskGetIdleTaskHandle() no longer accepts xCoreID argument in SMP so that
there is not change in API between single-core and SMP
- xTaskGetIdleTaskHandle() now returns the Active idle task handle in SMP,
which matches the behavior in single-core.
- Added xTaskGetIdleTaskHandleForCore() in SMP which accepts an xCoreID
argument. This function can be used to obtain the Passive idle task handles.

* Update xTaskGetIdleTaskHandle

---------

Co-authored-by: Ching-Hsin Lee <chinglee@amazon.com>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
  • Loading branch information
5 people authored Dec 5, 2023
1 parent c0ce725 commit cd5c774
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
16 changes: 11 additions & 5 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -1886,14 +1886,20 @@
#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle()
#endif
#else
#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle( xCoreID )
#endif

#if ( configNUMBER_OF_CORES == 1 )
#ifndef traceRETURN_xTaskGetIdleTaskHandle
#define traceRETURN_xTaskGetIdleTaskHandle( xIdleTaskHandle )
#endif
#endif

#ifndef traceRETURN_xTaskGetIdleTaskHandle
#define traceRETURN_xTaskGetIdleTaskHandle( xIdleTaskHandle )
#ifndef traceENTER_xTaskGetIdleTaskHandleForCore
#define traceENTER_xTaskGetIdleTaskHandleForCore( xCoreID )
#endif

#ifndef traceRETURN_xTaskGetIdleTaskHandleForCore
#define traceRETURN_xTaskGetIdleTaskHandleForCore( xIdleTaskHandle )
#endif

#ifndef traceENTER_vTaskStepTick
Expand Down
17 changes: 8 additions & 9 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -2030,24 +2030,23 @@ BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
* xTaskGetIdleTaskHandle() is only available if
* INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
*
* Simply returns the handle of the idle task. It is not valid to call
* xTaskGetIdleTaskHandle() before the scheduler has been started.
* In single-core FreeRTOS, this function 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.
* no other task is available to run. Call xTaskGetIdleTaskHandle() or
* xTaskGetIdleTaskHandleForCore() with xCoreID set to 0 to get the Active
* idle task handle. Call xTaskGetIdleTaskHandleForCore() with xCoreID set to
* 1,2 ... ( configNUMBER_OF_CORES - 1 ) to get the Passive idle task handles.
*/
#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 ) */
TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;

/**
* configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
Expand Down
28 changes: 12 additions & 16 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4472,7 +4472,6 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )

#if ( configNUMBER_OF_CORES == 1 )

TaskHandle_t xTaskGetIdleTaskHandle( void )
{
traceENTER_xTaskGetIdleTaskHandle();
Expand All @@ -4485,26 +4484,23 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char

return xIdleTaskHandles[ 0 ];
}
#endif /* if ( configNUMBER_OF_CORES == 1 ) */

#else /* if ( configNUMBER_OF_CORES == 1 ) */

TaskHandle_t xTaskGetIdleTaskHandle( BaseType_t xCoreID )
{
traceENTER_xTaskGetIdleTaskHandle( xCoreID );

/* Ensure the core ID is valid. */
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );
TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID )
{
traceENTER_xTaskGetIdleTaskHandleForCore( xCoreID );

/* If xTaskGetIdleTaskHandle() is called before the scheduler has been
* started, then xIdleTaskHandles will be NULL. */
configASSERT( ( xIdleTaskHandles[ xCoreID ] != NULL ) );
/* Ensure the core ID is valid. */
configASSERT( taskVALID_CORE_ID( xCoreID ) == pdTRUE );

traceRETURN_xTaskGetIdleTaskHandle( xIdleTaskHandles[ xCoreID ] );
/* If xTaskGetIdleTaskHandle() is called before the scheduler has been
* started, then xIdleTaskHandles will be NULL. */
configASSERT( ( xIdleTaskHandles[ xCoreID ] != NULL ) );

return xIdleTaskHandles[ xCoreID ];
}
traceRETURN_xTaskGetIdleTaskHandleForCore( xIdleTaskHandles[ xCoreID ] );

#endif /* if ( configNUMBER_OF_CORES == 1 ) */
return xIdleTaskHandles[ xCoreID ];
}

#endif /* INCLUDE_xTaskGetIdleTaskHandle */
/*----------------------------------------------------------*/
Expand Down

0 comments on commit cd5c774

Please # to comment.