CS 2200 - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

CS 2200

Description:

Phone a friend? Assume same as last burst? Weighted history. Priority ... Assume all arrived at T = 0 (in order shown)! P1. P2. P3. P5. P4. Preemptive Algorithms ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 51
Provided by: BillL161
Category:
Tags: at | phones

less

Transcript and Presenter's Notes

Title: CS 2200


1
CS 2200
  • Presentation 8
  • Process Issues
  • Scheduling Algorithms

2
Where are we?
Control
Datapath
Timer
I/O
I/O
INT ACK
INT REQ
3
Once upon a time...
  • Computers did one thing at a time.

4
Once upon a time...
  • Computers did one thing at a time.
  • There is a big difference between the speed of
    the processor and speed of the outside world.

Processors Nanoseconds
Peripherals Micro-Milliseconds
People Seconds-Long lazy afternoons
5
Once upon a time...
  • Computers did one thing at a time.
  • There is a big difference between speed on the
    processor and speed of the outside world.
  • So, in the interests of efficiency, systems were
    developed to allow the processor to work on may
    jobs concurrently.

6
Processor Scheduling
  • Why do we need it?
  • Objective
  • Have some job running at all times

7
Environment
  • Specific goals depend on system environment
  • dedicated
  • multiprogramming
  • interactive or time-sharing

8
Definitions
  • Program
  • Code
  • Passive
  • Resides on disk
  • Process
  • Code
  • Active
  • Current Activity
  • PC
  • Stack
  • Registers
  • Data
  • Memory (and Disk)
  • Resources

Basic Unit of Scheduling
9
Process States
New
Terminated
Ready
Running
Waiting
10
What do we need to keep track of?
11
Process Control Block
Pointer
Process State
Process Number
Program Counter
Registers
Scheduling Info
Memory Limits
I/O Status Info
Accounting Info
12
Process Control Block
  • enum state_type new, ready, running, waiting,

  • halted
  • typedef struct _control_block
  • struct control_block next_pcb
  • enum state_type state
  • int pid
  • address PC
  • int reg_fileNumRegs
  • int priority
  • address page_table
  • ...
  • control_block

13
Scheduling First Principles
  • What is a scheduler?
  • Program run by OS
  • Decides which processes should be in what state
  • Where are these processes?
  • In memory
  • Abstracted in process control blocks
  • Managed with a series of queues

14
Question
  • Assume acme is a single CPU machine and you write
    a program in C.
  • Are the actual instructions that your C program
    produced run on the processor (choice 1) or is
    there some kind of OS that runs your program to
    allow for protection of the system (choice 2) or
    thinking about things like this makes your head
    hurt (choice 7)?

15
Interrupts
16
Question?
  • Is the operating system running all the time?
  • Yes
  • No
  • Depends
  • Add a bit

17
Scheduling First Principles
  • How do we switch from one running job to another?
  • Context switch
  • Move all state info from job to be context
    switched out into PCB.
  • Move all state info from job to be context
    switched in from PCB into registers, PC etc.
  • Typical time 1?sec - 1 ms (Hardware dependent)
  • Performed by dispatcher

18
Types of Schedulers
  • Short term
  • CPU Scheduler
  • Selects from ready-to-run processes
  • Runs very frequently (every few milliseconds)
  • Must be quick/small
  • Timesharing
  • Long term scheduler
  • Controls degree of multiprogramming
  • Number of processes in memory
  • Must balance between CPU-bound and I/O-bound
    processes

19
Bound?
  • CPU Bound
  • Compute intensive
  • Generates I/O Requests Infrequently
  • I/O Bound
  • Spends most of its time doing I/O

20
CPU-I/O Burst Cycle
Compute
Wait for I/O
Compute Bound
I/O Bound
21
Types of schedulers
  • May also have Medium term scheduler
  • Reduce thrashing
  • Dispatcher
  • Transfer control to a selected process
  • Switches context
  • Switches to user mode
  • Jumps to proper starting point.

22
Process Scheduling
23
Algorithms
  • timer interrupt
  • save context and enqueue in ready queue
  • goto select
  • I/O request
  • save context and enqueue in device queue
  • goto select
  • I/O completion
  • move context from device to ready queue
  • termination
  • free context
  • goto select
  • select
  • get head of queue
  • set timer
  • dispatch

24
Non-Preemptive Scheduling
Long Term Scheduler sending jobs in
Process has control of CPU until it gives it up
voluntarily
CPU
Ready Queue
I/O
I/O Request
I/O Queue
Time Slice Expired
Child Executes
Fork a Child
Wait for an Interrupt
Interrupt Occurs
25
Preemptive Scheduling
Long Term Scheduler sending jobs in
Processes may be forced to give up CPU.
CPU
Ready Queue
I/O
I/O Request
I/O Queue
Time Slice Expired
Child Executes
Fork a Child
Wait for an Interrupt
Interrupt Occurs
26
Forking
  • Technique used to start up a process
  • System call fork()
  • Essentially duplicates process creating a child

Parent
x fork()
Parent
Child
x child pid
x 0
27
Questions?
28
Scheduling Algorithms
29
Scheduling Algorithms
  • Metrics
  • CPU utilization ()
  • Throughput
  • Processes completed per unit time
  • Turnaround time
  • Submission to completion
  • Waiting time
  • Time in ready queue
  • Response time
  • Interactive systems

30
Consider a copying machine
31
Scheduling Algorithms
  • First-Come, First-Served
  • Shortest-Job-First
  • Priority
  • Round-Robin
  • Multilevel Queue
  • Multilevel Feedback Queue
  • Algorithm Evaluation

32
First-Come, First-Served
  • Non-preemptive
  • Process has to voluntarily relinquish by
    terminating or by making a blocking system call
  • Intrinsic property used Arrival time
  • Expected performance
  • No starvation
  • Variance in turnaround time
  • Convoy effect CPU followed by I/O bursts
  • gt Poor utilization

33
Convoy Effect
CPU
Ready Queue
IOB
IOB
IOB
CPUB
I/O
I/O Request
I/O Queue
CPU is running CPUB while I/O Bound jobs wait.
34
Convoy Effect
CPU
Ready Queue
IOB
IOB
I/O
I/O Request
I/O Queue
IOB
CPUB
CPUB does small amount of I/O
35
Convoy Effect
CPU
Ready Queue
CPUB
IOB
I/O
I/O Request
I/O Queue
IOB
IOB
I/O Bound jobs take very small amount of CPU
time, do some I/O
36
Convoy Effect
CPU
Ready Queue
IOB
IOB
CPUB
IOB
I/O
I/O Request
I/O Queue
But most of the time I/O Bound jobs are waiting
in ready queue
37
First-Come, First-Served
Process
Burst Time
P1
24
P2
3
P3
3
Start
P1
P3
P2
  • average waiting time ?
  • 0) 10ms
  • 17ms
  • 30 ms

38
First-Come, First-Served
Process
Burst Time
P1
24
P2
3
P3
3
Start
P1
P3
P2
average waiting time (0 24 27)/3 17 ms
P3
P2
P1
average waiting time (0 3 6)/3 3 ms
39
Shortest-Job-First
  • Non-preemptive
  • Better response for short jobs
  • Provably optimal
  • min avg. waiting time for a pool of jobs
  • Intrinsic property CPU burst time required
  • How to know this?
  • Ask the user?
  • Phone a friend?
  • Assume same as last burst?
  • Weighted history

40
Priority
  • Extrinsic property Associate priority with each
    process
  • SJF is a special case of this where
  • p 1/burst-time
  • One queue for each priority level
  • FCFS within each level
  • Problem with priority?
  • Solution?
  • Increase priority with aging

41
Priority Scheme
  • 15 Emergency 10.0 50.00
  • 14 Rush 10.0
  • 13 Rush systems n/a
  • 12 Friends of Governor n/a
  • 11 Rich alumni n/a
  • 10 Systems n/a
  • 9 Aged High 1.5
  • 8 High 1.5
  • 7 Aged Normal 1.0
  • 6 Normal 1.0
  • 5 Aged Overnight 0.5
  • 4 Overnight 0.5
  • 3 Aged Background 0.3
  • 2 Background 0.3
  • 1 Idle 0.1
  • 0 Hold n/a

42
Priority Scheduling
Process
Priority
Burst Time
P1
3
7
P2
1
1
P3
3
2
P4
4
1
P5
2
5
Assume all arrived at T 0 (in order shown)!
P1
P2
P3
P5
P4
43
Preemptive Algorithms
  • FCFS intrinsically non-preemptive
  • SJF and Priority algorithms can be made
    preemptive
  • How?
  • SJF Shortest remaining time first
  • Priority
  • Scheduler for time-sharing systems
  • Preemptive or non-preemptive?

44
Round-Robin
  • Preemptive
  • Good for time-sharing systems
  • When to preempt?
  • Processor assigned in time quantum or time
    slice units (q)
  • FCFS is a special case of RR
  • q infinity
  • Processor sharing
  • q 1?sec
  • Appears as though every process is on a processor
    running at speed 1/n.
  • Balancing q with context switch time

45
Round-Robin Example
Process
Burst Time
P1
24
P2
3
P3
3
Assume q 4...
2
1
3
1
1
1
1
1
46
Multilevel Queues
  • Partition Ready Queue
  • Each queue has its own scheduling algorithm
  • E.g. foreground (interactive, RR) and background
    (batch, FCFS) queues
  • Approaches
  • Higher queues have absolute priority over lower
    level queues OR
  • Time slice between the queues

47
Multilevel Feedback Queues
  • Add feedback to the queues
  • Why?
  • Adjust priority dynamically
  • Move jobs between the queues

Quantum 8
Quantum 16
FCFS
48
Evaluation
  • Modeling
  • Deterministic - Requires exact numbers
  • Queueing - Uses distribution of bursts
  • Simulation
  • Create software models of systems.
  • Lots of work
  • Very time consuming
  • Actual implementation test
  • Cost
  • May change behavior

49
Questions?
50
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com