View on GitHub

Notes

reference notes

SCHEDULING OBJECTIVES

Processor Scheduling Aims

System objectives: performance

  1. Low response time (fast response)
    • Response Time: Time elapse from the submission of a request to the beginning of the response.
    • Process needs to run as soon as it enters the system
  2. High Throughput:
    • Throughput: Number of processes completed per unit time
    • Try getting as much process/jobs done at a time
  3. Processor efficiency:
    • High processor utilization (min processor idle time)
    • Processor is always doing task

Scheduling Types

The key to multiprogramming is scheduling.

Four types of scheduling typically involves:

It directly relates to the PROCESS STATES

Long-term scheduling( job scheduler):

SCHEDULING FUNCTIONS AND PROCESS STATE TRANSITIONS

Long-Term Scheduler

s

Creates processes from the queue when it can, but must decide:

Medium-Term Scheduler

s

Short-Term Scheduler

s

Examples:

Nesting of Scheduling Functions

s

SCHEDULING POLICIES AND ALGORITHMS

Alternative Scheduling Policies

s

Selection Function

Determines which process, among ready processes, is selected next for execution

May be based on:

  1. Priority
  2. Resource requirements
  3. The execution characteristics of the process
    • if based on execution characteristics then important quantities are:
      • w = time spent in system so far, waiting
      • e = time spent in execution so far
      • s = total service time required by the process, including e; generally, this quantity must be estimated or supplied by the user

Decision Mode

Specifies the instants in time at which the selection function is exercised

Two categories:

  1. Nonpreemptive
    • once a process is in the RUNNING STATE, it will continue to execute until
      1. it terminates or
      2. blocks itself to wait for I/O, or request some OS service
  2. Preemptive
    • currently running process may be interrupted and moved to ready state by the OS
    • preemption may occur when:
      1. A new process arrives
      2. An interrupt occurs that places a blocked process in the Ready state
      3. Periodically

Scheduling Criteria

Different scheduling algorithms have different properties and may favor one class of processes over another.

The characteristics used for comparison can make substantial difference in the determination of the best algorithm.

The criteria are:

  1. CPU utilization - keep CPU as busy as possible.
  2. Throughput - number of processes that complete their execution per time unit.
  3. Turnaround time - amount of time to execute a particular process.
  4. Waiting time - amount of time a process has been waiting in the ready queue
  5. Response time - amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

Scheduling Policies

We will use these set of processes as a running example

Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

Policies:

  1. First Come First Serve (FCFS)
  2. Shortest Process Next (SPN)
  3. Highest Response Ratio Next (HRRN)
  4. Shortest Remaining Time (SRT)
  5. Round Robin (RR)
  6. Feedback

Non-Preemptive Policies

First-Come-First-Served (FCFS)

Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

Waiting time = start execution time – arrival time

Process A -> 0 - 0 = 0
Process B -> 3 - 2 = 1
Process C -> 9 - 4 = 5
Process D -> 13 - 6 = 7
Process E -> 18 - 8 = 10
                        Total waiting time
Average Waiting Time = --------------------
                        Number of processes

= 0+1+5+7+10
  -------------
        5

= 4.6ms

Performs much better for long processes than short ones

Tends to favor processor-bound processes (mostly uses processor) over I/O-bound processes (mostly uses I/O)

  1. When a processor-bound process is running, all of the I/O bound processes must wait.
  2. Some of these may be in I/O queues (blocked state) but may move back to the ready queue while the processor-bound process is executing.
  3. At this point, most or all of the I/O devices may be idle, even though there is potentially work for them to do.
  4. When the currently running process leaves the Running state, the ready I/Obound processes quickly move through the Running state and become blocked on I/O events.
  5. If the processor-bound process is also blocked, the processor becomes idle.
  6. Thus, FCFS may result in inefficient use of both the processor and the I/O devices.

Shortest Process Next (SPN)

Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

Waiting time = total of (start execution time – arrival time)

Process A -> 0
Process B -> 3 - 2 = 1
Process C -> 11 - 4 = 7
Process D -> 15 - 6 = 9
Process E -> 9 - 8 = 1

s

                        Total waiting time
Average Waiting Time = --------------------
                        Number of processes
= 1+7+9+1
  -------------
        5

= 3.6ms

One difficulty is the need to know, or at least estimate, the required processing time of each process

If the programmer’s estimate is substantially under the actual running time, the system may abort the job

Highest Response Ratio Next (HRRN)

Calculate the time spent waiting:

Calculate the Ration using the above formula:

Preemptive Policies

Shortest Remaining Time (SRT)

Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

s see how as soon as proccess C arrived its given immediate control

Waiting time = total of (start execution time – arrival time)

Process A -> 0
Process B -> (3 - 2) + (10-4) = 7
Process C -> 4-4 = 0
Process D -> 15-6 = 9
Process E -> 8-8 = 0

average wt = 3.2ms

Round Robin

(q=1)

Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

s

Running Ready A,A,B (interrupts A), A (waits in the queue), A (interrupts B), B (waits in the queue), B, C (interrupts B), B (waits in the queue), B (interrupts C), D (arrive), C (waits in the queue), D (interrupts B), B (waits in the C (interrupts D), queue), D (waits in the queue), B (interrupts C), C (waits in the queue), E (arrive), E (interrupts B) B (waits in the queue),

Waiting time = total of (start execution time – arrival time)

Process A -> 3-2 = 1
Process B -> (4-3) + (6-5) + (9-7) + (13-10)+ (17-14) = 10
Process C -> (5-4) + (8-6) + (12-9) + (16-13)= 9
Process D -> (7-6) + (11-8) + (15-12) + (18-16) = 9
Process E -> (10-8) + (14-11) = 5

Feedback

Process Arrival Time Service Time
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

s

Summary

The operating system must make three types of scheduling decisions with respect to the execution of processes:

  1. Long-term – determines when new processes are admitted to the system
  2. Medium-term – part of the swapping function and determines when a program is brought into main memory so that it may be executed
  3. Short-term – determines which ready process will be executed next by the processor