Preemptive Scheduling - PowerPoint PPT Presentation

About This Presentation
Title:

Preemptive Scheduling

Description:

while loop example from last time. Going from randVal = 9 to randVal = 0 may take ... Lamport's paper added to readings. Project 4 stripped down from last year ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 22
Provided by: int655
Category:

less

Transcript and Presenter's Notes

Title: Preemptive Scheduling


1
Preemptive Scheduling
  • Vivek Pai / Kai Li
  • Princeton University

2
Errata
  • while loop example from last time
  • Going from randVal 9 to randVal 0 may take
    loop overhead
  • So, its not really guaranteed to be random

3
Mechanics
  • Lamports paper added to readings
  • Project 4 stripped down from last year
  • People are hiring good news

4
Overview for Today
  • Wrap up swapping
  • Move on to pre-emptive scheduling

5
Job Swapping
Swap in
Swap out
Partially executed swapped-out processes
Ready Queue
CPU
Terminate
I/O Waiting queues
I/O
6
Add Job Swapping toState Transition Diagram
Swap out
Swap
Terminate (call scheduler)
Running
Scheduler dispatch
Block for resource (call scheduler)
Swap in
Yield (call scheduler)
Create a process
Ready
Blocked
Resource becomes available (move to ready queue)
7
Think About Swapping
  • Is swapping
  • Necessary
  • Desirable
  • Good
  • Ideal
  • Things to consider
  • Performance
  • Complexity
  • Efficiency

8
The Hello/Goodbye Server
  • Server Hello
  • User Hello
  • Server Drink Slurm! (ka-ching!)
  • User Goodbye
  • Server Goodbye

9
Life is Simple Until
  • Hello,
  • My name is Bill Gates. Please try out my new
    Hello/Goodbye Server and Ill give you a
    million dollars and a new cat. Tell your friends.
  • I wuv you,
  • Bill Gates

10
You Have to Fix It
  • accept new connection say hello
  • wait for hello print advertising message
  • wait for goodbye, say goodbye
  • close connection

11
Whats the Simplest Option?
  • While (1)
  • accept new connection
  • fork new process
  • let process handle connection
  • Drawback lots of process creation/deletion

12
Can We Reduce Forks?
  • At program launch, fork some number
  • While (1)
  • accept
  • wait for hello
  • wait for goodbye
  • close
  • Note wait implicit yield

13
But What If We Do More
  • While (1)
  • accept
  • wait for hello
  • perform possibly unbounded calculation
  • wait for goodbye
  • close
  • Problem when do we yield?

14
Signals and Interrupts
  • Both are asynchronous
  • Used to notify system of event occurrence
  • Signal delivered by OS to process
  • Interrupt delivered by hardware to OS
  • Some overlap/interaction? Definitely
  • Examples?
  • Code tries executing divide-by-zero
  • User disconnects (hangs up)

15
I/O and Timer Interrupts
  • Why
  • Timer interrupt to do CPU management
  • Asynchronous I/O to overlap with computation
  • Interrupt
  • Between instructions
  • Within an instruction
  • Enable and disable

CPU
Memory
Interrupt
16
Using Interrupts For Scheduling
  • Timer interrupt
  • Generated by hardware
  • Assume changing requires privilege
  • Delivered to the OS
  • Main idea
  • Before moving process to running, set timer
  • If process yields/blocks, clear timer
  • Timer expires? Go to scheduler

17
Scheduling Considerations
  • Timer granularity
  • Finer timers more responsive
  • Coarse timers more efficient
  • Accounting
  • Cheap
  • Accurate
  • Fair consider I/O versus CPU applications

18
Preemptive Scheduling
Terminate (call scheduler)
Running
Scheduler dispatch
Block for resource (call scheduler)
Yield, Timer Interrupt (call scheduler)
Create
Ready
Blocked
I/O completion interrupt (move to ready queue)
19
No Control Over Yielding
  • Reasons for yielding
  • Timer goes off
  • Higher-priority interrupt occurs
  • Higher-priority process becomes ready
  • Some unintentional block (e.g. page fault)

20
Atomic Pieces of Code
  • Example bank transaction
  • Read account balance
  • Add/subtract money
  • Write account balance
  • Problem what happens when two transactions are
    being posted to the same account?

21
Next Time
  • Atomic pieces known as critical sections
  • Very common in concurrent/parallel programming
  • Must share memory
  • Possible via forked processes
  • Default via threads
  • Cover some scheduling policies
Write a Comment
User Comments (0)
About PowerShow.com