Process Scheduling

Embed Size (px)

DESCRIPTION

The total description is about process scheduling in Operating System - by Jagadamba . Professor

Citation preview

  • P.V.S. Lakshmi JagadambaProcess Management

    Process Scheduling

    Mrs. PVS Lakshmi Jagadamba

    Associate Professor

    Department of CSE

    School of Engineering

    GVP College For Degree & PG Courses (Technical Campus)

    Rushikonda, Visakhapatnam.

  • P.V.S. Lakshmi JagadambaProcess Management

    Objectives

    To introduce CPU scheduling, which is the basis for multi

    programmed operating systems

    To describe various CPU-scheduling algorithms

    To discuss evaluation criteria for selecting a CPU-

    scheduling algorithm for a particular system

  • P.V.S. Lakshmi JagadambaProcess Management

    Scheduling Concepts

    Multiprogramming A number of programs can be in memory

    at the same time. Allows overlap of CPU

    and I/O.

    Jobs (batch) are programs that run without

    user interaction.

    User (time shared) are programs that may have

    user interaction.

    Process is the common name for both.

    CPU - I/O burst cycle Characterizes process execution, which

    alternates, between CPU and I/O activity.

    CPU times are generally much shorter

    than I/O times.

    Preemptive Scheduling An interrupt causes currently running

    process to give up the CPU and be

    replaced by another process.

  • P.V.S. Lakshmi JagadambaProcess Management

    Most Processes Dont Use Up Their Scheduling Quantum!

    Scheduling Behavior

    CPU bursts tend to have a frequency curve similar to the exponential curveshown above. It is characterized by a large number of short CPU bursts and asmall number of long CPU bursts. An I/O-bound program typically has manyshort CPU bursts; a CPU-bound program might have a few long CPU bursts.

  • P.V.S. Lakshmi JagadambaProcess Management

    CPU Scheduler

    The CPU scheduler selects from among the processes in memory that are ready to execute and allocates the CPU to one of them

    CPU scheduling is affected by the following set of circumstances:

    1. (N) A process switches from running to waiting state

    2. (P) A process switches from running to ready state

    3. (P) A process switches from waiting to ready state

    4. (N) A processes switches from running to terminated state

    Circumstances 1 and 4 are non-preemptive; they offer no schedule choice

    Circumstances 2 and 3 are pre-emptive; they can be scheduled

  • P.V.S. Lakshmi JagadambaProcess Management

    The Dispatcher

    Dispatcher module gives control of the CPU to the process selected by the short-

    term scheduler; this involves:

    switching context

    switching to user mode

    jumping to the proper location in the user program to restart that program

    Dispatch latency time it takes for the dispatcher to stop one process and start another running

  • P.V.S. Lakshmi JagadambaProcess Management

    Process Scheduling

    Maximize CPU use, quickly switch processes onto CPU

    for time sharing

    Process scheduler selects among available processes for

    next execution on CPU

    Maintains scheduling queues of processes

    Job queue set of all processes in the system

    Ready queue set of all processes residing in main

    memory, ready and waiting to execute

    Device queues set of processes waiting for an I/O

    device

    Processes migrate among the various queues

  • P.V.S. Lakshmi JagadambaProcess Management

    Ready Queue And Various I/O Device Queues

  • P.V.S. Lakshmi JagadambaProcess Management

    Representation of Process Scheduling

    Queueing diagram represents queues, resources, flows

  • P.V.S. Lakshmi JagadambaProcess Management

    Schedulers Long-term scheduler (or job scheduler or scheduling in Batch Systems)

    selects which processes should be brought into the ready queue

    Short-term scheduler (or CPU scheduler or scheduling in Interactive

    Systems) selects which process should be executed next and allocates CPU

    Sometimes the only scheduler in a system

    Short-term scheduler is invoked very frequently (milliseconds) (must be fast)

    Long-term scheduler is invoked very infrequently (seconds, minutes) (may be

    slow)

    The long-term scheduler controls the degree of multiprogramming

    Processes can be described as either:

    I/O-bound process spends more time doing I/O than computations, many

    short CPU bursts

    CPU-bound process spends more time doing computations; few very long

    CPU bursts

    Long-term scheduler strives for good process mix

  • P.V.S. Lakshmi JagadambaProcess Management

    Addition of Medium Term Scheduling

    Medium-term scheduler can be added if degree of multiple programming needs to decrease

    Remove process from memory, store on disk, bring back in from disk to continue execution:

    swapping

  • P.V.S. Lakshmi JagadambaProcess Management

    Classification of Scheduling Activity

    Long-term: which process to admit?

    Medium-term: which process to swap in or out?

    Short-term: which ready process to execute next?

  • P.V.S. Lakshmi JagadambaProcess Management

    Queuing Diagram for Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Long-Term Scheduling

    Determines which programs are admitted to the system for processing

    Controls the degree of multiprogramming

    Attempts to keep a balanced mix of processor-bound and I/O-bound

    processes

    CPU usage

    System performance

  • P.V.S. Lakshmi JagadambaProcess Management

    Medium-Term Scheduling

    Makes swapping decisions based on the current degree of

    multiprogramming

    Controls which remains resident in memory and which jobs

    must be swapped out to reduce degree of multiprogramming

  • P.V.S. Lakshmi JagadambaProcess Management

    Short-Term Scheduling

    Selects from among ready processes in memory which one is to execute next

    The selected process is allocated the CPU

    It is invoked on events that may lead to choose another process for execution:

    Clock interrupts

    I/O interrupts

    Operating system calls and traps

    Signals

  • P.V.S. Lakshmi JagadambaProcess Management

    Characterization of Scheduling Policies

    The selection function determines which ready process is selectednext for execution

    The decision mode specifies the instants in time the selection

    function is exercised

    Nonpreemptive

    Once a process is in the running state, it will continue until it

    terminates or blocks for an I/O

    Preemptive

    Currently running process may be interrupted and moved to the

    Ready state by the OS

    Prevents one process from monopolizing the processor

  • P.V.S. Lakshmi JagadambaProcess Management

    Short-Tem Scheduling Criteria

    User-oriented criteria

    Response Time: Elapsed time between the submission of arequest and the receipt of a response

    Turnaround Time: Elapsed time between the submission of aprocess to its completion

    System-oriented criteria

    Processor utilization

    Throughput: number of process completed per unit time

    fairness

  • P.V.S. Lakshmi JagadambaProcess Management

    Scheduling Criteria

    Different CPU scheduling algorithms have different properties

    The choice of a particular algorithm may favor one class of processes overanother

    In choosing which algorithm to use, the properties of the various algorithmsshould be considered

    Criteria for comparing CPU scheduling algorithms may include the following

    CPU utilization percent of time that the CPU is busy executing a process

    Throughput number of processes that are completed per time unit

    Response time amount of time it takes from when a request wassubmitted until the first response occurs (but not the time it takes to outputthe entire response)

    Waiting time the amount of time before a process starts after firstentering the ready queue (or the sum of the amount of time a process hasspent waiting in the ready queue)

    Turnaround time amount of time to execute a particular process fromthe time of submission through the time of completion

  • P.V.S. Lakshmi JagadambaProcess Management

    Optimization Criteria

    It is desirable to

    Maximize CPU utilization

    Maximize throughput

    Minimize turnaround time

    Minimize start time

    Minimize waiting time

    Minimize response time

    In most cases, we strive to optimize the average measure of each metric

    In other cases, it is more important to optimize the minimum or

    maximum values rather than the average

  • P.V.S. Lakshmi JagadambaProcess Management

    Scheduling: high-level goals

    Interleave the execution of processes to maximize CPUutilization while providing reasonable response time

    The scheduler determines:

    o Who will run

    o When it will run

    o For how long

  • P.V.S. Lakshmi JagadambaProcess Management

    Criteria by system type

  • P.V.S. Lakshmi JagadambaProcess Management

    Categories of Scheduling Algorithms

    Based on number of processes to be scheduled

    Batch Systems:

    First Come First Served (FCFS)

    Shortest Job First (SJF)

    Shortest Remaining Time Next (SRTN)

    Interactive Systems:

    Round Robin (RR)

    Priority

    Multi level Queue

    Multi level feedback queue

    Shortest Process Next

    Guaranteed Scheduling

    Lottery Scheduling

    Fair-Share Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Categories of Scheduling Algorithms

    Based on number of processors used

    Single Processor Scheduling:

    First Come First Served (FCFS)

    Shortest Job First (SJF)

    Shortest Remaining Time Next (SRTN)

    Round Robin (RR)

    Priority

    Multi level Queue

    Multi level feedback queue

    Multiple processor scheduling:

    Asymmetric

    Symmetric

  • P.V.S. Lakshmi JagadambaProcess Management

    First Come, First Served (FCFS) Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    First-Come, First-Served (FCFS) Scheduling

    Process Burst Time

    P1 24

    P2 3

    P3 3

    Suppose that the processes arrive in the order: P1 , P2 , P3The Gantt Chart for the schedule is:

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

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

    Average turn-around time: (24 + 27 + 30)/3 = 27

    P1 P2 P3

    24 27 300

  • P.V.S. Lakshmi JagadambaProcess Management

    FCFS Scheduling (Cont.)

    Case #2: Suppose that the processes arrive in the order:

    P2 , P3 , P1

    The Gantt chart for the schedule is:

    Waiting time for P1 = 6; P2 = 0; P3 = 3

    Average waiting time: (6 + 0 + 3)/3 = 3

    Average turn-around time: (3 + 6 + 30)/3 = 13

    P1P3P2

    63 300

  • P.V.S. Lakshmi JagadambaProcess Management

    FCFS Scheduling (Cont.)

    Case #1 is an example of the convoy effect; all the other processes wait for

    one long-running process to finish using the CPU

    This problem results in lower CPU and device utilization; Case #2 shows

    that higher utilization might be possible if the short processes were

    allowed to run first

    The FCFS scheduling algorithm is non-preemptive

    Once the CPU has been allocated to a process, that process keeps the

    CPU until it releases it either by terminating or by requesting I/O

    It is a troublesome algorithm for time-sharing systems

  • P.V.S. Lakshmi JagadambaProcess Management

    First Come First Served (FCFS)

    Selection function: the process that has been waiting the longest in

    the ready queue (hence, FCFS)

    Decision mode: non-preemptive

    a process runs until it blocks for an I/O

  • P.V.S. Lakshmi JagadambaProcess Management

    FCFS drawbacks

    Favors CPU-bound processes

    A CPU-bound process monopolizes the processor

    I/O-bound processes have to wait until completion of CPU-

    bound process

    I/O-bound processes may have to wait even after their I/Os are

    completed (poor device utilization)

    Better I/O device utilization could be achieved if I/O bound

    processes had higher priority

  • P.V.S. Lakshmi JagadambaProcess Management

    Shortest Job First (SJF) Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Shortest-Job-First (SJF) Scheduling

    The SJF algorithm associates with each process the length of its next CPU burst

    When the CPU becomes available, it is assigned to the process that has the smallest

    next CPU burst (in the case of matching bursts, FCFS is used)

    SJF is optimal gives minimum average waiting time for a given set of processes

    The difficulty is knowing the length of the next CPU request

    Could ask the user

    Two schemes:

    Nonpreemptive once the CPU is given to the process, it cannot be preempted

    until it completes its CPU burst

    Preemptive if a new process arrives with a CPU burst length less than the

    remaining time of the current executing process, preempt. This scheme is know as

    the Shortest-Remaining-Time-Next (SRTN)

  • P.V.S. Lakshmi JagadambaProcess Management

    ProcessArrival Time Burst Time

    P1 0.0 6

    P2 0.0 4

    P3 0.0 1

    P4 0.0 5

    SJF (non-preemptive, simultaneous arrival)

    Average waiting time = (0 + 1 + 5 + 10)/4 = 4

    Average turn-around time = (1 + 5 + 10 + 16)/4 = 8

    Non-Preemptive SJF (simultaneous arrival)

    P1P3 P2

    51 160

    P4

    10

  • P.V.S. Lakshmi JagadambaProcess Management

    ProcessArrival Time Burst Time

    P1 0.0 7

    P2 2.0 4

    P3 4.0 1

    P4 5.0 4

    SJF (non-preemptive, varied arrival times)

    Average waiting time

    = ( (0 0) + (8 2) + (7 4) + (12 5) )/4

    = (0 + 6 + 3 + 7)/4 = 4

    Average turn-around time:

    = ( (7 0) + (12 2) + (8 - 4) + (16 5))/4

    = ( 7 + 10 + 4 + 11)/4 = 8

    Non-Preemptive SJF (varied arrival times)

    P1 P3 P2

    73 160

    P4

    8 12

    Waiting time : sum of time that a process has spent waiting in the ready queue

  • P.V.S. Lakshmi JagadambaProcess Management

    Preemptive SJF (Shortest-remaining-time-Next)

    ProcessArrival Time Burst Time

    P1 0.0 7

    P2 2.0 4

    P3 4.0 1

    P4 5.0 4

    SJF (preemptive, varied arrival times)

    Average waiting time

    = ( [(0 0) + (11 - 2)] + [(2 2) + (5 4)] + (4 - 4) + (7 5) )/4

    = 9 + 1 + 0 + 2)/4

    = 3

    Average turn-around time = (16 + 7 + 5 + 11)/4 = 9.75

    P1 P3P2

    42 110

    P4

    5 7

    P2 P1

    16

    Waiting time : sum of time that a process has spent waiting in the ready queue

  • P.V.S. Lakshmi JagadambaProcess Management

    Priority Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Priority Scheduling

    The SJF algorithm is a special case of the general priority scheduling algorithm

    A priority number (integer) is associated with each process

    The CPU is allocated to the process with the highest priority (smallest integer = highest priority)

    Priority scheduling can be either preemptive or non-preemptive

    A preemptive approach will preempt the CPU if the priority of the newly-arrived process is higher than the priority of the currently running process

    A non-preemptive approach will simply put the new process (with the highest priority) at the head of the ready queue

    SJF is a priority scheduling algorithm where priority is the predicted next CPU burst time

    The main problem with priority scheduling is starvation, that is, low priority processes may never execute

    A solution is aging; as time progresses, the priority of a process in the ready queue is increased

  • P.V.S. Lakshmi JagadambaProcess Management

    Example of Priority Scheduling

    ProcessAarri Burst TimeT Priority

    P1 10 3

    P2 1 1

    P3 2 4

    P4 1 5

    P5 5 2

    Priority scheduling Gantt Chart

    Average waiting time = 8.2 msec

    Average Turn around time = 10 msec

    P2 P3P5

    1 180 16

    P4

    196

    P1

  • P.V.S. Lakshmi JagadambaProcess Management

    Round Robin (RR) Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Round Robin (RR)

    Each process gets a small unit of CPU time (time quantum q),

    usually 10-100 milliseconds. After this time has elapsed, the

    process is preempted and added to the end of the ready queue.

    If there are n processes in the ready queue and the time quantum

    is q, then each process gets 1/n of the CPU time in chunks of at

    most q time units at once. No process waits more than (n-1)q

    time units.

    Timer interrupts every quantum to schedule next process

    Performance

    q large FIFO

    q small q must be large with respect to context switch,

    otherwise overhead is too high

  • P.V.S. Lakshmi JagadambaProcess Management

    Example of RR with Time Quantum = 20Process Burst Time

    P1 53

    P2 17

    P3 68

    P4 24

    The Gantt chart is:

    Typically, higher average turnaround than SJF, but better response time

    Average waiting time = ( [(0 0) + (77 - 20) + (121 97)] + (20 0) + [(37 0) + (97 - 57) + (134 117)] + [(57 0) + (117 77)] ) / 4 = (0 + 57 + 24) + 20 + (37 + 40 + 17) + (57 + 40) ) / 4 = (81 + 20 + 94 + 97)/4= 292 / 4 = 73

    Average turn-around time = 134 + 37 + 162 + 121) / 4 = 113.5

    P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

    0 20 37 57 77 97 117 121 134 154 162

  • P.V.S. Lakshmi JagadambaProcess Management

    EXAMPLE DATA:

    Process Arrival Service

    Time Time

    1 0 8

    2 1 4

    3 2 9

    4 3 5

    0 8 12 16 26

    P2 P3 P4 P1

    Round Robin, quantum = 4, no priority-based preemption

    Average wait = ( (20-0) + (8-1) + (26-2) + (25-3) )/4 = 74/4 = 18.5

    P1

    4

    P3 P4

    20 24 25

    P3

    Round Robin SCHEDULING

    Note:Example violates rules for quantum

    size since most processes dont finish in one quantum.

  • P.V.S. Lakshmi JagadambaProcess Management

    Time Quantum and Context Switch Time

  • P.V.S. Lakshmi JagadambaProcess Management

    Turnaround Time Varies With

    The Time Quantum

    80% of CPU bursts should be shorter than q

  • P.V.S. Lakshmi JagadambaProcess Management

    Multi-level Queue Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Multi-level Queue Scheduling

    Multi-level queue scheduling is used when processes can be classified into groups

    For example, foreground (interactive) processes and background (batch) processes

    The two types of processes have different response-time requirements and so may have different scheduling needs

    Also, foreground processes may have priority (externally defined) over background processes

    A multi-level queue scheduling algorithm partitions the ready queue into several separate queues

    The processes are permanently assigned to one queue, generally based on some property of the process such as memory size, process priority, or process type

    Each queue has its own scheduling algorithm

    The foreground queue might be scheduled using an RR algorithm

    The background queue might be scheduled using an FCFS algorithm

    In addition, there needs to be scheduling among the queues, which is commonly implemented as fixed-priority pre-emptive scheduling

    The foreground queue may have absolute priority over the background queue

  • P.V.S. Lakshmi JagadambaProcess Management

    Multi-level Queue Scheduling One example of a multi-level queue are the five queues shown below

    Each queue has absolute priority over lower priority queues

    For example, no process in the batch queue can run unless the queues above it are empty

    However, this can result in starvation for the processes in the lower priority queues

  • P.V.S. Lakshmi JagadambaProcess Management

    Multilevel Queue Scheduling

    Another possibility is to time slice among the queues

    Each queue gets a certain portion of the CPU time, which it can then schedule among

    its various processes

    The foreground queue can be given 80% of the CPU time for RR scheduling

    The background queue can be given 20% of the CPU time for FCFS scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Multi-level Feedback Queue Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Multilevel Feedback Queue

    A process can move between the various queues; aging can be

    implemented this way

    Multilevel-feedback-queue scheduler defined by the following

    parameters:

    number of queues

    scheduling algorithms for each queue

    method used to determine when to upgrade a process

    method used to determine when to demote a process

    method used to determine which queue a process will enter

    when that process needs service

  • P.V.S. Lakshmi JagadambaProcess Management

    Example of Multilevel Feedback Queue

    Three queues:

    Q0 RR with time quantum 8 milliseconds

    Q1 RR time quantum 16 milliseconds

    Q2 FCFS

    Scheduling

    A new job enters queue Q0 which is served

    FCFS

    When it gains CPU, job receives 8

    milliseconds

    If it does not finish in 8 milliseconds, job is

    moved to queue Q1

    At Q1 job is again served FCFS and receives 16

    additional milliseconds

    If it still does not complete, it is preempted

    and moved to queue Q2

  • P.V.S. Lakshmi JagadambaProcess Management

    Guaranteed Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Guaranteed Scheduling

    To achieve guaranteed 1/n of cpu time (for nprocesses/users logged on):

    Monitor the total amount of CPU time per process andthe total logged on time

    Calculate the ratio of allocated cpu time to the amountof CPU time each process is entitled to

    Run the process with the lowest ratio

    Switch to another process when the ratio of therunning process has passed its goal ratio

  • Guaranteed scheduling example

    1

    0

    1

    0

    Process 1 Process 2 Process 3

    0

    0

    0

    0

    0

    0

    0

  • 10

    1

    0

    3/1

    1

    Process 1 Process 2 Process 3

    1

    3/1

    0

    3/1

    0

    Guaranteed scheduling example

  • 10

    1

    0

    3/2

    1

    Process 1 Process 2 Process 3

    2

    3/2

    0

    3/2

    1

    Guaranteed scheduling example

  • 10

    1

    0

    3/3

    1

    Process 1 Process 2 Process 3

    3

    3/3

    1

    3/3

    1

    Guaranteed scheduling example

  • 10

    1

    0

    3/4

    2

    Process 1 Process 2 Process 3

    4

    3/4

    1

    3/4

    1

    Guaranteed scheduling example

  • 10

    1

    0

    3/5

    2

    Process 1 Process 3

    5

    3/5

    2

    Guaranteed scheduling example

  • 10

    1

    0

    3/6

    3

    Process 1 Process 2 Process 3

    6

    3/6

    2

    3/6

    1

    Guaranteed scheduling example

  • 10

    1

    0

    3/7

    3

    Process 1 Process 2 Process 3

    7

    3/7

    2

    3/7

    2

    Guaranteed scheduling example

  • 10

    1

    0

    3/8

    3

    Process 1 Process 2 Process 3

    8

    3/8

    2

    3/8

    3

    Guaranteed scheduling example

  • 10

    1

    0

    3/9

    3

    Process 1 Process 2 Process 3

    9

    3/9

    3

    3/9

    3

    Guaranteed scheduling example

  • P.V.S. Lakshmi JagadambaProcess Management

    Fair Share Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Fair Share Scheduling

    FSS controls users access to system resources

    Some user groups more important than others

    Ensures that less important groups cannot monopolize resources

    Unused resources distributed according to the proportion of

    resources each group has been allocated

    Groups not meeting resource-utilization goals get higher priority

  • P.V.S. Lakshmi JagadambaProcess Management

    Standard UNIX process scheduler. The scheduler grants the processor

    to users, each of whom may have many processes. (Property of AT&T Archives.

    Reprinted with permission of AT&T.)

    Fair Share Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Fair share scheduler. The fair share scheduler divides system resource

    capacity into portions, which are then allocated by process schedulers assigned to

    various fair share groups. (Property of AT&T Archives. Reprinted with permission of

    AT&T.)

    Fair Share Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Deadline Scheduling

    Deadline scheduling

    Process must complete by specific time

    Used when results would be useless if not delivered on-time

    Difficult to implement

    Must plan resource requirements in advance

    Incurs significant overhead

    Service provided to other processes can degrade

  • P.V.S. Lakshmi JagadambaProcess Management

    Real-Time Scheduling

    Real-time scheduling

    Related to deadline scheduling

    Processes have timing constraints

    Also encompasses tasks that execute periodically

    Two categories

    Soft real-time scheduling

    Does not guarantee that timing constraints will be met

    For example, multimedia playback

    Hard real-time scheduling

    Timing constraints will always be met

    Failure to meet deadline might have catastrophic results

    For example, air traffic control

  • P.V.S. Lakshmi JagadambaProcess Management

    Real-Time Scheduling

    Static real-time scheduling

    Does not adjust priorities over time

    Low overhead

    Suitable for systems where conditions rarely change

    Hard real-time schedulers

    Rate-monotonic (RM) scheduling

    Process priority increases monotonically with the frequency

    with which it must execute

    Deadline RM scheduling

    Useful for a process that has a deadline that is not equal to its

    period

  • P.V.S. Lakshmi JagadambaProcess Management

    Real-Time Scheduling

    Dynamic real-time scheduling

    Adjusts priorities in response to changing conditions

    Can incur significant overhead, but must ensure that the overhead

    does not result in increased missed deadlines

    Priorities are usually based on processes deadlines

    Earliest-deadline-first (EDF)

    Preemptive, always dispatch the process with the earliest

    deadline

    Minimum-laxity-first

    Similar to EDF, but bases priority on laxity, which is based

    on the processs deadline and its remaining run-time-to-

    completion

  • P.V.S. Lakshmi JagadambaProcess Management

    Java Thread Scheduling

    Operating systems provide varying thread scheduling support

    User-level threads

    Implemented by each program independently

    Operating system unaware of threads

    Kernel-level threads

    Implemented at kernel level

    Scheduler must consider how to allocate processor time to a

    processs threads

  • P.V.S. Lakshmi JagadambaProcess Management

    Java Thread Scheduling

    Java threading scheduler

    Uses kernel-level threads if available

    User-mode threads implement timeslicing

    Each thread is allowed to execute for at most one quantum

    before preemption

    Threads can yield to others of equal priority

    Only necessary on nontimesliced systems

    Threads waiting to run are called waiting, sleeping or blocked

  • P.V.S. Lakshmi JagadambaProcess Management

    Figure 8.7 Java thread priority scheduling.

    Java Thread Scheduling

  • P.V.S. Lakshmi JagadambaProcess Management

    Choosing a Scheduling Policy

    Scheduling policy depends on the nature of operations.

    An OS policy may be chosen to suit situations with specific

    requirements.

    Within a computer system, we need policies to schedule access

    to processor, memory, disc, IO and shared resource (e.g.

    printers).

    Policy Selection 1:

    A scheduling policy is often determined by a machines

    configuration and its pattern of usage. Scheduling is considered

    in the following context:

    We have only one processor in they system

    We have a multi-programming system more than one

    ready-to-run program in memory.

  • P.V.S. Lakshmi JagadambaProcess Management

    Choosing a Scheduling Policy

    Policy Selection 2: Study the effect on the following quality

    parameters:

    Response time to users

    Turn around time

    Processor utilization

    Throughput of the system

    Fairness of allocation

    Effect on other resources.

    We see that measures for response time and turn around are

    user centred parameters.

  • P.V.S. Lakshmi JagadambaProcess Management

    Choosing a Scheduling Policy

    Policy Selection 3:

    Process utilization and throughput are system centered

    considerations.

    Fairness of allocation and effect on other resources affect

    both the system and users.

    An OS performance can be tuned by choosing an

    appropriate scheduling policy.

  • P.V.S. Lakshmi JagadambaProcess Management

    Comparison of Policies

    Let us consider 5 processes P1 through P5.

    Assumptions:

    The jobs have to run to completion.

    No new jobs arrive till these jobs are processed.

    Time required for each job is known appropriately.

    During the run of jobs there is no suspension for IO

    operation.

  • P.V.S. Lakshmi JagadambaProcess Management

    Comparison of Three Non-Preemptive

    Scheduling Policies

  • P.V.S. Lakshmi JagadambaProcess Management

    Summary of Results

    Case B : Average time to complete - 50 (case of FCFS)

    Case C: Average time to complete - 52 (case of prioritized)

    Case D: Average time to complete 35 (case of SJF)

    Clearly it would seem that shortest job first is the best policy. In

    fact theoretically also this can be proved

  • P.V.S. Lakshmi JagadambaProcess Management

    Preemptive Policies - 1

  • P.V.S. Lakshmi JagadambaProcess Management

    Summary of Results

    In the figure, we compare four cases:

    Round-robin allocation with time slice = 5 units (CASE B)

    Round-robin allocation with time slice = 10 units (CASE C)

    Shortest Job First within the Round-robin; time slice = 5 units

    (CASE D)

    Shortest Job First within the Round-robin; time slice = 10 units.

    (CASE E)

    Case B Average time to complete - 52

    Case C Average time to complete - 53

    Case D Average time to complete - 45

    Case E Average time to complete - 41

    Clearly it would seem that shortest job first is the best policy. In fact

    theoretically also this can be proved

  • P.V.S. Lakshmi JagadambaProcess Management

    End of Chapter 3