# Second core Wake up sequence in SMP

**URL:** <https://forums.freertos.org/t/second-core-wake-up-sequence-in-smp/19917>\
**Category:** Kernel\
**Created:** [April 30, 2024, 8:25am UTC](https://forums.freertos.org/t/second-core-wake-up-sequence-in-smp/19917 "2024-04-30T08:25:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaid](https://avatars.discourse-cdn.com/v4/letter/z/e95f7d/32.png) [@Zaid](https://forums.freertos.org/u/Zaid)\
**Post date:** [April 30, 2024, 8:25am UTC](https://forums.freertos.org/t/second-core-wake-up-sequence-in-smp/19917/1 "2024-04-30T08:25:10Z")

</div>

Hi,

I am porting armR8 for SMP freertos. Everything is working fine for the primary core. So my questions are regarding the secondary core.

In the initialization of the secondary core, I initialize its stack and memory, etc., and then send it into sleep mode using wfi instruction. Then after a while, the scheduler from the primary core wakes it up to schedule some tasks and sends the control to irq, which calls portSAVE\_CONTEXT, vTaskSwitchContextConst, and portRESTORE\_CONTEXT.

I know the abovementioned sequence is wrong as the secondary core never got to run vPortRestoreTaskContext. I also observed other SMP ports, and it seems they are running vTaskStartScheduler(); on all cores. Does this mean all cores are running complete main(); ?

My questions are:

1. When should the secondary core be put to sleep, and when should it be woken up?
2. What should the secondary core run first when it is woken up?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![cookpate](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/cookpate/32/2962_2.png) [@cookpate](https://forums.freertos.org/u/cookpate)\
**Post date:** [May 1, 2024, 9:28pm UTC](https://forums.freertos.org/t/second-core-wake-up-sequence-in-smp/19917/2 "2024-05-01T21:28:19Z")

</div>

Hello @Zaid,

1. The secondary core should be started at `xPortStartScheduler()`. FreeRTOS does not stop cores unless tickless idle is configured and active.
2. The secondary core should also run the scheduler. See the RP2040 port for an example: [FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/port.c at 30afc1a2c05157fcac1a46dc773b0125bd680b82 · FreeRTOS/FreeRTOS-Kernel · GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/30afc1a2c05157fcac1a46dc773b0125bd680b82/portable/ThirdParty/GCC/RP2040/port.c#L381C37-L381C84)

This port example uses an API function on the RP2040 to start and run a function on core 1. This function sets up the ISR routine from core 0. On the timer tick, each core will sequentially run the scheduler and then trigger the next core’s interrupt. If a core calls a kernel function which reschedules, it simply runs scheduler immediately.

---

<div class="post-metadata">

**Author:** ![Zaid](https://avatars.discourse-cdn.com/v4/letter/z/e95f7d/32.png) [@Zaid](https://forums.freertos.org/u/Zaid)\
**Post date:** [May 7, 2024, 7:09am UTC](https://forums.freertos.org/t/second-core-wake-up-sequence-in-smp/19917/3 "2024-05-07T07:09:14Z")

</div>

Combined with my previous understanding from [this](https://forums.freertos.org/t/which-should-be-the-first-task-to-run-in-smp-port/19865), the secondary core should be sent to sleep or an empty infinite loop after basic initialization.  
Then it should resume processing at `xPortStartScheduler()`, where it should call `vPortRestoreTaskContext()` or an equivalent function. This function will set the idle task in the currentTCB and it will be the first task any core will execute.

Is my understanding correct?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 7, 2024, 7:11am UTC](https://forums.freertos.org/t/second-core-wake-up-sequence-in-smp/19917/4 "2024-05-07T07:11:18Z")

</div>

> [@Zaid](#):
>
> Is my understanding correct?

Yes, that is correct.
