Thread stack alignment assertion Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
mck1117
Posts: 33
Joined: Wed Nov 11, 2020 6:41 am
Has thanked: 1 time
Been thanked: 8 times

Thread stack alignment assertion  Topic is solved

Postby mck1117 » Wed Jan 22, 2025 1:32 am

Hi, I'm running off of pretty close to master on GitHub, and I'm hitting this assertion: https://github.com/ChibiOS/ChibiOS/blob ... ads.c#L392 (I'm not doing anything unusual, it's a normal statically allocated thread I'm trying to start). STM32F0, so armv6m.

stktop gets aligned on PORT_NATURAL_ALIGN (4), but then we check that it's aligned to PORT_STACK_ALIGN (8). Is that intentional? Shouldn't it get aligned on PORT_STACK_ALIGN instead?

If I skip the assertion (or change the math for stktop to use PORT_STACK_ALIGN), the firmware works fine, as it did on older ChibiOS.

User avatar
Giovanni
Site Admin
Posts: 14565
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1112 times
Been thanked: 937 times
Contact:

Re: Thread stack alignment assertion

Postby Giovanni » Wed Jan 22, 2025 5:04 am

Hi,

You are right, this is a recent incomplete change on my side, now the thread structure is supposed to be always stack-aligned.

Code: Select all

#define THD_WORKING_AREA_SIZE(n)                                            \
  (MEM_ALIGN_NEXT(PORT_WA_SIZE(n), PORT_STACK_ALIGN) +                      \
   MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN))


Fixed on subversion.

This has been caused by the recent introduction of the new threading API, chThdSpawnXXX() vs chThdCreateXXX(), which triggered some changes also in the old API.

The RT in trunk is being optimized for multi-core systems.The new API is like the old one except the thread_t structure is no more included in the working area but passed from outside.

Stack and thread structure being in the same RAM is no more optimal when you consider NUMA SMP systems. The stack can and should be in a core-private RAM (a TCM for example) and can be non-coherently cached, the thread structure must be in a RAM reachable by all cores and not cached (or coherently cached).

Giovanni

mck1117
Posts: 33
Joined: Wed Nov 11, 2020 6:41 am
Has thanked: 1 time
Been thanked: 8 times

Re: Thread stack alignment assertion

Postby mck1117 » Wed Jan 22, 2025 8:38 am

Works for me now, thanks!


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 17 guests