[Ilugc] KERNEL / DISTRO / DESKTOP / APPLICATION interdependency?

  • From: anand.kumar@xxxxxxxxxx (Anand Kumar Saha)
  • Date: Wed Sep 1 21:55:35 2004



  | How does the kernel know which process' window has focus 
  | and give it an
  | interactivity boost?  Isn't this behaviour just a xine quirk?
  | 
  | I would not want my compiles to get lower priority when my 
  | window focus
  | is on mutt :-P
  `--------

The kernel knows many tricks :)  The kernel divide tasks into 
two categories  - 

1. Processor bound
2. I/O bound

Processor bound tasks spend most of their time slice executing 
code, while I/O bound tasks spend most of their time waiting 
for I/O, interrupts etc.

The interractive tasks (games, editors etc. ) are all I/O bound 
tasks while gcc is an example of a processor bound task.

To give a 'feel' of interractivity to the user, the kernel gives 
higher dynamic priority to the I/O bound tasks (interractive tasks) 
than Processor bound tasks.

The billion dollar question is - how does the kernel know which 
task is what bound ? Simple - the kernel 'observes' the tasks. 
Each task starts with a default dynamic priority of 0 (ranging 
from -20 to 19, -20 being the highest priority [1]). If the kernel 
observes that the task is using up all the time slice allocated 
to it, in executing code, and not sleeping, waiting for I/O, 
kernel knows that this is a processor bound task, and marks it
so. 

On the otherhand, if a task spends most of its time sleeping, 
waiting for some interrupt or data, it is marked as I/O bound 
task. These are given higher dynamic priority.

So when you click on a window, the mouse interrupt handler is
executed on behalf of the window manager (which the kernel must
have observed to be a I/O bound task :)  ), and hence gave it a 
higher priority. The window is highlighted immediately to give 
you a feel of high interractivity.

[1] makes you remember the 'nice' command ?   

saha
--






Other related posts: