Você está na página 1de 8

InvestigatingProcessScheduling

WhataretheLearningOutcomesofthistutorial?
Attheendofthislabyoushouldbeableto:
1. Entersourcecodeinthecompilerandcompileittoexecutableprograms.
2. LoadtheprogramsintotheCPUsimulatorsmemory.
3. CreateprocessesfromprogramsintheOSsimulator.
4. SelectdifferentschedulingpoliciesandruntheprocessesintheOSsimulator.
5. Explainthedifferencesbetweenpreemptiveandnonpreemptivescheduling.
6. LocatetheCPUregistervaluesinaprocesssPCBwhenitisinthereadyqueue.
7. ExplainhowtheCPUregistervaluesinPCBareusedinRoundRobinscheduling.

WhyareCPUandOSSimulatorsusedforthistutorial?
Thecomputerarchitecturetutorialsaresupportedbysimulators,whicharecreatedto
underpintheoreticalconceptsnormallycoveredduringthelectures.Thesimulators
providevisualandanimatedrepresentationofmechanismsinvolvedandenablethe
studentstoobservethehiddeninnerworkingsofsystems,whichwouldbedifficultor
impossibletodootherwise.Theaddedadvantageofusingsimulatorsisthattheyallow
thestudentstoexperimentandexploredifferenttechnologicalaspectsofsystems
withouthavingtoinstallandconfiguretherealsystems.

Whatisthebasictheorybehindthetutorialexercises?
ThedifferentOSschedulingpoliciesarediscussedduringthelecturesonProcess
Management.Thistutorialisbasedontheselectures.

Conductofthetutorial
Thefollowingpracticalexercisesaredesignedtohelpyoubetterunderstandthetheory
coveredduringthelectures.Youwillonlyfullybenefitfromtheseexercisesifyoutake
noteofthefollowingguidelines:

Familiarizeyourselfwiththebasictheory(seethelecturenotes)
FollowtheinstructionsinFULL
AttemptALLthequestion(s)attheendofeachexercise
CompleteALLtheexercisesinthistutorial
Workwithothermember(s)ofyourgroup

Youareexpectedtoworkinasmallgroupofstudents(twoorthree).Thereisstrong
evidencethatlearningisbestfacilitatedbyworkingincollaborationwithyourpeersand
underthesupervisionofyourtutor.

Preparationforthetutorial
TheCPUOSSimulatorsoftwareisinstalledonallthePCsinthelab.Askyourtutor
forhelpifyouhavedifficultylocatingit.
Note:Fromtimetotime,theCPU/OSsimulatorsoftwareisupdated.Inthiscase
yourtutormaysupplyyouwithordirectyoutoanotherversiontoupdatetheone
onthedrive.Pleasefollowyourtutorsinstructionsonhowtodothis.
Warning:Sometimes,duetoa(yetundiscovered)buginthesimulatorsoftware,the
simulatormaycrash.Ifthishappensrestartthesimulatorandcarryonfromwhere
youleft.Pleasemakesureyousaveyourwork,e.g.sourcecode,atregularintervals
tominimisetheimpactofthis.

Now,westartthetutorialexercises
Learning outcome 1: Enteringsourcecodeinthecompilerandcompilingittoan
executableprogram.
YouneedtocreatesomeexecutablecodesothatitcanberunbytheCPUsimulator
underthecontroloftheOSsimulator.Inordertocreatethiscode,youneedtousethe
compilerwhichispartofthesystemsimulator.Thiscompilerisabletocompilesimple
highlevelsourcestatementssimilartoVisualBasic.Todothis,openthecompiler
windowbyselectingtheCOMPILERbuttoninthecurrentwindow.Youshouldnowbe
lookingatthecompilerwindow.

Inthecompilerwindow,enterthefollowingsourcecodeinthecompilerssourceeditor
window(underPROGRAMSOURCEframetitle):

program LoopTest
i = 0
for n = 0 to 40
i = i + 1
next
end

Nowyouneedtocompilethisinordertogeneratetheexecutablecode.Todothis,click
ontheCOMPILEbutton.YoushouldseethecodecreatedontherightinPROGRAM
CODEview.Makeahabitofsavingyoursourcecode.

ClickonthebuttonSHOWinBINARYCODEview.YoushouldnowseetheBinaryCode
forLOOPTESTwindow.Studytheprogramcodedisplayedinhexadecimalformat.
Providebriefanswerstothefollowingquestionsandthenclosethewindow.

Q1.Howdoesthehexadecimalcodehererelatetotheinformationinthecompiler
windowandtheCPUsimulatorwindow?




Q2.ClickontheSHOWINSTRUCTIONSTATSbuttonandmakeanoteofthemost
usedinstruction.Doesthissurpriseyou?Explain.


Learning outcome 2: LoadingtheprogramintotheCPUsimulatorsmemory.
Now,thiscodeneedstobeloadedinmemorysothattheCPUcanexecuteit.Todothis,
firstweneedtospecifyabaseaddress(inASSEMBLYCODEview):unchecktheboxnext
totheeditboxwithlabelBaseAddress,andthenenter100intheeditbox.Now,click
ontheLOADINMEMORYbuttoninthecurrentwindow.Youshouldnowseethecode
loadedinmemoryreadytobeexecuted.YouarealsobackintheCPUsimulatoratthis
stage.Thisactionisequivalenttoloadingtheprogramcodenormallystoredonadisc
driveintoRAMontherealcomputersystems.

Q1.BrieflyexplainwhatthecolumnheadersnamedPAddandLAddsignify.Whyare
theydifferent?



Q2.ObservethevaluesofthePCandtheBRregisters.Whatdothesevaluessignify?

Learning outcome 3: CreateprocessesfromprogramsintheOSsimulator.


WearenowgoingtousetheOSsimulatortorunthiscode.ToentertheOSsimulator,
clickontheOSbuttoninthecurrentwindow.TheOSwindowopens.Youshouldsee
anentry,titledLoopTest,inthePROGRAMLISTview.Nowthatthisprogramisavailable
totheOSsimulator,wecancreateasmanyinstances,i.e.processes,ofitaswelike.You
dothisbyclickingontheCREATENEWPROCESSbutton.Repeatthisfourtimes.Observe
thefourinstancesoftheprogrambeingqueuedinthereadyqueuewhichis
representedbytheREADYPROCESSESview.

Learning outcome 4: Selectdifferentschedulingpoliciesandruntheprocessesin


theOSsimulator.
Learning outcome 5: Explainthedifferencesbetweenpreemptiveandnonpre
emptivescheduling.
MakesuretheFirstComeFirstServed(FCFS)optionisselectedinthe
SCHEDULER/Policiesview.AtthispointtheOSisinactive.Toactivate,firstmovethe
Speedslidertothefastestposition,thenclickontheSTARTbutton.Thisshouldstartthe
OSsimulatorrunningtheprocesses.Now,followtheinstructionsbelowwithoutany
deviation:
4


1. Makeanoteofwhatyouobserveastheprocessesarerun(youneedto
concentrateonthetwoviews:RUNNINGPROCESSESandtheREADYPROCESSES
duringthisperiod).

2. Whenalltheprocessesfinished,dothefollowing.SelectthePriority(static)
optionintheSCHEDULER/Policiesview.ThenselecttheNonpreemptiveoption
intheSCHEDULER/Policies/PriorityTypeframe.Createthreeprocesseswiththe
followingpriorities(usethePrioritydropdownlistinthePROGRAM
LIST/Processesview):3,2,4.SlidetheSpeedselectorhalfwaydownandthen
hittheSTARTbutton.Whilethefirstprocessisbeingrundothefollowing.
Createafourthprocesswithpriority1.Makeanoteofwhatyouobserve.

3. Now,slidetheSpeedselectortofastestpositionandwaitfortheprocessesto
complete(orusetheKILLbuttontoterminatetheprocessesonebyone).Next,
selectthePreemptiveoptionintheSCHEDULER/Policies/PriorityTypeframe.
Createthreeprocesseswiththefollowingpriorities:3,2,4.SlidetheSpeed
selectorhalfwaydownandthenhittheSTARTbutton.Whilethefirstprocessis
beingrundothefollowing.Createafourthprocesswithpriority1.Makeanote
ofwhatyouobserve.Howisthisdifferentthan(2)above?

4. SlidetheSpeedselectortofastestpositionandwaitfortheprocessesto
complete(orusetheKILLbuttontoterminatetheprocessesonebyone).Select
theRoundRobin(RR)optionintheSCHEDULER/Policiesview.Thenselectthe
NonpreemptiveoptionintheSCHEDULER/Policies/PriorityTypeframe.Create
fourprocessesandhittheSTARTbutton.Makeanoteofwhatyouobserve.

5. Waitforalltheprocessestocomplete(orkillthem).Gotothecompilerwindow
(usetheCOMPILERbuttonintheGOTOframeforthis).ClicktheNEWbutton
inthePROGRAMSOURCEviewandenterthefollowingsourcecode:

program LoopForeverTest1
n = 0
while true
n = n + 1
wend
end

Compilethiscodeandloaditinmemoryaspreviouslydescribedabove(Use
BaseAddress200inthiscase).GototheOSwindow(usetheOSbuttonfor
this).YoushouldnowseeanadditionalentryinthePROGRAMLISTviewtitled
LoopForeverTest1.Selectthisentrybyclickingonit.Wearenowgoingtocreate
processesofthisprogrambutthistimewewillassignalifetime(inseconds)to
each.Wellcreatethreeprocesseswiththefollowinglifetimevalues(usethe
LifetimetextboxforthevaluesandalsoselecttheSecsradiobutton):10
seconds,32seconds,6seconds.Now,wearegoingtoselectthetimeslotvalue.
Todothisselect4secondsfromthedropdownlistinSCHEDULER/Policies/RR
TimeSliceview.HittheSTARTbuttonandwaituntilallprocessesfinish.

OpentheOSActivityLogwindowbyclickingtheVIEWLOGbuttoninthe
SCHEDULER/Viewstab.Observetherelevantlogentriesandcheckoutthe
sequenceoftherunningprocessesandnotethetimespentbyeachprocess
duringeachrunningstate.Recordthisinformationintheboxbelow.

Learning outcome 6: LocatetheCPUregistervaluesinaprocesssPCBwhenitisin


thereadyqueue.
Learning outcome 7: ExplainhowtheCPUregistervaluesinPCBareusedinRound
Robinscheduling.
Now,gotothecompilerandenterthefollowingcodeinthesourcecodeeditor.You
needtoclickontheNEWbuttontostartanewsourcecodetabintheeditor:
6

program LoopForeverTest2
while true
n = n + 1
i = i + n
p = n + i + 5
wend
end

Compilethisnewsourceandloadinmemory(useBaseAddress300inthiscase).Goto
theOSsimulator.YoullobserveathirdentryinthePROGRAMLISTviewtitled
LoopForeverTest2.ClickontheentryLoopTestandcreateaprocess.Clickon
LoopForeverTest2andcreateaprocessofit.Thereshouldnowbetwoprocessesinthe
readyqueue.MakesuretheRoundRobinschedulingisselected;theprioritytypeis
NonpreemptiveandthattheRRTimeSliceissetto10ticks(youcanselectthisfrom
thedropdownlist).

1. SelecteachprocessinturnandclickonthePCBbutton.Observethevaluesof
thePCRegistersineachcaseandmakenoteoftheseintheboxbelow.Also,
notedownwhatotherinformationisinthePCB(selectthreeexamples)and
brieflyexplainwhythisinformationisrequired.

2. SelecttheSuspendonruncheckboxintheREADYPROCESSESview.
3. Whenthecurrentlyrunningprocessisputbackinthereadyqueue,selectitand
clickonthePCBbuttoninthereadyqueue.MakeanoteofthePCRegister
valueandthevaluesoftheregistersR00toR05.

4. ClickontheRESUMEbuttonandwhenthesecondprocessisputbackonthe
readyqueuemakeanoteofthePCRegisterandtheR00toR05registervalues
initsPCBintheabovebox.


5. Now,selecttheSuspendonruncheckboxintheRUNNINGPROCESSESview.
SlowdowntheOSsimulationtominimum.ClickontheRESUMEbuttonand
whenthequeuedprocessisputbackinrunningstatethesimulationwillbe
automaticallysuspended.ClickontheRESUMEbuttonandimmediatelyclickon
theSUSPENDbutton(thisisthesameastheRESUMEbutton).Makeanoteof
thevaluesinthePCregisterandtheregistersR00toR05.Comparethesevalues
withtheonesrecordedin(3)and(4)above.

6. ClickontheRESUMEbuttonandkillthecurrentlyrunningprocess.Clickonthe
RESUMEbuttonandimmediatelyclickontheSUSPENDbutton.Makeanoteof
thevaluesinthePCregisterandintheregistersR00toR05.Comparethese
valueswiththeonesin(3)and(4)above.Brieflyexplainwhathasbeen
happening.