版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter5CPUSchedulingOperatingSystemConceptsChapter5:CPUSchedulingBasicConceptsSchedulingCriteriaSchedulingAlgorithmsMultiple-ProcessorSchedulingThreadSchedulingAlgorithmEvaluationOperatingSystemConceptsBasicConceptsMaximumCPUutilizationobtainedwithmultiprogrammingCPU–I/OBurstCycle–ProcessexecutionconsistsofacycleofCPUexecutionandI/Owait.OperatingSystemConceptsAlternatingSequenceofCPUAndI/OBurstsOperatingSystemConceptsOperatingSystemConceptsCPU-I/OBurstCycleProcessexecutionrepeatstheCPUburstandI/Oburstcycle.WhenaprocessbeginsanI/Oburst,anotherprocesscanusetheCPUforaCPUburst.OperatingSystemConceptsCPU-boundandI/O-boundAprocessisCPU-boundifitgeneratesI/Orequestsinfrequently,usingmoreofitstimedoingcomputation.AprocessisI/O-boundifitspendsmoreofitstimetodoI/Othanitspendsdoingcomputation.ACPU-boundprocessmighthaveafewverylongCPUbursts.AnI/O-boundprocesstypicallyhasmanyshortCPUburstsOperatingSystemConceptsOperatingSystemConceptsCPUSchedulerWhentheCPUisidle,theOSmustselectanotherprocesstorun.Thisselectionprocessiscarriedoutbytheshort-termscheduler
(orCPUscheduler).TheCPUschedulerselectsaprocessfromthereadyqueue,andallocatestheCPUtoit.ThereadyqueuedoesnothavetobeaFIFOone.Therearemanywaystoorganizethereadyqueue.OperatingSystemConceptsCircumstancesthatscheduling
maytakeplace1.Aprocessswitchesfromtherunningstatetothewaitstate(e.g.,doingforI/O)2.Aprocessswitchesfromtherunningstatetothereadystate(e.g.,aninterruptoccurs)3.Aprocessswitchesfromthewaitstatetothereadystate(e.g.,I/Ocompletion)4.AprocessterminatesOperatingSystemConceptsOperatingSystemConceptsPreemptivevs.Non-preemptiveNon-preemptivescheduling:schedulingoccurswhenaprocessvoluntarilyentersthewaitstate(case1)orterminates(case4).Simple,butveryinefficientPreemptivescheduling:schedulingoccursinallpossiblecases.OperatingSystemConceptsDispatcherDispatchermodulegivescontroloftheCPUtotheprocessselectedbytheshort-termscheduler;thisinvolves:switchingcontextswitchingtousermodejumpingtotheproperlocationintheuserprogramtorestartthatprogramDispatchlatency–timeittakesforthedispatchertostoponeprocessandstartanotherrunning.OperatingSystemConceptsChapter6:CPUSchedulingBasicConceptsSchedulingCriteria
SchedulingAlgorithmsMultiple-ProcessorSchedulingReal-TimeSchedulingAlgorithmEvaluationOperatingSystemConceptsSchedulingCriteriaTherearemanycriteriaforcomparingdifferentschedulingalgorithms.Herearefivecommonones:CPUutilizationThroughputTurnaroundtimeWaitingtimeResponsetimeOperatingSystemConceptsCPUUtilizationWewanttokeeptheCPUasbusyaspossible.CPUutilizationrangesfrom0to100percent.Normally40%islightlyloadedand90%orhigherisheavilyloaded.YoucanbringupaCPUusagemetertoseeCPUutilizationonyoursystem.OperatingSystemConceptsThroughputThenumberofprocessescompletedpertimeunitiscalledthroughput.Higherthroughputmeansmorejobsgetdone.However,forlongprocesses,thisratemaybeonejobperhour,and,forshortjobs,thisratemaybe10perminute.OperatingSystemConceptsTurnaroundTimeThetimeperiodbetweenjobsubmissiontocompletionistheturnaroundtime.Fromauser’spointofview,turnaroundtimeismoreimportantthanCPUutilizationandthroughput.Turnaroundtimeisthesumofwaitingtimebeforeenteringthesystemwaitingtimeinthereadyqueuewaitingtimeinallotherevents(e.g.,I/O)timetheprocessactuallyrunningontheCPUOperatingSystemConceptsWaitingTimeWaitingtimeisthesumoftheperiodsthataprocessspendswaitinginthereadyqueue.Whyonlyreadyqueue?CPUschedulingalgorithmsdonotaffecttheamountoftimeduringwhichaprocessiswaitingforI/Oandotherevents.However,CPUschedulingalgorithmsdoaffectthetimethataprocessstaysinthereadyqueueOperatingSystemConceptsResponseTimeThetimefromthesubmissionofarequest(inaninteractivesystem)tothefirstresponseiscalledresponsetime.Itdoesnotincludethetimethatittakestooutputtheresponse.Forexample,infrontofyourworkstation,youperhapscaremoreaboutthetimebetweenhittingtheReturnkeyandgettingyourfirstoutputthanthetimefromhittingtheReturnkeytothecompletionofyourprogram(e.g.,turnaroundtime).OperatingSystemConceptsOptimizationCriteriaMaxCPUutilizationMaxthroughputMinturnaroundtimeMinwaitingtimeMinresponsetimeOperatingSystemConceptsChapter6:CPUSchedulingBasicConceptsSchedulingCriteriaSchedulingAlgorithmsMultiple-ProcessorSchedulingReal-TimeSchedulingAlgorithmEvaluationOperatingSystemConceptsSchedulingAlgorithmsWewilldiscussanumberofschedulingalgorithms:First-Come,First-Served(FCFS)Shortest-Job-First(SJF)PriorityRound-RobinMultilevelQueueMultilevelFeedbackQueueOperatingSystemConceptsFirst-Come,First-Served(FCFS)SchedulingTheprocessthatrequeststheCPUfirstisallocatedtheCPUfirst.Thiscaneasilybeimplementedusingaqueue.FCFSisnotpreemptive.OnceaprocesshastheCPU,itwilloccupytheCPUuntiltheprocesscompletesorvoluntarilyentersthewaitstate.OperatingSystemConceptsFCFSScheduling(Cont.)
Process
BurstTime
P1 24
P2 3
P3 3
Supposethattheprocessesarriveintheorder:P1,P2,P3
TheGanttChartforthescheduleis:P1P2P32427300Waitingtime?Averagewaitingtime?OperatingSystemConceptsFCFSScheduling(Cont.)Supposethattheprocessesarriveintheorder
P2,P3,P1.TheGanttchartforthescheduleis:
WaitingtimeforP1=6;
P2=0;P3=3Averagewaitingtime:(6+0+3)/3=3Muchbetterthanpreviouscase.ConvoyeffectshortprocessbehindlongprocessP1P3P263300OperatingSystemConceptsFCFSProblemsItiseasytohavetheconvoyeffect:alltheprocesseswaitfortheonebigprocesstogetofftheCPU.CPUutilizationmaybelow.ConsideraCPU-boundprocessrunningwithmanyI/O-boundprocess.Itisinfavoroflongprocessesandmaynotbefairtothoseshortones.Whatifyour1-minutejobisbehinda10-hourjob?Itistroublesomefortime-sharingsystems,whereeachuserneedstogetashareoftheCPUatregularintervals.OperatingSystemConceptsShortest-Job-First(SJF)SchedulingAssociatewitheachprocessthelengthofitsnextCPUburst.Usetheselengthstoscheduletheprocesswiththeshortesttime.Whenaprocessmustbeselectedfromthereadyqueue,theprocesswiththesmallestnextCPUburstisselected.Thus,theprocessesinthereadyqueuearesortedinCPUburstlength.OperatingSystemConceptsShortest-Job-First(SJF)Scheduling(Cont.)SJFcanbenon-preemptiveorpreemptive.nonpreemptive–onceCPUgiventotheprocessitcannotbepreempteduntilcompletesitsCPUburst.preemptive–ifanewprocessarriveswithCPUburstlengthlessthanremainingtimeofcurrentexecutingprocess,preempt.Thisschemeisknowasthe
Shortest-Remaining-Time-First(SRTF).SJFisoptimal–givesminimumaveragewaitingtimeforagivensetofprocesses.OperatingSystemConceptsSJFisprovablyoptimalEverytimewemakeashortjobbeforealongjob,wereduceaveragewaitingtime.Wemayswitchoutoforderjobsuntilalljobsareinorder.Ifthejobsaresorted,jobswitchingisimpossible.OperatingSystemConcepts
Process ArrivalTime
BurstTime
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4SJF(non-preemptive)Averagewaitingtime=(0+6+3+7)/4=4ExampleofNon-PreemptiveSJFP1P3P273160P4812OperatingSystemConceptsExampleofPreemptiveSJF
Process ArrivalTime
BurstTime
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4SJF(preemptive)Averagewaitingtime=(9+1+0+2)/4=3P1P3P242110P457P2P116OperatingSystemConceptsHowdoweknowtheNextCPUBurst?Withoutagoodanswertothisquestion,SJFcannotbeusedforCPUscheduling.WetrytopredictthenextCPUburst!CanbedonebyusingthelengthofpreviousCPUbursts,usingexponentialaveraging.OperatingSystemConceptsOperatingSystemConceptsExamplesofExponentialAveraging=0n+1=nRecenthistorydoesnotcount.=1n+1=tnOnlytheactuallastCPUburstcounts.OperatingSystemConceptsPredictionoftheLengthoftheNextCPUBurstOperatingSystemConceptsExamplesofExponentialAveraging(Cont.)Ifweexpandtheformula,weget:n+1=tn+(1-)tn-1
+…
+(1-)jtn-j
+…
+(1-)n+10Sincebothand(1-)arelessthanorequalto1,eachsuccessivetermhaslessweightthanitspredecessor.OperatingSystemConceptsSJFProblemsItisdifficulttoestimatethenextbursttimevalueaccurately.SJFisinfavorofshortjobs.Asaresult,somelongjobsmaynothaveachancetorunatall.Thisisstarvation.OperatingSystemConceptsPrioritySchedulingEachprocesshasapriority.Prioritymaybedeterminedinternallyorexternally:internalpriority:determinedbytimelimits,memoryrequirement,#offiles,andsoon.externalpriority:notcontrolledbytheOS(e.g.,importanceoftheprocess)Thescheduleralwayspickstheprocess(inreadyqueue)withthehighestprioritytorun.FCFSandSJFarespecialcasesofpriorityscheduling.(Why?)OperatingSystemConceptsPriorityScheduling(Cont.)Priorityschedulingcanbenon-preemptiveorpreemptive.Withpreemptivepriorityscheduling,ifthenewlyarrivedprocesshasahigherprioritythantherunningone,thelatterispreempted.Indefiniteblock(orstarvation)mayoccur:alowpriorityprocessmayneverhaveachancetorunOperatingSystemConceptsAgingAgingisatechniquetoovercomethestarvtionproblem.Aging:graduallyincreasesthepriorityofprocessesthatwaitinthesystemforalongtime.Example:If0isthehighest(resp.,lowest)priority,thenwecoulddecrease(resp.,increase)thepriorityofawaitingprocessby1everyfixedperiod(e.g.,everyminute).OperatingSystemConceptsRoundRobin(RR)RRissimilartoFCFS,exceptthateachprocessisassignedatimequantum.AllprocessesinthereadyqueueisaFIFOlist.WhentheCPUisfree,theschedulerpicksthefirstandletsitrunforonetimequantum.IfthatprocessusesCPUforlessthanonetimequantum,itismovedtothetailofthelist.Otherwise,whenonetimequantumisup,thatprocessispreemptedbytheschedulerandmovedtothetailofthelist.OperatingSystemConceptsExampleofRRwithTimeQuantum=20
Process
BurstTime P1 53
P2 17
P3 68
P4 24TheGanttchartis:
Typically,higheraverageturnaroundthanSJF,butbetterresponse.P1P2P3P4P1P3P4P1P3P302037577797117121134154162OperatingSystemConceptsRRScheduling:SomeIssuesIftimequantumistoolarge,RRreducestoFCFSIftimequantumistoosmall,RRbecomesprocessorsharingContextswitchingmayaffectRR’sperformanceShortertimequantummeansmorecontextswitchesTurnaroundtimealsodependsonthesizeoftimequantum.Ingeneral,80%oftheCPUburstsshouldbeshorterthanthetimequantumOperatingSystemConceptsTimeQuantumandContextSwitchTimeOperatingSystemConceptsTurnaroundTimeVariesWithTheTimeQuantumHowtocalculate?OperatingSystemConceptsMultilevelQueueReadyqueueispartitionedintoseparatequeues:
foreground(interactive)
background(batch)Eachprocessisassignedpermanentlytoonequeuebasedonsomepropertiesoftheprocess(e.g.,memoryusage,priority,processtype)Eachqueuehasitsownschedulingalgorithm,
foreground–RR
background–FCFSOperatingSystemConceptsAprocessPcanrunonlyifallqueuesabovethequeuethatcontainsPareempty.Whenaprocessisrunningandaprocessinahigherpriorityqueuecomesin,therunningprocessispreempted.OperatingSystemConceptsMultilevelQueue(Cont.)Schedulingmustbedonebetweenthequeues.Fixedpriorityscheduling;(i.e.,serveallfromforegroundthenfrombackground).Possibilityofstarvation.Timeslice–eachqueuegetsacertainamountofCPUtimewhichitcanscheduleamongstitsprocesses;i.e.,80%toforegroundinRR,20%tobackgroundinFCFSOperatingSystemConceptsMultilevelFeedbackQueueMultilevelqueuewithfeedbackscheduling
issimilartomultilevelqueue;however,itallowsprocessestomovebetweenqueues.agingcanbeimplementedthiswayIfaprocessusesmore(resp.,less)CPUtime,itismovedtoaqueueoflower(resp.,higher)priority.Asaresult,I/O-bound(resp.,CPU-bound)processeswillbeinhigher(resp.,lower)priorityqueues.OperatingSystemConceptsExampleofMultilevelFeedbackQueueThreequeues:Q0–timequantum8millisecondsQ1–timequantum16millisecondsQ2–FCFSSchedulingAnewjobentersQ0
whichisserved
FCFS.WhenitgainsCPU,jobreceives8milliseconds.Ifitdoesnotfinishin8milliseconds,jobismovedtoQ1.AtQ1jobisagainservedFCFSandreceives16additionalmilliseconds.Ifitstilldoesnotcomplete,itispreemptedandmovedtoqueueQ2.OperatingSystemConceptsMultilevelFeedbackQueuesOperatingSystemConceptsProcessesinqueueihavetimequantum2iWhenaprocess’behaviorchanges,itmaybeplaced(i.e.,promotedordemoted)intoadifferencequeue.Thus,whenanI/O-boundprocessstartstousemoreCPU,itmaybedemotedtoalowerqueueOperatingSystemConceptsMultilevelFeedbackQueue(Cont.)Multilevel-feedback-queueschedulerdefinedbythefollowingparameters:numberofqueuesschedulingalgorithmsforeachqueuemethodusedtodeterminewhentoupgradeaprocessmethodusedtodeterminewhentodemoteaprocessmethodusedtodeterminewhichqueueaprocesswillen
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030全球新能源电池CCS集成母排行业调研及趋势分析报告
- 2025-2030全球无线蓝牙肉类温度计行业调研及趋势分析报告
- 2025-2030全球血栓弹力图检测试剂盒行业调研及趋势分析报告
- 2025-2030全球核电站管道系统行业调研及趋势分析报告
- 2025-2030全球环氧干式变压器行业调研及趋势分析报告
- 2025年全球及中国超声软组织手术刀行业头部企业市场占有率及排名调研报告
- 2025年全球及中国一次性3D储液袋行业头部企业市场占有率及排名调研报告
- 2025-2030全球聚氨酯泡沫开孔剂行业调研及趋势分析报告
- 2025年全球及中国家具弹性带行业头部企业市场占有率及排名调研报告
- 2025【合同范本】服装专卖店加盟合同
- 2024年湖南高速铁路职业技术学院高职单招数学历年参考题库含答案解析
- 上海铁路局招聘笔试冲刺题2025
- 国旗班指挥刀训练动作要领
- 春季安全开学第一课
- 植物芳香油的提取 植物有效成分的提取教学课件
- 肖像绘画市场发展现状调查及供需格局分析预测报告
- 2021-2022学年辽宁省重点高中协作校高一上学期期末语文试题
- 同等学力英语申硕考试词汇(第六版大纲)电子版
- 墓地个人协议合同模板
- 2024年部编版初中语文各年级教师用书七年级(上册)
- 中日合同范本
评论
0/150
提交评论