# FreeRTOS SMP: Idle tasks affinity

**URL:** <https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868>\
**Category:** Kernel\
**Tags:** debug, smp\
**Created:** [April 6, 2025, 7:16pm UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868 "2025-04-06T19:16:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matth9814](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/matth9814/32/5174_2.png) [@Matth9814](https://forums.freertos.org/u/Matth9814)\
**Post date:** [April 6, 2025, 7:16pm UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868/1 "2025-04-06T19:16:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sudeep-mohanty](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/sudeep-mohanty/32/5280_2.png) [@sudeep-mohanty](https://forums.freertos.org/u/sudeep-mohanty)\
**Post date:** [April 7, 2025, 7:42am UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868/2 "2025-04-07T07:42:35Z")

</div>

This is indeed because the IDLE tasks are not created with a fixed affinity in the SMP kernel. [See here](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/03db672b8f45db24aa99f12051f7cf86746b9ed9/tasks.c#L3654). So the behavior that you see is correct.

---

<div class="post-metadata">

**Author:** ![Saiiijchan](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/saiiijchan/32/3287_2.png) [@Saiiijchan](https://forums.freertos.org/u/Saiiijchan)\
**Post date:** [April 8, 2025, 1:21am UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868/3 "2025-04-08T01:21:18Z")

</div>

Have you found the reason for stack overflow?

---

<div class="post-metadata">

**Author:** ![Matth9814](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/matth9814/32/5174_2.png) [@Matth9814](https://forums.freertos.org/u/Matth9814)\
**Post date:** [April 8, 2025, 11:57am UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868/4 "2025-04-08T11:57:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Saiiijchan](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/saiiijchan/32/3287_2.png) [@Saiiijchan](https://forums.freertos.org/u/Saiiijchan)\
**Post date:** [April 9, 2025, 5:26am UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868/5 "2025-04-09T05:26:37Z")

</div>

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](https://github.com/FreeRTOS/FreeRTOS/blob/91659446648a00f24b0b8af6327230658cc65c07/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/multiple_priorities_no_timeslice_utest.c#L93) to setup passive idle task sack. Hope this help you.

---

<div class="post-metadata">

**Author:** ![Matth9814](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/matth9814/32/5174_2.png) [@Matth9814](https://forums.freertos.org/u/Matth9814)\
**Post date:** [April 9, 2025, 10:21am UTC](https://forums.freertos.org/t/freertos-smp-idle-tasks-affinity/22868/6 "2025-04-09T10:21:16Z")

</div>

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.
