SMP Porting Checklist - A53 *4 as reference

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, the following are required configuration to be added to enable SMP scheduler.

#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 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() 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 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

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.

7. Define portENTER_CRITICAL() and portEXIT_CRITICAL()
These macros should be implemented with vTaskEnterCritical() and vTaskExitCritical().
Example RP2040 implementation.

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.

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.

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

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.

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 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 also include SMP support. It can be used as a starting point for developing a new FreeRTOS SMP port.

3 Likes