stack filling in 21.6.x Topic is solved

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

stack filling in 21.6.x

Postby wild-boar » Sun Aug 15, 2021 2:45 pm

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: stack filling in 21.6.x

Postby Giovanni » Sun Aug 15, 2021 5:43 pm

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: 14
Joined: Thu May 08, 2014 11:58 pm
Been thanked: 6 times

Re: stack filling in 21.6.x  Topic is solved

Postby wild-boar » Sun Aug 15, 2021 6:04 pm

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: stack filling in 21.6.x

Postby Giovanni » Mon Aug 16, 2021 7:30 am

Hi,

Fixed as bug #1171.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 6 guests