Stack usage is still all over the place #1662

This commit is contained in:
rusefi 2020-08-01 21:31:23 -04:00
parent bba404ac41
commit 4210632cd1
3 changed files with 12 additions and 11 deletions

View File

@ -119,18 +119,17 @@ static void sayHello(void) {
}
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
static uintptr_t CountFreeStackSpace(const void* wabase)
{
int CountFreeStackSpace(const void* wabase) {
const uint8_t* stackBase = reinterpret_cast<const uint8_t*>(wabase);
const uint8_t* stackUsage = stackBase;
// thread stacks are filled with 0x55
// thread stacks are filled with CH_DBG_STACK_FILL_VALUE
// find out where that ends - that's the last thing we needed on the stack
while(*stackUsage == 0x55) {
while (*stackUsage == CH_DBG_STACK_FILL_VALUE) {
stackUsage++;
}
return stackUsage - stackBase;
return (int)(stackUsage - stackBase);
}
#endif
@ -144,15 +143,15 @@ static void cmd_threads(void) {
scheduleMsg(&logger, "name\twabase\ttime\tfree stack");
while(tp) {
uintptr_t freeBytes = CountFreeStackSpace(tp->wabase);
scheduleMsg(&logger, "%s\t%08x\t%lu\t%lu", tp->name, tp->wabase, tp->time, freeBytes);
while (tp) {
int freeBytes = CountFreeStackSpace(tp->wabase);
scheduleMsg(&logger, "%s\t%08x\t%lu\t%d", tp->name, tp->wabase, tp->time, freeBytes);
tp = chRegNextThread(tp);
}
uintptr_t isrSpace = CountFreeStackSpace(reinterpret_cast<void*>(0x20000000));
scheduleMsg(&logger, "isr\t0\t0\t%lu", isrSpace);
int isrSpace = CountFreeStackSpace(reinterpret_cast<void*>(0x20000000));
scheduleMsg(&logger, "isr\t0\t0\t%d", isrSpace);
#else // CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS

View File

@ -50,7 +50,8 @@ typedef unsigned int time_t;
* project-wide default thread stack size
* See also PORT_INT_REQUIRED_STACK
* See getRemainingStack()
* See getMaxUsedStack()
* See getMaxUsedStack() and CountFreeStackSpace()
* See "threadsinfo" command cmd_threads
*/
#ifndef UTILITY_THREAD_STACK_SIZE
#define UTILITY_THREAD_STACK_SIZE 400

View File

@ -29,5 +29,6 @@ extern "C"
* See also getMaxUsedStack()
*/
EXTERNC int getRemainingStack(thread_t *otp);
int CountFreeStackSpace(const void* wabase);
#define HAS_OS_ACCESS