# portDISABLE\_INTERRUPTS() question on SMP

**URL:** <https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292>\
**Category:** Kernel\
**Created:** [October 7, 2023, 11:39am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292 "2023-10-07T11:39:50Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [October 7, 2023, 11:39am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292/1 "2023-10-07T11:39:50Z")

</div>

Hi,  
I am porting smp on arm cortex-a7 using gic-v2 and the portable part is refered to portable/GCC/ARM\_CA9.  
I followed the [SMP change description](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/smp/design/FreeRTOS%20SMP%20change%20description.pdf) to porting. I continued to use **portDISABLE\_INTERRUPTS()** and **portSET\_INTERRUPT\_MASK\_FROM\_ISR()** – [portDISABLE\_INTERRUPT](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/eb80149cd724dfd057c14d5f8ab75026ef8148fe/portable/GCC/ARM_CA9/port.c#L503C10-L503C32)，because they match the description in the documentation.

> portDISABLE\_INTERRUPTS()  
> This must now also return the interrupt mask prior to disabling. It may still be called without  
> checking the return value.

portDISABLE\_INTERRUPTS() sets GICC\_ PMR and clears CPSR I bit to enable IRQ.

The FreeRTOS\_SWI\_Handler and FreeRTOS\_IRQ\_Handler is also implemented as same as [ARM\_CA9/portASM.S](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/smp/portable/GCC/ARM_CA9/portASM.S), but stack corruption happends. Because interrupt is re-enabled is vTaskSwitchContext( CoreID ) which will calls xTaskGetCurrentTaskHandle() and portDISABLE\_INTERRUPTS, IRQ is re-enabled at this time and interrupt preempts vTaskSwitchContext().

Main branch has added new marcore portSET\_INTERRUPT\_MASK() which has return value. I want to know what is the difference between portSET\_INTERRUPT\_MASK() and portDISABLE\_INTERRUPTS and how to implent them.

Thank you!

---

<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:** [October 9, 2023, 9:16am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292/2 "2023-10-09T09:16:25Z")

</div>

> [@Saiiijchan](#):
>
> Because interrupt is re-enabled is vTaskSwitchContext( CoreID ) which will calls xTaskGetCurrentTaskHandle() and portDISABLE\_INTERRUPTS, IRQ is re-enabled at this time and interrupt preempts vTaskSwitchContext().

I do not see a call to xTaskGetCurrentTaskHandle in vTaskSwitchContext, Are you using the latest code in the main branch?

---

<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:** [October 9, 2023, 9:20am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292/3 "2023-10-09T09:20:53Z")

</div>

No, I am using old smp branch [smp](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/smp).  
xTaskGetCurrentTaskHandle() in main branch uses portSET\_INTERRUPT\_MASK() instead of portDISABLE\_INTERTUPT().

---

<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:** [October 9, 2023, 9:34am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292/4 "2023-10-09T09:34:10Z")

</div>

> [@Saiiijchan](#):
>
> No, I am using old smp branch [smp](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/smp).

I’d suggest switching to main branch as smp branch is now deprecated.

> [@Saiiijchan](#):
>
> xTaskGetCurrentTaskHandle() in main branch uses portSET\_INTERRUPT\_MASK() instead of portDISABLE\_INTERTUPT().

Some platforms allow us to mask interrupts selectively. We divide interrupts into 2 parts on such platforms -

1. High priority interrupts - these are not masked by FreeRTOS critical sections. You cannot call FreeRTOS APIs from the corresponding ISRs.
2. Low priority interrupts - these are masked by FreeRTOS critical sections. You can call FreeRTOS APIs from the corresponding ISRs.

portSET\_INTERRUPT\_MASK is helpful when you want to mask interrupts selectively. The call sequence looks like:

```auto
            uxSavedInterruptStatus = portSET_INTERRUPT_MASK();
            {
                /* Critical section code. */
            }
            portCLEAR_INTERRUPT_MASK( uxSavedInterruptStatus );

```

If you want to disable all the interrupts always, you can choose to implement portSET\_INTERRUPT\_MASK using portDISABLE\_INTERTUPT.

---

<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:** [October 9, 2023, 10:51am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292/5 "2023-10-09T10:51:46Z")

</div>

Got it! When using gic, mask interrupts selectively by setting GICC\_PMR to configMAX\_SYSCALL\_INTERRUPT\_PRIORITY, I will try main branch. Thanks for your reply.

BTW, is there any relevant implements that can be refered to?

---

<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:** [October 9, 2023, 11:52am UTC](https://forums.freertos.org/t/portdisable-interrupts-question-on-smp/18292/6 "2023-10-09T11:52:55Z")

</div>

> [@Saiiijchan](#):
>
> BTW, is there any relevant implements that can be refered to?

- [https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/ThirdParty/GCC/RP2040](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/ThirdParty/GCC/RP2040)
- [https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/ThirdParty/xClang/XCOREAI](https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/main/portable/ThirdParty/xClang/XCOREAI)
