Topics

Does ISR cause a preemptible thread to be swapped out


George Kumar
 

Hi,

In Zephyr scheduling, after an ISR is done, can a preemptible thread be swapped out, and a higher priority thread, if ready, is allowed to run?

I understand the behaviour for the cooperative threads, but now sure if after an ISR a context switch can happen for preemptible threads.

Thanks.
George


Jett ✈ Rink
 

Hey George,

When coming back from an ISR, Zephyr should switch to the highest priority thread that is ready (with some caveats around multiple cooperative threads being ready). At least that is what I see from looking around in sched.c.

Also as a thought experiment, let's say that an ISR did come back to the same preemptible thread (not true). The first thing that would happen is that thread would get preempted by the higher priority thread that is now ready, so the original, lower priority, preemptible thread wouldn't be able to execute anything meaningful before it got preempted anyway.

-Jett



On Wed, Sep 9, 2020 at 2:23 PM George Kumar <grgkumar4@...> wrote:
Hi,

In Zephyr scheduling, after an ISR is done, can a preemptible thread be swapped out, and a higher priority thread, if ready, is allowed to run?

I understand the behaviour for the cooperative threads, but now sure if after an ISR a context switch can happen for preemptible threads.

Thanks.
George


Boie, Andrew P
 

Hi George,

 

  • In Zephyr scheduling, after an ISR is done, can a preemptible thread be swapped out, and a higher priority thread, if ready, is allowed to run?

 

Yes this is guaranteed. There should always be a scheduler hook when coming out of a non-nested peripheral interrupt and if any higher priority thread(s) are runnable, the kernel will context switch to the highest one if the current thread is preemptible.  Feel free to file a bug if you are not seeing this to be the case.

 

HTH,

Andrew


George Kumar
 

Thanks Andrew P. Yes this is the behaviour I am observing. So I guess everything is as expected.

Thanks to all for responding.
George


On Wed, Sep 9, 2020 at 3:08 PM Boie, Andrew P <andrew.p.boie@...> wrote:

Hi George,

 

  • In Zephyr scheduling, after an ISR is done, can a preemptible thread be swapped out, and a higher priority thread, if ready, is allowed to run?

 

Yes this is guaranteed. There should always be a scheduler hook when coming out of a non-nested peripheral interrupt and if any higher priority thread(s) are runnable, the kernel will context switch to the highest one if the current thread is preemptible.  Feel free to file a bug if you are not seeing this to be the case.

 

HTH,

Andrew