Skip to content

Commit

Permalink
pw_thread_freertos: Fix peak stack usage capture
Browse files Browse the repository at this point in the history
Change-Id: I39ca6b4a9fb352d3fdd3a445e9e9de934bc4de39
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/108150
Reviewed-by: Armando Montanez <[email protected]>
Commit-Queue: Medha Kini <[email protected]>
  • Loading branch information
Medha Kini authored and CQ Bot Account committed Aug 26, 2022
1 parent d5524c8 commit fbf06e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pw_thread_freertos/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ via ``xTaskGetSchedulerState()``.
------------------------
Thread Iteration Backend
------------------------
A backend for ``pw::thread::thread_iteration``. This requires
``pw_thread_freertos_TSKTCB_BACKEND`` and
``pw_third_party_freertos_DISABLE_TASKS_STATICS`` to be enabled and configured
properly.
``pw_thread_freertos_TSKTCB_BACKEND`` to be configured
properly and ``pw_third_party_freertos_DISABLE_TASKS_STATICS`` to be enabled.
To allow for peak stack usage measurement, the FreeRTOS config
``INCLUDE_uxTaskGetStackHighWaterMark`` should also be enabled.

--------------------
Thread Sleep Backend
Expand Down
12 changes: 9 additions & 3 deletions pw_thread_freertos/thread_iteration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ bool StackInfoCollector(TaskHandle_t current_thread,
thread_info.set_stack_high_addr(
reinterpret_cast<uintptr_t>(tcb.pxEndOfStack));
#if INCLUDE_uxTaskGetStackHighWaterMark
// Walk through the stack from start to end to measure the current peak
// using high-water marked stack data.
thread_info.set_stack_peak_addr(uxTaskGetStackHighWaterMark(thread));
// Walk through the stack from start to end to measure the current peak
// using high-water marked stack data.
#if (portSTACK_GROWTH > 0)
thread_info.set_stack_peak_addr(thread_info.stack_high_addr().value() -
uxTaskGetStackHighWaterMark(current_thread));
#else
thread_info.set_stack_peak_addr(thread_info.stack_low_addr().value() +
uxTaskGetStackHighWaterMark(current_thread));
#endif // portSTACK_GROWTH > 0
#endif // INCLUDE_uxTaskGetStackHighWaterMark
#endif // configRECORD_STACK_HIGH_ADDRESS

Expand Down
1 change: 1 addition & 0 deletions targets/stm32f429i_disc1_stm32cube/config/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern unsigned long getRunTimeCounterValue(void);
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1

// Instead of defining configASSERT(), include a header that provides a
// definition that redirects to pw_assert.
Expand Down

0 comments on commit fbf06e6

Please sign in to comment.