Docsity

Scheduling Methods in Operating Systems: FIFO, SJF, SRT, and Real-Time Scheduling, Study notes of Operating Systems

Toggle sidebar
bg1
1
COP4600 : Operating Systems Joohan Lee
COP 4600 (Sec 1): Operating Systems
Lecture 6
School of Computer Science
University of Central Florida
Instructor : Joohan Lee
http://www.cs.ucf.edu/~jlee/cop4600
COP4600 : Operating Systems Joohan Lee
Chapter 8 – Processor Scheduling
Outline
8.1 Introduction
8.2 Schedul ing Levels
8.3 Preempt ive vs. Nonpreemptive Scheduling
8.4 Priorities
8.5 Scheduling Objectives
8.6 Schedul ing Criteria
8.7 Schedul ing Algorithms
8.7.1 First-In-First-Out (FIFO) Scheduling
8.7.2 Round-Robin (RR) Scheduling
8.7.3 Shortest-Process-First (SPF) Scheduling
8.7.4 Highest-Response-Ratio-Next (HRRN) Scheduling
8.7.5 Shortest-Remaining-Time (SRT) Sche duling
8.7.6 Multilevel Feedback Queues
8.7.7 Fair Share Scheduling
8.8 Deadlin e Scheduling
8.9 Real-T ime Scheduling
8.10 Java Thread Scheduling
COP4600 : Operating Systems Joohan Lee
Objectives
• After reading this chapter, you should understand:
– the goals of processor scheduling.
– preemptive vs. nonpreemptive scheduling.
– the role of priorities in scheduling.
– scheduling criteria.
– common scheduling algorithms.
– the notions of deadline scheduling and real-time scheduling.
– Java thread scheduling.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Scheduling Methods in Operating Systems: FIFO, SJF, SRT, and Real-Time Scheduling and more Study notes Operating Systems in PDF only on Docsity!

COP4600 : Operating Systems Joohan Lee

COP 4600 (Sec 1): Operating Systems

Lecture 6

School of Computer Science University of Central Florida

Instructor : Joohan Lee [email protected]

http://www.cs.ucf.edu/~jlee/cop

COP4600 : Operating Systems Joohan Lee

Chapter 8 – Processor Scheduling

Outline 8.1 Introduction 8.2 Scheduling Levels 8.3 Preemptive vs. Nonpreemptive Scheduling 8.4 Priorities 8.5 Scheduling Objectives 8.6 Scheduling Criteria 8.7 Scheduling Algorithms 8.7.1 First-In-First-Out (FIFO) Scheduling 8.7.2 Round-Robin (RR) Scheduling 8.7.3 Shortest-Process-First (SPF) Scheduling 8.7.4 Highest-Response-Ratio-Next (HRRN) Scheduling 8.7.5 Shortest-Remaining-Time (SRT) Scheduling 8.7.6 Multilevel Feedback Queues 8.7.7 Fair Share Scheduling 8.8 Deadline Scheduling 8.9 Real-Time Scheduling 8.10 Java Thread Scheduling

COP4600 : Operating Systems Joohan Lee

Objectives

  • After reading this chapter, you should understand:
    • the goals of processor scheduling.
    • preemptive vs. nonpreemptive scheduling.
    • the role of priorities in scheduling.
    • scheduling criteria.
    • common scheduling algorithms.
    • the notions of deadline scheduling and real-time scheduling.
    • Java thread scheduling.

COP4600 : Operating Systems Joohan Lee

Process and Thread Scheduling

  • Process scheduling
    • Decision making policies to determine the order in which active processes should compete for the use of processors
  • Process dispatcher
    • The actual binding of a selected process to a processor
    • Remove the process from the ready queue, change its status, load the processor state
  • Jointly we refer to both components as the scheduler

COP4600 : Operating Systems Joohan Lee

Schedulers

  • Long-term scheduler (or job scheduler)
    • selects which processes should be brought into the ready queue.
    • (Caution) A process may have not been loaded into the memory yet
    • invoked very infrequently (second, minutes)
    • Degree of multiprogramming
    • Good process mix (I/O bound vs CPU bound)
  • Short-term scheduler (or CPU scheduler)
    • selects which process should be executed next and allocates CPU.
    • Schedule only those processes already in the memory
    • invoked very frequently (millisecond)
    • CPU utilization

COP4600 : Operating Systems Joohan Lee

Organization of Schedulers

  • Embedded
    • Called as a function at the end of kernel call
    • Runs as part of the calling process
    • Shared by the processes
    • May have several different OSs by having a group processes belong to different schedulers
  • Autonomous
    • A separate process
    • May have dedicated CPU on a multiprocessor for scheduling Æ preferable in multiprocessor or distributed systems
    • On single-processor, run at every quantum: scheduler and other processes alternate

COP4600 : Operating Systems Joohan Lee

Figure 8.1 Scheduling levels.

8.2 Scheduling Levels

COP4600 : Operating Systems Joohan Lee

8.3 Preemptive vs. Nonpreemptive

Scheduling

  • Preemptive processes
    • Can be removed from their current processor
    • Can lead to improved response times
    • Important for interactive environments
    • Preempted processes remain in memory
  • Nonpreemptive processes
    • Run until completion or until they yield control of a processor
    • Unimportant processes can block important ones indefinitely

COP4600 : Operating Systems Joohan Lee

8.4 Priorities

  • Static priorities
    • Priority assigned to a process does not change
    • Easy to implement
    • Low overhead
    • Not responsive to changes in environment
  • Dynamic priorities
    • Responsive to change
    • Promote smooth interactivity
    • Incur more overhead than static priorities
      • Justified by increased responsiveness

COP4600 : Operating Systems Joohan Lee

8.5 Scheduling Objectives

  • Different objectives depending on system
    • Maximize throughput
    • Maximize number of interactive processes receiving acceptable response times
    • Minimize resource utilization
    • Avoid indefinite postponement
    • Enforce priorities
    • Minimize overhead
    • Ensure predictability

COP4600 : Operating Systems Joohan Lee

8.5 Scheduling Objectives

  • Several goals common to most schedulers
    • Fairness
    • Predictability
    • Scalability

COP4600 : Operating Systems Joohan Lee

8.6 Scheduling Criteria

  • Processor-bound processes
    • Use all available processor time
  • I/O-bound
    • Generates an I/O request quickly and relinquishes processor
  • Batch processes
    • Contains work to be performed with no user interaction
  • Interactive processes
    • Requires frequent user input

COP4600 : Operating Systems Joohan Lee

Scheduling Methods

  • When is scheduler invoked?
    • Decision mode
      • Nonpreemptive
        • Scheduler called when process terminates or blocks
        • More economical
        • Not adequate for real-time and time-shared systems
      • Preemptive
        • Scheduler called periodically (quantum-oriented) or when system state changes (create or unblock)
        • More costly than non-preemptive » Process switching time » Additional logic in the scheduler » Possible swapping of programs and data between main memory and secondary memory

COP4600 : Operating Systems Joohan Lee

Scheduling Methods

  • Most OSs combine both strategies
    • Kernel routine: non-preemptive
    • Use process: preemptive
  • How does it select highest priority process?
    • Priority function: P = Priority(p)
      • For all active processes, evaluate priority functions
    • Arbitration rule: break ties when there is more than one process with the same priority

COP4600 : Operating Systems Joohan Lee

8.7 Scheduling Algorithms

  • Scheduling algorithms
    • Decide when and for how long each process runs
    • Make choices about
      • Preemptibility
      • Priority
      • Running time
      • Run-time-to-completion
      • fairness

COP4600 : Operating Systems Joohan Lee

Scheduling Algorithms

  • Problem Description
    • Two processes P1 and P
    • P1: arrives at 0, needs five CPU time units
    • P2: arrives at 2, needs two CPU time units

COP4600 : Operating Systems Joohan Lee

Scheduling Algorithms

  • FIFO (First Come First Out)
    • Criterion:
      • According to the arrival time (real-time r)
      • P = r
      • The earlier the arrival, the higher the priority
    • Non-preemptive

P

P

COP4600 : Operating Systems Joohan Lee

Scheduling Algorithms

  • SJF (Shortest Job First)
    • Criterion:
      • According to the total service time (t)
      • P = -t
      • The larger the value of t, the lower the priority
    • Non-preemptive

P2 P

COP4600 : Operating Systems Joohan Lee

Figure 8.2 First-in-first-out scheduling.

8.7.1 First-In-First-Out (FIFO)

Scheduling

COP4600 : Operating Systems Joohan Lee

8.7.2 Round-Robin (RR) Scheduling

  • Round-robin scheduling
    • Based on FIFO
    • Processes run only for a limited amount of time called a time slice or quantum
    • Preemptible
    • Requires the system to maintain several processes in memory to minimize overhead
    • Often used as part of more complex algorithms

COP4600 : Operating Systems Joohan Lee

Figure 8.3 Round-robin scheduling.

8.7.2 Round-Robin (RR) Scheduling

COP4600 : Operating Systems Joohan Lee

8.7.2 Round-Robin (RR) Scheduling

  • Selfish round-robin scheduling
    • Increases priority as process ages
    • Two queues
      • Active
      • Holding
    • Favors older processes to avoids unreasonable delays

COP4600 : Operating Systems Joohan Lee

8.7.2 Round-Robin (RR) Scheduling

  • Quantum size
    • Determines response time to interactive requests
    • Very large quantum size
      • Processes run for long periods
      • Degenerates to FIFO
    • Very small quantum size
      • System spends more time context switching than running processes
    • Middle-ground
      • Long enough for interactive processes to issue I/O request
      • Batch processes still get majority of processor time

COP4600 : Operating Systems Joohan Lee

8.7.3 Shortest-Process-First (SPF)

Scheduling

  • Scheduler selects process with smallest time to finish
    • Lower average wait time than FIFO
      • Reduces the number of waiting processes
    • Potentially large variance in wait times
    • Nonpreemptive
      • Results in slow response times to arriving interactive requests
    • Relies on estimates of time-to-completion
      • Can be inaccurate or falsified
    • Unsuitable for use in modern interactive systems

COP4600 : Operating Systems Joohan Lee

Priority Scheduling

  • Problem
    • Starvation
    • low priority processes may never execute.
    • (eg) When they shut down the IBM 7094 at MIT in 1973, they found a low-priority process that had been submitted in 1967 and had not yet been run
  • Solution
    • Aging – as time progresses increase the priority of the process.
    • Decrement the priority of a waiting process by 1 every 15 minutes

COP4600 : Operating Systems Joohan Lee

MLF (Multilevel Feedback)

  • Like ML, but priority changes dynamically
  • A process can move between the various queues
  • Every process enters at highest level n
  • Each level P prescribes maximum time t (^) P
  • t (^) P increases as P decreases
  • Typically:

t n = T (constant)

t (^) P = 2 × t (^) P+

COP4600 : Operating Systems Joohan Lee

MLF (Multilevel Feedback)

COP4600 : Operating Systems Joohan Lee

Example of Multilevel Feedback Queue

  • Three queues:
    • Q 0 – time quantum 8 milliseconds
    • Q 1 – time quantum 16 milliseconds
    • Q 2 – FCFS
  • Scheduling
    • A new job enters queue Q 0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q 1.
    • At Q 1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q 2.

COP4600 : Operating Systems Joohan Lee

Multilevel Feedback Queues

COP4600 : Operating Systems Joohan Lee

8.7.6 Multilevel Feedback Queues

  • Different processes have different needs
    • Short I/O-bound interactive processes should generally run before processor-bound batch processes
    • Behavior patterns not immediately obvious to the scheduler
  • Multilevel feedback queues
    • Arriving processes enter the highest-level queue and execute with higher priority than processes in lower queues
    • Long processes repeatedly descend into lower levels
      • Gives short processes and I/O-bound processes higher priority
      • Long processes will run when short and I/O-bound processes terminate
    • Processes in each queue are serviced using round-robin
      • Process entering a higher-level queue preempt running processes

COP4600 : Operating Systems Joohan Lee

Figure 8.5 Standard UNIX process scheduler. The scheduler grants the processor to users, each of whom may have many processes. (Property of AT&T Archives. Reprinted with permission of AT&T.)

8.7.7 Fair Share Scheduling

COP4600 : Operating Systems Joohan Lee

Figure 8.6 Fair share scheduler. The fair share scheduler divides system resource capacity into portions, which are then allocated by process schedulers assigned to various fair share groups. (Property of AT&T Archives. Reprinted with permission of AT&T.)

8.7.7 Fair Share Scheduling

COP4600 : Operating Systems Joohan Lee

8.8 Deadline Scheduling

  • Deadline scheduling
    • Process must complete by specific time
    • Used when results would be useless if not delivered on-time
    • Difficult to implement
      • Must plan resource requirements in advance
      • Incurs significant overhead
      • Service provided to other processes can degrade

COP4600 : Operating Systems Joohan Lee

8.9 Real-Time Scheduling

  • Real-time scheduling
    • Related to deadline scheduling
    • Processes have timing constraints
    • Also encompasses tasks that execute periodically
  • Two categories
    • Soft real-time scheduling
      • Does not guarantee that timing constraints will be met
      • For example, multimedia playback
    • Hard real-time scheduling
      • Timing constraints will always be met
      • Failure to meet deadline might have catastrophic results
      • For example, air traffic control

COP4600 : Operating Systems Joohan Lee

8.9 Real-Time Scheduling

  • Static real-time scheduling
    • Does not adjust priorities over time
    • Low overhead
    • Suitable for systems where conditions rarely change
      • Hard real-time schedulers
    • Rate-monotonic (RM) scheduling
      • Process priority increases monotonically with the frequency with which it must execute
    • Deadline RM scheduling
      • Useful for a process that has a deadline that is not equal to its period

COP4600 : Operating Systems Joohan Lee

8.9 Real-Time Scheduling

  • Dynamic real-time scheduling
    • Adjusts priorities in response to changing conditions
    • Can incur significant overhead, but must ensure that the overhead does not result in increased missed deadlines
    • Priorities are usually based on processes’ deadlines
      • Earliest-deadline-first (EDF)
        • Preemptive, always dispatch the process with the earliest deadline
      • Minimum-laxity-first
        • Similar to EDF, but bases priority on laxity, which is based on the process’s deadline and its remaining run-time-to-completion

COP4600 : Operating Systems Joohan Lee

8.10 Java Thread Scheduling

  • Java threading scheduler
    • Uses kernel-level threads if available
    • User-mode threads implement timeslicing
      • Each thread is allowed to execute for at most one quantum before preemption
    • Threads can yield to others of equal priority
      • Only necessary on nontimesliced systems
      • Threads waiting to run are called waiting, sleeping or blocked

COP4600 : Operating Systems Joohan Lee

Figure 8.7 Java thread priority scheduling.

8.10 Java Thread Scheduling

COP4600 : Operating Systems Joohan Lee

Comparison of Methods

  • FIFO, SJF, SRT
    • Developed primarily for batch processing systems
    • SJF and SRT are preferable to FIFO if the total service times known in that the shorter jobs are serviced first - Fast checkout line in the supermarket!
    • Reduced average turnaround time
      • The order in which process are executed has no effect on the total time to complete all processes
      • Depending on the scheduling policy, the turnaround time can be reduced
      • Average turnaround time
        • (r1+r2+…+rn)/n where ri = the real time for process I and n = total number of processes

COP4600 : Operating Systems Joohan Lee

Comparison of Methods

  • FIFO, SJF, SRT
    • FIFO simplest, SJF & SRT have better average turnaround times:
    • (eg) two processes, p1 and p p1: total service time t1 during its lifetime p2: total service time t2 during its lifetime assume that t1 < t2 and both arrive at the same time
    • SJF: p1 Æ p2 therefore, average turnaround time = (t1+(t1+t2))/
    • It’s the best performance in that the other scheduling leads to (t2+(t2+t1))/n

COP4600 : Operating Systems Joohan Lee

4 time units

2 time units 1 time unit

COP4600 : Operating Systems Joohan Lee

Comparison of Methods

Average Turnaround Time