This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

When does RTX (re)evaluate which thread to run next?

Hi,
a hopefully simple example to explain the background of my question.

Say, an interrupt handler is interrupting a thread "some_thread_id_A" and looks as follows:

SomeIRQHandler(void)

{

... some code that handles the source of the event

// trigger an event for an RTX-operated thread

osSignalSet(some_thread_id_B, SOME_EVENT);

}


Now, let's further assume that the thread "some_thread_id_B"

- is suspended on SOME_EVENT before the above interrupt happens.

- is the highest prio thread in the application code


After the above interrupt, the event has obviously happened and some_thread_id_B would no longer be suspended.


Now, here's the question:

When does RTX evaluate the thread priorities and the events? When does it figure out that some_thread_id_B is now ready to run? Right after the interrupt handler returns? Or at the time tick?

To be even more specific: Will SomeIRQHandler() return to thread "some_thread_id_A" (no longer being the highest prio ready-to-run thread after the event) or will it return to thread "some_thread_id_b"?


I'm running RTX on a Cortex M0.

Thx


P.S: You might remember that this question has been asked by me in the old ARM discussions Forums, but I asked this Forum's admins, they told me that it has not been migrated and that I should ask the question again.

Parents
  • Hi,

    In ARM Cortex-M-based devices the RTX task manager handles the scheduling of tasks and runs when the system timer tick interrupt occurs or when an interrupt calls one of the isr_functions. For example interrupts can generate event, semaphore or mailbox messages (using an isr_ library function) that signal a higher priority task that is waiting for the message. The higher priority task must preempt the current task, but can do so only after the interrupt function completes. The interrupt therefore forces the timer tick interrupt, which runs when the current interrupt finishes. The forced tick timer interrupt starts the task manager (clock task) scheduler. The task scheduler process all the tasks and then puts the highest ready task into the running state. The highest priority task can then continue with its execution.


    The RTX System Task Manager section on the keil.com site goes into much more detail and explains how this fits in with the different scheduling options of RTX (Pre-emptive scheduling, Round-Robin scheduling, Co-operative multi-tasking).


    I hope that helps!


    Thanks,

    Ken

Reply
  • Hi,

    In ARM Cortex-M-based devices the RTX task manager handles the scheduling of tasks and runs when the system timer tick interrupt occurs or when an interrupt calls one of the isr_functions. For example interrupts can generate event, semaphore or mailbox messages (using an isr_ library function) that signal a higher priority task that is waiting for the message. The higher priority task must preempt the current task, but can do so only after the interrupt function completes. The interrupt therefore forces the timer tick interrupt, which runs when the current interrupt finishes. The forced tick timer interrupt starts the task manager (clock task) scheduler. The task scheduler process all the tasks and then puts the highest ready task into the running state. The highest priority task can then continue with its execution.


    The RTX System Task Manager section on the keil.com site goes into much more detail and explains how this fits in with the different scheduling options of RTX (Pre-emptive scheduling, Round-Robin scheduling, Co-operative multi-tasking).


    I hope that helps!


    Thanks,

    Ken

Children
  • Hi, Ken

    thanks for answer - let me just confirm that I got what you are saying, using my example:

    If I call "osSignalSet()" from an ISR, it will call "isrSignalSet()" (down the path). Once this call is completed (through all the involved subroutines etc.), RTX will enter its scheduler, decide what is the next READY thread and return to this READY thread. This thread is not necessarily the thread which was executed when the ISR came up. Correct?

    Thx
    Arndt

  • Hi arndt,

    You understand it correctly and just to emphasize it is good practice to keep the interrupt service routine (ISR) as short as possible. By passing messages to tasks to handle the heavy lifting of the application this can help keep the ISR small.

    I hope this helps and if this answers the question please mark it as answered.

    Thanks,
    Ken

  • Does this also apply if I use a peripheral timer (e.g. RITIMER) as the system tick timer for RTX?

    Thanks,

    Chiong