From 0eb2470a61da7397525ff23a2e9419ddec6c211e Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 12 Feb 2019 18:47:16 -0500 Subject: [PATCH] getMaxUsedStack() - stack usage reseach mini progress --- firmware/global.h | 1 + firmware/util/efilib2.cpp | 13 +++++++++++++ firmware/util/efilib2.h | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/firmware/global.h b/firmware/global.h index 304847f4f3..82d3adfbde 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -101,6 +101,7 @@ typedef unsigned int time_t; /* * Stack debugging + * See also getMaxUsedStack() */ int getRemainingStack(thread_t *otp); diff --git a/firmware/util/efilib2.cpp b/firmware/util/efilib2.cpp index 34335fcffe..5b0a1358d1 100644 --- a/firmware/util/efilib2.cpp +++ b/firmware/util/efilib2.cpp @@ -39,3 +39,16 @@ efitime_t Overflow64Counter::update(uint32_t value) { return state.highBits + state.lowBits; } #endif + +int getMaxUsedStack(uint8_t *ptr, int size) { + /** + * maximum used stack size total stack buffer size minus position of first modified byte + */ + int used = 0; + for (int i = 0; i < size; i++) { + if (ptr[i] != CH_DBG_STACK_FILL_VALUE) { + return size - i; + } + } + return 0; +} diff --git a/firmware/util/efilib2.h b/firmware/util/efilib2.h index 69fe8beaed..e311d48e0e 100644 --- a/firmware/util/efilib2.h +++ b/firmware/util/efilib2.h @@ -17,6 +17,10 @@ typedef struct { } State64; void updateAndSet(State64 *state, uint32_t value); +/** + * @return for a given stack memory region returns how much stack was ever used + */ +int getMaxUsedStack(uint8_t *ptr, int size); class Overflow64Counter {