Keen Learner
Keen Learner

Reputation: 195

Kernel preemption on same priority tasks

Can someone help me understand with clear explantion or any reference link, How kernel handles preemption on tasks having same priority. Suppose i have three TASKS A, B and C assigned with High priority

TASK(A) { High Priority Reading Asynchronous messages }

TASK(B) { High Priority Sending Asynchronous messages }

TASK(C) { High Priority Draw process }

In this case which Task will be considered for processing and how is it preempted?

Upvotes: 0

Views: 1215

Answers (1)

Oleksii Shmalko
Oleksii Shmalko

Reputation: 3768

General scheduling order is

  1. Kernel invokes function schedule() either directly in kernel context or when TIF_NEED_RESCHED flag is set and kernel returning from interrupt context.
  2. This function invokes pick_next_task() to receive the task, which will preempt currently running one.
  3. pick_next_task() invokes every scheduler class' pick_next_task() in order of descending priority until one of them returns task. Note, that priority means class' priority (e.g. soft real-time or normal), not process' one.
  4. The CFS's approach (scheduler for normal processes) is to give each process an equal amount of virtual run-time. Virtual run-time is a process' real run-time weighted with its priority (process' priority). So CFS class returns task with lesser virtual runtime.

For scheduler, there is no matter what process are doing, what massages it sends or receives. So, in general case, if your processes have equal priorities, process with less run-time will preempt another process on the next schedule() invokation.

Upvotes: 2

Related Questions