Top Banner

of 22

CPU Scheduling Algorithm

Feb 24, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/25/2019 CPU Scheduling Algorithm

    1/22

    Schedulin

    g

    Algorithm

    s1Group No. 2

  • 7/25/2019 CPU Scheduling Algorithm

    2/22

    Overview

    Basic Concepts

    Scheduling Criteria

    Scheduling Algorithms

    Implementation in C++

    Demonstration

    Involvement of Operating System

    2CPU Scheduling Algorithms

  • 7/25/2019 CPU Scheduling Algorithm

    3/22

    CPU Scheduling Algorithms 3

    Basic Concepts

    Main objective of multiprogramming is toeep on running processes all the time forma!imum C"# utili$ation%

    Scheduling is fundamental function of OS%

    &he tas of selecting the processes inmemory that are ready to e!ecute' andallocating them to the C"# is performedby the C"# Scheduler%

  • 7/25/2019 CPU Scheduling Algorithm

    4/22

    4

    CPU Scheduler

    C"# scheduling decisions may taeplace (hen a process)o *% S(itches from running to (aiting

    stateo % S(itches from running to ready

    stateo ,% S(itches from (aiting to readyo -% &erminates

    Scheduling under * and - is nonpreemptive%

    All other scheduling is preemptive%

    CPU Scheduling Algorithms

  • 7/25/2019 CPU Scheduling Algorithm

    5/22

    5

    .onpreemptive

    Once a process is allocated the C"#' itdoes not leave unless)o it has to (ait' e%g%' for I/O re0uesto it terminates

    "reemptiveo OS can force 2preempt3 a process

    from C"# at anytimeo 4%g%' to allocate C"# to another

    higher5priority process

    CONT

    CPU Scheduling Algorithms

    CPU Scheduler

  • 7/25/2019 CPU Scheduling Algorithm

    6/22

    6

    Scheduling Criteria

    C"# utili$ation)eep the C"# as busyas possible

    Ma!imi$e&hroughput) .o of processes that

    complete their e!ecution per time unit

    Ma!imi$e&urnaround time) amount of time to

    e!ecute a particular process 2timefrom submission to termination3

    Minimi$e

    CPU Scheduling Algorithms

  • 7/25/2019 CPU Scheduling Algorithm

    7/227

    CONT

    CPU Scheduling Algorithms

    6aiting time)amount of time a processhas been (aiting in the ready 0ueue2sum of time (aiting in ready 0ueue3o Minimi$e

    7esponse time 8 amount of time ittaes from (hen a re0uest (assubmitted until the 9rst response is

    produced' not output 2for time5sharing environment3o Minimi$e

    Scheduling Criteria

  • 7/25/2019 CPU Scheduling Algorithm

    8/22

    Scheduling Algorithms

    :irst Come' :irst Served

    Shortest ;ob :irst

    "riority

    7ound 7obin

    CPU Scheduling Algorithms

  • 7/25/2019 CPU Scheduling Algorithm

    9/22!CPU Scheduling Algorithms

    Implementation in C++

    Class)cpuschedule

    Attributes)o n 8 number of processeso Bu< = 8 Array to store Burst

    &imeo A< = 8 Array to store Arrival

    &imeo 6t< = 8 Array to store 6aiting

    &imeo &(t 8 &otal 6aiting &imeo A(t 8 Average 6aiting &ime

  • 7/25/2019 CPU Scheduling Algorithm

    10/221"CPU Scheduling Algorithms

    Implementation in C++

    o >etdata23 8 &o get number ofprocesses and Burst &imes fromthe user

    o

    :cfs23 8 :irst Come' :irst ServedAlgorithm

    o Sjf23 8 Shortest ;ob :irst2normal3 Algorithm

    o

    Sjf"23 8 Shortest ;ob :irst2"reemption3 Algorithm

    o Sjf.p23 8 Shortest ;ob :irst 2nonpreemption3 Algorithm

    o

    "riority23 8 "riority Algorithm

    CONT

    Operations)

  • 7/25/2019 CPU Scheduling Algorithm

    11/2211

    "rocess Burst &ime

    P1 -

    P2 ,

    P3 ,

    Suppose that the processes arrive in theorder)

    P1'P2'P3

    &he >antt Chart for the schedule is)

    6aiting time forP1 ? @P2 ? -P3 ?

    Average (aiting time) 2@ + - + 3/, ? *CPU Scheduling Algorithms

    irst Come! irstServed

    P1

    P2

    P3

    24 27 3""

  • 7/25/2019 CPU Scheduling Algorithm

    12/2212

    Suppose that the processes arrive in theorder )

    P2'P3'P12P1:-'P2:,'P3:,3

    &he >antt chart for the schedule is)

    6aiting time forP1=;P2? @;P3= ,

    Average (aiting time) 2 + @ + ,3/, ? ,

    Much better than previous case

    Convoy eect 5 short process behind long

    process

    CONT

    CPU Scheduling Algorithms

    irst Come irstServed

    P1

    P3

    P2

    63 3""

  • 7/25/2019 CPU Scheduling Algorithm

    13/2213CPU Scheduling Algorithms

    Shortest "o# irst

    .ormal S;:

    "rocess Burst &ime

    P1

    P2 , P3 -

    &he >antt Chart for S;: 2.ormal3 is)

    Average (aiting time ? 2@ + , + 3/, ?,%,,

    P2

    P3 P1

    730 14

  • 7/25/2019 CPU Scheduling Algorithm

    14/22

    14

    "rocess Arrival &ime Burst &ime

    P1 @%@

    P2 %@ -P3 -%@ *

    P4 E%@ -

    &he >antt Chart for S;: 2non5preemptive3is)

    Avera e (aitin time ? @ + + , + -

    .on5"reemptive S;:

    CPU Scheduling Algorithms

    Shortest "o# irstCONT

    P1

    P3

    P2

    72 160

    P4

    8 124 5

  • 7/25/2019 CPU Scheduling Algorithm

    15/22

    15

    CONT

    "rocess Arrival &ime Burst &imeP1 @%@ P2 %@ -P3 -%@ *P4 E%@ -

    &he >antt Chart for S;: 2preemptive3 is)

    Average (aiting time ? 2F + * + @ +3/- ? ,

    P1 P3P2

    42 11"

    P4

    5 7

    P2 P1

    16

    CPU Scheduling Algorithms

    "reemptive S;:

    Shortest "o# irst

  • 7/25/2019 CPU Scheduling Algorithm

    16/22

    Associate (ith each process the length ofits ne!t C"# burst%

    #se these lengths to schedule the process(ith the shortest time%

    &(o schemes)o .on5"reemptive) once C"# given to the

    process it cannot be preempted untilcompletes its C"# burst%

    o "reemptive) if a ne( process arrives (ithC"# burst length less than remaining

    time of current e!ecuting process'preempt% &his scheme is no( as theShortest57emaining5&ime5:irst 2S7&:3%

    S;: is optimal) gives minimum average(aiting time for a given set of processes%

    Shortest "o# irstCONT

    CPU Scheduling Algorithms 16

  • 7/25/2019 CPU Scheduling Algorithm

    17/22

    17CPU Scheduling Algorithms

    Priorit$

    "rocess Burst &ime "riority P1 *@ , P2 * * P3 -

    P4 * E P5 E

    >antt Chart

    Average (aiting time ? 2 + @ + * + *G +

    *3/E ? G%

    P2 P1P5

    61 16"

    P3

    1

    P4

    1!

  • 7/25/2019 CPU Scheduling Algorithm

    18/22

    A priority number 2integer3 is associated(ith each process%Hager the C"# burst lo(er the priority%&he C"# is allocated to the process (ith

    the highest priority 2smallest integer

    highest priority3Starvation 2In9nity blocing3) lo(

    priority processes may never e!ecute%Aging) as time progresses increase the

    priority of the process%

    Priorit$CONT

    CPU Scheduling Algorithms 1

  • 7/25/2019 CPU Scheduling Algorithm

    19/22

    1!CPU Scheduling Algorithms

    %ound %o#in

    "rocess Burst &imeP1 -

    P2 ,

    P3 ,

    uantum time ? - milliseconds&he >antt chart is)

    Average (aiting time ? J

  • 7/25/2019 CPU Scheduling Algorithm

    20/22

    &ypically' higher average turnaroundthan S;:' but better response

    4ach process gets a small unit of C"#time 2time 0uantum3' usually *@5*@@milliseconds% After this time haselapsed' the process is preempted andadded to the end of the ready 0ueue%

    "erformance

    o0 large :C:S

    o0 small 0 must be large (ithrespect to conte!t s(itch' other(iseoverhead is too high

    CPU Scheduling Algorithms 2"

    %ound %o#inCONT

  • 7/25/2019 CPU Scheduling Algorithm

    21/22

    CPU Scheduling Algorithms 21

    Involvement o& OSSource Code '(c)

    Conversion

    *ecuta#le '(ee)

    Compiler

    ,icroso&t-indows

    ,icro./ernel

    '(i ! (o)

    ,emor$

    CPU

    'load eecuta#ledirectl$ to memor$)

    *ecut

    e

    SchedulingAlgorithms

  • 7/25/2019 CPU Scheduling Algorithm

    22/22

    Scheduling

    Algorithm

    sGroup No 2 22

    0roup No(1