# Scheduler priority in higher then MAX\_SYSCALL

**URL:** <https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722>\
**Category:** Kernel\
**Created:** [May 31, 2021, 8:53am UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722 "2021-05-31T08:53:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrajNandan](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@BrajNandan](https://forums.freertos.org/u/BrajNandan)\
**Post date:** [May 31, 2021, 8:53am UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/1 "2021-05-31T08:53:20Z")

</div>

Hi,

I am working with cortex-m4, Please let me know what will be the effects if the scheduler is working in SysTick interrupt (priority 0 Highest) and configMAX\_SYSCALL\_INTERRUPT\_PRIORITY is set to 5.

I have doubt as I have read “full interrupt nesting model is achieved by setting configMAX\_SYSCALL\_INTERRUPT\_PRIORITY above (that is, at a higher priority level) than configKERNEL\_INTERRUPT\_PRIORITY. **This means the FreeRTOS kernel does not completely disable interrupts, even inside critical sections.** ”

We do not have configKERNEL\_INTERRUPT\_PRIORITY but still scheduler in running on higher priority then configMAX\_SYSCALL\_INTERRUPT\_PRIORITY. Please guide.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [May 31, 2021, 8:59am UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/2 "2021-05-31T08:59:38Z")

</div>

Hi there,

what is unclear about the documentation?

Your service interrupt handler MUST POSITIVELY run on the LOWEST interrupt priority as it may only interrupt tasks, not other ISRs.

Every ISR that does use OS services (trivially including the sys tick handler) MUST POSITIVELY execute LOWER than configMAX\_SYSCALL\_INTERRUPT\_PRIORITY.

If you don’t follow those guidelines, you risk all kinds of random crashes and other unpredictable phenomena.

As for the numbering of Cortex priorities, I think that this has been discussed so frequently here that we don’t need to discuss it again.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [May 31, 2021, 9:45am UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/3 "2021-05-31T09:45:04Z")

</div>

As mentioned by @RAc there are many posts here in the forum regarding interrupt priorities especially related to wide spread Cortex-M MCUs.  
Search for `configMAX_SYSCALL_INTERRUPT_PRIORITY` and/or `configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY`.

However, did you already read the FreeRTOS docs (in case you’re using a Cortex-M MCU as I suppose) [RTOS for ARM Cortex-M](https://www.freertos.org/RTOS-Cortex-M3-M4.html) ?  
IMO this post [Understanding priority levels of ISR and FreeRTOS APIs - #16 by aggarg](https://forums.freertos.org/t/understanding-priority-levels-of-isr-and-freertos-apis/10453/16) contains a good and easy to understand explanation. There are more…

BTW: You should always include the MCU or the processor core and the FreeRTOS version you are using when asking for help.

---

<div class="post-metadata">

**Author:** ![BrajNandan](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@BrajNandan](https://forums.freertos.org/u/BrajNandan)\
**Post date:** [May 31, 2021, 1:29pm UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/4 "2021-05-31T13:29:39Z")

</div>

Hi sir,

Thanks for the prompt reply.

I am using Renesas MCU R7FA6M3AF3CFB and core cortex-m4 with FreeRTOS version 10.3.0

> [@RAc](#):
>
> what is unclear about the documentation?

numbering of Cortex priorities is clear to me.

We got the FreeRTOS port from Renesas and the scheduler is running in SysTick interrupt and its priority in -1 which is higher then configMAX\_SYSCALL\_INTERRUPT\_PRIORITY. That’s why i got confused.

Now As i understand we need to call the scheduler from the lowest interrupt.

As per the quote

> [@BrajNandan](#):
>
> **This means the FreeRTOS kernel does not completely disable interrupts, even inside critical sections.** ”

I still have one more doubt As in our current port we are using PendSV\_Handler for context switch do we need to change it too? As PendSV\_Handler is a higher priority interrupt.

As I can Recall in STMController port too we use PendSV\_Handler.

Thanks again.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [May 31, 2021, 1:44pm UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/6 "2021-05-31T13:44:51Z")

</div>

> [@BrajNandan](#):
>
> We got the FreeRTOS port from Renesas and the scheduler is running in SysTick interrupt and its priority in -1 which is higher then configMAX\_SYSCALL\_INTERRUPT\_PRIORITY. That’s why i got confused.

Please show some source.

---

<div class="post-metadata">

**Author:** ![BrajNandan](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@BrajNandan](https://forums.freertos.org/u/BrajNandan)\
**Post date:** [May 31, 2021, 2:03pm UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/7 "2021-05-31T14:03:47Z")

</div>

let me re-phrase my doubt,

My current system architecture.

```
        Logical Numerical
       Priorities Priorities
       +--------+ +-------+ ^
	   | | | | |
       | | | | |
       | | | | <---------------- PendSV Priority
       | | | | |
       | | | | <---------------- SysTick Priority 
       | | | | |		   
       | | | | |
       | | | | | Not masked by FreeRTOS kernel
       | Higher | | Lower | | ( FreeRTOS APIs can not be
       | | | | | called from these ISRs. )
       | | | | |
	   | | | | |
       | | | | |
       | | | | v
       +--------+ +-------+ <---------------- configMAX_SYSCALL_INTERRUPT_PRIORITY
       | | | | ^
       | | | | |
       | | | | |
       | | | | |
       | Lower | |Higher | | Masked by FreeRTOS Kernel
       | | | | | ( FreeRTOS APIs can be
       | | | | | called from these ISRs. ) 
       | | | | |
       | | | | |
       | | | | |
       | | | | |
       +--------+ +-------+ v

```

In the SysTick Handler scheduler is being called.

```
/* Increment the RTOS tick. */
if (xTaskIncrementTick() != pdFALSE)
{
    /* A context switch is required. Context switching is performed in
     * the PendSV interrupt. Pend the PendSV interrupt. */
    SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
}

```

And PendSV interrupt is being used for the context switch.

**As I have understood I need to call the scheduler from the lowest interrupt.**

**Do I also need to change anything regarding Context switch as it is being called from logical higher Interrupt i.e. PendSV Hendler?**

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [May 31, 2021, 2:16pm UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/8 "2021-05-31T14:16:01Z")

</div>

> [@BrajNandan](#):
>
> And PendSV interrupt is being used for the context switch.

Oh I see, that’s your fallacy…

The ISR is not being CALLED at that point, just SCHEDULED (marked pending on the MCU level). As soon as no higher pri ISR is running (which means no sooner than the sys tick isr has terminated, but possibly even later if other ISRs cut in in the mean time), the pending service ISR is invoked. That’s the beauty of it!

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [May 31, 2021, 2:16pm UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/9 "2021-05-31T14:16:57Z")

</div>

`PendSV` and `SysTick` interrupt priorities are different to the FreeRTOS default if really configured this way.  
FreeRTOS uses `configKERNEL_INTERRUPT_PRIORITY` for them, which is the lowest interrupt priority. I can’t imagine why Renesas should have changed that.  
There are very good reasons setting them to the lowest interrupt priority e.g.

**configKERNEL\_INTERRUPT\_PRIORITY is set to the _lowest_ urgency interrupt level in the system.** So this means the interrupts of the kernel (SysTick and context switches) run with the lowest possible urgency. This makes sense as the kernel should not block or interrupt the other interrupts in the system.

---

<div class="post-metadata">

**Author:** ![BrajNandan](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@BrajNandan](https://forums.freertos.org/u/BrajNandan)\
**Post date:** [May 31, 2021, 2:27pm UTC](https://forums.freertos.org/t/scheduler-priority-in-higher-then-max-syscall/12722/10 "2021-05-31T14:27:23Z")

</div>

Thanks a lot. I will change the scheduler interrupt and check the PendSV functionality.
