Skip to content

Commit f163e1e

Browse files
authored
Merge pull request #3624 from TomoYamanaka/master
Fix Stack stats by running the test command with "-DMBED_HEAP_STATS_ENABLED=1"
2 parents def8b32 + 33d5c51 commit f163e1e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

rtos/rtx/TARGET_CORTEX_A/RTX_Conf_CA.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@
107107
// <i> Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer.
108108
// <i> Enabling this option increases significantly the execution time of osThreadCreate.
109109
#ifndef OS_STKINIT
110-
#define OS_STKINIT 0
110+
#if (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED)
111+
#define OS_STKINIT 1
112+
#else
113+
#define OS_STKINIT 0
114+
#endif
111115
#endif
112116

113117
// <o>Processor mode for thread execution

rtos/rtx/TARGET_CORTEX_A/rt_CMSIS.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,27 @@ os_InRegs osEvent_type svcThreadGetInfo (osThreadId thread_id, osThreadInfo info
843843
}
844844

845845
if (osThreadInfoStackMax == info) {
846-
// Cortex-A RTX does not have stack init so
847-
// the maximum stack usage cannot be obtained.
848-
ret.status = osErrorResource;
849-
return osEvent_ret_status;
846+
uint32_t i;
847+
uint32_t *stack_ptr;
848+
uint32_t stack_size;
849+
if (!(os_stackinfo & (1 << 28))) {
850+
// Stack init must be turned on for max stack usage
851+
ret.status = osErrorResource;
852+
return osEvent_ret_status;
853+
}
854+
stack_ptr = (uint32_t*)ptcb->stack;
855+
stack_size = ptcb->priv_stack;
856+
if (0 == stack_size) {
857+
// This is an OS task - always a fixed size
858+
stack_size = os_stackinfo & 0x3FFFF;
859+
}
860+
for (i = 1; i <stack_size / 4; i++) {
861+
if (stack_ptr[i] != MAGIC_PATTERN) {
862+
break;
863+
}
864+
}
865+
ret.value.v = stack_size - i * 4;
866+
return osEvent_ret_value;
850867
}
851868

852869
if (osThreadInfoEntry == info) {

0 commit comments

Comments
 (0)