您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > 计算机操作系统原理6
wency@cuit.edu.cn20106.1OperatingSystemConceptsChapter6:CPUSchedulingBasicConceptsSchedulingCriteriaSchedulingAlgorithmsReal-TimeSchedulingProcessSchedulingModels*wency@cuit.edu.cn20106.2OperatingSystemConcepts6.1BasicConceptsTheobjectiveofmultiprogrammingistomaximumCPUutilizationwithseveralprocessesrunningatalltimes.Inuniprocessorsystem,onlyoneprocessmayrunatatime.AnyotherprocessesmustwaituntilCPUisfreeandcanberescheduled.SchedulingisafundamentalOSfunction.Asoneoftheprimarycomputerresource,CPUschedulingiscentral.wency@cuit.edu.cn20106.3OperatingSystemConcepts6.1BasicConcepts(1)CPUscheduler--Selectsfromamongtheprocessesinmemorythatarereadytoexecute,andallocatestheCPUtooneofthem.CPUschedulingdecisionsmaytakeplacewhenaprocess:1.Switchesfromrunningtowaitingstate.2.Switchesfromrunningtoreadystate.3.Ahighpriorityswitchesfromwaitingtoready.4.Terminates.Schedulingmodes--Schedulingunder1and4isnonpreemptive.Allotherschedulingispreemptive.--CPUSchedulerwency@cuit.edu.cn20106.4OperatingSystemConcepts6.1BasicConcepts(2)Nonpreemptivescheduling–onceCPUhasbeenallocatedtoaprocess,itkeepsCPUuntilitreleasetheCPUeitherbyterminatingorbyswitchingtothewaitingstate.Preemptivescheduling–schedulercanswitchCPUfromarunningprocesstoanotheraccordingtothepolicy.Availablepolicies–suchastimeslice,priority,andshortest-jobfirstRequiresspecialhardwaresupportandhasaneffectonthedesignofoperatingsystemkernel.Canbeusedinallcircumstances.--CPUSchedulerwency@cuit.edu.cn20106.5OperatingSystemConcepts6.1BasicConcepts(2)Dispatcher--givescontroloftheCPUtotheprocessselectedbytheshort-termscheduler;thisinvolves:switchingcontextswitchingtousermodejumpingtotheproperlocationintheuserprogramtorestartthatprogramDispatchlatency–thetimeittakesforthedispatchertostoponeprocessandstartanotherrunning.--Dispatcherwency@cuit.edu.cn20106.6OperatingSystemConcepts6.2SchedulingCriteriaCPUutilization–keeptheCPUasbusyaspossible.Throughput–thenumberofprocessesthatcompletetheirexecutionpertimeunit.Turnaroundtime–amountoftime(fromsubmissiontocompletion)toexecuteaparticularprocess.Waitingtime–amountoftimeaprocesshasbeenwaitinginthereadyqueue.Responsetime–amountoftimeittakesfromwhenarequestwassubmitteduntilthefirstresponseisproducedOptimizationCriteria--MaxCPUutilization,Maxthroughput,Minturnaroundtime,Minwaitingtime,andMinresponsetimewency@cuit.edu.cn20106.7OperatingSystemConcepts6.3SchedulingAlgorithmsFirst-Come,First-Served(FCFS)SchedulingShortest-Job-First(SJF)SchedulingPrioritySchedulingRound-RobinSchedulingMultilevelQueueSchedulingMultilevelFeedbackQueueSchedulingwency@cuit.edu.cn20106.8OperatingSystemConcepts6.3.1FCFSSchedulingFCFS–whicheverrequestsCPUfirstisallocatedtheCPUfirst.ImplementedasaFIFOqueue.Averagewaitingtimeisoftenquitelong.exampleProcessBurstTimeP124P23P33Supposethattheprocessesarriveattime0,intheorder:P1,P2,P3,theGanttChartforthescheduleis:WaitingtimeforP1=0;P2=24;P3=27Averagewaitingtime:(0+24+27)/3=17P1P2P32427300wency@cuit.edu.cn20106.9OperatingSystemConcepts6.3.1FCFSScheduling(1)Supposethattheprocessesarriveintheorder:P2,P3,P1.TheGanttchartforthescheduleis:WaitingtimeforP1=6;P2=0;P3=3Averagewaitingtime:(6+0+3)/3=3Thisismuchbetterthanpreviouscase.Thusaveragewaitingtimeforthisisnotminimal,andmayvarysubstantiallyifprocessCPU-bursttimesvarygreatly.Thecauseistheshortprocessbehindlongprocess.ThiseffectmayresultinlowerCPUanddeviceutilizationthanmightbepossibleifshorterallowedtogofirst.P1P3P263300wency@cuit.edu.cn20106.10OperatingSystemConcepts6.3.2SJFSchedulingSJF--AssociatewitheachprocessthelengthofitsnextCPUburst.Usetheselengthstoscheduletheprocesswiththeshortesttime.Twoschemes:nonpreemptive–onceCPUgiventotheprocessitcannotbepreempteduntilcompletesitsCPUburst.preemptive–ifanewprocessarriveswithCPUburstlengthlessthanremainingtimeofcurrentexecutingprocess,preempt.ThisschemeisknowastheShortest-Remaining-Time-First(SRTF).SJFisoptimal–givesminimumaveragewaitingtimeforagivensetofprocesses.SJFisusedfrequentlyinlong-termscheduling,andcannotbeimplementedinCPU-scheduling.ThereisnowaytoknowthelengthofthenextCPUburst.wency@cuit.edu.cn20106.11OperatingSystemConceptsExampleofNon-PreemptiveSJFProcessArrivalTimeBurstTimeP107P224P341P454SJF(non-preemptive)Averagewaitingtime=(0+6+3+7)/4=46.3.2SJFScheduling(1)P1P3P273160P4812wency@cuit.edu.cn20106.12OperatingSystemConceptsP1P3P242110P457P2P1166.3.2SJFScheduling(2)ExampleofPreemptiveSJFProcessArrivalTimeBurstTimeP107P224P341P454SJF(preemptive)Averagewaitingtime=(9+1+0+2)/4=3wency@cuit.edu.cn20106.13OperatingSystemConcepts6.3.3PrioritySchedulingPriority--Anumber(integer)isassociatedwitheachprocess.CPUisallocatedtotheprocesswiththehighestpriority.Equal-priorityprocessesarescheduledinFCFSorder.Preemptive–preemptCPUifthepriorityofnewlyarrivedprocessishigherthanthatofthecurrentlyrunningprocess.Nonpreemptive–simplyputthenewprocessattheheadofreadyqueue.SJFisapriorityschedulingwherepriorityisthepredictednextCPUbursttime.ProblemStarvation–lowpriorityproce
本文标题:计算机操作系统原理6
链接地址:https://www.777doc.com/doc-5263254 .html