Page 1 of 1

stack filling in 21.6.x

Posted: Sun Aug 15, 2021 2:45 pm
by wild-boar
I recently upgraded a project from 20.3.x to 21.6.x. I have custom software that monitors the stack usage. I noticed in 21.6.x that the idle stack was not being filled with known values like 20.3.x. All other stacks worked normally.

Here is a patch that restores the functionality:

Code: Select all

diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c
index 2c9a5fff9..4b96ab551 100644
--- a/os/rt/src/chthreads.c
+++ b/os/rt/src/chthreads.c
@@ -269,6 +269,12 @@ thread_t *chThdCreateSuspended(const thread_descriptor_t *tdp) {
  */
 thread_t *chThdCreateI(const thread_descriptor_t *tdp) {
 
+#if CH_DBG_FILL_THREADS == TRUE
+  __thd_memfill((uint8_t *)tdp->wbase,
+                (uint8_t *)tdp->wend,
+                CH_DBG_STACK_FILL_VALUE);
+#endif
+
   return chSchReadyI(chThdCreateSuspendedI(tdp));
 }


Thanks!

Re: stack filling in 21.6.x

Posted: Sun Aug 15, 2021 5:43 pm
by Giovanni
Hi,

It is intentional, it is an I-class function and could be called from interrupts, filling memory there would keep interrupts disabled for too long time. There is this none:

Code: Select all

 * @note    Threads created using this function do not obey to the
 *          @p CH_DBG_FILL_THREADS debug option because it would keep
 *          the kernel locked for too much time.


Giovanni

Re: stack filling in 21.6.x

Posted: Sun Aug 15, 2021 6:04 pm
by wild-boar
I did not see the note. I think it is important to maintain consistency across threads with respect to the CH_DBG_FILL_THREADS option. The idle thread, from a thread perpective, is not special or different.

Can we instead fix is with the patch below?

Thanks!


Code: Select all

diff --git a/os/rt/src/chinstances.c b/os/rt/src/chinstances.c
index ca55ff8e1..55248b92c 100644
--- a/os/rt/src/chinstances.c
+++ b/os/rt/src/chinstances.c
@@ -173,6 +173,12 @@ void chInstanceObjectInit(os_instance_t *oip,
       .arg      = NULL
     };
 
+#if CH_DBG_FILL_THREADS == TRUE
+    __thd_memfill((uint8_t *)idle_descriptor.wbase,
+                  (uint8_t *)idle_descriptor.wend,
+                  CH_DBG_STACK_FILL_VALUE);
+#endif
+
     /* This thread has the lowest priority in the system, its role is just to
        serve interrupts in its context while keeping the lowest energy saving
        mode compatible with the system status.*/

Re: stack filling in 21.6.x

Posted: Mon Aug 16, 2021 7:30 am
by Giovanni
Hi,

Fixed as bug #1171.

Giovanni