5.CPU Scheduling
Upcoming SlideShare
Loading in...5
×
 

5.CPU Scheduling

on

  • 1,028 views

Senthilkanth,MCA.. ...

Senthilkanth,MCA..
The following ppt's full topic covers Operating System for BSc CS, BCA, MSc CS, MCA students..
1.Introduction
2.OS Structures
3.Process
4.Threads
5.CPU Scheduling
6.Process Synchronization
7.Dead Locks
8.Memory Management
9.Virtual Memory
10.File system Interface
11.File system implementation
12.Mass Storage System
13.IO Systems
14.Protection
15.Security
16.Distributed System Structure
17.Distributed File System
18.Distributed Co Ordination
19.Real Time System
20.Multimedia Systems
21.Linux
22.Windows

Statistics

Views

Total Views
1,028
Views on SlideShare
1,028
Embed Views
0

Actions

Likes
0
Downloads
106
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    5.CPU Scheduling 5.CPU Scheduling Presentation Transcript

    • Chapter 5: CPU SchedulingChapter 5: CPU Scheduling
    • 5.2 Silberschatz, Galvin and GagneOperating System ConceptsChapter 5: CPU SchedulingChapter 5: CPU SchedulingBasic ConceptsScheduling CriteriaScheduling AlgorithmsMultiple-Processor SchedulingReal-Time SchedulingThread SchedulingOperating Systems ExamplesJava Thread SchedulingAlgorithm Evaluation
    • 5.3 Silberschatz, Galvin and GagneOperating System ConceptsBasic ConceptsBasic ConceptsMaximum CPU utilization obtained with multiprogrammingCPU–I/O Burst Cycle – Process execution consists of a cycle ofCPU execution and I/O waitCPU burst distribution
    • 5.4 Silberschatz, Galvin and GagneOperating System ConceptsAlternating Sequence of CPU And I/OAlternating Sequence of CPU And I/OBurstsBursts
    • 5.5 Silberschatz, Galvin and GagneOperating System ConceptsHistogram of CPU-burst TimesHistogram of CPU-burst Times
    • 5.6 Silberschatz, Galvin and GagneOperating System ConceptsCPU SchedulerCPU SchedulerSelects from among the processes in memory that are ready toexecute, and allocates the CPU to one of themCPU scheduling decisions may take place when a process:1. Switches from running to waiting state2. Switches from running to ready state3. Switches from waiting to ready4. TerminatesScheduling under 1 and 4 is nonpreemptiveAll other scheduling is preemptive
    • 5.7 Silberschatz, Galvin and GagneOperating System ConceptsDispatcherDispatcherDispatcher module gives control of the CPU to the processselected by the short-term scheduler; this involves:switching contextswitching to user modejumping to the proper location in the user program to restartthat programDispatch latency – time it takes for the dispatcher to stop oneprocess and start another running
    • 5.8 Silberschatz, Galvin and GagneOperating System ConceptsScheduling CriteriaScheduling CriteriaCPU utilization – keep the CPU as busy as possibleThroughput – # of processes that complete their executionper time unitTurnaround time – amount of time to execute a particularprocessWaiting time – amount of time a process has been waitingin the ready queueResponse time – amount of time it takes from when arequest was submitted until the first response is produced,not output (for time-sharing environment)
    • 5.9 Silberschatz, Galvin and GagneOperating System ConceptsOptimization CriteriaOptimization CriteriaMax CPU utilizationMax throughputMin turnaround timeMin waiting timeMin response time
    • 5.10 Silberschatz, Galvin and GagneOperating System ConceptsFirst-Come, First-Served (FCFS)First-Come, First-Served (FCFS)SchedulingSchedulingProcess Burst TimeP1 24P2 3P3 3Suppose that the processes arrive in the order: P1 , P2 , P3The Gantt Chart for the schedule is:Waiting time for P1 = 0; P2 = 24; P3 = 27Average waiting time: (0 + 24 + 27)/3 = 17P1 P2 P324 27 300
    • 5.11 Silberschatz, Galvin and GagneOperating System ConceptsFCFS Scheduling (Cont.)FCFS Scheduling (Cont.)Suppose that the processes arrive in the orderP2 , P3 , P1The Gantt chart for the schedule is:Waiting time for P1 = 6;P2 = 0; P3 = 3Average waiting time: (6 + 0 + 3)/3 = 3Much better than previous caseConvoy effect short process behind long processP1P3P263 300
    • 5.12 Silberschatz, Galvin and GagneOperating System ConceptsShortest-Job-First (SJR) SchedulingShortest-Job-First (SJR) SchedulingAssociate with each process the length of its next CPU burst. Usethese lengths to schedule the process with the shortest timeTwo schemes:nonpreemptive – once CPU given to the process it cannot bepreempted until completes its CPU burstpreemptive – if a new process arrives with CPU burst lengthless than remaining time of current executing process, preempt.This scheme is know as theShortest-Remaining-Time-First (SRTF)SJF is optimal – gives minimum average waiting time for a givenset of processes
    • 5.13 Silberschatz, Galvin and GagneOperating System ConceptsProcess Arrival Time Burst TimeP1 0.0 7P2 2.0 4P3 4.0 1P4 5.0 4SJF (non-preemptive)Average waiting time = (0 + 6 + 3 + 7)/4 = 4Example of Non-Preemptive SJFExample of Non-Preemptive SJFP1 P3 P273 160P48 12
    • 5.14 Silberschatz, Galvin and GagneOperating System ConceptsExample of Preemptive SJFExample of Preemptive SJFProcess Arrival Time Burst TimeP1 0.0 7P2 2.0 4P3 4.0 1P4 5.0 4SJF (preemptive)Average waiting time = (9 + 1 + 0 +2)/4 = 3P1 P3P242 110P45 7P2 P116
    • 5.15 Silberschatz, Galvin and GagneOperating System ConceptsDetermining Length of Next CPUDetermining Length of Next CPUBurstBurstCan only estimate the lengthCan be done by using the length of previous CPU bursts, usingexponential averaging:Define4.10,3.burstCPUnexttheforvaluepredicted2.burstCPUoflenghtactual1.1≤≤==+αατnthnnt( ) .11 nnnt ταατ −+==
    • 5.16 Silberschatz, Galvin and GagneOperating System ConceptsPrediction of the Length of the Next CPUPrediction of the Length of the Next CPUBurstBurst
    • 5.17 Silberschatz, Galvin and GagneOperating System ConceptsExamples of Exponential AveragingExamples of Exponential Averagingα =0τn+1 = τnRecent history does not countα =1τn+1 = α tnOnly the actual last CPU burst countsIf we expand the formula, we get:τn+1 = α tn+(1 - α)α tn -1 + …+(1 - α )jα tn -j + …+(1 - α )n +1τ0Since both α and (1 - α) are less than or equal to 1, eachsuccessive term has less weight than its predecessor
    • 5.18 Silberschatz, Galvin and GagneOperating System ConceptsPriority SchedulingPriority SchedulingA priority number (integer) is associated with each processThe CPU is allocated to the process with the highest priority(smallest integer ≡ highest priority)PreemptivenonpreemptiveSJF is a priority scheduling where priority is the predicted next CPUburst timeProblem ≡ Starvation – low priority processes may never executeSolution ≡ Aging – as time progresses increase the priority of theprocess
    • 5.19 Silberschatz, Galvin and GagneOperating System ConceptsRound Robin (RR)Round Robin (RR)Each process gets a small unit of CPU time (time quantum),usually 10-100 milliseconds. After this time has elapsed, theprocess is preempted and added to the end of the ready queue.If there are n processes in the ready queue and the timequantum is q, then each process gets 1/n of the CPU time inchunks of at most q time units at once. No process waits morethan (n-1)q time units.Performanceq large ⇒ FIFOq small ⇒ q must be large with respect to context switch,otherwise overhead is too high
    • 5.20 Silberschatz, Galvin and GagneOperating System ConceptsExample of RR with Time Quantum =Example of RR with Time Quantum =2020Process Burst TimeP1 53P2 17P3 68P4 24The Gantt chart is:Typically, higher average turnaround than SJF, but better responseP1 P2 P3 P4 P1 P3 P4 P1 P3 P30 20 37 57 77 97 117 121 134 154 162
    • 5.21 Silberschatz, Galvin and GagneOperating System ConceptsTime Quantum and Context SwitchTime Quantum and Context SwitchTimeTime
    • 5.22 Silberschatz, Galvin and GagneOperating System ConceptsTurnaround Time Varies With The TimeTurnaround Time Varies With The TimeQuantumQuantum
    • 5.23 Silberschatz, Galvin and GagneOperating System ConceptsMultilevel QueueMultilevel QueueReady queue is partitioned into separate queues:foreground (interactive)background (batch)Each queue has its own scheduling algorithmforeground – RRbackground – FCFSScheduling must be done between the queuesFixed priority scheduling; (i.e., serve all from foreground thenfrom background). Possibility of starvation.Time slice – each queue gets a certain amount of CPU timewhich it can schedule amongst its processes; i.e., 80% toforeground in RR20% to background in FCFS
    • 5.24 Silberschatz, Galvin and GagneOperating System ConceptsMultilevel Queue SchedulingMultilevel Queue Scheduling
    • 5.25 Silberschatz, Galvin and GagneOperating System ConceptsMultilevel Feedback QueueMultilevel Feedback QueueA process can move between the various queues; aging can beimplemented this wayMultilevel-feedback-queue scheduler defined by the followingparameters:number of queuesscheduling algorithms for each queuemethod used to determine when to upgrade a processmethod used to determine when to demote a processmethod used to determine which queue a process will enterwhen that process needs service
    • 5.26 Silberschatz, Galvin and GagneOperating System ConceptsExample of Multilevel FeedbackExample of Multilevel FeedbackQueueQueueThree queues:Q0 – RR with time quantum 8 millisecondsQ1 – RR time quantum 16 millisecondsQ2 – FCFSSchedulingA new job enters queue Q0 which is served FCFS. When itgains CPU, job receives 8 milliseconds. If it does not finish in 8milliseconds, job is moved to queue Q1.At Q1 job is again served FCFS and receives 16 additionalmilliseconds. If it still does not complete, it is preempted andmoved to queue Q2.
    • 5.27 Silberschatz, Galvin and GagneOperating System ConceptsMultilevel Feedback QueuesMultilevel Feedback Queues
    • 5.28 Silberschatz, Galvin and GagneOperating System ConceptsMultiple-Processor SchedulingMultiple-Processor SchedulingCPU scheduling more complex when multiple CPUs areavailableHomogeneous processors within a multiprocessorLoad sharingAsymmetric multiprocessing – only one processoraccesses the system data structures, alleviating the needfor data sharing
    • 5.29 Silberschatz, Galvin and GagneOperating System ConceptsReal-Time SchedulingReal-Time SchedulingHard real-time systems – required to complete acritical task within a guaranteed amount of timeSoft real-time computing – requires that criticalprocesses receive priority over less fortunate ones
    • 5.30 Silberschatz, Galvin and GagneOperating System ConceptsThread SchedulingThread SchedulingLocal Scheduling – How the threads library decides whichthread to put onto an available LWPGlobal Scheduling – How the kernel decides which kernelthread to run next
    • 5.31 Silberschatz, Galvin and GagneOperating System ConceptsPthread Scheduling APIPthread Scheduling API#include <pthread.h>#include <stdio.h>#define NUM THREADS 5int main(int argc, char *argv[]){int i;pthread t tid[NUM THREADS];pthread attr t attr;/* get the default attributes */pthread attr init(&attr);/* set the scheduling algorithm to PROCESS or SYSTEM */pthread attr setscope(&attr, PTHREAD SCOPE SYSTEM);/* set the scheduling policy - FIFO, RT, or OTHER */pthread attr setschedpolicy(&attr, SCHED OTHER);/* create the threads */for (i = 0; i < NUM THREADS; i++)pthread create(&tid[i],&attr,runner,NULL);
    • 5.32 Silberschatz, Galvin and GagneOperating System ConceptsPthread Scheduling APIPthread Scheduling API/* now join on each thread */for (i = 0; i < NUM THREADS; i++)pthread join(tid[i], NULL);}/* Each thread will begin control in thisfunction */void *runner(void *param){printf("I am a threadn");pthread exit(0);}
    • 5.33 Silberschatz, Galvin and GagneOperating System ConceptsOperating System ExamplesOperating System ExamplesSolaris schedulingWindows XP schedulingLinux scheduling
    • 5.34 Silberschatz, Galvin and GagneOperating System ConceptsSolaris 2 SchedulingSolaris 2 Scheduling
    • 5.35 Silberschatz, Galvin and GagneOperating System ConceptsSolaris Dispatch TableSolaris Dispatch Table
    • 5.36 Silberschatz, Galvin and GagneOperating System ConceptsWindows XP PrioritiesWindows XP Priorities
    • 5.37 Silberschatz, Galvin and GagneOperating System ConceptsLinux SchedulingLinux SchedulingTwo algorithms: time-sharing and real-timeTime-sharingPrioritized credit-based – process with most credits isscheduled nextCredit subtracted when timer interrupt occursWhen credit = 0, another process chosenWhen all processes have credit = 0, recrediting occurs Based on factors including priority and historyReal-timeSoft real-timePosix.1b compliant – two classes FCFS and RR Highest priority process always runs first
    • 5.38 Silberschatz, Galvin and GagneOperating System ConceptsThe Relationship Between Priorities and Time-sliceThe Relationship Between Priorities and Time-slicelengthlength
    • 5.39 Silberschatz, Galvin and GagneOperating System ConceptsList of Tasks Indexed According toList of Tasks Indexed According toProritiesProrities
    • 5.40 Silberschatz, Galvin and GagneOperating System ConceptsAlgorithm EvaluationAlgorithm EvaluationDeterministic modeling – takes a particular predeterminedworkload and defines the performance of each algorithmfor that workloadQueueing modelsImplementation
    • 5.41 Silberschatz, Galvin and GagneOperating System Concepts5.155.15
    • End of Chapter 5End of Chapter 5
    • 5.43 Silberschatz, Galvin and GagneOperating System Concepts5.085.08
    • 5.44 Silberschatz, Galvin and GagneOperating System ConceptsIn-5.7In-5.7
    • 5.45 Silberschatz, Galvin and GagneOperating System ConceptsIn-5.8In-5.8
    • 5.46 Silberschatz, Galvin and GagneOperating System ConceptsIn-5.9In-5.9
    • 5.47 Silberschatz, Galvin and GagneOperating System ConceptsDispatch LatencyDispatch Latency
    • 5.48 Silberschatz, Galvin and GagneOperating System ConceptsJava Thread SchedulingJava Thread SchedulingJVM Uses a Preemptive, Priority-Based Scheduling AlgorithmFIFO Queue is Used if There Are Multiple Threads With the SamePriority
    • 5.49 Silberschatz, Galvin and GagneOperating System ConceptsJava Thread Scheduling (cont)Java Thread Scheduling (cont)JVM Schedules a Thread to Run When:1. The Currently Running Thread Exits the Runnable State2. A Higher Priority Thread Enters the Runnable State* Note – the JVM Does Not Specify Whether Threads are Time-Slicedor Not
    • 5.50 Silberschatz, Galvin and GagneOperating System ConceptsTime-SlicingTime-SlicingSince the JVM Doesn’t Ensure Time-Slicing, the yield() MethodMay Be Used:while (true) {// perform CPU-intensive task. . .Thread.yield();}This Yields Control to Another Thread of Equal Priority
    • 5.51 Silberschatz, Galvin and GagneOperating System ConceptsThread PrioritiesThread PrioritiesPriority CommentThread.MIN_PRIORITY Minimum Thread PriorityThread.MAX_PRIORITY Maximum Thread PriorityThread.NORM_PRIORITY Default Thread PriorityPriorities May Be Set Using setPriority() method:setPriority(Thread.NORM_PRIORITY + 2);