FreeRTOS SMP: Idle tasks affinity

Hi, I am currently using FreeRTOS 11.1.0 in Symmetric MultiProcessing and I am encountering a strange error while executing a simple example program. I have defined the traceTASK_SWITCHED_IN and traceTASK_SWITCHED_OUT to track the tasks execution on 2 cores and this is the result:

---------- New Session ----------
Hello from Freertos example main
[TASK] IDLE0 SWITCHED-IN ## CORE 0
[TASK] IDLE1 SWITCHED-OUT ## CORE 1
[TASK] Tmr Svc SWITCHED-IN ## CORE 1
[TASK] IDLE0 SWITCHED-OUT ## CORE 0
[TASK] IDLE1 SWITCHED-IN ## CORE 0
[TASK] IDLE1 SWITCHED-OUT ## CORE 0
HALT: Task IDLE1 overflowed its stack.

Aside from increasing the stack size of the idle tasks (which btw didn’t solve the problem), I also investigated why CORE0 executes IDLE1 since, from my understanding, each core can only execute its idle task. I found out that the core affinity of idle tasks is set to -1 so they can be scheduled on every available core. Is this the correct behavior?

This is indeed because the IDLE tasks are not created with a fixed affinity in the SMP kernel. See here. So the behavior that you see is correct.

1 Like

Have you found the reason for stack overflow?

Nope, not yet. I am currently trying to reliably trace both cores during the program execution.

On smp,if set configSUPPORT_STATIC_ALLOCATION , you can refer FreeRTOS/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/multiple_priorities_no_timeslice_utest.c at 91659446648a00f24b0b8af6327230658cc65c07 · FreeRTOS/FreeRTOS · GitHub to setup passive idle task sack. Hope this help you.

Thank you. Are you suggesting to use static allocation to check if the program behaves differently with dynamic and static allocation? At the moment I have configSUPPORT_STATIC_ALLOCATION disabled.