# SMP Porting Checklist - A53 \*4 as reference

**URL:** <https://forums.freertos.org/t/smp-porting-checklist-a53-4-as-reference/14499>\
**Category:** Kernel\
**Created:** [February 16, 2022, 8:21pm UTC](https://forums.freertos.org/t/smp-porting-checklist-a53-4-as-reference/14499 "2022-02-16T20:21:25Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Fresh](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@Fresh](https://forums.freertos.org/u/Fresh)\
**Post date:** [December 14, 2023, 11:47am UTC](https://forums.freertos.org/t/smp-porting-checklist-a53-4-as-reference/14499/6 "2023-12-14T11:47:28Z")

</div>

Hi jen,

Thank you for listing the port macros changed in main branch.

The checklist above is for porting to FreeRTOS SMP branch. FreeRTOS SMP branch is deprecated now. I update the checklist with RP2040 port example.

**1. Define SMP configuration in FreeRTOSConfig.h**  
Based on the [sample confiugration](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/examples/sample_configuration), the following are required configuration to be added to enable SMP scheduler.

```c
#define configNUMBER_OF_CORES /* The number of cores in the platform. Set core numbers to greater than 1 to enable SMP scheduler */
#define configUSE_PASSIVE_IDLE_HOOK 0 /* 

```

You may reference [SMP Specific Configuration Options](https://www.freertos.org/symmetric-multiprocessing-introduction.html#smp-specific-configuration-options) for more information about other SMP configurations.

**2. Define portGET\_CORE\_ID()**  
Returns the core ID ( between 0 and configNUMBER\_OF\_CORES - 1 ) of the calling core.  
RP2040 port makes use of the [get\_num\_core()](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/include/portmacro.h#L141) API from PICO SDK to implement this function.

**3. Define portYIELD\_CORE( xCoreID )**  
The core calling this API must interrupt the other core with ID xCoreID. The interrupted core must behave as if it call `portYIELD()`.  
RP2040 makes use of a [FIFO](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/port.c#L536) to interrupt other cores.

**4. Define portSET\_INTERRUPT\_MASK() and portCLEAR\_INTERRUPT\_MASK( ulState )**  
Interrupt mask should be returned and cleared with these macros.  
[Example RP2040 port implementation](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/include/portmacro.h#L169-L176)

**5. Define portGET\_TASK\_LOCK() and portGET\_ISR\_LOCK()**  
Acquire the task or ISR lock. TASK and ISR lock are recursive lock. They should be able to be locked by the same core multiple times.

**6. Define portRELEASE\_TASK\_LOCK() and portRELEASE\_ISR\_LOCK()**  
Release the task or ISR lock. If these locks are locked by the same core multiple times, they should be released as many times as it is locked.  
[Example RP2040 recursive lock implementation.](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/include/portmacro.h#L209)

**7. Define portENTER\_CRITICAL() and portEXIT\_CRITICAL()**  
These macros should be implemented with `vTaskEnterCritical()` and `vTaskExitCritical()`.  
[Example RP2040 implementation.](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/include/portmacro.h#L198-L199)

**8. Define portENTER\_CRITICAL\_FROM\_ISR() and portEXIT\_CRITICAL\_FROM\_ISR()**  
Enter/exit critical section from ISR. These macros should be implemented with `vTaskEnterCriticalFromISR()` and `vTaskExitCriticalFromISR( x )`.  
[Example RP2040 implementation.](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/include/portmacro.h#L200-L201)

**9. Define portCRITICAL\_NESTING\_IN\_TCB**  
Port can decide to keep the critical nesting count in TCB or in port by setting `portCRITICAL_NESTING_IN_TCB` in portmacro.h file. RP2040 port provides an example of [keeping critical nesting count in the port](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/include/portmacro.h#L158-L163).

**10. Update portSET\_INTERRUPT\_MASK\_FROM\_ISR and portCLEAR\_INTERRUPT\_MASK\_FROM\_ISR implementation in port**  
These macros should now be implemented as the macro name suggested, set or clear interrupt mask from ISR if nested interrupt are supported.  
[Example RP2040 implementation](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/port.c#L514-L532)

**11. Call xTaskIncrementTick in critical section in port**  
Access shared kernel data in interrupt handler now need to be performed in critical section due to multiple cores consideration.  
[Example RP2040 implementation.](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/port.c#L739-L759)

**12. Update xPortStartScheduler**  
The port should start scheduler on the number of cores specified by configNUMBER\_OF\_CORES. Each core must end this function by restoring the context of the task assigned to it.

**13. Use pxCurrentTCBs in the port**  
Pointers to Current TCB now are an array indexed by core ID. Whenever task state needs to be saved or restored, this array must now be indexed first to get the stack pointer in TCB\_t.  
Example [Index the pxCurrentTCBs](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/e0bb21f832cdcef9250e7dfe1c82abf9264f9d31/portable/ThirdParty/GCC/RP2040/port.c#L648-L650) in RP2040 port

**14. Pass core ID to vTaskSwitchContext as parameter**  
vTaskSwitchContext now takes core ID as parameter to switch context of the core ID in pxCurrentTCBs.

This checklist may be rough and not completed. Feedback and update to the checklist are welcomed.  
The [template port](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/template) also include SMP support. It can be used as a starting point for developing a new FreeRTOS SMP port.

---

_[View the full topic](https://forums.freertos.org/t/smp-porting-checklist-a53-4-as-reference/14499)._
