1 / 39

Finish Scheduling & Intro to Deadlock

Finish Scheduling & Intro to Deadlock. Ch 2.5 and Ch 3 Tuesday, February 20, 2007. Today’s Schedule. Review & Complete Scheduling CPU Ch & Sec 2.5 Deadlock - Chapter 3 Skip multiple resources (3.4.2 & 3.5.4). Objectives – You can name …. Scheduling CPU

tamatha
Télécharger la présentation

Finish Scheduling & Intro to Deadlock

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Finish Scheduling &Intro to Deadlock Ch 2.5 and Ch 3 Tuesday, February 20, 2007

  2. Today’s Schedule • Review & Complete Scheduling CPU Ch & Sec 2.5 • Deadlock - Chapter 3 • Skip multiple resources (3.4.2 & 3.5.4)

  3. Objectives – You can name … • Scheduling CPU • The advantages and disadvantages of process scheduling algorithms that are preemptive versus those that are nonpreemptive • The goals of process scheduling policies • Up to six different process scheduling algorithms • Deadlock • Several causes of system deadlock • The difference between preventing and avoiding deadlocks

  4. Types of Scheduling Policies • Preemptive scheduling policy: • Interrupts processing of a job and transfers the CPU to another job • Nonpreemptive scheduling policy: • Functions without external interrupts

  5. Process Scheduling Algorithms • Types of Process Scheduling Algorithms: • First Come, First Served (FCFS) • Shortest Job Next (SJN) • Shortest Remaining Time (SRT) • Three Level Scheduler (Batch) • Round Robin • Multiple Level Queues

  6. Ex. First-Come, First-Served • Jobs arrival sequence: A, B, C • Job A has a CPU cycle of 15 milliseconds • • Job B has a CPU cycle of 2 milliseconds • • Job C has a CPU cycle of 1 millisecond Average turnaround time: 16.67 s Timeline for job sequence A, B, C using theFCFSalgorithm

  7. First-Come, First-Served • Nonpreemptive • Handles jobs according to their arrival time: the earlier they arrive, the sooner they’re served • Simple algorithm to implement: uses a FIFO queue • Good for batch systems; unacceptable for interactive systems • Turnaround time is unpredictable

  8. Ex #2: First-Come, First-Served • Jobs arrival sequence: C, B, A • Job A has a CPU cycle of 15 milliseconds • • Job B has a CPU cycle of 2 milliseconds • • Job C has a CPU cycle of 1 millisecond Average turnaround time: 7.3 s Timeline for job sequence C, B, A using the FCFSalgorithm

  9. Shortest Job Next (SJN) • Nonpreemptive • Handles jobs based on length of their CPU cycle time • Easiest to implement in batch environments • Doesn’t work in interactive systems • Optimal only when all jobs are available at same timeand the CPU estimates are available and accurate

  10. Ex. Shortest Job Next (SJN) Four batch jobs A, B, C, D, all in the READY queue Job: A B C D CPU cycle: 5 2 6 4 Average turnaround time: 9 s Timeline for job sequence B, D, A, C using the SJN algorithm

  11. Ex: Shortest Remaining Time Arrival time: 0 1 2 3 Job: A B C D CPU cycle: 6 3 1 4 Job: A B C D Turnaround: 14 4 1 6 Average Turnaround: 6.25s Timeline for job sequenceA, B, C, D using the preemptiveSRT algorithm

  12. Shortest Remaining Time • Preemptive version of the SJN algorithm • Processor allocated to job closest to completion • Current job can be preempted if newer job in READYqueue has shorter time to completion • Cannot be implemented in interactive system • Requires advance knowledge of the CPU time required to finish each job • SRT involves more overhead than SJN • OS monitors CPU time for all jobs in READY queueand performs context switching

  13. Scheduling in Batch Systems Three level scheduling

  14. Schedulers • Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue. • Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.

  15. Schedulers (Cont.) • Short-term scheduler is invoked very frequently (milliseconds)  (must be fast). • Long-term scheduler is invoked very infrequently (seconds, minutes)  (may be slow). • controls the degree of multiprogramming. • Processes can be described as either: • I/O-bound process – spends more time doing I/O than computations, many short CPU bursts. • CPU-bound process – spends more time doing computations; few very long CPU bursts.

  16. Context Switch • When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. • Context-switch time is overhead; the system does no useful work while switching. • Time dependent on hardware support.

  17. Round Robin • Preemptive • Used extensively in interactive systems • Based on a predeterminedslice of time (time quantum) that’s given to each job • Size of time quantum crucial to system performance • Usually varies from 100 ms to 1-2 s • Ensures CPU is equally shared among all activeprocesses and is not monopolized by any one job

  18. Ex: Round Robin Arrival time: 0 1 2 3 Job: A B C D CPU cycle: 8 4 9 5 Job: A B C D Turnaround: 20 7 24 22 Average Turnaround: 18.25 s Time slice: 4ms Timeline for job sequenceA, B, C, D using the preemptive round robin algorithm

  19. Round Robin (continued) • If Job’s CPU cycle > time quantum • Job is preempted and put at the end of the READY queue and its information is saved in its PCB • If Job’s CPU cycle < time quantum • If job is finished, all resourcesallocated to it are released & completed job is returned touser • If interrupted by I/O request, then infois saved in PCB & it is linked at end of theappropriate I/O queue • Once I/O request is satisfied, job returns to end of READY queue to await allocation of CPU

  20. Round Robin (continued) • Efficiency depends on the size of time quantum in relation tothe average CPU cycle • If the quantum is too large - larger than most CPUcycles • Algorithm reduces to the FCFS scheme • If the quantum is too small • Amount of context switching slows down the execution of the jobs • Amount of overhead is dramatically increased

  21. Round Robin (continued) • General rules of thumb for selecting the proper time quantum: • Should be long enough to allow 80% of CPU cycles to run tocompletion • Should be at least 100 times longer than the time required to performone context switch • These rules are flexible and depend on the system

  22. Scheduling in Interactive Systems A scheduling algorithm with four priority classes

  23. Multiple-Level Queues • Work in conjunction with several other schemes • Found in systems with jobs that can be grouped according to a common characteristic • Priority-based system with different queues for each priority level • System with all CPU-bound jobs in one queue and all I/O-bound jobs inanother • Hybrid system with batch jobs in background queue and interactive jobs in aforeground queue

  24. Multiple-Level Queues (continued) • Four primary methods to the movement of jobs: • No Movement Between Queues • Movement Between Queues • Variable Time Quantum Per Queue • Aging

  25. Multiple-Level Queues • No Movement Between Queues: • The processor is allocated to the jobs in the high-priority queue in FCFS fashion • Allocated to jobs in lower priority queues only when the high priority queues are empty • Movement Between Queues • Adjusts the priorities assigned to each job • A job may also have its priority increased • Good in interactive systems

  26. Multiple-Level Queues • Variable Time Quantum Per Queue: • Each of the queues is given a time quantum twice as long as the previousqueue • CPU-bound job can execute forlonger and longer periods of time, thus improving its chances of finishing faster • Aging: • System moves the old job to the next highest queue, and so on until it reaches the top queue • Ensures that jobs in the lower-level queues will eventually completetheir execution

  27. Scheduling in Real-Time Systems • Schedulable? • If the sum of the ratios CPU Time to Period time is less than one • Sum(CPU/Period) <= 1

  28. Policy versus Mechanism • Separate what is allowed to be done with how it is done • a process knows which of its children threads are important and need priority • Scheduling algorithm parameterized • mechanism in the kernel • Parameters filled in by user processes • policy set by user process

  29. Thread Scheduling Possible scheduling of user-level threads • 50-msec process quantum • threads run 5 msec/CPU burst

  30. Kernel-level Thread Scheduling Possible scheduling of kernel-level threads • 50-msec process quantum • threads run 5 msec/CPU burst

  31. Deadlocking over Resources • An object granted • Hardware (disk, cpu) • Piece of Information (memory, record in DB) • Preemptable & non-preemptable • Memory vs. Writing CD-ROM

  32. Utilizing a Resource • Protect “Critical Region” • Request resource • Use Resource • Release resource • Use a semaphore/mutex to get/release lock on resource

  33. Deadlock Defined • From our more playful days … • I’ve got the ball and want the bat • You’ve got the bat and want the ball • “A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.”

  34. D A S T U R B C Process Aholdingresource R Process Brequestingresource S Circularity = Deadlock Resource Allocation Graphs Which are ball and bat? Which are the two players?

  35. Conditions for Deadlock • Mutual exclusion of resource • Hold and Wait (processes with a resource can request other resources) • Non-preemptable resources • Circular wait (chain of processes in wait) • See RAGs (previous slide)

  36. Dealing with Deadlock • Ostrich Algorithm • Detection & Recovery • Dynamic Avoidance • Prevention

  37. Ostrich Algorithm • Stick your head in the sand and pretend there is no problem at all • What is the typical use of the system? • What is the probability of deadlock? • Do the costs associated with dealing w/ deadlock outweigh the benefits?

  38. Summary • Scheduler responsible for many goals • Use algorithm to meet goals of the system/users • Scheduling algorithms complex • Know your arithmetic! • Every operating system must dynamically allocate a limited number of resources while avoiding the two extremes of deadlock and starvation • Several methods of dealing with deadlocks include prevention, avoidance, and detection and recovery

  39. Thurs, Feb 22, Complete Deadlock • Resources & Deadlock • Ostrich Algorithm • Deadlock Detection (skip 3.4.2 Multiple Resources) • Deadlock Recovery (3.4.3) • Deadlock Avoidance (skip 3.5.4 Mult-Resource) • Deadlock Prevention

More Related