Outline - PowerPoint PPT Presentation

About This Presentation
Title:

Outline

Description:

How to check a directory that is valid or not. Using opendir and closedir. Using access ... A commonly used convention is that lower numbers have higher priority ... – PowerPoint PPT presentation

Number of Views:10
Avg rating:3.0/5.0
Slides: 72
Provided by: xiuwe
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Outline


1
Outline
  • Announcements
  • Process Scheduling continued
  • Preemptive scheduling algorithms
  • SJN
  • Priority scheduling
  • Round robin
  • Multiple-level queue

Please pick up your quiz if you have not done
so Please pick up a copy of Homework 2
2
Announcements
  • About the first quiz
  • If the first quiz is not the worst among all of
    your quizzes, it will replace the worst you have
  • If the first quiz is the worst among all of your
    quizzes, it will be ignored in grading

3
Announcements cont.
  • A few things about the first lab
  • How to check a directory that is valid or not
  • Using opendir and closedir
  • Using access()
  • Note that your program should accept both command
    names only and full path commands
  • Using strchr to check if / occurs in my_argv0
  • If yes, execv(my_argv0, my_argv)
  • If no, then you need to search through the
    directories

4
Scheduling - review
  • Scheduling mechanism is the part of the process
    manager that handles the removal of the running
    process of CPU and the selection of another
    process on the basis of a particular strategy
  • Scheduler chooses one from the ready threads to
    use the CPU when it is available
  • Scheduling policy determines when it is time for
    a thread to be removed from the CPU and which
    ready thread should be allocated the CPU next

5
Process Scheduler - review
6
Voluntary CPU Sharing
  • Each process will voluntarily share the CPU
  • By calling the scheduler periodically
  • The simplest approach
  • Requires a yield instruction to allow the running
    process to release CPU

7
Involuntary CPU Sharing
  • Periodic involuntary interruption
  • Through an interrupt from an interval timer
    device
  • Which generates an interrupt whenever the timer
    expires
  • The scheduler will be called in the interrupt
    handler
  • A scheduler that uses involuntary CPU sharing is
    called a preemptive scheduler

8
Programmable Interval Timer
9
Scheduler as CPU Resource Manager
10
The Scheduler Organization
11
Dispatcher
  • Dispatcher module gives control of the CPU to the
    process selected by the scheduler this involves
  • switching context
  • switching to user mode
  • jumping to the proper location in the user
    program to restart that program

12
Diagram of Process State
13
CPU Scheduler
  • Selects from among the processes in memory that
    are ready to execute, and allocates the CPU to
    one of them.
  • CPU scheduling decisions may take place when a
    process
  • 1. Switches from running to waiting state.
  • 2. Switches from running to ready state.
  • 3. Switches from waiting/new to ready.
  • 4. Terminates.

14
CPU Scheduler cont.
  • Non-preemptive and preemptive scheduling
  • Scheduling under 1 and 4 is non-preemptive
  • A process runs for as long as it likes
  • In other words, non-preemptive scheduling
    algorithms allow any process/thread to run to
    completion once it has been allocated to the
    processor
  • All other scheduling is preemptive
  • May preempt the CPU before a process finishes its
    current CPU burst

15
Working Process Model and Metrics
  • P will be a set of processes, p0, p1, ..., pn-1
  • S(pi) is the state of pi
  • t(pi), the service time
  • The amount of time pi needs to be in the running
    state before it is completed
  • W (pi), the wait time
  • The time pi spends in the ready state before its
    first transition to the running state
  • TTRnd(pi), turnaround time
  • The amount of time between the moment pi first
    enters the ready state and the moment the process
    exists the running state for the last time

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

18
First-Come-First-Served
  • First-Come-First-Served
  • Assigns priority to processes in the order in
    which they request the processor

19
Predicting Wait Time in FCFS
  • In FCFS, when a process arrives, all in ready
    list will be processed before this job
  • Let m be the service rate
  • Let L be the ready list length
  • Wavg(p) L1/m 0.5 1/m L/m1/(2m)
  • Compare predicted wait with actual in earlier
    examples

20
Shortest-Job-Next Scheduling
  • Associate with each process the length of its
    next CPU burst.
  • Use these lengths to schedule the process with
    the shortest time.
  • SJN is optimal
  • gives minimum average waiting time for a given
    set of processes.

21
Nonpreemptive SJN
22
Determining Length of Next CPU Burst
  • Can only estimate the length.
  • Can be done by using the length of previous CPU
    bursts, using exponential averaging.

23
Examples of Exponential 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.

24
Priority Scheduling
  • In priority scheduling, processes/threads are
    allocated to the CPU based on the basis of an
    externally assigned priority
  • A commonly used convention is that lower numbers
    have higher priority
  • SJN is a priority scheduling where priority is
    the predicted next CPU burst time.
  • FCFS is a priority scheduling where priority is
    the arrival time

25
Nonpreemptive Priority Scheduling
26
Priority Scheduling cont.
  • Starvation problem
  • low priority processes may never execute.
  • Solution through aging
  • as time progresses increase the priority of the
    process

27
Deadline Scheduling
28
Real-Time Scheduling
  • Hard real-time systems required to complete a
    critical task within a guaranteed amount of time.
  • Soft real-time computing requires that critical
    processes receive priority over less fortunate
    ones.

29
Preemptive Schedulers
  • Highest priority process is guaranteed to be
    running at all times
  • Or at least at the beginning of a time slice
  • Dominant form of contemporary scheduling
  • But complex to build analyze

30
Preemptive Shortest Job Next
  • Also called the shortest remaining job next
  • When a new process arrives, its next CPU burst is
    compared to the remaining time of the running
    process
  • If the new arrivers time is shorter, it will
    preempt the CPU from the current running process

31
Example of Preemptive SJF
  • Process Arrival Time Burst Time
  • P1 0.0 7
  • P2 2.0 4
  • P3 4.0 1
  • P4 5.0 4
  • Average time spent in ready queue (9 1 0
    2)/4 3

32
Comparison of Non-Preemptive and Preemptive SJF
  • Process Arrival Time Burst Time
  • P1 0.0 7
  • P2 2.0 4
  • P3 4.0 1
  • P4 5.0 4
  • SJN (non-preemptive)
  • Average time spent in ready queue
  • (0 6 3 7)/4 4

33
Round Robin (RR)
  • Each process gets a small unit of CPU time (time
    quantum), usually 10-100 milliseconds. After
    this time has elapsed, the process is preempted
    and added to the end of the ready queue.
  • If there are n processes in the ready queue and
    the time quantum is q, then 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.

34
Round Robin (TQ50)
i t(pi) 0 350 1 125 2 475 3 250 4
75
0
50
p0
W(p0) 0
35
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
100
0
p0
p1
W(p0) 0 W(p1) 50
36
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
100
0
p0
p2
p1
W(p0) 0 W(p1) 50 W(p2) 100
37
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
200
100
0
p0
p3
p2
p1
W(p0) 0 W(p1) 50 W(p2) 100 W(p3) 150
38
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
200
100
0
p0
p4
p3
p2
p1
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
39
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
300
200
100
0
p0
p0
p4
p3
p2
p1
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
40
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
475
400
300
200
100
0
p0
p4
p0
p4
p3
p2
p1
p1
p2
p3
TTRnd(p4) 475
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
41
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
475
400
300
200
100
0
550
p0
p4
p1
p0
p4
p3
p2
p1
p1
p2
p3
p0
TTRnd(p1) 550 TTRnd(p4) 475
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
42
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
475
400
300
200
100
0
550
650
p0
p4
p1
p0
p4
p3
p2
p1
p1
p2
p3
p0
p3
p2
650
750
850
950
p0
p3
p2
p0
p3
p2
TTRnd(p1) 550 TTRnd(p3) 950 TTRnd(p4) 475
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
43
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
475
400
300
200
100
0
550
650
p0
p4
p1
p0
p4
p3
p2
p1
p1
p2
p3
p0
p3
p2
650
750
850
950
1050
p0
p3
p2
p0
p3
p2
p0
p2
p0
TTRnd(p0) 1100 TTRnd(p1) 550 TTRnd(p3)
950 TTRnd(p4) 475
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
44
Round Robin (TQ50) cont.
i t(pi) 0 350 1 125 2 475 3 250 4
75
475
400
300
200
100
0
550
650
p0
p4
p1
p0
p4
p3
p2
p1
p1
p2
p3
p0
p3
p2
650
750
850
950
1050
1150
1250
1275
p0
p3
p2
p0
p3
p2
p0
p2
p0
p2
p2
p2
p2
TTRnd(p0) 1100 TTRnd(p1) 550 TTRnd(p2)
1275 TTRnd(p3) 950 TTRnd(p4) 475
W(p0) 0 W(p1) 50 W(p2) 100 W(p3)
150 W(p4) 200
45
Round Robin (TQ50) cont.
46
Round Robin cont.
  • Performance
  • q large ? FIFO
  • q small ? q must be large with respect to context
    switch, otherwise overhead is too high.

47
Turnaround Time Varies With The Time Quantum
48
How a Smaller Time Quantum Increases Context
Switches
49
Round-robin Time Quantum
50
Process/Thread Context
51
Context Switching - review
52
Cost of Context Switching
  • Suppose there are n general registers and m
    control registers
  • Each register needs b store operations, where
    each operation requires K time units
  • (nm)b x K time units
  • Note that at least two pairs of context switches
    occur when application programs are multiplexed
    each time

53
Round Robin (TQ50) cont.
  • Overhead must be considered

i t(pi) 0 350 1 125 2 475 3 250 4
75
54
Multi-Level Queues
Preemption or voluntary yield
Ready List0
Scheduler
New Process
Ready List1
CPU
Done
Ready List2
  • All processes at level i run before
  • any process at level j
  • At a level, use another policy, e.g. RR

Ready List3
55
Multilevel Queues
  • Ready queue is partitioned into separate queues
  • foreground (interactive)
  • background (batch)
  • Each queue has its own scheduling algorithm
  • foreground RR
  • background FCFS

56
Multilevel Queues cont.
  • Scheduling must be done between the queues.
  • Fixed priority scheduling i.e., serve all from
    foreground then from background. Possibility of
    starvation.
  • Time slice each queue gets a certain amount of
    CPU time which it can schedule amongst its
    processes i.e.,
  • 80 to foreground in RR
  • 20 to background in FCFS

57
Multilevel Queue Scheduling
58
Multilevel Feedback Queue
  • A process can move between the various queues
    aging can be implemented this way.
  • Multilevel-feedback-queue scheduler defined by
    the following parameters
  • 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

59
Multilevel Feedback Queues cont.
60
Example of Multilevel 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.

61
Two-queue scheduling
62
Three-queue scheduling
63
Multiple-Processor Scheduling
  • CPU scheduling more complex when multiple CPUs
    are available.
  • Homogeneous processors within a multiprocessor.
  • Load sharing
  • Asymmetric multiprocessing only one processor
    accesses the system data structures, alleviating
    the need for data sharing.

64
Algorithm Evaluation
  • Deterministic modeling takes a particular
    predetermined workload and defines the
    performance of each algorithm for that workload.
  • Queuing models
  • Implementation

65
Evaluation of CPU Schedulers by Simulation
66
Contemporary Scheduling
  • Involuntary CPU sharing -- timer interrupts
  • Time quantum determined by interval timer --
    usually fixed for every process using the system
  • Sometimes called the time slice length
  • Priority-based process (job) selection
  • Select the highest priority process
  • Priority reflects policy
  • With preemption
  • Usually a variant of Multi-Level Queues

67
Scheduling in real OSs
  • All use a multiple-queue system
  • UNIX SVR4 160 levels, three classes
  • time-sharing, system, real-time
  • Solaris 170 levels, four classes
  • time-sharing, system, real-time, interrupt
  • OS/2 2.0 128 level, four classes
  • background, normal, server, real-time
  • Windows NT 3.51 32 levels, two classes
  • regular and real-time
  • Mach uses hand-off scheduling

68
BSD 4.4 Scheduling
  • Involuntary CPU Sharing
  • Preemptive algorithms
  • 32 Multi-Level Queues
  • Queues 0-7 are reserved for system functions
  • Queues 8-31 are for user space functions
  • nice influences (but does not dictate) queue level

69
Windows NT/2K Scheduling
  • Involuntary CPU Sharing across threads
  • Preemptive algorithms
  • 32 Multi-Level Queues
  • Highest 16 levels are real-time
  • Next lower 15 are for system/user threads
  • Range determined by process base priority
  • Lowest level is for the idle thread

70
Scheduler in Linux
  • In file kernel/sched.c
  • The policy is a variant of RR scheduling

71
Summary
  • The scheduler is responsible for multiplexing the
    CPU among a set of ready processes / threads
  • It is invoked periodically by a timer interrupt,
    by a system call, other device interrupts, any
    time that the running process terminates
  • It selects from the ready list according to its
    scheduling policy
  • Which includes non-preemptive and preemptive
    algorithms
Write a Comment
User Comments (0)
About PowerShow.com