Docsity

CPU Scheduling in Operating Systems: Types, Concepts, and Algorithms, Study notes of Computer Science

Partial preview of the text

Download CPU Scheduling in Operating Systems: Types, Concepts, and Algorithms and more Study notes Computer Science in PDF only on Docsity!

Operating SystemsOperating Systems

CMPSC 473 CMPSC 473

CPU Scheduling CPU Scheduling

February 12, 2008 - Lecture February 12, 2008 - Lecture 88

Instructor: Trent Jaeger Instructor: Trent Jaeger

  • Last class:
    • Threads
  • Today:
    • CPU Scheduling

Resources Types

  • Memory : Allocate portion of finite resource
    • Virtual memory tries to make this appear infinite
    • Physical resources are limited
  • I/O : Allocate portion of finite resource and time with

resource

  • Store information on disk
  • A time slot to store that information
  • CPU : Allocate time slot with resource
  • A time slot to run instructions
  • We will focus on CPU scheduling in the section

CPU Scheduling Examples

• Single process view

  • GUI request
    • Click on the mouse
  • Scientific computation
    • Long-running, but want to complete ASAP

• System view

  • Get as many tasks done as quickly as possible
  • Minimize waiting time for processes
  • Utilize CPU fully

Scheduling Problem

  • Choose the ready/running process to run at any time
    • Maximize “performance”
  • Model/estimate “performance” as a function
    • System performance of scheduling each process
      • f(process) = y
    • What are some choices for f(process)?
  • Choose the process with the best y
    • Estimating overall performance is intractable
      • E.g., scheduling so all tasks are completed as soon as possible

Scheduling Concepts

Preemptive vs Non-

preemptive

  • Can we reschedule a process that is actively running?
    • If so, we have a preemptive scheduler
    • If not, we have a non-preemptive scheduler
  • Suppose a process becomes ready
    • E.g., new process is created or it is no longer waiting
  • It may be better to schedule this process
    • So, we preempt the running process
  • In what ways could the new process be better?

Bursts

• A process runs in CPU and I/O Bursts

  • Run instructions (CPU Burst)
  • Wait for I/O (I/O Burst)

• Scheduling is aided by knowing the length of

these bursts

  • More later…

CPU Burst Duration

Dispatcher

  • Dispatcher module gives control of the CPU to the

process selected by the short-term scheduler; this

involves:

  • Switching context
  • Switching to user mode
  • Jumping to the proper location in the user program to restart that program
  • Dispatch latency – time it takes for the dispatcher to stop

one process and start another running

Scheduling Criteria

  • Utilization/efficiency: keep the CPU busy 100% of the time with useful work
  • Throughput: maximize the number of jobs processed per hour.
  • Turnaround time: from the time of submission to the time of completion.
  • Waiting time: Sum of times spent (in Ready qqueue) waiting to be scheduled on the CPU.
  • Response Time: time from submission till the first response is produced (mainly for interactive jobs)
  • Fairness: make sure each process gets a fair share of the CPU

Scheduling Algorithms

First-Come, First-Served (FCFS) Process Burst Time P 1 24 P 2 3 P 3 3

  • Suppose that the processes arrive in the order: P 1 , P 2 , P 3 The Gantt Chart for the schedule is:
  • Waiting time for P 1 = 0; P 2 = 24; P 3 = 27
  • Average waiting time: (0 + 24 + 27)/3 = 17 P 1 P 2 P 3 0 24 27 30

Reducing Waiting Time

Suppose that the processes arrive in the order P 2 , P 3 , P 1

  • The Gantt chart for the schedule is:
  • Waiting time for P 1 = 6 ; P 2 = 0 ; P 3 = 3
  • Average waiting time: (6 + 0 + 3)/3 = 3
  • Much better than previous case
  • Convoy effect short process behind long process P 2 P 3 P 1 0 3 6 30