CPU????(CPU Scheduling) ~ - PowerPoint PPT Presentation

About This Presentation
Title:

CPU????(CPU Scheduling) ~

Description:

CPU (CPU Scheduling) ~ job scheduling CPU scheduling swapping (Basic Concepts) – PowerPoint PPT presentation

Number of Views:198
Avg rating:3.0/5.0
Slides: 38
Provided by: Meey5
Category:

less

Transcript and Presenter's Notes

Title: CPU????(CPU Scheduling) ~


1
CPU????(CPU Scheduling)
  • ???? ????
  • ?? job scheduling
  • ?? CPU scheduling
  • ?? swapping

?? ??(Basic Concepts)
  • CPU-I/O ??? ??(burst cycle)
  • cycle CPU ??(CPU burst) lt--gt I/O ??(I/O burst)
  • CPU burst ??
  • I/O bound program ?? ?? CPU burst ??
  • CPU bound program ?? ?? ? CPU burst ??
  • CPU ????
  • ?? ????(short-term scheduler) ready queue?? ??
  • FIFO(First-In First-Out)?
  • ???? ?
  • ??
  • ?????

2
Alternating Sequence of CPU And I/O Bursts
3
Histogram of CPU-burst Times
4
CPU????(CPU Scheduling)
  • ?? ????(Preemptive Scheduling)
  • ??(preemptive) ????
  • ??????(timer)??
  • ?? ???? ?? ???? ??? ??
  • ???(non preemptive) ?? ???(cooperative) ????
  • MS-Windows, ?? ????(timer) ??
  • ?? ?? I/O?? ?? CPU??
  • Kernel? ?? ??
  • case 1(?? Unix) system call ?? ?? I/O ??? ? ??
    ????? ????
  • ??? ????? ?? ????? ??
  • case 2 interrupt ? ?? interrupt enable(?????
    ??) ?? ?? system call? preemptible
  • critical section(?? ??? ???? ?? ??)? ?? ??
    interrupt disable ?? ?
  • CPU scheduling decision time
  • running -gt waiting non preemptive
  • running -gt ready (interrupt) preemptive
  • waiting -gt ready (I/O ??) preemptive
  • halt non preemptive

5
CPU????(CPU Scheduling)
  • ???(Dispatcher)
  • ?? ??
  • ??? ??? ??
  • ????? ??? ??? ???? ???? ???
  • (dispatch latency? ??? ?)

???? ??(Scheduling Criteria)
  • ???(CPU utilization) 40 90
  • ???(throughput) ??? ???? ??/?? ??
  • ????(turnaround time) system in -gt system out
    ?? ??
  • ????(waiting time) ready queue?? ??? ??
  • ????(response time) ??? ????? ? ????? ??

6
???? ????(Scheduling Algorithm)
  • ?? ?? ?? ??(average waiting time)
  • ?? ???(First-Come, First-Served) ????
  • ??? ????
  • FIFO queue First-inlt- tail First-outlt- head
  • p141-142 ?(Gantt chart)
  • ?? ??(convoy effect) ? job??? ???? ??
    ???(CPU-bound process? ???? I/O bounded process??
    ???)
  • non-preemptive?(time-sharing??? ??)
  • ?? ?? ??(Shortest-Job-First) ????
  • Shortest Next CPU Burst Scheduling
  • ?? CPU burst ??? ?? ?? ??????
  • ? ?? ???? ??
  • non-preemptive SJF p143 ?
  • preemptive SJF Shortest Remaining Rime First
    Scheduling p145 ?
  • ??(Optimal)
  • ?? ?? ??(starvation)
  • long-term scheduling? ??(???? ??? ??? ?? ? ??)
  • short-term scheduling ?? ?? ?? CPU burst ?? ???
    ????
  • ?? CPU ??? ?? ?? ??

7
First-Come, First-Served (FCFS) Scheduling
  • Example 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

8
FCFS Scheduling (Cont.)
  • 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.
  • Convoy effect short process behind long process

P1
P3
P2
6
3
30
0
9
Example of Non-Preemptive SJF
  • Process Arrival Time Burst Time
  • P1 0.0 7
  • P2 2.0 4
  • P3 4.0 1
  • P4 5.0 4
  • SJF (non-preemptive)
  • Average waiting time (0 6 3 7)/4 4

P1
P3
P2
P4
7
3
16
0
8
12
10
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
  • SJF (preemptive)
  • Average waiting time (9 1 0 2)/4 3

P1
P3
P2
P4
P2
P1
11
16
0
4
2
5
7
11
Determining Length of Next CPU Burst
  • CPU ??? ?? ??? ? ?? ??? ?? ??
  • ?? CPU ??? ???? ??? ??(exponential averaging)??
    ??

12
Examples of Exponential Averaging
  • ? 0
  • ?n1 ?n
  • ??? ?? CPU ??? ??? ?? ??
  • ? 1
  • ?n1 tn
  • ??? ?? CPU ??? ??? ??
  • ?? ????
  • ?n1 ? tn (1 - ?) ?n
  • ? tn (1 - ?) (? tn-1 (1 - ?) ?n-1 )
  • ? tn (1 - ?) ? tn-1 (1 - ?) 2 ?n-1
  • ? tn (1 - ?) ? tn-1
  • (1 - ? ) j ? tn-1
  • (1 - ? ) n1 ?0
  • ?? (1 - ?)? 1?? ????, ???? ? ??? ?? ???? ??
    ?(weight)? ? ???

13
???? ????(Scheduling Algorithm)
  • ????(Priority) ????
  • ?? ?? ??? ??????
  • ready queue priority queue -gt heap??? ??
  • FCFS equal-priority
  • SJF p 1/T (T ?? CPU ??? ?? ?? ?)
  • priority??(OS??)
  • ?? ??(time limits)
  • ??? ???
  • ?? ?? ?
  • (average I/O burst)/(average CPU burst) ?? ?
  • priority??(OS??)
  • ???? ???
  • ??? ??? ??? ??
  • ?? ??
  • ??? ?? ?
  • preemptive ? ?? non-preemptive ? ??
  • ??? ?? ??(blocking) ?? ?? ??(starvation)
  • CPU? ??? ??? ?? ????? system crash ? ?????
  • (?) IBM 7094 at MIT 1973, 1967 job

14
???? ????(Scheduling Algorithm)
  • ?? ??(Round-Robin) ????
  • FCFS preemption (time slice ??)
  • ready queue ?? FIFO queue
  • preemptive ?
  • time sharing??time quantum? ??? ??
  • 1 time quantum gt context switching time
  • 80 CPU burst lt 1 time quantum
  • p148, p150 ?
  • ??? ?(Multilevel Queue) ????
  • ? ????? ?? ??? ?? ?? ?? ? ? ??? ??? ?? p151 ??
    5.6
  • ? queue? ??? ??? scheduling algorithm ??
  • foreground (interactive) queue RR????
  • background (batch) queue FCFS????
  • queue? ??? scheduling ?? ?? ?? ?? ????(fixed
    priority preemptive scheduling)
  • ? ??? CPU time slice ?? ?
  • 80 for RR
  • 20 for FCFS
  • ???? ?? ??? ???? ??

15
Example RR with Time Quantum 20
  • Process Burst Time
  • P1 53
  • P2 17
  • P3 68
  • P4 24
  • The Gantt chart is
  • Typically, higher average turnaround than SJF,
    but better response.

0
20
37
57
77
97
117
121
134
154
162
16
How a Smaller Time Quantum Increases Context
Switches
17
Turnaround Time Varies With The Time Quantum
18
Multilevel Queue Scheduling
19
???? ???? (Scheduling Algorithm)
  • ??? ?? ?(Multilevel Feedback Queue) ????
  • ????? ?? ? ??? ?? ?? 6.7
  • ?? ????(I/O bound, interactive processes)? ??
  • ? ????? ?? ?? ?? ??
  • aging(?? ???? ???? ?? ?? ?? ??)
  • preemptive ?(? ??)
  • the most sophisticated, the most complex
  • ?? ??? -gt ?? ???? ?? ????(configure)
  • ?? ??
  • ? ?? ???? ????
  • ?? ?? ??? ?? ?? ??
  • ?? ?? ??? ?? ?? ??
  • ?? ?? ??? ???
  • HRN(Highest-Response-ratio Next) ????
  • 1971 Brinch Hansen
  • SJF? ?? ??
  • dynamic priority (time waiting service time)
    / (service time)
  • ?? ??? ????? time waiting? ????? priority ???
  • short process??? priority ??

20
Multilevel Feedback Queues
21
Example of Multilevel Feedback Queue
  • Three queues
  • Q0 time quantum 8 milliseconds
  • Q1 time quantum 16 milliseconds
  • Q2 FCFS
  • Scheduling
  • FCFS queue Q0 ? ?? ??? ??? 8 milliseconds ?? CPU?
    ??? ??? ??? ??? ???? queue Q1?? ??
  • Q1? ??? FCFS? 16 additional milliseconds? ?? ???
    ??? ??? ???? queue Q2? ??

22
Unix ???? ????? ?
  • CPUdecay(CPU)CPU/2
  • ???? (??? CPU ???)/2 (?? ?? ??? ???? 60)
  • Unix ???? ?? ????? 0 (???? ?? ?? ?? ???? ??)

??
????A
????B
????C
????
????
????
CPU??
CPU??
CPU??
0
0 1 2 60 30
60
60
60
0
0
1
60
60
75
0
0 1 2 60 30
2
60
75
67
15
0 1 2 60 30
3
75
67
63
7 8 9 67 33
15
67
63
15
4
76
7 8 9 67 33
63
76
68
16
7
5
23
?? ???? ????(Multiple-Processor Scheduling)
  • ?? ?? ????(homogeneous multiprocessor)
  • ????? ?? ?? ?? ????(any processes)? ??
  • ?? ??(load sharing)
  • ??? ?? ?(separate ready queue)
  • ?? ?? ?(common ready queue)
  • ?? ?? ????(heterogeneous multiprocessor)
  • ????? ???(dedicated) ????? ??
  • distributed systems
  • ?? ?? ? ?? ?? ???? ???(common ready queue on
    homogeneous multiprocessor)? ????
  • ? ????? ??? ????(self-scheduling) symmetric
    (SMP)
  • master-slave(asymmetric) asymmetric
  • master? kernel system data structure? ?? ??
  • ? ????? ?? ???? ????
  • master server all system activity
  • client user code only

24
Real-Time Scheduling
  • hard real-time system
  • ??????? ???? ???? ?????? ???
  • ?? H/W??? ???? ?? S/W? ???
  • soft real-time system
  • ?? ????? ??(general-purpose computer system???
    ??)
  • multimedia, high-speed interactive graphics?(soft
    real-time computing? ??)
  • soft real-time OS ??? ????
  • 1. ???? ????? ?? ?(must have priority scheduling)
  • ??? ????? ??? ?? ??? ???? ?
  • 2. ????? ????? ???? ? (the dispatch latency must
    be small)
  • ???? OS context switching ??? ???? system call?
    ????? I/O? ?? block??? ???? ?
  • -gt ??
  • ? system call? preemptible??
  • ? system call?? preemption points(? ?? ?? ???
    ????? ?? check, ??? interrupt)
  • ? kernel??? preemptible??
  • Kernel data??? ?? synchronization ??.
  • (?) Solaris 2
  • ???? ??(priority inversion)
  • ? kernel data ?? ?? ?? control? ?? ?? ??

25
Real-Time Scheduling
  • ???? ??(priority inversion)
  • kernel data ???? ????? ?? ????? ????? ???? ?????
    ???? ???
  • ???? ?? ????(priority inheritance protocol)
  • kernel data ???? ?? ?? ??? ????? ????? ????? ??
    ????? ?? ??, ??? ??? ???
  • ?? ??(complict phase)? ?? ?? 6.8
  • 1. ???? ?? ?? ????? ??
  • 2. ?? ??(?? ?? ?? ????? ?? ?? ?? ????? ???? ???
    ???)
  • (?) Solaris 2
  • dispatch latency nonpreemptible 100 ms
  • dispatch latency preemptible 2 ms

26
Dispatch Latency
27
Rate Monotonic vs. EDF
28
Thread Scheduling
  • 2 thread levels
  • User level process local scheduling
  • threads library? ?? ??? LWP? thread? ???? ??
  • Kernel level system global scheduling
  • kernel? ?? ??? kernel thread? ???? ??
  • Solaris 2 Scheduling
  • priority-based process scheduling
  • 4 classes (?? 6.9 ??)
  • real time ??? ????
  • system ???? ??? ? ??
  • interactive multi-level feedback queue
    scheduling
  • windowing application? ?? ????
  • time sharing default class, multi-level feedback
    queue scheduling
  • the higher the priority, the smaller the time
    slice
  • interactive processes
  • the lower the priority, the larger the time slice
  • CPU-bound processes
  • Scheduler? class-specific priorities? global
    priorities? ??
  • ???? ?? ?? round-robin

29
Solaris 2 Scheduling
30
Java Thread Scheduling
  • JVM? ????? ?
  • Preemptive, Priority-Based Scheduling Algorithm
    ??
  • ???? ??? FIFO Queue ?? (RR algorithm)
  • Time slicing
  • time-sliced a thread runs until
  • time quantum
  • exit the Runnable state
  • preempted
  • not time-sliced a thread runs until
  • exit the Runnable state
  • preempted
  • yield() method? ??? ?? (time slicing ??)
  • cooperative multitasking

31
Time-Slicing
  • Since the JVM Doesnt Ensure Time-Slicing(??? ??
    ??), the yield() Method May Be Used
  • while (true)
  • // perform CPU-intensive task
  • . . .
  • Thread.yield()
  • This Yields Control to Another Thread of Equal
    Priority.

32
Java Thread Scheduling
  • Thread priority
  • ??? ???? thread? Runnable thread? ???
  • Thread ??? defalut priority(??? ??) -gt
    setPriority()? ??
  • Thread.MIN_PRIORITY 1
  • Thread.MAX_PRIORITY 10
  • Thread.NORM_PRIORITY 5 (default priority)
  • setPriority(Thread.NORM_PRIORITY 2)
  • Java-Based Round-robin Scheduler thread with
    priority 6 (?? 6.11 ??)
  • schedulers queue? addThread() priority 2
  • ?? ?? ???? priority 4
  • ????? 1 time quantum ?? ??? CPU? priority 4?
    thread?
  • 1 time quantum ? ??? ??? ????? priority 4?
    thread? ??(preempt)
  • CircularList class? queue? ???? ???? isEmpty()
    ???? ?? ??? ?? ????? ?? queue ???? ?? busy-wait
    ??
  • JVM? ?? ??? thread? ????? ??
  • ?? ?? ??? thread? Runnable State? ???? ?
  • ?? ????? thread? Runnable State? ???? ?
  • Note the JVM Does Not Specify Whether Threads
    are Time-Sliced or Not.

33
Round-robin Scheduler
public void run() Thread current this.setPrio
rity(6) while (true) //get the next
thread current (Thread)queue.getNext() if
((current ! null) (current.isAlive()))
current.setPriority(4) schedulerSleep() cur
rent.setPriority(2) private CircularList
queue private int timeSlice private static
final int DEFAULT_TIME_SLICE 1000
  • public class Scheduler extends Thread
  • public Scheduler()
  • timeSlice DEFAULT_TIME_SLICE
  • queue new CircilarList()
  • public Scheduler(int quantum)
  • timeSlice quantum
  • queue new CircilarList()
  • public void addThread(Thread t)
  • t.setPriority(2)
  • queue.addItem(t)
  • private void scheculerSleep()
  • try
  • thread.sleep(timeSlice)
  • catch (InterruotedException e)

34
TestThread
  • class TestThread extends Thread
  • private String name
  • public TestThread(String id)
  • name id
  • this.setPriority(Thread.NORM_PRIORITY)
  • public void run()
  • /
  • The thread does something
  • /
  • while (true)
  • for (int i 0 i lt 500000 i)
  • System.out.println("I am thread " name)

35
TestScheduler
  • public class TestScheduler
  • public static void main(String args)
  • Thread.currentThread().setPriority(Thread.MAX_P
    RIORITY)
  • Scheduler CPUScheduler new Scheduler()
  • CPUScheduler.start()
  • TestThread t1 new TestThread("Thread 1")
  • t1.start()
  • CPUScheduler.addThread(t1)
  • TestThread t2 new TestThread("Thread 2")
  • t2.start()
  • CPUScheduler.addThread(t2)
  • TestThread t3 new TestThread("Thread 3")
  • t3.start()
  • CPUScheduler.addThread(t3)

36
???? ??(Algorithm Evaluation)
  • ??? ???(Deterministic Modeling)
  • ????(workload)? ?? ?? ?? p158-159 ?? ??
  • ????
  • ???? ?
  • CPU ??? ?? ? ?? ??? ?? ??
  • ?? ??(Queueing Models)
  • CPU-I/O ??? ? ??? ???? ????? ??? ??? ????
  • ???? ???? ?? ???, ?? ? ??, ?????? ? ? ??
  • Little? ?? (?? ? ??) (?? ?) x (???? ??)
  • ?? ??? ?????? ???? ?
  • ?? ??(Simulations)
  • ????? ????? clock variable, system state
    variables? ???? ??
  • ?? ??? ???(??, ??, ???), ?? ????? ??
  • ?? ?? ?? ?? ?? ?? trace tapes ??
  • ???? ??? ?? ?
  • ??(Implementation)
  • ?? ???? ?? ?? ??? ??? ??
  • ?? ??? ?? ???? ????(flexible scheduling
    algorithm)
  • tunable scheduling

37
Evaluation of CPU Schedulers by Simulation
Write a Comment
User Comments (0)
About PowerShow.com