Preemptive Scheduling and Task Priorities

| 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?

Preemptive Scheduling and Task Priorities

Anybody?

Preemptive Scheduling and Task Priorities

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.


Preemptive Scheduling and Task Priorities

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.

Preemptive Scheduling and Task Priorities

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

Preemptive Scheduling and Task Priorities

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.