Tutorial 4 Scheduling Why do we need scheduling

  • Slides: 14
Download presentation
Tutorial 4 Scheduling

Tutorial 4 Scheduling

Why do we need scheduling? • To manage processes according to requirements of a

Why do we need scheduling? • To manage processes according to requirements of a system, like: – User responsiveness or – Throughput • Performance of a scheduler is determined mainly by: – Context switch time – Scheduling policy

1, 2, 3, 4, 5, 6, Context Switch! • Switching from one process running

1, 2, 3, 4, 5, 6, Context Switch! • Switching from one process running on the CPU to another process • Saves all the registers of outgoing process (to memory), then loads all the registers of incoming process (from memory) • Can be time-costly; mostly hardwaredependent

Scheduling • The mechanism that determines when the CPU will be allocated to processes,

Scheduling • The mechanism that determines when the CPU will be allocated to processes, and in what order • Two classes of scheduling strategies: – Nonpreemptive (aka Batch) – Preemptive

Non-preemptive policies • Allow any process to run to completion once it has been

Non-preemptive policies • Allow any process to run to completion once it has been allocated to the CPU. Current process does not get interrupted. • Some examples: – First Come First Serve (FCFS) – Shortest Job Next (SJN) – Priority scheduling – Deadline scheduling

Preemptive policies • Allow another process to interrupt current process if: – It has

Preemptive policies • Allow another process to interrupt current process if: – It has a higher priority – The time quantum has elapsed • Some examples: – Round Robin – Multiple-level Queues

Scheduling examples • Given three threads, their execution times and I/O needs, apply scheduling

Scheduling examples • Given three threads, their execution times and I/O needs, apply scheduling policies • Threads are placed on ready queue in order: T 1, T 2 then T 3 * Specific to Round Robin: – Time Quantum of 3 ms – Context switch time considered negligible in this example

First Come First Serve Thread CPU 1 st I/O 2 nd I/O T 1

First Come First Serve Thread CPU 1 st I/O 2 nd I/O T 1 10 ms n/a T 2 15 ms at 2 ms for 5 ms n/a T 3 12 ms at 4 ms for 2 ms at 8 ms for 2 ms 1 CPU: 0 I/O: 5 2 10 3 2 15 2 20 3 3 25 30 3 35 3 40

Shortest Job First (Nonpreemptive) Thread CPU 1 st I/O 2 nd I/O T 1

Shortest Job First (Nonpreemptive) Thread CPU 1 st I/O 2 nd I/O T 1 10 ms n/a T 2 15 ms at 2 ms for 5 ms n/a T 3 12 ms at 4 ms for 2 ms at 8 ms for 2 ms 1 CPU: 0 I/O: 5 3 10 2 3 15 3 2 20 2 25 3 3 30 35 40

Shortest Job First (Preemptive) Thread CPU 1 st I/O 2 nd I/O T 1

Shortest Job First (Preemptive) Thread CPU 1 st I/O 2 nd I/O T 1 10 ms n/a T 2 15 ms at 2 ms for 5 ms n/a T 3 12 ms at 4 ms for 2 ms at 8 ms for 2 ms 1 CPU: 0 I/O: 5 3 10 2 3 15 3 2 20 2 3 25 3 2 30 35 40

Priority (Preemptive) Thread Prio CPU 1 st I/O 2 nd I/O T 1 2

Priority (Preemptive) Thread Prio CPU 1 st I/O 2 nd I/O T 1 2 10 ms n/a T 2 3 15 ms at 2 ms for 5 ms n/a T 3 1 12 ms at 4 ms for 2 ms at 8 ms for 2 ms 3 CPU: 0 I/O: 1 5 3 3 1 10 3 15 3 1 20 2 2 25 30 2 35 40

Round Robin Thread CPU 1 st I/O 2 nd I/O T 1 10 ms

Round Robin Thread CPU 1 st I/O 2 nd I/O T 1 10 ms n/a T 2 15 ms at 2 ms for 5 ms n/a T 3 12 ms at 4 ms for 2 ms at 8 ms for 2 ms 3 1 CPU: 0 I/O: 2 3 1 5 13 2 10 2 1 15 3 3 20 2 32 2 25 3 30 3 2 35 40

Recapping Scheduling in Java 1. 2. 1 and prior (“green”) threads: • Threads are

Recapping Scheduling in Java 1. 2. 1 and prior (“green”) threads: • Threads are managed by Java VM • One thread runs at a time • Thread is only taken off the CPU when: – it yields – it blocks (on a resource) – it exits – a higher priority thread becomes runnable (not always)

New-Style Scheduling in Java Post-1. 2. 1 versions of Java: • Threads are managed

New-Style Scheduling in Java Post-1. 2. 1 versions of Java: • Threads are managed by the host OS • Allows multiple threads to run “concurrently” • Thread is taken off the CPU as in previous versions, but also – when its time quantum expires (if supported by OS)