CPU Scheduling - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

CPU Scheduling

Description:

High utilization (efficiency) Lots of processes (decisions in scheduler? ... Time slice 100ms: nearly 5% of disk utilization with Round Robin ... – PowerPoint PPT presentation

Number of Views:136
Avg rating:3.0/5.0
Slides: 35
Provided by: Kai45
Category:

less

Transcript and Presenter's Notes

Title: CPU Scheduling


1
CPU Scheduling
  • Vivek Pai / Kai Li
  • Princeton University

2
Gedankentexperimenten(Thought Experiments)
  • Can you implement semaphores using Mesa-style
    monitors? If so, how?
  • Java has monitors, but no condition variables.
    There are equivalents to wait( ) and signal( ),
    but they operate on a per-monitor basis. How does
    this change life?

3
Reading Assignments
  • Sections 2.4 and 3.3 in text
  • Obviously not due for next Tuesday
  • What about the last readings?
  • Wanted to put thread issue in context
  • Preparation for project
  • Am I going to ask annoying details about the man
    pages? No
  • Are you responsible for the general concepts? Yes

4
Center For Teaching Learning
  • They perform diagnostic of class
  • Why?
  • Helps me figure out whats going well
  • Helps me figure out what can be improved
  • Gets you thinking about what works well in your
    own personal situation
  • In-class, probably at end of lecture?

5
Implement Semaphores with Mesa-Monitors
  • P( s )
  • Acquire( s.mutex )
  • --s.value
  • if (s.value lt 0 )
  • Wait(s.mutex,s.cond )
  • Release( s.mutex)
  • V( s )
  • Acquire( s.mutex )
  • s.value
  • if (s.value gt 0 )
  • Signal( s.cond )
  • Release( s.mutex)

6
Monitors and Java-like Approach
  • P( s )
  • Acquire( s.mutex )
  • --s.value
  • if (s.value lt 0 )
  • Wait( )
  • Release( s.mutex)
  • Code on left not correct
  • Small tweak makes it work
  • Whats the tweak?
  • What impact does it have?

7
CPU Scheduling
  • What is it?
  • Mechanism policy
  • Current mechanism fairly simple
  • Policy choices harder
  • Is mechanism always simple?
  • No, still open for research

8
What Issues are in Policy?
  • Fairness
  • Flexibility
  • High utilization (efficiency)
  • Good response time
  • Other issues?
  • Smooth media playback, device handling

9
What Issues are in Policy?
  • Fairness
  • All users should get access to CPU
  • Amount of CPU should be roughly even
  • Somewhat related forward progress
  • More of a correctness issue
  • Global forward progress needs some fairness

10
What Issues are in Policy?
  • High utilization (efficiency)
  • Lots of processes (decisions in scheduler?)
  • Lots of resources (want full parallelism)
  • Different resource profiles
  • Issue?
  • How do you get the most useful work out of the
    system?

11
What Issues are in Policy?
  • Flexibility - variability in job types
  • Long versus short
  • Interactive versus non-interactive
  • I/O-bound versus compute-bound
  • Issues?
  • Short jobs shouldnt suffer
  • Users shouldnt be annoyed

12
Goals and Assumptions
  • Goals
  • Short response time type on a keyboard
  • Maximize throughput operations (jobs) per second
  • Minimize overhead of context switches
  • Efficient utilization (CPU, memory, disk etc)
  • Minimize turnaround batch users wait
  • Fairness
  • Is there a difference between fairness and avg
    response time?
  • What about average response time and throughput?
  • Assumptions
  • One program per user and one thread per program
  • Programs are independent

13
Non-Preemptive FIFO (FCFS) Policy
  • What does it mean?
  • Run to completion (old days)
  • Run until blocked or yield
  • Advantages
  • Simple
  • Disadvantage
  • Short jobs behind long jobs

14
Round Robin
Ready queue
Current process
  • Each runs a time slice or quantum
  • How do you choose time slice?
  • Overhead vs. throughputs
  • Overhead is typically about 1 or less

15
Is Fairness Always Good?
  • Assume 10 jobs, each takes 100 seconds
  • Assume no other overhead
  • Total CPU time? 1000 seconds, always
  • Implications?
  • Last job always finishes at 1000 seconds
  • So whats the point of scheduling?

16
FIFO Example
  • Job 1 start 0, end 100
  • Job 2 start 100, end 200
  • Job 10 start 900, end 1000
  • Average wait time? 100 200 / N
  • 550 seconds

17
Round Robin Example
  • Assume each quantum is 1 second
  • Job 0 0, 10, 20, 30, 40,, 990
  • Job 1 1, 11, 21, 31,, 991
  • Job 2 2, 12, 22, 32,, 992
  • Average wait time? 990991/N
  • 995 seconds

18
Like, Whoa! Dude!
  • Unfair policy was faster!
  • Job 10 always ended at the same time
  • Round-Robin just hurt jobs 1-9 with no gain

19
So Why Use Round-Robin?
  • Imagine 10 jobs
  • Jobs 1-9 are 100 seconds
  • Job 10 is 10 seconds
  • Which policy is better now?

20
Queuing Theory
  • An entire discipline to itself
  • Mathematically oriented
  • Some neat results
  • Systems harder to model these days
  • Whats used now? Simulation

21
Adding I/O Into the Mix
  • Resource utilization example
  • A and B each uses 100 CPU
  • C loops forever (1ms CPU and 10ms disk)
  • Time slice 100ms nearly 5 of disk utilization
    with Round Robin
  • Time slice 1ms nearly 90 of disk utilization
    with Round Robin and nearly 100 of CPU
    utilization
  • What do we learn from this example?
  • Small time slice can improve utilization

22
Virtual Round Robin
Timeout
  • To improve fairness for I/O bound processes
  • Aux queue is FIFO
  • I/O bound processes go to aux queue (instead of
    ready queue) to get scheduled
  • Aux queue has preference over ready queue

Dispatch
CPU
Admit
Aux queue
I/O wait
I/O wait
I/O completion
I/O wait
23
STCF vs. SRTCF
  • Shortest time to completion first (shortest job
    first)
  • Non-preemptive
  • Shortest remaining time to completion first
  • Preemptive version
  • Advantage
  • Minimal average response time
  • Disadvantage
  • Can cause starvation difficult to know the
    future
  • Question
  • Can you do better than SRTCF in terms of average
    response time?

24
Priority Scheduling
  • The method
  • Assign each process a priority
  • Run the process with highest priority in the
    ready queue first
  • Adjust priority dynamically (I/O wait raises the
    priority)
  • Advantage
  • Fairness
  • Disadvantage
  • Users can hit keyboard frequently

25
Multiple Queue (Feedback)
Priority 0 1 2 3
Time slices 1 2 4 8
  • Jobs start at highest priority queue
  • If timeout expires, drop one level
  • If timeout doesnt expires, stay or pushup one
    level

26
Lottery Scheduling
  • Motivations
  • SRTCF does well with avg response time, but
    unfair
  • Adjusting priority is a bit ad hoc. For example,
    what rate?
  • Lottery method
  • Give each job a number of tickets
  • Randomly pick a winning tickets
  • To approximate SRTCF, short jobs give more
    tickets
  • To avoid starvation, give each job at least one
    ticket
  • For more details
  • C.A. Waldspurger and W.E. Weihl, Lottery
    Scheduling Flexible Proportional-Share Resource
    Management. Proc. of the 1st USENIX Symp. on
    Operating System Design and Implementation. Nov
    1994.

27
Traditional Unix Scheduling (SVR3, 4.3 BSD)
  • Multi-Queue Feedback with 1 second preemption
  • 1 sec preemption
  • Preempt if a process doesnt block or complete
    within 1 second
  • Priority is recomputed every second
  • Pi base CPUi-1/ 2 nice, where CPUi (Ui
    CPUi-1) / 2
  • Base is the base priority of the process
  • Ui is process utilization in interval i
  • Priorities
  • Swapper
  • Block I/O device control
  • File operations
  • Character I/O device control
  • User processes

28
Multiprocessor and Cluster
CPU
CPU
CPU


L1
L1
L1
L2
L2
L2
External Network
Memory
  • Cluster/Multicomputer
  • Distributed memory
  • An OS on each box
  • Multiprocessor architecture
  • L2 cache coherence
  • A Single image OS

29
Multiprocessor/Cluster Scheduling
  • New design issue process/thread to processor
    assignment
  • Gang scheduling (coscheduling)
  • Threads of the same process will run together (on
    a multiprocessor)
  • Processes of the same application run together
    (on a cluster)
  • Dedicated Processor Assignment
  • Threads will be running to specific processors to
    completion
  • Is this a good idea?
  • Yes cache misses in shared multiprocessor can be
    avoided
  • No lack of fairness

30
Real-Time Scheduling
  • Two types of real-time
  • Hard deadline must meet, otherwise can cause
    fatal error
  • Soft headline meet most of the time, but not
    mandatory
  • Characteristics
  • Deterministic upper bound on when to get
    services on an I/O
  • Responsive how long does OS delays before ack an
    interrupt
  • User control provide users with abilities to
    control and specify
  • Reliability reduced level of service instead of
    reboot

31
Deadline Scheduling
  • Admission control
  • Take a job only if the system can guarantee
    real-time
  • Information needed
  • Ready time time at which task becomes ready
  • Starting deadline time by which a task must
    begin
  • Completion deadline time by which a task must
    complete
  • Processing time time required to execute the
    task to completion
  • Resource requirements
  • Priority
  • Subtask structure

32
Rate Monotonic Scheduling (Liu 73)
  • Assign priorities to tasks based on basis of
    their periods
  • Highest priority with the shortest period
  • For earliest deadline first, we can meet all
    deadlines if following hold
  • where Ci computation time, and Ti period
  • For RMS algorithm, the following holds
  • The upper bound is conservative. In practice,
    the utilization is close to 90

Ci
?
? 1
Ti
Ci
?
? N(21/n 1)
Ti
33
Unix SVR4 Scheduling
  • Two major modifications
  • A static priority scheduler with 3 classes, 160
    priorities, and round-robin within each priority
  • Insertion of preemption points identify
    preemptive regions of code
  • Three classes
  • Real time (159-100) can make preemptive points
    in the kernel
  • Kernel (99-60) run before any time-shared
    processes but after real time
  • Time shared (59-0) intended for user processes
    that are not real time


Bit vector
0
1
0
1
0

Dispatch queue
i
0
1
2
159
34
Windows NT Scheduling
  • Classes and priorities
  • Real time 16 static priorities
  • Variable 16 variable priorities, start at a
    base priority
  • If a process has used up its quantum, lower its
    priority
  • If a process waits for an I/O event, raise its
    priority
  • Priority-driven scheduler
  • For real-time class, do round robin within each
    priority
  • For variable class, multiple queue feedback
  • Multiprocessor scheduling
  • For N processors, run N-1 highest priority
    threads on N-1 processors and run remaining
    threads on a single processor
  • A thread will wait for processors in its affinity
    set, if there are other threads available (for
    variable priorities)
Write a Comment
User Comments (0)
About PowerShow.com