+ All Categories
Home > Documents > Finals) (PDF)

Finals) (PDF)

Date post: 07-Apr-2018
Category:
Upload: michaeleano
View: 234 times
Download: 0 times
Share this document with a friend

of 20

Transcript
  • 8/3/2019 Finals) (PDF)

    1/20

    Scheduling Algorithm

  • 8/3/2019 Finals) (PDF)

    2/20

    Scheduling Algorithms

    Introduction

    Problem definition:

    One CPU with a number of processes. Only

    one process can use the CPU at a time and each

    process is specialized in one, and one task.

    Whats the best way to organize the processes

    (schedule them) ? [1]How will the CPU time be divided among the

    processes and threads competing to use it ? [2]

  • 8/3/2019 Finals) (PDF)

    3/20

    Scheduling Algorithms

    Embedded OS Architecture

    Kernel:

    The executor

    Executive: The manager

    Application Programs:

    The programmer tasks Real World Interfacing:

    S/W handling the H/W

  • 8/3/2019 Finals) (PDF)

    4/20

    Scheduling Algorithms

    Basic Assumptions

    A pool of runnable processes are contending for one CPU;

    The processes are independent and compete for resources;

    The job of the scheduler is to distribute the scarce resourceof the CPU to the different processes fairly and in an

    optimal way;

    The job of the dispatcher is to provide the mechanism for

    running the processes; The OS is a multitasking, but not a multiprocessor, one;

    Only CPU scheduling is considered (the lowest level of

    scheduling).

  • 8/3/2019 Finals) (PDF)

    5/20

    Scheduling Algorithms

    Evaluation Characteristics

    CPU utilization Keep it as high aspossible

    Throughput Number of processes

    completed per unittime

    Waiting time Amount of time spentready to run but not

    runnin

    Response time Amount of time

    between submission ofrequests and first

    response to the request

    Scheduler efficiency Minimize the

    overhead

    Turnaround time Mean time fromsubmission to

  • 8/3/2019 Finals) (PDF)

    6/20

    Scheduling Algorithms

    Processes and Resources

    Resources:

    Preemptible:

    Take resource away,use it for something

    else, then give it back.

    (e.g. processor or I/O

    channel)

    Non-preemptible: Once give, it cant be

    reused until process

    gives it back. (e.g. file

    space or terminal)

    Processes:

    IO bound:

    Perform lots of IOoperations.

    IO burst ---- short CPU burst

    to process IO --- IO burst

    CPU bound:

    Perform lots ofcomputation and do

    little IO

    CPU burst ----------- Small IO

    burst ----------- CPU burst

  • 8/3/2019 Finals) (PDF)

    7/20

    Scheduling Algorithms

    Process State Transitions

    The states of a process, at any

    given time, is comprised of the

    following minimal set:

    Running: The CPU is currently

    executing the code belonging

    to the process.

    Ready:

    The process could be running,

    but another process has theCPU.

    Waiting:

    Before the process can run,

    some external event must

    occur.

  • 8/3/2019 Finals) (PDF)

    8/20

    Scheduling Algorithms

    Types of Schedulers

    Long-term scheduler: admits new processes to the system;

    required because each process needs a portion of theavailable memory for its code and data.

    Medium-term scheduler: is not found in all systems;

    required to control the temporary removal from memory of aprocess when the latter is extractable.

    Short-term scheduler: determines the assignment of the CPU to ready processes;

    required because of IO requests and completions.

  • 8/3/2019 Finals) (PDF)

    9/20

    Scheduling Algorithms

    The Contestants (1)

    First-Come First-Serve (FCFS)

    One ready queue;

    OS runs the process at head of the queue;New processes come in at the end of the queue;

    Running process does not give up the CPU until it

    terminates or it performs IO.

    Round Robin Process runs for one time slice, then moved to back of the

    queue;

    Each process gets equal share of the CPU.

  • 8/3/2019 Finals) (PDF)

    10/20

    Scheduling Algorithms

    The Contestants (2)

    Shortest Time to Completion (STCF)

    Process with shortest computation time left is picked;

    Varianted by preemption; Requires knowledge of the future.

    Exponential Queue (Multi-level Feedback) Gives newly runnable processes a high priority and a very

    short time slice; If process uses up the time slice without blocking then

    decrease priority by one and double time slice for next time;

    Solves both efficiency and response time problems.

  • 8/3/2019 Finals) (PDF)

    11/20

    Scheduling Algorithms

    The Contestants (3) - Priorities

    Priority Systems The highest priority ready process is selected

    In case of a tie, FCFS can be used Priorities could be assigned:

    Externally (e.g. by a system manager)

    Internally (e.g. by some algorithm)

    Combination of external and internal

    Preemptive schemes: Once a process starts executing, allow it to continue until it

    voluntarily yields the CPU

    Non-preemptive schemes:

    A running process may be forced to yield the CPU by an external

    event rather than by its own action

  • 8/3/2019 Finals) (PDF)

    12/20

    Scheduling Algorithms

    First-Come First-Serve

    Non-preemptive FCFS (no priority scheme) Simplest implementation of scheduling algorithms

    Used on timeshared systems (with timer interruption)

    Non-preemptive FCFS (with priority scheme)

    Next highest priority process is picked when CPU is yielded

    Once process grabs CPU, former keeps latter until completion

    Rarely used in real-time systems

    Preemptive FCFS (with priority scheme)

    Most popular FCFS algorithm

  • 8/3/2019 Finals) (PDF)

    13/20

    Scheduling Algorithms

    Round Robin

    Used mostly on timeshared

    systems

    Allows multiple users slicesof the CPU on a round

    robin basis

    Majority of users have the

    same priority Not a popular scheme with

    dynamic priority systems

  • 8/3/2019 Finals) (PDF)

    14/20

    Scheduling Algorithms

    Shortest Time to Completion

    Priorities are assigned in inverse order of time needed for completion

    of the entire job

    Minimizes average turnaround time

    Exponential averaging is used to estimate the process burst duration

    A job exceeding the resource estimation is aborted

    A job exceeding the time estimation is preempted

    Store estimated value in PCB for the current burst, and compare with

    actual value

  • 8/3/2019 Finals) (PDF)

    15/20

    Scheduling Algorithms

    Exponential Queues

    Popular in interactive systems

    A single queue is maintained for each

    priority level

    A new process is added at the end of thehighest priority queue

    It is alloted a single time quantum when

    it reaches the front

    If it yields the CPU within the time

    quantum, it is moved to the rear

    If not, it is placed at the rear of the nextqueue down

    Dispatcher selects the head of the

    highest priority queue

    A job that succeeds moves up

    A job that fails moves down

  • 8/3/2019 Finals) (PDF)

    16/20

    Scheduling Algorithms

    Implementation - Data Structures

    A queue of processes is implemented by linking PCBs together using a linked list (with first and

    last node pointers)

    Since this projects queues are known to be short, priority is implemented by using priority

    queues, and PriorityInsert() function calls

    Different queues are used to represent different states of processes (Ready, Suspended) Self-release of CPU

    Internal signal

    Process completion

    Forced-release of CPU

    Time slot expired

    External signal

    Process ID

    Status

    Priority

    Next Process

  • 8/3/2019 Finals) (PDF)

    17/20

    Scheduling Algorithms

    Implementation - Progress

    Used an OO template in order to easily and

    efficiently implement any necessary queue

    Used structurally defined functions to simulatethe scheduler and dispatcher

    fill_poolQ(), get_tasks(src,dest), sort(queue)

    Implemented FCFS, RR and STCF RR was implemented to fairly compare schemes

    Theoretical work still needs to be done

    comparison and evaluation

  • 8/3/2019 Finals) (PDF)

    18/20

    Scheduling Algorithms

    Implementation - Issues

    The underlying interrupt system

    basically readies the task for a

    switch, but does not perform

    the switch Process switches are directly

    handled by the scheduler

    This causes a delay from the

    time of readiness to the time of

    the switch, which is nottolerated for, lets say, system

    exceptions

    The solution is to completely

    by-pass the scheduler (OS) and

    go directly to an ISR. [1]

    Each process is allocated its

    own private stack and

    workspace

    This is done to avoid differentprocesses overwriting each

    others data and code

    This is based on a strict process

    model, where all heavyweight

    processes do not shareresources

    Code that can be shared safely

    is called re-entrant code [1]

  • 8/3/2019 Finals) (PDF)

    19/20

    Scheduling Algorithms

    Implementation - Analysis

    Direct analysis

    Pick a task set and observe results

    Apply queueing theory to obtain results

    Multi-level feedback queue scheme

    Simulations of scheme implementations

    FCFS, RR, STCF

    Innovations and projections

    Lottery scheduling and own algorithm

  • 8/3/2019 Finals) (PDF)

    20/20

    Scheduling Algorithms

    References

    1)Cooling, J.E. Software Design for Real-Time Systems. Chapman &Hall, London, UK: 1995.

    2) Stallings, William. Operating Systems: Internals and DesignPrinciples. Upper Saddle River, NJ: Prentice Hall, 1998.

    3) http://www.cs.wisc.edu/~bart/537/lecturenotes/s11.html - viewed on

    03/24/2000

    4) Savitzky, Stephen. Real-Time Microprocessor Systems. Van Nostrand

    Reinhold Company, N.Y.: 1985.5) Undergraduate Operating System Course Notes (Ottawa University,

    1998)


Recommended