Академический Документы
Профессиональный Документы
Культура Документы
Readsdominateprocessorcacheaccesses.Allinstructionaccesses
arereads,andmostinstructionsdonotwritetomemory.Theblock
canbereadatthesametimethatthetagisreadandcompared,so
theblockreadbeginsassoonastheblockaddressisavailable.Ifthe
readisamiss,thereisnobenefit-butalsonoharm;justignorethe
valueread.
Thereadpoliciesare:
ReadThrough-readingawordfrommainmemorytoCPU
NoReadThrough-readingablockfrommainmemorytocache
andthenfromcachetoCPU
Suchisnotthecaseforwrites.Modifyingablockcannotbeginuntil
thetagischeckedtoseeiftheaddressisahit.Alsotheprocessor
specifiesthesizeofthewrite,usuallybetween1and8bytes;only
thatportionoftheblockcanbechanged.Incontrast,readscan
accessmorebytesthannecessarywithoutaproblem.
Thewritepoliciesonwritehitoftendistinguishcachedesigns:
WriteThrough-theinformationiswrittentoboththeblockinthe
cacheandtotheblockinthelower-levelmemory.
Advantage:
-readmissneverresultsinwritestomainmemory
-easytoimplement
-mainmemoryalwayshasthemostcurrentcopyofthedata
(consistent)
Disadvantage:
-writeisslower
-everywriteneedsamainmemoryaccess
-asaresultusesmorememorybandwidth
Writeback-theinformationiswrittenonlytotheblockinthe
cache.Themodifiedcacheblockiswrittentomainmemoryonlywhen
itisreplaced.Toreducethefrequencyofwritingbackblockson
replacement,adirtybitiscommonlyused.Thisstatusbitindicates
whethertheblockisdirty(modifiedwhileinthecache)orclean(not
modified).Ifitiscleantheblockisnotwrittenonamiss.
Advantage:
-writesoccuratthespeedofthecachememory
-multiplewriteswithinablockrequireonlyonewritetomain
memory
-asaresultuseslessmemorybandwidth
Disadvantage:
-hardertoimplement
-mainmemoryisnotalwaysconsistentwithcache
-readsthatresultinreplacementmaycausewritesofdirtyblocks
tomainmemory
Therearetwocommonoptionsonawritemiss:
WriteAllocate-theblockisloadedonawritemiss,followedby
thewrite-hitaction.
NoWriteAllocate-theblockismodifiedinthemainmemoryand
notloadedintothecache.
Althougheitherwrite-misspolicycouldbeusedwithwritethroughor
writeback,write-backcachesgenerallyusewriteallocate(hopingthat
subsequentwritestothatblockwillbecapturedbythecache)and
write-throughcachesoftenuseno-writeallocate(sincesubsequent
writestothatblockwillstillhavetogotomemory).
Table1showsallpossiblecombinationsofinteractionpolicieswith
mainmemoryonwrite,thecombinationsusedinpracticeareinbold
case.
Writehit
policy
Writemiss
policy
WriteThrough WriteAllocate
WriteThrough
NoWrite
Allocate
WriteBack
WriteAllocate
WriteBack
NoWriteAllocate
Table1.Possiblecombinationsof
interactionpolicieswithmain
memoryonwrite.
WriteThroughwithNoWriteAllocate:
onhitsitwritestocacheandmainmemory;
onmissesitupdatestheblockinmainmemorynotbringingthat
blocktothecache;
Subsequentwritestotheblockwillupdatemainmemorybecause
WriteThroughpolicyisemployed.So,sometimeissavednot
bringingtheblockinthecacheonamissbecauseitappearsuseless
anyway.
WriteBackwithWriteAllocate:
onhitsitwritestocachesettingdirtybitfortheblock,main
memoryisnotupdated;
onmissesitupdatestheblockinmainmemoryandbringsthe
blocktothecache;
Subsequentwritestothesameblock,iftheblockoriginallycaused
amiss,willhitinthecachenexttime,settingdirtybitfortheblock.
Thatwilleliminateextramemoryaccessesandresultinveryefficient
executioncomparedwithWriteThroughwithWriteAllocate
combination.
WriteBackwithNoWriteAllocate:
onhitsitwritestocachesettingdirtybitfortheblock,main
memoryisnotupdated;
onmissesitupdatestheblockinmainmemorynotbringingthat
blocktothecache;
Subsequentwritestothesameblock,iftheblockoriginallycaused
amiss,willgeneratemissesallthewayandresultinveryinefficient
execution.
Thefollowingappletshowsthedynamicsofinteractionpolicies.By
clickingonwhitesquaresoftheappletonecanchosethepolicyto
testdependingonwhetheritisreadorwrite,hitormiss.Onreadhit
thereisnotmuchchoiceofpolicies.Theblockisjustreadfrom
cachetoCPU.
Thefollowingappletwillshowyouthedynamicsofinteractionpolicies.
Consideracomputerwiththefollowingfeatures:
90%ofallmemoryaccessesarefoundinthecache(hitratio=0.9);
Theblocksizeis2wordsandthewholeblockisreadonanymiss;
TheCPUsendsreferencestothecacheattherateof107wordspersecond;
25%oftheabovereferencesarewrites(writes=25%,reads=75%);
Thebuscansupport107wordspersecond,readorwrites(totalbusbandwidth=107);
Thebusreadsorwritesasinglewordatatime;
Assumeatanyonetime,30%oftheblockframesinthecachehavebeenmodified;
Thecacheuseswriteallocateonawritemiss.
Youareconsideringaddingaperipheraltothebus,andyouwanttoknowhowmuchofthe
busbandwidthisalreadyused.Calculatethepercentageofthebusbandwidthusedonthe
averageinthetwocasesbelow.Thispercentageiscalledthetrafficratio.Stateanyfurther
assumptionsyouneed,ifany.
a)Thecacheiswritethrough.
Bus
BandwidthReasoning
Used
Read
hit
Read
miss
Hitmeansreferenceisfoundincache,sonobusbandwidthused
107*0.1 missratio=1-hitratio=1-0.9=0.1
*0.75* readsare75%oftotalnumberofreferences
2
blocksize=2words
Write
hit
Write
miss
107*0.9
*0.25*
1
Becausewehavewritethroughpolicywehavetowritetomainmemory
oneveryhit.Butwehavetowriteonly1word.
Writesare25%oftotalnumberofreferences,
hitratio=0.9
Oneverywritemisswehavetoloadablock(2words)tocachebecause
10 *0.1 ofwriteallocatepolicy,andwrite1word(thewordtowritefromCPU)
*0.25* becauseofwritethroughpolicy.
(2+1)
Writesare25%oftotalnumberofreferences,
hitratio=0.9
TotalBandwidthUsed=BWusedonReadhit
;+BWusedonReadmiss
;+BWusedonWritehit
;+BWusedonwritemiss
;=0+107*0.1*0.75*2+107*0.9*0.25*
1+107*0.1*0.25*(2+1)
;=107*0.45
TotalBandwidthUsed107*0.45
----------------------------=-------------=0.45
TotalBandwidth107
b)Thecacheiswriteback.
BusBandwidth
Used
Readhit0
Reasoning
Hitmeansreferenceisfoundincache,sonobusbandwidth
used
missratio=1-hitratio=1-0.9=0.1
readsare75%oftotalnumberofreferences
Read
miss
writesare25%oftotalnumberofreferences
107*0.1*0.75*
blocksize=2words
[2*0.3+2]
*Theterm2*0.3referstoreplacingthedirtyblock(0.3isthe
probabilityoftheblocktobedirty).Wewritebackthedirtyblock
(2words)andreadneededblock(another2words).
Writehit0
Write
miss
Writehitdoesnotgenerateanytrafficonthebus,justmakesthe
blockincachedirty.
Onawritemisswehavetoloadablock(2words)tocache
107*0.1*0.25*
becauseofwriteallocatepolicy,
[2*0.3+2]
andwriteadirtyblocktomainmemory(2*0.3).
TotalBandwidthUsed=BWusedonReadhit
;+BWusedonReadmiss
;+BWusedonWritehit
;+BWusedonwritemiss
;=0+107*0.1*0.75*[2*0.3+2]+0+107
*0.1*0.25*[2*0.3+2]
;=107*0.26
TotalBandwidthUsed107*0.26
----------------------------=-------------=0.26
TotalBandwidth107