Re: Two questions about scheduler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sunday 22. March 2009 11.44.13 Peter Chen wrote:
> Dear all,
>
> Recently, I have read the book <<Understanding the Linux Kernel>>
>
> And I have two points not clearly about scheduler, hope someone here can
> help me. Thank you in advance.

Note: UTLK describes the O(1) scheduler. From 2.6.23 the CFS has replaced the 
O(1) and how priorities are represented and how next tasks are found has 
changed. The basics are the same though. If another task has higher priority

See http://lxr.linux.no/linux+v2.6.28.8/Documentation/scheduler/sched-design-
CFS.txt for an intro to CFS.

>
> 1. At book, there are below formula:
> base time quantum = (140-static priority)*20  if static priority < 120
>                     (140-static priority)*20  if static priority >=120
>
> it is for i386/686, and this value should be HZ related. But I can't
> find related code at sched.c, can anyone point it to me?

HZ is defined when you configure the kernel. See a .config. It can be 100, 250, 
300 and 1000.


> 2. For the preemptive kernel, I know below situation may will happen
> preempt implicitly(if i am error, please point out), are there any
> situation will happen preempt?

Basially the kernel will preempt curr if there are one or more other ready 
tasks with higher priority. This can be done either implicitly as you say, or 
explicitly (by the function calling schedule() itself).

> 1. The situation for each timer interrupt occurs:
> 	i: If process time quantum expires, it will be replaced
>         ii: If process A(who owns CPU)'s priority is lower than process
> B who is also at running queue. The process A will be replaced for
> process B.
> 2. At IRQ handler, it wakes up process B. then, after IRQ exiting, the
> higher priority process B will preempt process A who is interrupted by
> above IRQ.

Actually, most likely, the IRQ will set TIF_NEED_RESCHED.


Whenever the kernel returns from kernel-mode to user-mode, it will test curr 
for TIF_NEED_RESCHED (the need reschedule flag). If this is set, it will invoke 
schedule(), and the kernel will change curr with a new task.

henrik

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux