Operating System Concepts - PowerPoint PPT Presentation

1 / 61
About This Presentation
Title:

Operating System Concepts

Description:

Operating System Concepts Ku-Yaw Chang canseco_at_mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University – PowerPoint PPT presentation

Number of Views:153
Avg rating:3.0/5.0
Slides: 62
Provided by: IBM7185
Category:

less

Transcript and Presenter's Notes

Title: Operating System Concepts


1
Operating System Concepts
  • Ku-Yaw Chang
  • canseco_at_mail.dyu.edu.tw
  • Assistant Professor, Department of Computer
    Science and Information Engineering
  • Da-Yeh University

2
Chapter 6 CPU Scheduling
  • CPU scheduling
  • The basis of multiprogrammed OSs
  • Make the computer more production
  • Switch the CPU among processes
  • We introduce
  • The basic scheduling concepts
  • Several different CPU-scheduling algorithms
  • Selecting an algorithm for a particular system

3
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

4
6.1 Basic Concepts
  • Several processes are kept in memory at one time
  • When a process has to wait, the OS takes the CPU
    away from that process, and gives the CPU to
    another process.
  • Almost all computer resources are scheduled
    before use.

5
6.1.1 CPU-I/O Burst Cycle
  • Observed property of processes
  • Process execution consists of a cycle of
  • CPU execution
  • I/O wait
  • Process execution begins with a CPU burst.
  • That is followed by an I/O burst, then another
    CPU burst, then another I/O burst, and so on.

6
Alternating sequence ofCPU and I/O bursts
7
Histogram of CPU-burst times
8
6.1.1 CPU-I/O Burst Cycle
  • Measure CPU bursts
  • An I/O bound program
  • Many short CPU bursts
  • A CPU bound program
  • A few very long CPU bursts
  • Help select an appropriate CPU-scheduling
    algorithm

9
6.1.2 CPU Scheduler
  • Whenever the CPU becomes idle
  • Select one of the processes in the ready queue to
    be executed
  • Carried out by the short-term scheduler, also
    called CPU scheduler
  • A ready queue may be implemented as
  • A FIFO queue
  • A priority queue
  • A tree
  • An unordered linked list

10
6.1.3 Preemptive Scheduling
  • CPU scheduling decisions take place when a
    process
  • Switches from running to waiting state
  • Switches from running to ready state
  • Switches from waiting to ready
  • Terminates
  • Scheduling only under 1 and 4 is nonpreemptive
  • Otherwise is preemptive
  • Incur a cost

11
6.1.4 Dispatcher
  • Dispatcher module gives control of the CPU to the
    process selected by the short-term scheduler
  • 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.

12
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

13
6.2 Scheduling Criteria
  • CPU utilization (max)
  • keep the CPU as busy as possible
  • Throughput (max)
  • number of processes that complete their execution
    per time unit
  • Turnaround time (min)
  • amount of time to execute a particular process
  • Waiting time (min)
  • amount of time a process has been waiting in the
    ready queue
  • Response time (min)
  • amount of time it takes from when a request was
    submitted until the first response is produced,
    not output (for time-sharing environment)

14
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

15
6.3 Scheduling Algorithms
  • Dealing the problem of deciding which of the
    processes in the ready queue to be allocated the
    CPU
  • First-Come, First-Served Scheduling
  • Shortest-Job-First Scheduling
  • Priority Scheduling
  • Round-Robin Scheduling
  • Multilevel Queue Scheduling
  • Multilevel Feedback Queue Scheduling

16
6.3.1 First-Come, First-Served Scheduling
  • The process that requests the CPU first is
    allocated the CPU first.
  • The simplest CPU-scheduling algorithm
  • Implementation with a FIFO queue
  • Add to the tail of the queue
  • Remove from the head to the queue
  • The code is simple to write and understand
  • Average waiting time is often quite long.

17
6.3.1 First-Come, First-Served Scheduling
  • Process Burst Time
  • P1 24
  • P2 3
  • P3 3
  • Suppose that the processes arrive in the order
    P1 , P2 , P3 The Gantt Chart for the schedule
    is
  • Waiting time for P1 0 P2 24 P3 27
  • Average waiting time (0 24 27)/3 17

18
6.3.1 First-Come, First-Served Scheduling
  • Suppose that the processes arrive in the
    order
  • P2 , P3 , P1
  • The Gantt chart for the schedule is
  • Waiting time for P1 6 P2 0 P3 3
  • Average waiting time (6 0 3)/3 3
  • Much better than previous case.

19
6.3.1 First-Come, First-Served Scheduling
  • Convoy effect
  • All the other processes wait for one big process
    to get off the CPU
  • Results in lower CPU and device utilization
  • If the shorter processes were allowed to go first
  • FCFS is non-preemptive
  • Once the CPU has been allocated to a process,
    that process keeps the CPU until it releases the
    CPU.
  • Particular troublesome in time-sharing system
  • Each user needs to get a share of the CPU at
    regular intervals

20
6.3.2 Shortest-Job-First Scheduling
  • When the CPU is available, it is assigned to the
    process that has the smallest next CPU burst.
  • Associate each process with the length of the
    latters next CPU burst
  • Not its total length
  • Another term shortest next CPU burst
  • FCFS scheduling is used to break the tie
  • Provably optimal
  • Minimum average waiting time for a given set of
    processes
  • Real difficulty
  • Knowing the length of the next CPU burst
  • Used frequently in long-term scheduling

21
6.3.2 Shortest-Job-First Scheduling
  • Process Burst Time
  • P1 6
  • P2 8
  • P3 7
  • P4 3
  • The Gantt Chart for the schedule is
  • Waiting time for P1 3 P2 16 P3 9 P4
    0
  • Average waiting time (3 16 9 0) / 4 7
  • Using FCFS scheme ( 0 6 14 21) / 4 10.25

22
6.3.2 Shortest-Job-First Scheduling
  • To approximate SJF scheduling
  • To predict its value
  • Use the length of previous CPU bursts
  • exponential average

23
Prediction of the length of the next CPU burst
24
Examples ofExponential Averaging
  • ? 0
  • ?n1 ?n
  • Recent history does not count.
  • ? 1
  • ?n1 tn
  • Only the actual last CPU burst counts.
  • If we expand the formula, we get
  • ?n1 ? tn(1 - ?) ? tn -1
  • (1 - ? )j ? tn -1
  • (1 - ? )n1 tn ?0
  • Since both ? and (1 - ?) are less than or equal
    to 1, each successive term has less weight than
    its predecessor.

25
6.3.2 Shortest-Job-First Scheduling
  • Two schemes
  • Nonpreemptive
  • Allow the current running process to finish its
    CPU burst
  • Preemptive
  • If a new process arrives with CPU burst length
    less than remaining time of current executing
    process, preempt.
  • Called as Shortest-Remaining-Time-First (SRTF).

26
Example of Preemptive SJF
  • Process Arrival Time Burst Time
  • P1 0 8
  • P2 1 4
  • P3 2 9
  • P4 3 5
  • Preemptive SJF
  • Average waiting time ( (10-1) (1-1) (17-2)
    (5-3)) / 4 6.5

27
6.3.3 Priority Scheduling
  • The CPU is allocated to the process with the
    highest priority.
  • A priority is associated with each process
  • Fixed range of number, such as 0 to 7
  • We use low numbers to represent high priority
  • Equal-priority processes are scheduled in FCFS
    order
  • SJF is a special case of the general
    priority-scheduling algorithm
  • The priority is the inverse of the predicted next
    CPU burst

28
Example of priority scheduling
  • Process Burst Time Priority
  • P1 10 3
  • P2 1 1
  • P3 2 4
  • P4 1 5
  • P5 5 2
  • Priority scheduling
  • Average waiting time ( 6 0 16 18 1 ) /
    5 8.2

29
6.3.3 Priority Scheduling
  • Priorities can be defined
  • Internally
  • Use some measurable quantity
  • Time limits, memory requirements
  • Externally
  • Set by criteria external to OS
  • importance, political factors
  • Priority scheduling can be
  • Preemptive
  • Nonpreemptive
  • Major problem
  • Indefinite blocking or starvation
  • Solution aging
  • Gradually increase the priority of processes that
    wait for a long time

30
6.3.4 Round-Robin Scheduling
  • A small unit of time, called a time quantum ( or
    time slice) is defined.
  • Generally from 10 to 100 milliseconds
  • The ready queue is treated as a circular, FIFO
    queue.
  • The CPU scheduler goes around the ready queue
  • Allocate the CPU to each process for a time
    interval of up to 1 time quantum.
  • Designed especially for time-sharing systems
  • Two cases
  • CPU burst less than 1 time quantum
  • The process release the CPU voluntarily
  • CPU burst longer than 1 time quantum
  • Context switch will be executed

31
Example of round-robin scheduling
  • Process Burst Time
  • P1 24
  • P2 3
  • P3 3
  • Round-robin scheduling
  • A time-quantum of 4 milliseconds
  • Average waiting time ( 6 4 7 ) / 3 5.66
  • Often quite long
  • RR scheduling is preemptive.

32
6.3.4 Round-Robin Scheduling
  • n processes in the ready queue and the time
    quantum is q
  • Each process gets 1/n of the CPU time in chunks
    of at most q time units at once
  • No process waits more than (n-1)q time units
  • Performance
  • Depend heavily on the size of the time quantum
  • q is very large the same as the FCFS policy
  • q is very small called processor sharing
  • q must be large with respect to context switch,
    otherwise overhead is too high.

33
A smaller time quantumincreases context switches
34
6.3.4 Round-Robin Scheduling
  • Turnaround time also depends on the size of the
    time quantum.
  • Rule of thumb
  • 80 percent of the CPU burst shouldbe shorter
    thanthe time quantum

35
6.3.5 Multilevel Queue Scheduling
  • Processes are classified into different groups
  • Foreground (or interactive) processes
  • Background (or batch) processes
  • Multilevel queue-scheduling algorithm
  • Partition the ready queue into several separate
    groups
  • Each group has its own scheduling algorithm
  • Scheduling among the queues
  • Fixed-priority preemptive scheduling
  • Possibility of starvation
  • Time-slice between the queues
  • A certain portion of the CPU time

36
Multilevel Queue Scheduling
37
6.3.6 Multilevel Feedback Queue
  • A process can move between the various queues
  • Use too much CPU time move to a lower-priority
    queue
  • Wait too long move to a higher-priority queue
  • This form of aging prevents starvation
  • Multilevel-feedback-queue scheduler defined by
  • number of queues
  • scheduling algorithms for each queue
  • method used to determine when to upgrade a
    process
  • method used to determine when to demote a process
  • method used to determine which queue a process
    will enter when that process needs service

38
Example ofMultilevel Feedback Queue
  • Three queues
  • Q0 time quantum 8 milliseconds
  • Q1 time quantum 16 milliseconds
  • Q2 FCFS
  • Scheduling
  • A new job enters queue Q0 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 Q1.
  • At Q1 job is again served FCFS and receives 16
    additional milliseconds. If it still does not
    complete, it is preempted and moved to queue Q2.

39
Multilevel feedback queues
  • The most general and complex scheme

Q0
Q1
Q2
40
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

41
6.4 Multiple-Processor Scheduling
  • CPU scheduling is more complex when multiple CPUs
    are available
  • Homogeneous system
  • Identical processors
  • Load sharing can occur
  • Separate queue
  • Common queue
  • Self-scheduling
  • Master-slave structure
  • Heterogeneous system
  • Different processors

42
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

43
6.5 Real-Time Scheduling
  • Hard real-time systems
  • complete a critical task within a guaranteed
    amount of time.
  • Special-purpose software running on dedicated
    hardware
  • Lack the full functionality of modern computers
    and operating systems
  • Soft real-time computing
  • Critical processes receive priority over less
    fortunate ones
  • May cause unfair allocation of resources
  • A general-purpose system can also support special
    tasks

44
6.5 Real-Time Scheduling
  • Soft real-time computing
  • Priority scheduling
  • Real-time process must have the highest priority
  • The dispatch latency must be small
  • OSs are forced to wait for a system call to
    complete or an I/O block to take place before
    doing a context switch
  • Solution system calls must be preemptible
  • Insert preemption points
  • Make the entire kernel preemptible
  • Effective and complex method
  • Solaris 2
  • Over 100 ms v.s. 2 ms

45
Dispatch Latency
46
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

47
6.6 Algorithm Evaluation
  • How to select a CPU-scheduling algorithm for a
    particular system?
  • Define the criteria
  • CPU utilization
  • Response time
  • Throughput
  • A criteria may include several measures
  • Maximize CPU utilization under the constraint
    that the maximum response time is 1 second.
  • Maximize throughput such that turnaround time is
    linearly proportional to total execution time.

48
6.6.1 Deterministic Modeling
  • Take a particular predetermined workload and
    defines the performance of each algorithm for
    that workload
  • Example
  • Assume five processes arrive at time 0, in the
    order given, with the length of the CPU-burst
    time given in milliseconds
  • Process Burst Time Priority
  • P1 10 3
  • P2 1 1
  • P3 2 4
  • P4 1 5
  • P5 5 2
  • Consider the FCFS, SJF, and RR(quantum10
    milliseconds) scheduling algorithms for this set
    of processes.
  • Which gives the minimum average waiting time?

49
6.6.1 Deterministic Modeling
  • Advantage
  • Simple and fast
  • Exact numbers
  • Disadvantage
  • Too specific, and require too much exact
    knowledge, to be useful
  • Main use
  • Describing scheduling algorithms and providing
    examples

50
6.6.2 Queueing Models
  • No static set of processes (and times)
  • What can be determined
  • The distribution of CPU and I/O bursts
  • Measured and approximated by mathematical
    formulas
  • Queueing-network analysis
  • CPU is a server with its ready queue
  • I/O system is a server with its device queue
  • Knowing arrival rates and service rates
  • Utilization, average queue length, average wait
    time

51
6.6.2 Queueing Models
  • Littles formula n l W
  • n average queue length
  • W average waiting time
  • l average arrival rate for new processes
  • Advantage
  • Useful in comparing scheduling algorithms
  • Disadvantage
  • Approximation only
  • Fairly limited applicability

52
6.6.3 Simulations
  • Programming a model of the computer system
  • Simulator
  • A variable representing a clock
  • Modify the system state to reflect the activities
    of the devices, the processes, and the scheduler
  • Data generation
  • Random-number
  • Probability distribution
  • Empirically
  • Trace tapes
  • Monitor the real system
  • Expensive
  • More detailed simulation provides more accurate
    results

53
Evaluation of CPU schedulersby simulation
54
6.6.4 Implementation
  • A simulation is of limited accuracy.
  • The only completely accurate way
  • code it
  • put it in the OS
  • see how it work
  • The cost is high
  • In coding
  • In the reaction of users

55
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

56
6.7 Process Scheduling Models
  • User-level threads
  • Managed by a thread library
  • Kernel is unaware of them
  • Process local scheduling
  • Thread scheduling is done local to the
    application
  • System global scheduling
  • Decide which kernel thread to schedule
  • Case study
  • Solaris 2
  • Windows 2000
  • Linux

57
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

58
Summary
  • P.184 to 185

59
Chapter 6 CPU Scheduling
  1. Basic Concepts
  2. Scheduling Criteria
  3. Scheduling Algorithms
  4. Multiple-Processor Scheduling
  5. Real-Time Scheduling
  1. Algorithm Evaluation
  2. Process Scheduling Models
  3. Summary
  4. Exercises

60
Exercises
  • 6.2
  • 6.3
  • 6.4
  • 6.7
  • 6.10

61
The End
Write a Comment
User Comments (0)
About PowerShow.com