Docsity

Process and Thread Scheduling - Notes | Rel Std 5, Study notes of Anthropology of religion

Partial preview of the text

Download Process and Thread Scheduling - Notes | Rel Std 5 and more Study notes Anthropology of religion in PDF only on Docsity!

5. Process and thread scheduling5.1 Organization of Schedulers

Embedded and Autonomous Schedulers

Embedded and Autonomous Schedulers

Priority Scheduling

5 2 Scheduling Methods5.2 Scheduling Methods

A Framework for Scheduling

Common Scheduling Algorithms

g

g

Comparison of Methods

5.3 Priority Inversion

y

5.4 Multiprocessor and Distributed SchedulingCompSci 143A

Spring, 2009

Process and Thread Scheduling

  • Process scheduling

L

h d li

  • Long term scheduling– Move process to

Ready List (RL)

after creation

(Wh

d i

hi h

d

(When and in which order?)

  • Dispatching
    • Short term scheduling– Select process from Ready List to run
      • We use the term

scheduling

to refer to both

CompSci 143A

Spring, 2009

Priority Scheduling

  • Priority function returns numerical value

P

for process

:^

P

P i

it ( )

for

process

p

:^

P

= Priority(p)

  • Static priority: unchanged for lifetime of

p

i^

i^

i^

h

i

Dynamic priority: changes at runtime

  • Priority divides processes into levels
    • implemented as multi-level Run List–

p

at RL[

i ] run before

q

at RL[

j ] if

i>j

p

,^

q

at same level are ordered by other criteria

CompSci 143A

Spring, 2009

An Embedded Scheduler

Scheduler(){

d

{ do {

Find highest priority process p with p.status ==

ready_a

;

Find a free cpu;if (cpu != NIL) Allocate_CPU(p,cpu); } while (cpu != NIL);do {

Find highest priority process p with p.status ==

ready_a

;

Find lowest priority process q with p.status ==

running

;

if (Priority(p) > Priority(q)) Preempt(p,q); } while (Priority(p) > Priority(q));if (self->Status.Type!=’running’) Preempt(p,self); } CompSci 143A }

Spring, 2009

Priority function Parameters

  • Possible parameters:

A

i^

d

i^

i^

  • Attained service time (

a

  • Real time in system (

r )

  • Total service time (

t )

  • Period (

d

  • Deadline (explicit or implied by period)– External priority (

e

  • Memory requirements (mostly for batch)– System load (not process-specific)

CompSci 143A

Spring, 2009

Some Priority functions

  • First in/First out (FIFO)• Shortest Job First (SJF)• Shortest Remaining Time (SRT)• Round Robin (RR)• Multi-Level (ML)

Multi-Level (ML)

CompSci 143A

Spring, 2009

MLF (Multilevel Feedback)

-^

Like ML, but prioritychanges dynamically

g

y

y

-^

E

very process enters at highest level

n

-^

Each level P prescribesmaximum time

t

P

-^

tP

increases as P decreases tP

increases as P decreases

-^

Typically:

t^ n

= T

(a constant)

t^ P

= 2

×^

t^ P+

CompSci 143A

Figure 5-

Spring, 2009

Scheduling algorithms

MLF priority function:

Find

P

i^

for gi en

Find

P

= n–i

for

given

a

priority

attained time

n

a<T

n–

a<T+2T

n–

a<T+2T+4T

... ...

n–i

a<(

i+

–1)T

•^

Find smallest

i

such that

a<(

i+

–1)T

(^

•^

Solve for

i

:^

i =

log

(a/T+1) 2

•^

P

= n–i = n–

log

(a/T+1) 2

CompSci 143A

P

n i

n

⎣ log

(a/T 1) 2

Spring, 2009

Comparison of Methods

•^

FIFO, SJF, SRT: Primarily for batch systems– FIFO simplest

FIFO simplest

  • SJF & SRT have better average turnaround times:

(r1+r2+…+rn)/n

Average turnaround times:Average

turnaround times:

FIFO: ((0+5) + (3+2))/2 = 5.0SRT: ((2+5) + (0+2))/ SRT: ((2+5) + (0+2))/2 = 4.

Figure 5-

CompSci 143A

13

Spring, 2009

Comparison of Methods

  • Time-sharing systems

Response time is critical

  • Response time is critical– RR or MLF with RR within each queue are

suitablesuitable

  • Choice of quantum determines overhead
    • When q

RR approaches FIFO

  • When q

, RR approaches FIFO

  • When q

0, context switch overhead

Wh

i^

h

t^

th

t^

t^

it h

  • When q is much greater than context switch

overhead, n processes run concurrently at 1/nCPU speed

CompSci 143A

CPU speed

Spring, 2009

Example where RM fails

  • Process

p

has service time 1.5, period 4

  • Process

p

has service time 3, period 5

  • U=(1.5/4) +3/5=.975 < 1• RM fails

Figure 5-

CompSci 143A

Spring, 2009

Priority Inversion Problem

Fi Figure 5-

-^

Assume priority order

p1>p2>p

-^

p

enters CS

;^ p

preempts

p

;^ p

preempts

p

;^

p

blocks on CS

-^

p

enters

CS;

p

preempts

p

;^ p

preempts

p

;^

p

blocks on CS

-^

Effect: process

p

,^ unrelated to

p

and of lower priority

, may

delay

p

1

indefinitely.

y^

p^

y

-^

Note: problem is not simply that

p

blocks. This is unavoidable.

The problem is that

p

is waiting on

p

.

CompSci 143A

17

-^

Problem would not occur if

p

in CS had priority greater than

p

Spring, 2009

Priority Inversion Problem

Dynamic Priority Inheritance:

Wh

i

i^

i^

CS

d

i

•^

When

p

is in its CS and

p

attempts to enter its

CS…

i h

it

’^

(hi h

)^

i^

it

f^

th

d

ti

p

inherits

p

’s (higher) priority for the duration

of CS

Figure 5-

CompSci 143A

Spring, 2009

Multiprocessor and Distributed Scheduling• Two Principle approaches

Single Scheduler

Single

Scheduler

  • All processors are in the same resource pool• Any process can be allocated to any processor

M

ultiple Schedulers • Processors are divided into sets of separately schedulemachines, each with its own scheduler

,

  • Each process is permanently preallocated to a particular

group

  • Useful when different processors have different

Useful when different processors have differentcharacteristics and functions

  • Key problem:

load balancing

CompSci 143A

  • Evenly distributing load over multiple machines

Spring, 2009