Preemptive Scheduling and Task Priorities

dnewby wrote on Tuesday, February 07, 2017:

TaskName Priority State
TaskL1 1 RUN
TaskL2 1 RDY
TaskH1 2 BLOCKED

I am seeing the following behavior:

TaskH1 becomes ready.
TaskL1 is preempted and sent to the back of the Priority 1 Task Queue.
TaskH1 completes processing and blocks.
TaskL2 is set to RUN.

TaskH1 becomes ready.
TaskL2 is preempted and sent to the back of the Priority 1 Task Queue.
TaskH1 completes processing and blocks.
TaskL1 is set to RUN.

So, in effect, if we have the higher priority task running at a specific interval, and two lower (shared) priority tasks that are both ready to run, every time we switch to the high priority task, the lower priority tasks will swap RUN/RDY after the high priority task completes.

The desired functionality is that if the lower priority task is preempted, it will regain control of the processor after the higher priority task completes, whereas if it relinquishes control of the processor voluntarily, then tasks with the same priority will be able to run.

The current functionality is that it will not regain immediate control of the processor if it is forcibly preempted.

Is there configuration options available to get the desired functionality?

dnewby wrote on Friday, February 10, 2017:

Anybody?

rtel wrote on Friday, February 10, 2017:

I have answered this already but the reply does not seem to have shown up. I will answer again when I'm at my computer.


rtel wrote on Friday, February 10, 2017:

The behaviour you describe is that intended. Tasks of equal priority are scheduled in a round robin fashion, so the task that has been waiting the longest is the task that is scheduled next. You can turn time slicing off, but that won’t change the behaviour you are describing, it will just prevent a switch between equal priority tasks on a tick interrupt. What is desired by one application writer is not necessarily by another. The code that selects the next task to run is designed to be as small as possible, there are all sorts of alternative, but they would all take extra time to execute.

dnewby wrote on Friday, February 10, 2017:

I’m having trouble finding the code that actually puts the current task back in the ready queue when this occurs. Any hints?

rtel wrote on Friday, February 10, 2017:

The task never leaves the ready list - hence you can’t find the code
that puts it back in :o) The pxCurrentTCB point just points to it
within the ready list.