Hi couple of questions re thread stacks
1) What the easy way to find out what is consuming the stack working area ? I.e. what variables are responsible ?
2) Just had a stack issue, the failure is instant reset of MCU, no hard faults(as i capture these) where signaled, ive got all the debug defines switched on. Why was this not captured in the RTOS, the idea that the MCU can just reset with no warning is abit worrying.
Thread Stack Usage ?
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- Cesare
- Posts: 36
- Joined: Tue Jul 11, 2017 11:51 am
- Location: Milan, Italy
- Has thanked: 3 times
- Been thanked: 3 times
Re: Thread Stack Usage ?
Hi,
I had the same question, then I wrote this function which I call on demand using the shell
I had the same question, then I wrote this function which I call on demand using the shell
Code: Select all
static void stat_threads(BaseSequentialStream *chp)
{
static const char *states[] = {CH_STATE_NAMES};
thread_t *tp;
size_t n = 0;
size_t sz;
uint32_t used_pct;
chprintf(chp, "\r\n");
chprintf(chp, " begin end size used %% prio state name\r\n");
chprintf(chp, "--------------------------------------------------------------------\r\n");
tp = chRegFirstThread();
do {
n = 0;
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
uint32_t stklimit = (uint32_t)tp->wabase;
#else
uint32_t stklimit = 0U;
#endif
uint8_t *begin = (uint8_t *)stklimit;
uint8_t *end = (uint8_t *)tp;
sz = end - begin;
while(begin < end)
if(*begin++ == CH_DBG_STACK_FILL_VALUE) ++n;
used_pct = (n * 100) / sz;
chprintf(chp, "0x%08lx 0x%08lx %6u %6u %3u%% %4lu %9s %12s\r\n", stklimit, (uint32_t)tp,
sz,
n,
used_pct,
(uint32_t)tp->prio,
states[tp->state],
tp->name == NULL ? "" : tp->name);
tp = chRegNextThread(tp);
} while (tp != NULL);
chprintf(chp, "\r\n");
}
Re: Thread Stack Usage ?
Cesare wrote:Hi,
I had the same question, then I wrote this function which I call on demand using the shellCode: Select all
static void stat_threads(BaseSequentialStream *chp)
{
static const char *states[] = {CH_STATE_NAMES};
thread_t *tp;
size_t n = 0;
size_t sz;
uint32_t used_pct;
chprintf(chp, "\r\n");
chprintf(chp, " begin end size used %% prio state name\r\n");
chprintf(chp, "--------------------------------------------------------------------\r\n");
tp = chRegFirstThread();
do {
n = 0;
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
uint32_t stklimit = (uint32_t)tp->wabase;
#else
uint32_t stklimit = 0U;
#endif
uint8_t *begin = (uint8_t *)stklimit;
uint8_t *end = (uint8_t *)tp;
sz = end - begin;
while(begin < end)
if(*begin++ == CH_DBG_STACK_FILL_VALUE) ++n;
used_pct = (n * 100) / sz;
chprintf(chp, "0x%08lx 0x%08lx %6u %6u %3u%% %4lu %9s %12s\r\n", stklimit, (uint32_t)tp,
sz,
n,
used_pct,
(uint32_t)tp->prio,
states[tp->state],
tp->name == NULL ? "" : tp->name);
tp = chRegNextThread(tp);
} while (tp != NULL);
chprintf(chp, "\r\n");
}
I've got something similar, but that does not answer my questions really. Yes i can see stack usage, but that is no good when it resets. I want to know why it reset and what variable caused the stack to got off the rails
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Thread Stack Usage ?
Hi,
The stack usage is influenced by:
- The function stack frame which depends on the automatic variables defined in the function.
- The call tree, deeper trees require more stack.
Giovanni
The stack usage is influenced by:
- The function stack frame which depends on the automatic variables defined in the function.
- The call tree, deeper trees require more stack.
Giovanni
- Cesare
- Posts: 36
- Joined: Tue Jul 11, 2017 11:51 am
- Location: Milan, Italy
- Has thanked: 3 times
- Been thanked: 3 times
Re: Thread Stack Usage ?
Sometimes to understand the real stack issue in the application could be very tedious.
I usually start the developing phase setting very huge thread stacks and then monitoring the usage in polling
I usually start the developing phase setting very huge thread stacks and then monitoring the usage in polling
Who is online
Users browsing this forum: No registered users and 24 guests