stack filling in 21.6.x Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
wild-boar
Posts: 17
Joined: Thu May 08, 2014 11:58 pm
Been thanked: 9 times

stack filling in 21.6.x

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: stack filling in 21.6.x

Post 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
wild-boar
Posts: 17
Joined: Thu May 08, 2014 11:58 pm
Been thanked: 9 times

Re: stack filling in 21.6.x

Post 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.*/
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: stack filling in 21.6.x

Post by Giovanni »

Hi,

Fixed as bug #1171.

Giovanni
Post Reply