1

I have read here about situations where a scheduler is called. But what happens when a high priority task comes?

Community
  • 1
  • 1
user567879
  • 5,139
  • 20
  • 71
  • 105
  • 1
    High priority tasks are scheduled more often than low priority tasks but when a high priority task comes it still has to wait until the [quantum](http://en.wikipedia.org/wiki/Preemption_(computing)#Time_slice) of the running task is over. Edit: posted as an anwser – Ben Aug 26 '13 at 17:20

3 Answers3

1

High priority tasks are scheduled more often than low priority tasks but when a high priority task comes it still has to wait until the quantum of the running task is over.

Ben
  • 7,372
  • 8
  • 38
  • 46
0

Priority changes and is adjusted based on past CPU usage.

The longer version

In Linux, process priority is dynamic. The scheduler keeps track of what processes are doing and adjusts their priorities periodically; in this way, processes that have been denied the use of the CPU for a long time interval are boosted by dynamically increasing their priority. Correspondingly, processes running for a long time are penalized by decreasing their priority.

sealz
  • 5,348
  • 5
  • 40
  • 70
0

Scheduler maintains a set of all tasks that are ready to run in the system. In a multi-priority system, the task set usually supports the notion of priority. When a high priority task arrives in the system, it is put into the set of tasks sorted by priority.

There are certain points in the kernel where we check if a better process is available to run, compared to the currently running process. This can happen when the time slice expires OR when the ISR is done OR when a lock is unlocked, etc. Look for calls to switch() OR _switch() or something similar...this is the routine that checks the set of tasks and determines if the current task is the highest prio.

If the current task is not the highest prio task, then the current task is switched out and the highest prio task is obtained from the task set and scheduled to run.

lsk
  • 532
  • 4
  • 5