Merge branch 'change/freertos_make_task_snapshot_private' into 'master'

refactor(freertos/task_snapshot): Make task snapshot private

Closes IDF-8182

See merge request espressif/esp-idf!26115
This commit is contained in:
Darian
2023-10-09 16:32:18 +08:00
20 changed files with 155 additions and 131 deletions

View File

@@ -16,7 +16,7 @@
#ifdef CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/task_snapshot.h"
#include "esp_private/freertos_debug.h"
#endif // CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
/* Internal error codes used by the routines that parse the incoming gdb packet */

View File

@@ -11,6 +11,7 @@
#include "rv_decode.h"
#include "sdkconfig.h"
#include "esp_private/crosscore_int.h"
#include "esp_private/freertos_debug.h"
extern volatile esp_gdbstub_frame_t *temp_regs_frame;
@@ -85,15 +86,7 @@ void esp_gdbstub_int(__attribute__((unused)) void *frame)
/* Pointer to saved frame is in pxCurrentTCB
* See rtos_int_enter function
*/
/* Todo: Provide IDF interface for getting pxCurrentTCB (IDF-8182) */
int core_id = esp_cpu_get_core_id();
#if CONFIG_FREERTOS_USE_KERNEL_10_5_1
extern void **pxCurrentTCBs;
dummy_tcb_t *tcb = (dummy_tcb_t *) &pxCurrentTCBs[core_id];
#else
extern void **pxCurrentTCB;
dummy_tcb_t *tcb = (dummy_tcb_t *) &pxCurrentTCB[core_id];
#endif /* CONFIG_FREERTOS_USE_KERNEL_10_5_1 */
dummy_tcb_t *tcb = (dummy_tcb_t *)pvTaskGetCurrentTCBForCore(esp_cpu_get_core_id());
gdbstub_handle_uart_int((esp_gdbstub_frame_t *)tcb->top_of_stack);
}

View File

@@ -11,7 +11,7 @@
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/task_snapshot.h"
#include "esp_private/freertos_debug.h"
#include "esp_err.h"
#include "esp_attr.h"
#include "esp_check.h"

View File

@@ -8,7 +8,7 @@
#include "sdkconfig.h"
#include "soc/soc_memory_layout.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task_snapshot.h"
#include "esp_private/freertos_debug.h"
#include "esp_rom_sys.h"
#include "esp_core_dump_port.h"
#include "esp_core_dump_common.h"

View File

@@ -490,14 +490,6 @@ menu "FreeRTOS"
When enabled the selected Non-ISR FreeRTOS functions will be placed into Flash memory instead of IRAM.
This saves up to 8KB of IRAM depending on which functions are used.
config FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH
bool "Place task snapshot functions into flash"
default n
depends on !ESP_PANIC_HANDLER_IRAM
help
When enabled, the functions related to snapshots, such as vTaskGetSnapshot or uxTaskGetSnapshotAll,
will be placed in flash. Note that if enabled, these functions cannot be called when cache is disabled.
config FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE
# Todo: Check if we still need this (IDF-4986)
bool "Tests compliance with Vanilla FreeRTOS port*_CRITICAL calls"
@@ -536,10 +528,18 @@ menu "FreeRTOS"
Hidden option, gets selected by CONFIG_ESP_DEBUG_OCDAWARE
config FREERTOS_ENABLE_TASK_SNAPSHOT
# Invisible option that is always enabled. Task Snapshot APIs are now always enabled. This
# Invisible option that is always enabled. Task Snapshot APIs are now private thus are always enabled. This
# option is kept here in case any user code conditionally depends on this option.
# Todo: Remove in v6.0 (IDF-8143)
bool
default y
config FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH
# Invisible option that is always enabled. Task Snapshot APIs are now private API thus are always placed into
# flash by default. This option is kept here in case any user code conditionally depends on this option.
# Todo: Remove in v6.0 (IDF-8143)
bool
default y
depends on !ESP_PANIC_HANDLER_IRAM
endmenu # FreeRTOS

View File

@@ -8,7 +8,7 @@
#include "esp_assert.h"
#include "freertos/idf_additions.h"
#if CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT
#include "freertos/task_snapshot.h"
#include "esp_private/freertos_debug.h"
#endif /* CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT */
#include "esp_private/freertos_idf_additions_priv.h"
@@ -1181,6 +1181,26 @@ UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray,
}
/*----------------------------------------------------------*/
/* ----------------------------------------------------- Misc ----------------------------------------------------- */
void * pvTaskGetCurrentTCBForCore( BaseType_t xCoreID )
{
void * pvRet;
configASSERT( ( xCoreID >= 0 ) && ( xCoreID < configNUM_CORES ) );
#if CONFIG_FREERTOS_USE_KERNEL_10_5_1
pvRet = ( void * ) pxCurrentTCBs[ xCoreID ];
#else /* CONFIG_FREERTOS_USE_KERNEL_10_5_1 */
#if CONFIG_FREERTOS_SMP
/* SMP FreeRTOS defines pxCurrentTCB as a macro function call */
pvRet = pxCurrentTCB;
#else /* CONFIG_FREERTOS_SMP */
pvRet = ( void * ) pxCurrentTCB[ xCoreID ];
#endif /* CONFIG_FREERTOS_SMP */
#endif /* CONFIG_FREERTOS_USE_KERNEL_10_5_1 */
return pvRet;
}
/* ----------------------------------------------------- OpenOCD ---------------------------------------------------- */
#if CONFIG_FREERTOS_DEBUG_OCDAWARE

View File

@@ -0,0 +1,99 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
/*
* This header contains private API used by various ESP-IDF debugging features (e.g., esp_gdbstub).
*/
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* -------------------------------------------------- Task Snapshot ------------------------------------------------- */
/**
* @brief Task Snapshot structure
*
* - Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
* - We need this structure because TCB_t is defined (hidden) in tasks.c.
*/
typedef struct xTASK_SNAPSHOT
{
void * pxTCB; /*!< Address of the task control block. */
StackType_t * pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */
StackType_t * pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
* pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
} TaskSnapshot_t;
/**
* @brief Iterate over all tasks in the system
*
* - This function can be used to iterate over every task in the system
* - The first call to this function must set pxTask to NULL
* - When all functions have been iterated, this function will return NULL.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param pxTask Handle of the previous task (or NULL on the first call of this function)
* @return TaskHandle_t Handle of the next task (or NULL when all tasks have been iterated over)
*/
TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask );
/**
* @brief Fill a TaskSnapshot_t structure for specified task.
*
* - This function is used by the panic handler to get the snapshot of a particular task.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param[in] pxTask Task's handle
* @param[out] pxTaskSnapshot Snapshot of the task
* @return pdTRUE if operation was successful else pdFALSE
*/
BaseType_t vTaskGetSnapshot( TaskHandle_t pxTask,
TaskSnapshot_t * pxTaskSnapshot );
/**
* @brief Fill an array of TaskSnapshot_t structures for every task in the system
*
* - This function is used by the panic handler to get a snapshot of all tasks in the system
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param[out] pxTaskSnapshotArray Array of TaskSnapshot_t structures filled by this function
* @param[in] uxArrayLength Length of the provided array
* @param[out] pxTCBSize Size of the a task's TCB structure
* @return UBaseType_t
*/
UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray,
const UBaseType_t uxArrayLength,
UBaseType_t * const pxTCBSize );
/* ----------------------------------------------------- Misc ----------------------------------------------------- */
/**
* @brief Get a void pointer to the current TCB of a particular core
*
* @note This function provides no guarantee that the return TCB will still be the current task (or that the task still
* exists) when it returns. It is the caller's responsibility to ensure that the task does not get scheduled or deleted.
* @param xCoreID The core to query
* @return Void pointer to current TCB
*/
void * pvTaskGetCurrentTCBForCore( BaseType_t xCoreID );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */

View File

@@ -3,79 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* @brief Task Snapshot structure
*
* - Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
* - We need this structure because TCB_t is defined (hidden) in tasks.c.
*/
typedef struct xTASK_SNAPSHOT
{
void * pxTCB; /*!< Address of the task control block. */
StackType_t * pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */
StackType_t * pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
* pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
} TaskSnapshot_t;
/**
* @brief Iterate over all tasks in the system
*
* - This function can be used to iterate over every task in the system
* - The first call to this function must set pxTask to NULL
* - When all functions have been iterated, this function will return NULL.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param pxTask Handle of the previous task (or NULL on the first call of this function)
* @return TaskHandle_t Handle of the next task (or NULL when all tasks have been iterated over)
*/
TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask );
/**
* @brief Fill a TaskSnapshot_t structure for specified task.
*
* - This function is used by the panic handler to get the snapshot of a particular task.
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param[in] pxTask Task's handle
* @param[out] pxTaskSnapshot Snapshot of the task
* @return pdTRUE if operation was successful else pdFALSE
*/
BaseType_t vTaskGetSnapshot( TaskHandle_t pxTask,
TaskSnapshot_t * pxTaskSnapshot );
/**
* @brief Fill an array of TaskSnapshot_t structures for every task in the system
*
* - This function is used by the panic handler to get a snapshot of all tasks in the system
*
* @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
* does not acquire any locks.
* @param[out] pxTaskSnapshotArray Array of TaskSnapshot_t structures filled by this function
* @param[in] uxArrayLength Length of the provided array
* @param[out] pxTCBSize Size of the a task's TCB structure
* @return UBaseType_t
*/
UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray,
const UBaseType_t uxArrayLength,
UBaseType_t * const pxTCBSize );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#warning freertos/task_snapshot.h header is no longer used, and will be removed in future versions.
#include "esp_private/freertos_debug.h"

View File

@@ -9,7 +9,7 @@
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/task_snapshot.h"
#include "esp_private/freertos_debug.h"
#include "esp_cpu.h"
#include "esp_rom_sys.h"
#include "unity.h"