cpu scheduling l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CPU Scheduling PowerPoint Presentation
Download Presentation
CPU Scheduling

Loading in 2 Seconds...

play fullscreen
1 / 29

CPU Scheduling - PowerPoint PPT Presentation


  • 135 Views
  • Uploaded on

CS423UG Operating Systems . CPU Scheduling. Indranil Gupta Lecture 5 Sep 2, 2005. Schedule for Today’s Lecture. Why Scheduling? Scheduling Levels Basic Scheduling Algorithm (FCFS). Oh, the Process!. What is a Process?

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CPU Scheduling' - magee


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
cpu scheduling

CS423UG Operating Systems

CPU Scheduling

Indranil Gupta

Lecture 5

Sep 2, 2005

schedule for today s lecture
Schedule for Today’s Lecture
  • Why Scheduling?
  • Scheduling Levels
  • Basic Scheduling Algorithm (FCFS)

CS 423UG - Operating Systems,Indranil Gupta

oh the process
Oh, the Process!
  • What is a Process?
    • It’s one executing instance of a “program”
    • Consists of code, data, heap, stack, PC, regs, and a little other information in the PCB
      • Process state, priority, accounting
      • Program counter, register variables, stack pointers, etc
      • Open files and devices
    • It can start/manipulate/kill other processes

CS 423UG - Operating Systems,Indranil Gupta

threads lightweight processes
Threads: Lightweight Processes
  • A thread is a single execution
    • Stack
    • Program counter
    • Registers
  • All threads within a process share resources
    • Address space
    • Text, data, heap
    • Open files, etc
  • Implementations of threads
    • User-level, Kernel-level, Hybrid, Pop-up

CS 423UG - Operating Systems,Indranil Gupta

scheduling
Scheduling
  • Deciding which process/thread should occupy a resource (CPU, disk, etc.)

(CPU (horsepower))

I want to ride it

Whose turn is it?

Process 2

Process 3

Process 1

CS 423UG - Operating Systems,Indranil Gupta

when to schedule
When to schedule?

“to schedule”=change the process that is in “running” state

Options for when to schedule:

  • A new process starts
  • The running process exits
  • The running process is blocked/makes a syscall
  • I/O interrupt received (some processes may now be ready)
  • Clock interrupt (every 10 milliseconds)

CS 423UG - Operating Systems,Indranil Gupta

preemptive vs non preemptive
Preemptive vs. Non-preemptive
  • Non-preemptive scheduling:
    • The running process keeps the CPU until it voluntarily gives up the CPU
      • process exits
      • switches to blocked state
      • 1and 4 only (no 3)
  • Preemptive scheduling:
    • The running process can be preempted and must release the CPU (can be forced to give up CPU)

4

Terminated

Running

1

3

Ready

Blocked

CS 423UG - Operating Systems,Indranil Gupta

what are objectives of scheduling
What are objectives of scheduling?

(CPU (horsepower))

I want to ride it

Whose turn is it?

Process 2

Process 3

Process 1

CS 423UG - Operating Systems,Indranil Gupta

scheduling objectives
Scheduling Objectives
  • Fairness (nobody cries)
  • Priority (ladies first)
  • Efficiency (make best use of equipment)
  • Encourage good behavior (good boy/girl)
  • Support heavy loads (degrade gracefully)
  • Adapt to different environments (interactive, real-time, multimedia)

CS 423UG - Operating Systems,Indranil Gupta

concretely performance metrics
Concretely: Performance Metrics
  • Efficiency: percentage of time a resource is being used
  • Throughput: # of processes that complete per unit time
  • Turnaround Time (also called elapse time)
    • (process finish time – process entry time) : could be > process’s own total running time (why?)
  • Waiting Time
    • total amount of time process waits (in ready state)
  • Response Time
    • amount of time from when a request was first submitted until first response is produced: useful for interactive processes
  • Others
    • Fairness
    • Policy Enforcement: seeing that stated policy is carried out
    • Proportionality: meet users' expectation
    • Meeting Deadlines: avoid losing data

CS 423UG - Operating Systems,Indranil Gupta

different systems different focuses
Different Systems, Different Focuses
  • For all
    • Fairness, policy enforcement, resource efficiency, resource balance
  • Batch Systems (e.g., supercomputers)
    • Max throughput, min turnaround time, max CPU utilization
  • Interactive Systems (e.g., PCs)
    • Min Response time, best proportionality
  • Real-Time Systems (e.g., Space Shuttle)
    • Predictability, meeting deadlines

CS 423UG - Operating Systems,Indranil Gupta

process profiles
Process Profiles
  • CPU – Bound
    • Time spent in I/O < Time spent computing in CPU
  • I/O – Bound
    • Time spent in I/O > Time spent computing in CPU
      • Process may spend time waiting for interrupts
  • Process Mix
    • Scheduling should balance load between I/O bound and CPU-bound processes
    • Ideal would be to run all equipment at 100% utilization but that would not necessarily be good for response time

CS 423UG - Operating Systems,Indranil Gupta

program behaviors considered in scheduling
Program Behaviors Considered in Scheduling

I/O

I/O

  • Is it I/O bound? Example?
  • Is it CPU bound? Example?
  • Batch or interactive environment
  • Urgency
  • Priority
  • Frequency of preemption
  • Frequency of page faults
  • How much execution time it has already received
  • How much execution time it needs to complete

I/O

compute

compute

CS 423UG - Operating Systems,Indranil Gupta

scheduling levels
Scheduling Levels

“Job”=Process

  • Long-term scheduler: Which jobs allowed to compete for the CPU and other resources
  • Medium-term scheduler: Which jobs to temporarily suspend or resume to smooth fluctuations in system load
  • Short-term scheduler: Assigning CPU to a ready process

P3 P5 P8 P10 P2

Ready Queue

(of processes)

CS 423UG - Operating Systems,Indranil Gupta

cpu scheduler
CPU Scheduler
  • Proc 1: 14 time units
  • Proc2: 8 time units
  • Proc3: 8 time units
  • Dispatcher

CPU

Dispatcher

Proc 1

Proc 10

Proc 2

Proc 11

Proc 3

Proc 12

Ready queue

Blocked queue

CS 423UG - Operating Systems,Indranil Gupta

dispatcher
Dispatcher
  • Gives the control of the CPU to the process that is awarded CPU by short-term scheduler
  • Functions:
    • switching context
    • switching back to user mode
    • jumping to the proper location in the user process
  • Dispatch Latency = delay of above operations
    • Needs to be fast

CS 423UG - Operating Systems,Indranil Gupta

single processor scheduling algorithms
Single Processor Scheduling Algorithms
  • Batch systems
    • First Come First Serve (FCFS)
    • Shortest Job First
  • Interactive Systems
    • Round Robin
    • Priority Scheduling
    • Multi Queue & Multi-level Feedback
    • Shortest process time
    • Guaranteed Scheduling
    • Lottery Scheduling
    • Fair Sharing Scheduling

CS 423UG - Operating Systems,Indranil Gupta

first come first serve fcfs
First Come First Serve (FCFS)
  • Process that requests the CPU FIRST is allocated the CPU FIRST
  • Called “FIFO”, Non-preemptive, Used

in Batch Systems

  • Real life analogy: Any ticket counter
  • Implementation: FIFO queues
    • A new process enters the tail of the queue
    • The scheduler selects from the head of the queue.
  • Performance Metric: Average Waiting Time (AWT)
  • Given Parameters:
    • Burst Time (in ms), Arrival Time and Order
    • Can be generalized to processes with alternate CPU and I/O bursts: blocking process goes to queue’s tail

CS 423UG - Operating Systems,Indranil Gupta

fcfs example
FCFS Example

The final schedule:

P1 (24)

P2 (3)

P3 (4)

24

27

0

P1 waiting time: 0-0

P2 waiting time: 24-3

P3 waiting time: 27-4

The average waiting time: (0+21+23)/3 = 14.667

CS 423UG - Operating Systems,Indranil Gupta

problems with fcfs
Problems with FCFS
  • Non-preemptive
  • Not optimal average waiting time (AWT)
  • Cannot utilize resources in parallel:
    • Suppose there is 1 CPU-bound process and many I/O-bound processes
    • Result: Convoy effect, low CPU and I/O Device utilization

CS 423UG - Operating Systems,Indranil Gupta

what are convoy effects
What are Convoy Effects?
  • Consider n-1 jobs in system that are I/O bound and 1 job that is CPU bound.
  • I/O bound jobs pass quickly through the ready queue and suspend themselves waiting for I/O.
  • CPU bound job arrives at head of queue and executes until complete.
  • I/O bound jobs rejoin ready queue and wait for CPU bound job to complete.
  • I/O devices idle until CPU bound job completes.
  • When CPU bound job completes, other processes rush to wait on I/O again.
  • CPU becomes idle.

CS 423UG - Operating Systems,Indranil Gupta

mathematical understanding of scheduling queuing theory
Mathematical Understanding of Scheduling: Queuing Theory

ARRIVAL RATE

 processes/sec

Server (one process at a

time)

CPU

Input Queue

SERVICE RATE

1/ sec

CS 423UG - Operating Systems,Indranil Gupta

queueing theory
Queueing Theory
  • Poisson arrival with  constant arrival rate (customers per unit time)
    • memoryless, each arrival is independent of previous arrivals
    • if  is time to next process arrival, for Poisson:

Probability( t ) = 1- e–t

CS 423UG - Operating Systems,Indranil Gupta

analysis of queueing behavior
Analysis of Queueing Behavior
  • Probability n customers arrive in time interval t is:

e–t tn/ n!

  • Server/CPU: Assume exponential service times (similar to Poisson):
    •  = (constant service rate) customers serviced per unit time
    • If ’ is time to execute current process, for Poisson:

Probability( ’t ) = 1- e–t

CS 423UG - Operating Systems,Indranil Gupta

a useful fact from queuing theory
A Useful Fact from Queuing Theory

CS 423UG - Operating Systems,Indranil Gupta

analysis of fifo
Analysis of FIFO
  • Server Utilization: ρ = λ/μ
  • Time in System : W = 1/(μ-λ)
  • Time in Queue: Wq = ρ/(μ-λ)
  • Number in Queue (Little): Lq = ρ2/(1-ρ)

CS 423UG - Operating Systems,Indranil Gupta

work out
Work-Out
  • Example scheduler system
    • Arrival 2 jobs/sec
    • Service 3 jobs/sec
    • FIFO queue
    • Utilization ?
    • Time in system ?
    • Time in queue ?
    • Length of queue ?
  • Server Utilization: ρ = λ/μ
  • Time in System : W = 1/(μ-λ)
  • Time in Queue: Wq = ρ/(μ-λ)
  • Number in Queue (Little): Lq = ρ2/(1-ρ)

CS 423UG - Operating Systems,Indranil Gupta

work out28
Work-Out
  • Example scheduler system
    • Arrival 2 jobs/sec
    • Service 3 jobs/sec
    • FIFO queue
    • Utilization 66.66%
    • Time in system 1 sec
    • Time in queue .6666 sec
    • Length of queue 1.3333
  • Server Utilization: ρ = λ/μ
  • Time in System : W = 1/(μ-λ)
  • Time in Queue: Wq = ρ/(μ-λ)
  • Number in Queue (Little): Lq = ρ2/(1-ρ)

CS 423UG - Operating Systems,Indranil Gupta

summary
Summary
  • Scheduler: long-term, medium-term, short-term
  • FCFS
  • Queuing theory
  • Reading for this Lecture was: 2.5.0-2.5.2
  • Next Monday: no lecture!
  • Reading for next Wed lecture: 2.5.3-2.5.6
  • MP1 and HW1 ongoing
  • Have a good break!

CS 423UG - Operating Systems,Indranil Gupta