From 003c1c17f0e414edd253763538f21cd93b0b9420 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 13 Dec 2019 13:47:26 -0800 Subject: [PATCH] Make stacks smaller (#1055) * remove factually incorrect comment * shrinky stacky * shuffle comments --- firmware/config/boards/kinetis/chconf.h | 7 +++---- firmware/config/stm32f4ems/chconf.h | 9 ++++----- firmware/config/stm32f7ems/chconf.h | 7 +++---- firmware/controllers/global_shared.h | 12 +++++++----- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/firmware/config/boards/kinetis/chconf.h b/firmware/config/boards/kinetis/chconf.h index 693e73d42b..aa88a5f858 100644 --- a/firmware/config/boards/kinetis/chconf.h +++ b/firmware/config/boards/kinetis/chconf.h @@ -44,12 +44,11 @@ * */ -#define PORT_IDLE_THREAD_STACK_SIZE 64/*768*//*1024*/ +#define PORT_IDLE_THREAD_STACK_SIZE 32 -// rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. -// see also a strange comment about PORT_INT_REQUIRED_STACK in global_shared.h +// See global_shared.h notes about stack requirements // see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks -#define PORT_INT_REQUIRED_STACK 512/*768*/ +#define PORT_INT_REQUIRED_STACK 128 #define CHPRINTF_USE_FLOAT TRUE diff --git a/firmware/config/stm32f4ems/chconf.h b/firmware/config/stm32f4ems/chconf.h index ac805a917b..c9a783c24a 100644 --- a/firmware/config/stm32f4ems/chconf.h +++ b/firmware/config/stm32f4ems/chconf.h @@ -41,12 +41,11 @@ * */ -#define PORT_IDLE_THREAD_STACK_SIZE 1024 +#define PORT_IDLE_THREAD_STACK_SIZE 32 -// rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. -// see also a strange comment about PORT_INT_REQUIRED_STACK in global_shared.h +// See global_shared.h notes about stack requirements // see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks -#define PORT_INT_REQUIRED_STACK 768 +#define PORT_INT_REQUIRED_STACK 128 #define CHPRINTF_USE_FLOAT TRUE @@ -605,7 +604,7 @@ * tickless mode. */ #if !defined(CH_DBG_THREADS_PROFILING) -#define CH_DBG_THREADS_PROFILING FALSE +#define CH_DBG_THREADS_PROFILING TRUE #endif /** @} */ diff --git a/firmware/config/stm32f7ems/chconf.h b/firmware/config/stm32f7ems/chconf.h index 6adecfefcb..35a4721ef1 100644 --- a/firmware/config/stm32f7ems/chconf.h +++ b/firmware/config/stm32f7ems/chconf.h @@ -41,12 +41,11 @@ * */ -#define PORT_IDLE_THREAD_STACK_SIZE 1024 +#define PORT_IDLE_THREAD_STACK_SIZE 32 -// rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. -// see also a strange comment about PORT_INT_REQUIRED_STACK in global_shared.h +// See global_shared.h notes about stack requirements // see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks -#define PORT_INT_REQUIRED_STACK 768 +#define PORT_INT_REQUIRED_STACK 128 #define CHPRINTF_USE_FLOAT TRUE diff --git a/firmware/controllers/global_shared.h b/firmware/controllers/global_shared.h index df7cc3070a..859535914c 100644 --- a/firmware/controllers/global_shared.h +++ b/firmware/controllers/global_shared.h @@ -13,11 +13,13 @@ /** * The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance * optimization. - * - * rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. Problem - * is that PORT_INT_REQUIRED_STACK is included within each user thread stack, thus this large stack multiplies - * and this consumes a lot of valueable RAM. While forcing the compiler to inline helps to some degree, - * it would be even better not to waste stack on passing the parameter. + * + * Of note is that interrupts are NOT serviced on the stack of the thread that was running when the + * interrupt occurred. The only thing that happens on that thread's stack is that its registers are + * pushed (by hardware) when an interrupt occurs, just before swapping the stack pointer out for the + * main stack (currently 0x400=1024 bytes), where the ISR actually runs. + * + * see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks * * In the firmware we are using 'extern *Engine' - in the firmware Engine is a signleton *