cpu scheduling by furqan

Upload: musaab-qamar

Post on 05-Apr-2018

223 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/31/2019 CPU Scheduling by Furqan

    1/34

  • 7/31/2019 CPU Scheduling by Furqan

    2/34

    CPU Scheduling

    Presented by:

    Muhammad Ameen

    Muhammad Furqan

  • 7/31/2019 CPU Scheduling by Furqan

    3/34

  • 7/31/2019 CPU Scheduling by Furqan

    4/34

    Why CPU Scheduling Is Required?

    The objective of multiprogramming is tohave some process running at all timesto maximize CPU utilization.

    Almost all computer resources arescheduled before used.

  • 7/31/2019 CPU Scheduling by Furqan

    5/34

    CPU and I/O Burst Cycle

    The execution of a process consists of acycle of CPU and I/O wait.

    A process begins with a CPU burst , followed byan I/O burst , followed by another CPU burst andso on. The last CPU burst will end will a systemrequest to terminate the execution.

    The CPU burst durations vary from process

    to process and computer to computer.An I /O bound program has many very short CPUbursts.A CPU bound program might have a few very

    long CPU bursts.

  • 7/31/2019 CPU Scheduling by Furqan

    6/34

  • 7/31/2019 CPU Scheduling by Furqan

    7/34

  • 7/31/2019 CPU Scheduling by Furqan

    8/34

    CPU Scheduler

    Whenever, the CPU becomes idle, the OSmust select one of the processes in theready-queue to be executed.The selection process is carried out the CPUscheduler.The CPU scheduler select a process from the

    ready queue and allocates the CPU to thatprocess.

  • 7/31/2019 CPU Scheduling by Furqan

    9/34

  • 7/31/2019 CPU Scheduling by Furqan

    10/34

    Types of Scheduling

    There are four types of scheduling that anOS has to perform:

    Long Term scheduling Medium-Term Scheduling Short-Term Scheduling I/O Scheduling

  • 7/31/2019 CPU Scheduling by Furqan

    11/34

    Long Term scheduling

    The long term scheduling determineswhich programs are admitted to thesystem for processing.

    It controls the level of multiprogramming.Long term scheduling is performed when anew process is created.The criteria used for long-term schedulingmay include first-come-first serve, priority,expected execution time, and I/Orequirements.

  • 7/31/2019 CPU Scheduling by Furqan

    12/34

    Medium-Term Scheduling

    The medium-term scheduling is a part ofswapping function.This is a decision to add a process to those

    that are at least partially in main memory andtherefore available for execution.

    The swapping- In decision is made on the needto manage the degree of multiprogramming andthe memory requirements of the swapped-outprocess.

  • 7/31/2019 CPU Scheduling by Furqan

    13/34

    Short-Term Scheduling

    A decision of which ready process to executenext is made in short-term scheduling.

    I/O SchedulingThe decision as to which processs pendingI/O requests shall be handled by theavailable I/O device is made in I/O

    scheduling.

  • 7/31/2019 CPU Scheduling by Furqan

    14/34

    Scheduling Criteria

    CPU utilization : keep the CPU as busy as possible (from 0% to100%)

    Throughput : # of processes that complete their execution per

    time unitTurnaround time :Amount of time to execute a particularProcess

    Waiting time :Amount of time a process has been waiting in theready queue

    Response time:Amount of time it takes from when a request wassubmitted until the first response is produced

  • 7/31/2019 CPU Scheduling by Furqan

    15/34

    Optimization Criteria

    Max CPU utilizationMax throughput

    Min turnaround timeMin waiting timeMin Response time

  • 7/31/2019 CPU Scheduling by Furqan

    16/34

    Scheduling Algorithms

    CPU scheduling deals with the problem ofdeciding which of the processes in the

    ready queue is to be allocated the CPU.There are many different CPU schedulingalgorithms, which we will discuss now.

  • 7/31/2019 CPU Scheduling by Furqan

    17/34

    Scheduling Algorithms

    First-Come First-Served (FCFS)SchedulingShortest-Job First Scheduling (SJF)Priority SchedulingRound-Robin Scheduling

  • 7/31/2019 CPU Scheduling by Furqan

    18/34

    First-Come First-Served(FCFS) Scheduling

    The process that requests the CPU first isallocated the CPU first. It is no preemptivealgorithm.Can easily be implemented with a FIFOqueue.When a process enters the ready queue, its

    PCB is linked onto the tail of the queue.When CPU is free, it is allocated to theprocess at the head of the queue.

  • 7/31/2019 CPU Scheduling by Furqan

    19/34

  • 7/31/2019 CPU Scheduling by Furqan

    20/34

    Advantages

    Very simpleDisadvantages

    Long average and worst-case waitingtimesPoor dynamic behavior (convoy effect -short process behind long process)

  • 7/31/2019 CPU Scheduling by Furqan

    21/34

  • 7/31/2019 CPU Scheduling by Furqan

    22/34

    Example: Process Burst Time

    P1 24

    P2 3

    P3 3

    Suppose that the processes arrive in the orderP1, P2,P3.The Gantt Chart for the schedule is:

    P 1 P 2 P 3 24 27 30

    0

    Waiting time for P1 = 0; P2 = 24; P3 = 27

    Average waiting time: (0 + 24 + 27)/3 = 17

  • 7/31/2019 CPU Scheduling by Furqan

    23/34

    Cont Suppose that the processes arrive in the orderP2 , P3 , P1 . The Gantt chart for the schedule is:

    P 1 P 3 P 2

    6 3 30 0

    Waiting time for P1 = 6; P2 = 0 ; P3 = 3Average waiting time: (6 + 0 + 3)/3 = 3

  • 7/31/2019 CPU Scheduling by Furqan

    24/34

    Shortest-Job First Scheduling (SJF)

    This algorithm associates with each processthe length of its next CPU burst.

    When the CPU is available, it is assignedthe process that has the smallest next CPUburst.It is a non-preemptive policy.

  • 7/31/2019 CPU Scheduling by Furqan

    25/34

  • 7/31/2019 CPU Scheduling by Furqan

    26/34

    Cont

    If a new process arrives with CPU burstlength less than remaining time of currentexecuting process, preempt the currently

    executing process and allocate the CPU tothe new process.

  • 7/31/2019 CPU Scheduling by Furqan

    27/34

    Cont

    Advantages:Minimizes average waiting times.

    Problems:How to determine length of next CPUburst?Problem: starvation of jobs with longCPU bursts.

  • 7/31/2019 CPU Scheduling by Furqan

    28/34

    Priority Scheduling

    In priority scheduling, a priority (an integer)is associated with each process.Priorities can be assigned either externallyor internally.The CPU is allocated to the process withthe highest priority (smallest integer meanshighest priority).

    Priority scheduling can be:PreemptiveNo preemptive

  • 7/31/2019 CPU Scheduling by Furqan

    29/34

  • 7/31/2019 CPU Scheduling by Furqan

    30/34

    ProblemStarvation or indefinite blocking lowpriority processes may never execute.

    Solution Aging as time progresses increase thepriority of the process.

  • 7/31/2019 CPU Scheduling by Furqan

    31/34

  • 7/31/2019 CPU Scheduling by Furqan

    32/34

    Round-Robin Scheduling

    Each process gets a small unit of CPU time(called time quantum ), usually 10-100milliseconds.

    After this time has elapsed, the process ispreempted and added to the end of theready queue.

    Ready queue is treated as a circular queue.

    CPU scheduler goes around the readyqueue, allocating the CPU to each processfor a time interval of 1 time quantum.

  • 7/31/2019 CPU Scheduling by Furqan

    33/34

  • 7/31/2019 CPU Scheduling by Furqan

    34/34