Cache Hierarchy J. Nelson Amaral University of Alberta - - PowerPoint PPT Presentation

cache hierarchy
SMART_READER_LITE
LIVE PREVIEW

Cache Hierarchy J. Nelson Amaral University of Alberta - - PowerPoint PPT Presentation

Cache Hierarchy J. Nelson Amaral University of Alberta Address Transla;on (flashback) valid bit = 0 implies a page fault (there is no frame in


slide-1
SLIDE 1

Cache ¡Hierarchy ¡

  • J. ¡Nelson ¡Amaral ¡

University ¡of ¡Alberta ¡

slide-2
SLIDE 2

Address ¡Transla;on ¡ (flashback) ¡

valid ¡bit ¡= ¡0 ¡implies ¡ a ¡page ¡fault ¡(there ¡is ¡ no ¡frame ¡in ¡memory ¡ ¡ for ¡this ¡page) ¡

Baer, ¡p. ¡62 ¡

slide-3
SLIDE 3

Should ¡the ¡Cache ¡be ¡Accessed ¡with ¡ Physical ¡or ¡Virtual ¡Addresses? ¡

Baer, ¡p. ¡209 ¡

slide-4
SLIDE 4

Instruc;on ¡Cache ¡

  • Instruc;ons ¡are ¡fetched ¡either: ¡

– sequen;ally ¡(same ¡cache ¡line) ¡ – with ¡address ¡form ¡a ¡branch ¡target ¡buffer ¡(BTB) ¡

  • BTB ¡contains ¡physical ¡addresses ¡
  • When ¡needed, ¡transla;on ¡is: ¡

– done ¡in ¡parallel ¡with ¡delivery ¡of ¡previous ¡ instruc;on ¡

  • Thus ¡Instruc;on ¡Cache ¡can ¡be ¡physical ¡

Baer, ¡p. ¡209 ¡

slide-5
SLIDE 5

Data ¡Cache ¡

Index ¡ Virtual ¡ Virtual ¡ Tags ¡ Physical ¡ Physical ¡ Tags ¡ Physical ¡ For ¡a ¡2k ¡page ¡size, ¡ the ¡last ¡k ¡bits ¡are ¡ iden;cal ¡in ¡the ¡ virtual ¡and ¡physical ¡

  • addresses. ¡

If ¡the ¡cache ¡index ¡fits ¡within ¡these ¡k ¡bits, ¡ ¡ then ¡these ¡two ¡schemes ¡are ¡iden;cal. ¡

Baer, ¡p. ¡209 ¡

slide-6
SLIDE 6

Parallel ¡TLB ¡and ¡Cache ¡Access ¡

Only ¡works ¡if ¡index ¡+ ¡displ. ¡≤ ¡k ¡ Page ¡size ¡= ¡2k ¡

Baer, ¡p. ¡210 ¡

slide-7
SLIDE 7

Pipeline ¡Stages ¡

Stage ¡1: ¡Send ¡ ¡ Data ¡to ¡Register ¡ Stage ¡2: ¡If ¡Tag ¡in ¡TLB ¡ ¡≠ ¡Tag ¡in ¡TLB: ¡

  • ­‑ ¡Void ¡Data ¡in ¡Register ¡
  • ­‑ ¡ ¡Start ¡Replay ¡ ¡

Saves ¡a ¡pipeline ¡stage ¡when ¡ there ¡is ¡a ¡hit ¡in ¡the ¡TLB ¡and ¡cache. ¡ Baer, ¡p. ¡210 ¡

slide-8
SLIDE 8

Page ¡Sizes ¡are ¡typically ¡4KB ¡or ¡8KB. ¡ An ¡8KB ¡L1 ¡cache ¡is ¡too ¡small. ¡ Two ¡solu;ons: ¡ Increase ¡cache ¡associa;vity. ¡ Increase ¡the ¡number ¡of ¡bits ¡that ¡ are ¡not ¡translated. ¡

Baer, ¡p. ¡210 ¡

slide-9
SLIDE 9

Limits ¡on ¡Associa;vity ¡

Time ¡to ¡do ¡the ¡tag ¡comparisons ¡ Solu;on: ¡Do ¡comparisons ¡in ¡parallel ¡ S;ll ¡need ¡;me ¡for ¡latches/mul;plexors ¡ Solu;on: ¡Don’t ¡compare ¡with ¡all ¡tags. ¡How? ¡ Use ¡a ¡set ¡predictor. ¡ ¡ For ¡L1 ¡predictor ¡must ¡be ¡fast. ¡ ¡

Baer, ¡p. ¡210 ¡

slide-10
SLIDE 10

Page ¡Coloring ¡

  • Goal: ¡increase ¡number ¡of ¡non-­‑translated ¡bits ¡
  • Idea: ¡Restrict ¡mapping ¡of ¡pages ¡into ¡frames ¡

– Divide ¡both ¡pages ¡and ¡frames ¡into ¡colors. ¡ – A ¡page ¡must ¡map ¡to ¡a ¡frame ¡of ¡the ¡same ¡color. ¡ – For ¡l ¡addi;onal ¡non-­‑translated ¡bits ¡needs ¡2l ¡colors. ¡ Restrict ¡mapping ¡between ¡virtual ¡and ¡physical ¡ addresses ¡

  • Alterna,ve ¡to ¡coloring: ¡

– Use ¡a ¡predictor ¡for ¡the ¡l ¡bits. ¡

Baer, ¡p. ¡211 ¡

slide-11
SLIDE 11

Virtual ¡Cache ¡

  • Virtual ¡index ¡and ¡virtual ¡tags ¡allow ¡for ¡fast ¡access ¡

to ¡cache. ¡

  • However… ¡

– Page ¡protec;on ¡and ¡recency-­‑of-­‑use ¡informa;on ¡(stored ¡ in ¡TLB) ¡must ¡be ¡accessed. ¡

  • TLB ¡must ¡be ¡accessed ¡anyway ¡
  • TLB ¡access ¡can ¡be ¡in ¡parallel ¡with ¡cache ¡access ¡

– Context ¡switches ¡ac;vate ¡new ¡virtual ¡address ¡space ¡

  • En;re ¡cache ¡content ¡becomes ¡stale. ¡Either: ¡

– ¡flush ¡the ¡cache ¡ – append ¡a ¡PID ¡to ¡tag ¡in ¡cache ¡ » must ¡flush ¡part ¡of ¡cache ¡when ¡recycling ¡PIDs ¡

– Synonym ¡Problem ¡

Baer, ¡p. ¡211 ¡

slide-12
SLIDE 12

Synonym ¡Problem ¡

Virtual ¡Address ¡A ¡ Virtual ¡Address ¡B ¡ Physical ¡Address ¡1 ¡ Occurs ¡when ¡data ¡is ¡shared ¡among ¡processes ¡ What ¡happens ¡in ¡a ¡virtual ¡cache ¡if ¡two ¡ ¡ synonyms ¡are ¡cached ¡simultaneously, ¡ and ¡one ¡of ¡them ¡is ¡modified? ¡ The ¡other ¡becomes ¡inconsistent! ¡

Baer, ¡p. ¡211 ¡

slide-13
SLIDE 13

Avoiding ¡Stale ¡Synonyms ¡

  • Varia,on ¡on ¡Page ¡Coloring: ¡Require ¡that ¡the ¡

bits ¡used ¡to ¡index ¡the ¡cache ¡be ¡the ¡same ¡for ¡ all ¡synonyms ¡

  • Soiware ¡must ¡be ¡aware ¡about ¡poten;al ¡

synonyms ¡

– Easier ¡for ¡instruc;on ¡caches ¡ – Tricky ¡for ¡data ¡caches ¡

  • Sun ¡UltraSPARC ¡has ¡virtual ¡instruc;on ¡cache. ¡

Baer, ¡p. ¡212 ¡

slide-14
SLIDE 14

Example ¡

  • Page ¡size ¡is ¡4 ¡Kbytes ¡

– How ¡many ¡bits ¡for ¡page ¡number ¡and ¡page ¡offset? ¡

  • 20 ¡bits ¡for ¡page ¡number ¡and ¡12 ¡bits ¡for ¡page ¡offset ¡
  • Direct-­‑mapped ¡D-­‑Cache ¡has ¡16 ¡bytes ¡per ¡lines, ¡

512 ¡lines: ¡

– How ¡many ¡bits ¡for ¡tag, ¡index, ¡and ¡displacement? ¡

  • 16x512 ¡= ¡8192 ¡bytes ¡= ¡213 ¡bytes ¡
  • displacement ¡= ¡4 ¡bits ¡
  • index ¡= ¡13-­‑4 ¡= ¡9 ¡bits ¡
  • tag ¡= ¡32-­‑13 ¡= ¡19 ¡bits ¡

Lowest ¡bit ¡of ¡page ¡number ¡ is ¡part ¡of ¡the ¡index. ¡ Baer, ¡p. ¡212 ¡

slide-15
SLIDE 15

0 ¡ 4 ¡ 8 ¡ 12 ¡ 16 ¡ 20 ¡ 24 ¡ 28 ¡

Page ¡Number ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displ. ¡

Page ¡Offset ¡ Process ¡A ¡ Page ¡ 4 ¡ Physical ¡Pages ¡ Process ¡B ¡ Page ¡ 17 ¡ Page ¡ 14 ¡ Baer, ¡p. ¡212 ¡

slide-16
SLIDE 16

Page ¡Number ¡ Page ¡Offset ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

28 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

24 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

20 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

16 ¡

0 ¡ 1 ¡ 0 ¡ 0 ¡

12 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

8 ¡

1 ¡ 0 ¡ 0 ¡ 0 ¡

4 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

0 ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displac. ¡

Process ¡A ¡reads ¡line ¡8 ¡of ¡its ¡page ¡4 ¡(line ¡8 ¡physical ¡page ¡14): ¡

Index ¡ V ¡ d ¡ Tag ¡ Data ¡ … ¡ … ¡ … ¡ ... ¡ .. ¡ Page ¡Number ¡ Page ¡Offset ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

28 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

24 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

20 ¡

0 ¡ 0 ¡ 0 ¡ 1 ¡

16 ¡

0 ¡ 0 ¡ 0 ¡ 1 ¡

12 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

8 ¡

1 ¡ 0 ¡ 0 ¡ 0 ¡

4 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

0 ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displac. ¡

Process ¡B ¡reads ¡line ¡8 ¡of ¡its ¡page ¡17 ¡(line ¡8 ¡of ¡physical ¡page ¡14): ¡

Index ¡ V ¡ d ¡ Tag ¡ Data ¡ … ¡ ¡ ¡ ¡8 ¡ 1 ¡ 0 ¡ 0000 ¡0000 ¡0000 ¡0010 ¡ VMem[0x0000 ¡4080] ¡ … ¡ ... ¡ .. ¡ Baer, ¡p. ¡212 ¡

slide-17
SLIDE 17

Page ¡Number ¡ Page ¡Offset ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

28 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

24 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

20 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

16 ¡

0 ¡ 1 ¡ 0 ¡ 0 ¡

12 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

8 ¡

1 ¡ 0 ¡ 0 ¡ 0 ¡

4 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

0 ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displac. ¡

Process ¡A ¡reads ¡line ¡8 ¡of ¡its ¡page ¡4 ¡(line ¡8 ¡physical ¡page ¡14): ¡

Index ¡ V ¡ d ¡ Tag ¡ Data ¡ … ¡ 8 ¡ 1 ¡ 0 ¡ 0000 ¡0000 ¡0000 ¡0010 ¡ VMem[0x0000 ¡4080] ¡ … ¡ 264 ¡ 1 ¡ 0 ¡ 0000 ¡0000 ¡0000 ¡1000 ¡ VMem[0x0001 ¡1080] ¡ .. ¡ Page ¡Number ¡ Page ¡Offset ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

28 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

24 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

20 ¡

0 ¡ 0 ¡ 0 ¡ 1 ¡

16 ¡

0 ¡ 0 ¡ 0 ¡ 1 ¡

12 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

8 ¡

1 ¡ 0 ¡ 0 ¡ 0 ¡

4 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

0 ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displac. ¡

Process ¡B ¡reads ¡line ¡8 ¡of ¡its ¡page ¡17 ¡(line ¡8 ¡of ¡physical ¡page ¡14): ¡ Now ¡processor ¡ B ¡writes ¡to ¡its ¡ cache ¡line ¡8. ¡

Baer, ¡p. ¡212 ¡

slide-18
SLIDE 18

Page ¡Number ¡ Page ¡Offset ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

28 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

24 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

20 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

16 ¡

0 ¡ 1 ¡ 0 ¡ 0 ¡

12 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

8 ¡

1 ¡ 0 ¡ 0 ¡ 0 ¡

4 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

0 ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displac. ¡

Process ¡A ¡reads ¡line ¡8 ¡of ¡its ¡page ¡4 ¡(line ¡8 ¡physical ¡page ¡14): ¡

Index ¡ V ¡ d ¡ Tag ¡ Data ¡ … ¡ 8 ¡ 1 ¡ 0 ¡ 0000 ¡0000 ¡0000 ¡0010 ¡ VMem[0x0000 ¡4080] ¡ … ¡ 264 ¡ 1 ¡ 1 ¡ 0000 ¡0000 ¡0000 ¡1000 ¡ <New ¡Data> ¡ .. ¡ Page ¡Number ¡ Page ¡Offset ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

28 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

24 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

20 ¡

0 ¡ 0 ¡ 0 ¡ 1 ¡

16 ¡

0 ¡ 0 ¡ 0 ¡ 1 ¡

12 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

8 ¡

1 ¡ 0 ¡ 0 ¡ 0 ¡

4 ¡

0 ¡ 0 ¡ 0 ¡ 0 ¡

0 ¡ Cache ¡Tag ¡ Cache ¡Index ¡ Cache ¡

  • Displac. ¡

Process ¡B ¡reads ¡line ¡8 ¡of ¡its ¡page ¡17 ¡(line ¡8 ¡of ¡physical ¡page ¡14): ¡ Now ¡processor ¡ B ¡writes ¡to ¡its ¡ cache ¡line ¡8. ¡ We ¡have ¡a ¡synonym ¡problem: ¡two ¡copies ¡of ¡the ¡same ¡ physical ¡line ¡in ¡the ¡cache, ¡and ¡they ¡are ¡inconsistent. ¡ How ¡can ¡we ¡avoid ¡the ¡synonym? ¡

Baer, ¡p. ¡212 ¡

slide-19
SLIDE 19

Index ¡ V ¡ d ¡ Tag ¡ Data ¡ … ¡ 8 ¡ 1 ¡ 0 ¡ 0000 ¡0000 ¡0000 ¡0010 ¡ VMem[0x0000 ¡4080] ¡ … ¡ 264 ¡ 1 ¡ 1 ¡ 0000 ¡0000 ¡0000 ¡1000 ¡ <New ¡Data> ¡ .. ¡

Checks ¡on ¡a ¡cache ¡miss: ¡ (i) check ¡virtual ¡tags ¡to ¡ensure ¡that ¡there ¡is ¡a ¡ miss ¡(this ¡would ¡be ¡in ¡the ¡tag ¡at ¡line ¡264) ¡ (ii) ¡ ¡ ¡compare ¡the ¡physical ¡page ¡number ¡of ¡the ¡ missing ¡item ¡(page ¡14 ¡in ¡the ¡example) ¡with ¡ the ¡physical ¡tag(s) ¡of ¡all ¡other ¡loca;ons ¡in ¡the ¡ cache ¡that ¡could ¡be ¡poten;al ¡synonyms ¡ (physical ¡page ¡number ¡for ¡virtual ¡tag ¡of ¡line ¡8 ¡ in ¡the ¡example). ¡ ¡

Baer, ¡p. ¡212 ¡

slide-20
SLIDE 20

Other ¡drawbacks ¡of ¡Virtual ¡Caches ¡

I/O ¡addresses ¡are ¡physical. ¡ Cache ¡coherency ¡in ¡mul;processors ¡use ¡physical ¡addresses. ¡ Virtual ¡caches ¡are ¡not ¡currently ¡used ¡in ¡prac;ce. ¡

Baer, ¡p. ¡212 ¡

slide-21
SLIDE 21

Virtual ¡Index ¡and ¡Physical ¡Tags ¡

Idea: ¡limit ¡mapping ¡in ¡a ¡similar ¡way ¡to ¡page ¡coloring ¡ but ¡apply ¡it ¡only ¡to ¡the ¡cache. ¡ ¡ Example: ¡Consider ¡an ¡m-­‑way ¡set ¡associa;ve ¡cache ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡with ¡capacity ¡m ¡x ¡2k. ¡ Constraint: ¡Each ¡line ¡in ¡a ¡set ¡has ¡a ¡parern ¡of ¡l ¡bits ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡that ¡is ¡different ¡from ¡all ¡other ¡lines. ¡ The ¡parern ¡should ¡be ¡above ¡the ¡lower ¡k ¡bits, ¡and ¡ l ¡< ¡m. ¡ ¡

Baer, ¡p. ¡212 ¡

slide-22
SLIDE 22

Virtual ¡Index ¡and ¡Physical ¡Tags ¡(Cont.) ¡

On ¡an ¡access: ¡ Set: ¡determined ¡by ¡k ¡untranslated ¡bits. ¡ ¡ Use ¡a ¡predic;on ¡for ¡the ¡m ¡parerns ¡of ¡the ¡l ¡virtual ¡bits. ¡ If ¡the ¡predic;on ¡does ¡not ¡match ¡the ¡full ¡match ¡in ¡the ¡ TLB, ¡need ¡to ¡repeat ¡access. ¡ Drawback: ¡lines ¡mapped ¡to ¡the ¡same ¡set ¡with ¡the ¡same ¡ ¡ l-­‑bit ¡parern ¡cannot ¡be ¡in ¡the ¡cache ¡simultaneously. ¡

Baer, ¡p. ¡212 ¡

slide-23
SLIDE 23

“Faking” ¡Associa;vity ¡ ¡

Column-­‑associa,ve ¡Caches: ¡Treat ¡a ¡direct-­‑mapped ¡ cache ¡as ¡two ¡independent ¡halves. ¡ First ¡Access: ¡Access ¡the ¡cache ¡using ¡the ¡usual ¡index. ¡ Second ¡Access: ¡If ¡a ¡miss ¡occurs, ¡rehash ¡the ¡address ¡ ¡ and ¡perform ¡a ¡second ¡access ¡to ¡a ¡different ¡line. ¡ Swap: ¡If ¡the ¡second ¡access ¡is ¡a ¡hit, ¡swap ¡the ¡entries ¡ for ¡the ¡first ¡and ¡second ¡accesses. ¡

Baer, ¡p. ¡213 ¡

slide-24
SLIDE 24

Column-­‑Associa9ve ¡Cache ¡

… ¡

b ¡

¡Half ¡1 ¡ Half ¡2 ¡

… ¡

c ¡ Memory ¡ Cache ¡ Processor ¡ a ¡ a ¡ &a ¡ a ¡ Assume ¡that ¡ the ¡high ¡order ¡ bit ¡of ¡a ¡ ¡ makes ¡it ¡first ¡ to ¡be ¡looked ¡ at ¡Half ¡1. ¡

slide-25
SLIDE 25

Column-­‑Associa9ve ¡Cache ¡

… ¡

Half ¡1 ¡ Half ¡2 ¡

… ¡

c ¡ Memory ¡ Cache ¡ Processor ¡ a ¡ a ¡ &b ¡ a ¡ b ¡ b ¡ b ¡ Assume ¡that ¡ the ¡high ¡order ¡ bit ¡of ¡b ¡ ¡ makes ¡it ¡first ¡ to ¡be ¡looked ¡ at ¡Half ¡1. ¡

slide-26
SLIDE 26

Column-­‑Associa9ve ¡Cache ¡

… ¡

Half ¡1 ¡ ¡Half ¡2 ¡

… ¡

Memory ¡ Cache ¡ Processor ¡ a ¡ a ¡ &c ¡ a ¡ b ¡ b ¡ b ¡ c ¡ c ¡ Assume ¡that ¡ c’s ¡high ¡order ¡ bit ¡is ¡the ¡ ¡

  • pposite ¡of ¡

a ¡and ¡b. ¡ Thus, ¡look ¡ for ¡c ¡on ¡ Half ¡2 ¡first. ¡ c ¡

slide-27
SLIDE 27

Column-­‑Associa9ve ¡Cache ¡

… ¡

Half ¡1 ¡ ¡Half ¡2 ¡

… ¡

Memory ¡ Cache ¡ Processor ¡ a ¡ a ¡ &b ¡ a ¡ b ¡ b ¡ c ¡ c ¡ c ¡ b ¡

slide-28
SLIDE 28

Column-­‑Associa9ve ¡Cache ¡

… ¡

Half ¡1 ¡ ¡Half ¡2 ¡

… ¡

Memory ¡ Cache ¡ Processor ¡ a ¡ a ¡ &c ¡ a ¡ b ¡ b ¡ b ¡ c ¡ c ¡ c ¡

slide-29
SLIDE 29

Column-­‑Associa9ve ¡Cache ¡

… ¡

Half ¡1 ¡ ¡Half ¡2 ¡

… ¡

Memory ¡ Cache ¡ Processor ¡ a ¡ a ¡ &b ¡ a ¡ b ¡ b ¡ c ¡ c ¡ c ¡ b ¡

slide-30
SLIDE 30

Thus ¡the ¡sequence ¡abcbcbcbcbc…. ¡ results ¡in ¡a ¡miss ¡in ¡every ¡access. ¡ The ¡same ¡sequence ¡would ¡result ¡in ¡close ¡to ¡ 100% ¡hit ¡rate ¡in ¡a ¡2-­‑way ¡associa;ve ¡cache. ¡ Solu;on: ¡add ¡a ¡rehash ¡bit ¡that ¡indicates ¡that ¡the ¡ entry ¡is ¡not ¡in ¡its ¡original ¡loca;on ¡ If ¡there ¡is ¡a ¡miss ¡on ¡first ¡access ¡and ¡rehash ¡is ¡on, ¡ there ¡will ¡be ¡also ¡a ¡miss ¡on ¡the ¡second ¡access. ¡ The ¡entry ¡with ¡rehash ¡bit ¡on ¡is ¡the ¡LRU ¡and ¡should ¡ be ¡evicted. ¡

Baer, ¡p. ¡214 ¡

slide-31
SLIDE 31

Opera;on ¡of ¡Column-­‑Assoc. ¡Cache ¡

tag(index) ¡= ¡ tag_ref? ¡ It ¡is ¡a ¡hit. ¡ Serve ¡entry ¡to ¡processor. ¡

yes ¡

It ¡is ¡a ¡miss. ¡Enter: ¡

  • n ¡

index ¡ 0 ¡ tag_ref ¡ data ¡ rehash ¡bit ¡ It ¡is ¡a ¡secondary ¡hit. ¡ swap[entry(index),entry(index1)] ¡ rehash_bit(index1) ¡← ¡1 ¡ Serve ¡entry ¡to ¡processor ¡

yes ¡

tag(index1) ¡ = ¡tag_ref? ¡ rehash_bit (index) ¡

no ¡

index1 ¡← ¡flip_high_bit(index) ¡ ¡

  • ff ¡

It ¡is ¡a ¡secondary ¡miss. ¡Enter: ¡ swap[entry(index),entry(index1)] ¡ rehash_bit(index1) ¡← ¡1 ¡ index ¡ 1 ¡ tag_ref ¡ data ¡

no ¡

Baer, ¡p. ¡214 ¡

slide-32
SLIDE 32

Performance ¡of ¡Column-­‑Associa;ve ¡ Caches ¡(CAC) ¡

  • Comparing ¡CAC ¡with ¡Direct-­‑Mapped ¡Cache ¡

(DMC) ¡of ¡same ¡capacity: ¡

– Miss ¡ra;o(CAC) ¡< ¡Miss ¡ra;o(DMC) ¡ – Access ¡to ¡second ¡half(CAC) ¡> ¡Access(DMC) ¡

  • Comparing ¡with ¡a ¡Two-­‑Way ¡Set ¡Associa;ve ¡

Cache ¡(2SAC) ¡of ¡same ¡capacity: ¡

– miss ¡ra;o(CAC) ¡approaches ¡miss ¡ra;o(2SAC) ¡

Baer, ¡p. ¡215 ¡

slide-33
SLIDE 33

Design ¡Ques;on ¡

When ¡should ¡a ¡column-­‑associa;ve ¡cache ¡ ¡ be ¡chosen ¡over ¡a ¡2-­‑way ¡set ¡associa;ve ¡cache? ¡ When ¡the ¡2-­‑way ¡set ¡associa;ve ¡cache ¡ requires ¡the ¡processor ¡clock ¡to ¡be ¡longer. ¡

Baer, ¡p. ¡215 ¡

slide-34
SLIDE 34

Design ¡Ques;on ¡#2 ¡

Can ¡a ¡column-­‑associa;ve ¡cache ¡be ¡expanded ¡ to ¡higher ¡associa;vity? ¡How? ¡ Have ¡to ¡replace ¡the ¡hashing ¡func;on. ¡ ¡ The ¡single-­‑bit ¡hashing ¡does ¡not ¡work. ¡ Could ¡use ¡some ¡XOR ¡combina;on ¡of ¡PC ¡bits. ¡

Baer, ¡p. ¡215 ¡

slide-35
SLIDE 35

Vic9m ¡Caches ¡

Baer, ¡p. ¡215 ¡

slide-36
SLIDE 36

Opera;on ¡of ¡Vic;m ¡Cache ¡

tag(index) ¡= ¡ tag_ref? ¡ It ¡is ¡a ¡hit. ¡ Serve ¡entry ¡to ¡processor. ¡

yes ¡

swap(vic;m, ¡VC[i]) ¡ Update ¡VC ¡LRU ¡informa;on ¡ Serve ¡entry ¡to ¡processor ¡

yes ¡

Tag(VC[i]) ¡= ¡ VCTag ¡ VCTag ¡= ¡concat[index,tag(index)] ¡

  • Assoc. ¡search ¡vic;m ¡cache ¡for ¡VCtag ¡ ¡

no ¡

Let ¡VC(j) ¡be ¡the ¡LRU ¡entry ¡in ¡VC ¡

no ¡

VC(j) ¡dirty? ¡ Writeback(VC[j]) ¡

yes ¡

VC[j] ¡← ¡vic;m ¡ ¡

no ¡

Baer, ¡p. ¡216 ¡

slide-37
SLIDE 37

History: ¡First ¡Vic;m ¡Cache ¡

HP ¡7100, ¡introduced ¡in ¡1992 ¡ HP ¡7200, ¡introduced ¡in ¡1995 ¡ 64-­‑entry ¡vic;m ¡cache ¡ 120 ¡MHz ¡clock ¡

Baer, ¡p. ¡216 ¡

slide-38
SLIDE 38

Code ¡Reordering ¡

  • Procedure ¡reordering ¡
  • Basic ¡Block ¡Reordering ¡

Baer, ¡p. ¡217 ¡

slide-39
SLIDE 39

Data ¡Reordering ¡

  • Cache-­‑conscious ¡algorithms ¡
  • Pool ¡alloca;on ¡
  • Structure ¡reorganiza;on ¡
  • Loop ¡;ling ¡(cache ¡9ling?) ¡

Baer, ¡p. ¡218 ¡

slide-40
SLIDE 40

Hiding ¡Memory ¡Latencies ¡

  • Prefetching ¡

– Soiware ¡instruc;ons ¡ – Hardware ¡assisted ¡ – Hardware ¡only ¡(stream ¡prefetching) ¡

  • Between ¡any ¡two ¡levels ¡of ¡memory ¡hierarchy ¡
  • Prefetching ¡is ¡predic;ve, ¡can ¡we ¡use ¡the ¡same ¡

predictor ¡modeling ¡as ¡for ¡branches? ¡

Baer, ¡p. ¡218 ¡

slide-41
SLIDE 41

Prefetching ¡Predic;on ¡× ¡Branch ¡ Predic;on ¡

Differences ¡ Branch ¡ Prefetch ¡

When ¡to ¡predict? ¡ On ¡every ¡instruc;on ¡ Aier ¡a ¡cache ¡miss ¡or ¡while ¡ scanning ¡a ¡cache ¡line ¡ Misspredic;on ¡ Impacts ¡Correctness ¡ Requires ¡recovery ¡ Only ¡impacts ¡performance ¡ When ¡outcome ¡is ¡ known? ¡ Within ¡a ¡few ¡cycles ¡ Thousands ¡of ¡cycles ¡later. ¡ Cannot ¡benefit ¡from ¡ feedback ¡easily ¡

Baer, ¡p. ¡219 ¡

slide-42
SLIDE 42

Assessment ¡Criteria ¡for ¡Prefetching ¡

Timeliness: ¡

– too ¡early: ¡displaces ¡useful ¡data ¡that ¡have ¡to ¡be ¡ reloaded ¡before ¡prefetched ¡data ¡is ¡needed ¡ – too ¡late: ¡data ¡is ¡not ¡there ¡when ¡needed ¡

Accuracy = useful prefetches number of prefetches generated

Coverage = useful prefetches number of misses when prefetch is turned off

Baer, ¡p. ¡219 ¡

slide-43
SLIDE 43

Prefetching ¡

  • Why? ¡ ¡
  • What? ¡
  • When? ¡
  • Where? ¡

Baer, ¡p. ¡219 ¡

To ¡hide ¡memory ¡latency ¡by ¡increasing ¡hit ¡ra;o. ¡ Ideally ¡seman;c ¡objects. ¡In ¡prac;ce ¡cache ¡lines. ¡ In ¡a ¡;mely ¡manner ¡when ¡a ¡trigger ¡happens. ¡ A ¡given ¡cache ¡level ¡or ¡a ¡special ¡prefetch ¡storage ¡buffer. ¡

slide-44
SLIDE 44

Disadvantages ¡of ¡Prefetching ¡

  • Compete ¡for ¡resources ¡with ¡regular ¡memory ¡
  • pera;ons ¡

– P.e., ¡might ¡need ¡an ¡extra ¡port ¡in ¡cache ¡to ¡check ¡ tags ¡before ¡prefetching ¡ ¡ – Compe;;on ¡for ¡memory ¡bus ¡with ¡regular ¡loads ¡ and ¡stores ¡

Baer, ¡p. ¡220 ¡

slide-45
SLIDE 45

Soiware ¡Prefetching ¡

  • Non-­‑binding ¡loads: ¡a ¡load ¡that ¡does ¡not ¡write ¡

to ¡a ¡register ¡

  • More ¡sophis;cated ¡instruc;ons: ¡designate ¡the ¡

level ¡in ¡the ¡cache ¡hierarchy ¡where ¡prefetched ¡ line ¡should ¡stop ¡(Itanium) ¡

Baer, ¡p. ¡220 ¡

slide-46
SLIDE 46

Soiware ¡Prefetching ¡Example ¡

for ¡(i=0 ¡; ¡i<n ¡; ¡i++) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡ for ¡(i=0 ¡; ¡i<n ¡; ¡i++){ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch ¡(&a[i+1]); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch(&b[i+1]); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡ } ¡

Code ¡with ¡Prefetching: ¡

What ¡is ¡the ¡drawback ¡now? ¡ May ¡cause ¡an ¡excep;on ¡on ¡ the ¡last ¡itera;on. ¡ Each ¡prefetch ¡instruc;on ¡ ¡ brings ¡an ¡en;re ¡cache ¡line. ¡ Same ¡line ¡is ¡fetched ¡several ¡ ;mes. ¡

Baer, ¡p. ¡221 ¡

slide-47
SLIDE 47

Soiware ¡Prefetching ¡Example ¡

for ¡(i=0 ¡; ¡i<n ¡; ¡i++) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡ for ¡(i=0 ¡; ¡i<n ¡; ¡i++){ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡(i ¡≠ ¡n-­‑1 ¡and ¡i ¡mod ¡4 ¡= ¡0){ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch ¡(&a[i+1]); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch(&b[i+1]); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡ } ¡

Prefetching ¡with ¡Predicate: ¡

What ¡is ¡the ¡drawback ¡now? ¡ This ¡branch ¡is ¡not ¡easy ¡ to ¡predict ¡correctly. ¡

Baer, ¡p. ¡221 ¡

slide-48
SLIDE 48

Soiware ¡Prefetching ¡Example ¡

for ¡(i=0 ¡; ¡i<n ¡; ¡i++) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡ prefetch(&a[0]); ¡ prefetch(&b[0]); ¡ for ¡(i=0 ¡; ¡i<n-­‑4 ¡; ¡i ¡+= ¡4){ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch ¡(&a[i+4]); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch(&b[i+4]); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i+1]*b[i+!]; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i+2]*b[i+2]; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i+3]*b[i+3]; ¡ } ¡ for ¡( ¡; ¡i<n ¡; ¡i++) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡inner ¡= ¡inner ¡+ ¡a[i]*b[i]; ¡

With ¡Loop ¡Unrolling: ¡

Baer, ¡p. ¡221 ¡ Issues: ¡

  • ­‑ ¡register ¡pressure ¡
  • ­‑ ¡code ¡growth ¡
slide-49
SLIDE 49

Sequen9al ¡Prefetching ¡

  • or ¡one-­‑block ¡lookahead ¡(OBL) ¡prefetching: ¡ ¡

– prefetch ¡the ¡next ¡cache ¡line ¡

  • makes ¡the ¡line ¡size ¡look ¡larger ¡
  • Strategies ¡

– always-­‑prefetch: ¡high ¡coverage, ¡low ¡accuracy ¡ – prefetch-­‑on-­‑miss: ¡good ¡for ¡I-­‑caches ¡ – tagged-­‑prefetching: ¡good ¡for ¡D-­‑caches ¡

  • ¡one-­‑bit ¡tag ¡in ¡the ¡cache ¡indicates ¡if ¡next ¡line ¡should ¡be ¡

prefetched ¡

– when ¡line ¡is ¡prefetched: ¡tag ¡← ¡0 ¡ – when ¡line ¡is ¡referenced: ¡tag ¡← ¡1 ¡

Baer, ¡p. ¡222 ¡

slide-50
SLIDE 50

One-­‑Block ¡Ahead ¡Prefetching ¡

Problem: ¡Timeliness ¡of ¡OBL ¡is ¡usually ¡poor ¡(it ¡is ¡too ¡late). ¡

Baer, ¡p. ¡222 ¡

Solu,on: ¡Prefetch ¡mul;ple ¡lines ¡ahead. ¡ ¡accuracy ¡can ¡be ¡low. ¡ ¡ Number ¡of ¡lines ¡ahead ¡cold ¡be ¡adap;ve ¡on ¡ ¡ previous ¡success ¡(a ¡predictor!). ¡ ¡ unreliable ¡feedback: ¡;meless ¡of ¡feedback ¡ informa;on ¡is ¡also ¡poor. ¡

slide-51
SLIDE 51

Stream ¡Prefetching ¡

  • Bring ¡sequen;al ¡lines ¡into ¡a ¡FIFO ¡stream ¡
  • buffer. ¡

– On ¡a ¡miss, ¡check ¡the ¡head ¡of ¡the ¡stream ¡buffer ¡

  • If ¡the ¡head ¡of ¡the ¡stream ¡buffer ¡is ¡also ¡a ¡miss, ¡flush ¡the ¡

buffer ¡

– Works ¡well ¡for ¡I-­‑caches ¡(not ¡as ¡good ¡for ¡D-­‑caches) ¡

  • A ¡stream ¡buffer ¡with ¡four ¡entries ¡yields ¡significant ¡

performance ¡improvement. ¡

Baer, ¡p. ¡223 ¡

slide-52
SLIDE 52

Stride ¡Prefetching ¡

  • Types ¡of ¡access ¡in ¡a ¡loop ¡nest: ¡

– Scalar: ¡reference ¡to ¡scalar ¡variables ¡ – Zero ¡stride: ¡access ¡to ¡arrays ¡in ¡outer ¡loops ¡ – Constant ¡stride: ¡regular ¡accesses ¡to ¡arrays ¡ – Irregular: ¡access ¡through ¡pointers, ¡or ¡to ¡arrays ¡ using ¡complex ¡expressions ¡for ¡index; ¡

  • Example: ¡A[i1,B[i2]] ¡

Baer, ¡p. ¡223 ¡

slide-53
SLIDE 53

Stride ¡Prefetching ¡-­‑ ¡Example ¡

  • Consider ¡the ¡string ¡of ¡references ¡a, ¡b, ¡c, ¡… ¡

such ¡that ¡the ¡distance ¡between ¡consecu;ve ¡ references ¡is ¡constant ¡

– How ¡many ¡references ¡must ¡be ¡observed ¡to ¡detect ¡ that ¡this ¡is ¡a ¡strided ¡access? ¡

  • three ¡

– What ¡is ¡the ¡value ¡of ¡the ¡stride? ¡

b-­‑a ¡

  • Long ¡cache ¡lines ¡do ¡not ¡help ¡if ¡stride ¡is ¡large. ¡

Baer, ¡p. ¡223 ¡

slide-54
SLIDE 54

Stride ¡Prefetching ¡– ¡ Design ¡Decisions ¡

  • Where? ¡

– Cache ¡× ¡Stream ¡Buffers ¡

  • When? ¡

– How ¡much ¡lookahead? ¡

  • How ¡much? ¡

– How ¡many ¡references ¡to ¡prefetch? ¡

Baer, ¡p. ¡223 ¡

slide-55
SLIDE 55

Reference ¡Predic;on ¡Table ¡

based ¡on ¡instruc;on ¡address ¡ state ¡transi;on ¡field ¡ Baer, ¡p. ¡224 ¡

Goal: ¡To ¡indicate ¡whether ¡prefetching ¡should ¡be ¡done ¡ ¡ for ¡a ¡given ¡memory ¡access ¡opera;on. ¡

slide-56
SLIDE 56

Reference ¡Predic;on ¡Table ¡

Ini;al ¡

Decoding ¡an ¡M ¡that ¡ ¡ is ¡not ¡in ¡the ¡table ¡

Transient ¡

stride[i] ¡← ¡stride(M,i) ¡

Steady ¡

stride[i] ¡= ¡stride(M,i) ¡ Let ¡i ¡← ¡index ¡in ¡RPT ¡of ¡entry ¡that ¡matches ¡the ¡Tag ¡of ¡a ¡memory ¡reference ¡instruc;on ¡M ¡ stride(M,i) ¡← ¡Op.address(M) ¡– ¡Op.address(RPT[i]) ¡

No-­‑ Predic;on ¡

stride[i] ¡≠ ¡stride(M,i) ¡ stride[i] ¡≠ ¡stride(M,i) ¡ stride[i] ¡= ¡stride(M,i) ¡ stride[i] ¡≠ ¡stride(M,i) ¡ stride[i] ¡= ¡stride(M,i) ¡ Baer, ¡p. ¡224 ¡

slide-57
SLIDE 57

RPT ¡Table ¡-­‑ ¡Example ¡

int ¡A[100,100], ¡B[100,100], ¡C[100,100] ¡ for( ¡i=0 ¡; ¡i<100 ¡; ¡i++) ¡ ¡ ¡ ¡ ¡ ¡for( ¡j=0 ¡; ¡j<100 ¡; ¡j++){ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡A[i,j] ¡= ¡0; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for( ¡k=0 ¡; ¡k<100 ¡; ¡k++) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡A[i,j] ¡= ¡A[i,j] ¡+ ¡B[i,k] ¡× ¡C[k,j]; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡

Baer ¡p. ¡257 ¡ ¡ ¡ ¡ ¡Address ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Instruc;on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡0100 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡B[i,k] ¡ 0x0000 ¡0104 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡C[k,j] ¡ 0x0000 ¡0108 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡010c ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡A[i,j] ¡ What ¡are ¡the ¡RPT ¡contents ¡for ¡ these ¡instruc;ons ¡aier ¡itera;ons ¡ 0, ¡1, ¡and ¡2 ¡of ¡the ¡inner ¡loop? ¡ A[0,0] ¡ A[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ B[0,0] ¡ B[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ C[0,0] ¡ C[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ 0x0001 ¡0000 ¡ 0x0004 ¡0000 ¡ 0x0008 ¡0000 ¡

Memory ¡

Accesses ¡for ¡itera;on ¡ i=0; ¡j=0; ¡k=1: ¡ &(A[0,0]) ¡= ¡0x0001 ¡0000 ¡ &(B[0,1]) ¡= ¡0x0004 ¡0004 ¡ &(C[1,0]) ¡= ¡0x0008 ¡0190 ¡

slide-58
SLIDE 58

RPT ¡Table ¡-­‑ ¡Example ¡

Baer ¡p. ¡257 ¡

Accesses ¡for ¡itera;on ¡ i=0; ¡j=0; ¡k=1: ¡ &(A[0,0]) ¡= ¡0x0001 ¡0000 ¡ &(B[0,1]) ¡= ¡0x0004 ¡0004 ¡ &(C[1,0]) ¡= ¡0x0008 ¡0190 ¡

¡ ¡ ¡ ¡Address ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Instruc;on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡0100 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡B[i,k] ¡ 0x0000 ¡0104 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡C[k,j] ¡ 0x0000 ¡0108 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡010c ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡A[i,j] ¡ What ¡are ¡the ¡RPT ¡contents ¡for ¡ these ¡instruc;ons ¡aier ¡itera;ons ¡ 0, ¡1, ¡and ¡2 ¡of ¡the ¡inner ¡loop? ¡ A[0,0] ¡ A[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ B[0,0] ¡ B[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ C[0,0] ¡ C[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ 0x0001 ¡0000 ¡ 0x0004 ¡0000 ¡ 0x0008 ¡0000 ¡

Memory ¡

Tag ¡

  • Op. ¡Address ¡

Stride ¡ State ¡ 0x0100 ¡ 0 ¡ 0x0104 ¡ 0 ¡ 0x010C ¡ 0 ¡

Before ¡Itera;on ¡(i=0, ¡j=0, ¡k=0) ¡

slide-59
SLIDE 59

RPT ¡Table ¡-­‑ ¡Example ¡

Baer ¡p. ¡257 ¡

Accesses ¡for ¡itera;on ¡ i=0; ¡j=0; ¡k=1: ¡ &(A[0,0]) ¡= ¡0x0001 ¡0000 ¡ &(B[0,1]) ¡= ¡0x0004 ¡0004 ¡ &(C[1,0]) ¡= ¡0x0008 ¡0190 ¡

¡ ¡ ¡ ¡Address ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Instruc;on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡0100 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡B[i,k] ¡ 0x0000 ¡0104 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡C[k,j] ¡ 0x0000 ¡0108 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡010c ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡A[i,j] ¡ What ¡are ¡the ¡RPT ¡contents ¡for ¡ these ¡instruc;ons ¡aier ¡itera;ons ¡ 0, ¡1, ¡and ¡2 ¡of ¡the ¡inner ¡loop? ¡ A[0,0] ¡ A[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ B[0,0] ¡ B[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ C[0,0] ¡ C[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ 0x0001 ¡0000 ¡ 0x0004 ¡0000 ¡ 0x0008 ¡0000 ¡

Memory ¡

Tag ¡

  • Op. ¡Address ¡

Stride ¡ State ¡ 0x0100 ¡ 0x0004 ¡0000 ¡ 0 ¡ Ini;al ¡ 0x0104 ¡ 0x0008 ¡0000 ¡ 0 ¡ Ini;al ¡ 0x010C ¡ 0x0001 ¡0000 ¡ 0 ¡ Ini;al ¡

Aier ¡Itera;on ¡(i=0, ¡j=0, ¡k=0) ¡

slide-60
SLIDE 60

RPT ¡Table ¡-­‑ ¡Example ¡

Baer ¡p. ¡257 ¡ A[0,0] ¡ A[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ B[0,0] ¡ B[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ C[0,0] ¡ C[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ 0x0001 ¡0000 ¡ 0x0004 ¡0000 ¡ 0x0008 ¡0000 ¡

Accesses ¡for ¡itera;on ¡ i=0; ¡j=0; ¡k=1: ¡ &(A[0,0]) ¡= ¡0x0001 ¡0000 ¡ &(B[0,1]) ¡= ¡0x0004 ¡0004 ¡ &(C[1,0]) ¡= ¡0x0008 ¡0190 ¡

¡ ¡ ¡ ¡Address ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Instruc;on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡0100 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡B[i,k] ¡ 0x0000 ¡0104 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡C[k,j] ¡ 0x0000 ¡0108 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡010c ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡A[i,j] ¡ What ¡are ¡the ¡RPT ¡contents ¡for ¡ these ¡instruc;ons ¡aier ¡itera;ons ¡ 0, ¡1, ¡and ¡2 ¡of ¡the ¡inner ¡loop? ¡

Memory ¡

Tag ¡

  • Op. ¡Address ¡

Stride ¡ State ¡ 0x0100 ¡ 0x0004 ¡0004 ¡ 4 ¡ Transient ¡ 0x0104 ¡ 0x0008 ¡0190 ¡ 400 ¡ Transient ¡ 0x010C ¡ 0x0001 ¡0000 ¡ 0 ¡ Transient ¡

Aier ¡Itera;on ¡(i=0, ¡j=0, ¡k=1) ¡

slide-61
SLIDE 61

RPT ¡Table ¡-­‑ ¡Example ¡

Baer ¡p. ¡257 ¡ A[0,0] ¡ A[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ B[0,0] ¡ B[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ C[0,0] ¡ C[0,1] ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ ⋅⋅⋅ ¡ 0x0001 ¡0000 ¡ 0x0004 ¡0000 ¡ 0x0008 ¡0000 ¡

Accesses ¡for ¡itera;on ¡ i=0; ¡j=0; ¡k=1: ¡ &(A[0,0]) ¡= ¡0x0001 ¡0000 ¡ &(B[0,1]) ¡= ¡0x0004 ¡0004 ¡ &(C[1,0]) ¡= ¡0x0008 ¡0190 ¡

¡ ¡ ¡ ¡Address ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Instruc;on ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡0100 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡B[i,k] ¡ 0x0000 ¡0104 ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡C[k,j] ¡ 0x0000 ¡0108 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ 0x0000 ¡010c ¡ ¡ ¡ ¡ ¡ ¡ ¡load ¡A[i,j] ¡ What ¡are ¡the ¡RPT ¡contents ¡for ¡ these ¡instruc;ons ¡aier ¡itera;ons ¡ 0, ¡1, ¡and ¡2 ¡of ¡the ¡inner ¡loop? ¡

Memory ¡

Tag ¡

  • Op. ¡Address ¡

Stride ¡ State ¡ 0x0100 ¡ 0x0004 ¡0008 ¡ 4 ¡ Steady ¡ 0x0104 ¡ 0x0008 ¡0320 ¡ 400 ¡ Steady ¡ 0x010C ¡ 0x0001 ¡0000 ¡ 0 ¡ Steady ¡

Aier ¡Itera;on ¡(i=0, ¡j=0, ¡k=2) ¡

slide-62
SLIDE 62

Increasing ¡RPT’s ¡Timeliness: ¡ Lookahead ¡RPT ¡

Use ¡a ¡lookahead ¡program ¡counter ¡(LA-­‑PC) ¡ Ignore ¡non-­‑memory ¡instruc;ons ¡accessed ¡through ¡LA-­‑PC. ¡ Branch ¡predictor ¡modifies ¡LA-­‑PC. ¡ RPT ¡must ¡record ¡how ¡many ¡instruc;ons ¡ahead ¡of ¡the ¡ PC ¡the ¡LA-­‑PC ¡is. ¡ ¡ Use ¡a ¡counter ¡incremented ¡by ¡LA-­‑PC ¡and ¡decremented ¡by ¡PC. ¡ ¡ If ¡LA-­‑PC ¡gets ¡too ¡far ¡ahead, ¡stop ¡prefetching ¡with ¡LA-­‑PC. ¡ ¡ Branch ¡misspredic;on ¡forces ¡ ¡LA-­‑PC ¡← ¡PC. ¡ ¡

Baer, ¡p. ¡225 ¡

slide-63
SLIDE 63

Hardware ¡Complexity ¡of ¡LA-­‑PC ¡ ¡

Two-­‑port ¡RPT ¡ Need ¡to ¡check ¡if ¡line ¡to ¡be ¡prefetched ¡is ¡already ¡in ¡cache ¡ One ¡port ¡for ¡PC ¡ One ¡port ¡for ¡LA-­‑PC ¡ Addi;onal ¡port ¡in ¡Cache ¡

Baer, ¡p. ¡225 ¡

slide-64
SLIDE 64

Stream ¡Buffer ¡Extensions ¡

  • Mul;ple ¡buffers ¡

– IBM ¡POWER4 ¡has ¡eight ¡ – When ¡all ¡are ¡busy, ¡replace ¡LRU ¡buffer ¡

  • Filtering: ¡

– Only ¡prefetch ¡on ¡misses ¡to ¡consecu;ve ¡blocks ¡

  • An ¡extension ¡of ¡one-­‑block ¡lookahead ¡
  • Nonunit ¡stride: ¡

– Use ¡finite-­‑state ¡machines ¡for ¡different ¡regions ¡of ¡ state ¡space ¡ ¡

Baer, ¡p. ¡226 ¡

slide-65
SLIDE 65

Correla9on ¡Prefetches ¡

  • Use ¡a ¡Markov ¡model ¡to ¡find ¡correla;ons ¡

between ¡misses ¡

  • Dead ¡line: ¡a ¡line ¡that ¡is ¡s;ll ¡in ¡the ¡cache ¡but ¡

that ¡will ¡no ¡longer ¡be ¡used. ¡

  • Alterna;ve ¡to ¡miss-­‑based ¡Markov ¡model: ¡Use ¡

a ¡predictor ¡to ¡predict ¡when ¡a ¡line ¡becomes ¡

  • dead. ¡

Baer, ¡p. ¡227 ¡

slide-66
SLIDE 66

Prefetching ¡for ¡Pointer-­‑Based ¡ Structures ¡

Artour ¡Stoutchinin, ¡José ¡Nelson ¡Amaral, ¡Guang ¡R. ¡Gao, ¡Jim ¡ ¡ ¡ ¡ Dehnert, ¡Suneel ¡Jain, ¡and ¡Alban ¡Douillet, ¡“Specula;ve ¡Pointer ¡ Prefetching ¡of ¡Induc;on ¡Pointers,” ¡ ¡Compiler ¡Construc9on, ¡ Genova, ¡Italy, ¡April, ¡2001, ¡pp. ¡289-­‑303. ¡ ¡ key ¡ next ¡ key ¡ next ¡ key ¡ next ¡ key ¡ next ¡ key ¡ next ¡ Mo,va,on: ¡Oien ¡elements ¡of ¡a ¡linked ¡list ¡are ¡allocated ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡either ¡con;guous ¡in ¡memory, ¡or ¡with ¡a ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡constant ¡amount ¡of ¡alloca;ons ¡between ¡elements. ¡

slide-67
SLIDE 67

Prefetching ¡for ¡Pointer-­‑Based ¡ Structures ¡-­‑ ¡Example ¡

1 max ¡= ¡0; ¡ 2 current ¡= ¡head; ¡ 3 while(current ¡!= ¡NULL) ¡{ ¡ 4 ¡ ¡ ¡ ¡if(current ¡!= ¡NULL) ¡{ ¡ 5 ¡ ¡ ¡ ¡ ¡ ¡max ¡= ¡current ¡-­‑> ¡key; ¡ 6 ¡ ¡ ¡ ¡ ¡ ¡current ¡= ¡current ¡-­‑> ¡next; ¡ 7 } ¡

Pointer-­‑chasing ¡loop: ¡

1 max ¡= ¡0; ¡ 2 current ¡= ¡head; ¡ ¡ ¡ ¡ ¡ ¡ ¡tmp ¡= ¡current; ¡ 3 ¡ ¡ ¡ ¡while(current ¡!= ¡NULL) ¡{ ¡ 4 ¡ ¡ ¡ ¡if(current ¡!= ¡NULL) ¡{ ¡ 5 ¡ ¡ ¡max ¡= ¡current ¡-­‑> ¡key; ¡ 6 ¡ ¡ ¡ ¡ ¡ ¡ ¡current ¡= ¡current ¡-­‑> ¡next; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡stride ¡= ¡current ¡– ¡tmp; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefetch(current ¡+ ¡stride*k); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡tmp ¡= ¡current; ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡

With ¡prefetch: ¡

Stoutchinin ¡et ¡al., ¡CC ¡2001 ¡

slide-68
SLIDE 68

Prefetching ¡for ¡Pointer-­‑Based ¡ Structures ¡– ¡Instruc;on ¡Examples ¡

Stoutchinin ¡et ¡al., ¡CC ¡2001 ¡

for(…){ ¡ ¡ ¡ ¡ ¡ ¡… ¡ ¡ ¡ ¡ ¡node ¡= ¡ptr-­‑>next; ¡ ¡ ¡ ¡ ¡ptr ¡= ¡node-­‑>ptr; ¡ ¡ ¡ ¡ ¡… ¡ } ¡ for(…){ ¡ ¡ ¡ ¡ ¡… ¡ ¡ ¡ ¡ ¡father ¡= ¡father-­‑>pred; ¡ ¡ ¡ ¡ ¡… ¡ } ¡ for(…){ ¡ ¡ ¡ ¡ ¡… ¡ ¡ ¡ ¡ ¡r2 ¡← ¡r1; ¡ ¡ ¡ ¡ ¡r1 ¡← ¡load(r2, ¡offset_pred); ¡ ¡ ¡ ¡ ¡… ¡ } ¡ for(…){ ¡ ¡ ¡ ¡ ¡… ¡ ¡ ¡ ¡ ¡r1 ¡← ¡load(r2, ¡offset_next); ¡ ¡ ¡ ¡ ¡r2 ¡← ¡load(r1, ¡offset_ptr); ¡ ¡ ¡ ¡ ¡… ¡ } ¡ 20% ¡performance ¡improvement ¡for ¡mcf ¡on ¡a ¡MIPS ¡R10000 ¡machine ¡ with ¡a ¡32-­‑KB, ¡2-­‑way ¡associa;ve, ¡non-­‑blocking ¡L1 ¡and ¡with ¡a ¡ 1 ¡MB ¡L2. ¡

slide-69
SLIDE 69

Lockup-­‑free ¡Caches ¡

  • Hit-­‑under-­‑miss ¡policy: ¡allows ¡subsequent ¡

references ¡to ¡proceed ¡while ¡handling ¡a ¡miss. ¡

  • Lockup-­‑free ¡or ¡nonblocking ¡caches ¡allow ¡

several ¡concurrent ¡misses. ¡

Assuming ¡that ¡write ¡misses ¡and ¡dirty-­‑line ¡ replacements ¡are ¡handled ¡by ¡write ¡buffers, ¡ we ¡can ¡focus ¡only ¡on ¡read ¡misses. ¡

Baer, ¡p. ¡229 ¡

slide-70
SLIDE 70

Implementa;on ¡of ¡Lockup-­‑Free ¡Caches ¡

  • Associate ¡a ¡missing ¡status ¡holding ¡register ¡

(MSHR) ¡with ¡each ¡read ¡miss. ¡

If ¡there ¡is ¡no ¡free ¡ MSHR ¡to ¡give ¡to ¡a ¡ miss, ¡we ¡have ¡an ¡ structural ¡hazard ¡ → ¡stall ¡processor. ¡ On ¡a ¡miss, ¡the ¡line ¡address ¡of ¡all ¡MSHRs ¡are ¡checked ¡to ¡see ¡if ¡a ¡ request ¡for ¡that ¡miss ¡has ¡already ¡been ¡issued. ¡ Baer, ¡p. ¡229 ¡

slide-71
SLIDE 71

Implementa;on ¡of ¡Lockup-­‑Free ¡Caches ¡

  • Associate ¡a ¡missing ¡status ¡holding ¡register ¡

(MSHR) ¡with ¡each ¡read ¡miss. ¡

When ¡an ¡entry ¡arrives ¡from ¡the ¡next ¡level, ¡its ¡address ¡is ¡ compared ¡with ¡all ¡MSHRs. ¡One ¡must ¡match ¡the ¡entry. ¡ Baer, ¡p. ¡229 ¡ Necessary ¡for ¡cache ¡ coherence ¡protocols. ¡

slide-72
SLIDE 72

Cri;cal ¡Word ¡First ¡

  • L2 ¡first ¡sends ¡to ¡L1 ¡the ¡word ¡requested ¡by ¡the ¡
  • processor. ¡

– If ¡this ¡word ¡is ¡in ¡the ¡middle ¡of ¡a ¡line, ¡the ¡line ¡must ¡ be ¡rotated ¡by ¡L2 ¡

  • Only ¡requires ¡a ¡buffer ¡and ¡a ¡shiier ¡

Baer, ¡p. ¡231 ¡

slide-73
SLIDE 73

Mul;ple ¡write ¡misses ¡

  • When ¡a ¡large ¡structure ¡or ¡array ¡is ¡ini;alized ¡or ¡

copied ¡

– A ¡large ¡number ¡of ¡write ¡misses ¡occur ¡ ¡ – With ¡a ¡write-­‑back/write-­‑allocate ¡strategy ¡the ¡ write ¡buffer ¡will ¡fill ¡ ¡

  • processor ¡has ¡to ¡stall ¡because ¡of ¡structural ¡hazard ¡

Baer, ¡p. ¡231 ¡

int ¡A[1000000]; ¡ for(i=0 ¡; ¡i<N ¡; ¡i++){ ¡ ¡ ¡ ¡ ¡A[i] ¡= ¡0; ¡ } ¡ int ¡A[1000000], ¡B[1000000]; ¡ ¡ ¡ ¡ ¡ ¡⋅⋅⋅ ¡ for(i=0 ¡; ¡i<N ¡; ¡i++){ ¡ ¡ ¡ ¡ ¡A[i] ¡= ¡B[i]; ¡ } ¡

slide-74
SLIDE 74

Write ¡Validate ¡Policy ¡

  • Upon ¡a ¡write ¡miss, ¡write ¡directly ¡into ¡the ¡
  • cache. ¡

– Requires ¡a ¡valid ¡bit ¡per ¡word ¡in ¡the ¡line ¡ – If ¡one ¡word ¡is ¡wriren, ¡all ¡other ¡words ¡in ¡the ¡line ¡ must ¡be ¡invalidated ¡(the ¡tag ¡of ¡the ¡entry ¡changed) ¡ – Best ¡for ¡write-­‑through ¡caches ¡

Baer, ¡p. ¡232 ¡

slide-75
SLIDE 75

Mul;level ¡Inclusion ¡Property ¡

The ¡contents ¡of ¡L2 ¡are ¡a ¡superset ¡of ¡the ¡contents ¡of ¡L1. ¡ For ¡a ¡write-­‑back ¡policy: ¡ Space ¡has ¡been ¡allocated ¡in ¡L2 ¡ to ¡store ¡the ¡contents ¡of ¡L1. ¡

Baer, ¡p. ¡232 ¡

slide-76
SLIDE 76

Mul;level ¡Inclusion ¡Property ¡ (example) ¡

  • Assump;ons ¡for ¡the ¡example: ¡

– single ¡processor ¡ – write-­‑back ¡write ¡policy ¡ – L1 ¡and ¡L2 ¡have ¡the ¡same ¡line ¡sizes ¡ – Both ¡L1 ¡and ¡L2 ¡are ¡2-­‑way ¡set ¡associa;ve ¡with ¡LRU ¡ – a, ¡a’ ¡and ¡b ¡are ¡lines ¡in ¡L1 ¡ – A, ¡A’ ¡and ¡B ¡are ¡lines ¡in ¡L2 ¡

Baer, ¡p. ¡232 ¡

slide-77
SLIDE 77

Mul;level ¡Inclusion ¡Property ¡ (example) ¡

On ¡each ¡Miss: ¡New ¡line ¡is ¡allocated ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡in ¡both ¡caches. ¡

a ¡ B ¡

L1 ¡ L2 ¡

b ¡ A ¡

Baer, ¡p. ¡233 ¡

a’ ¡

LRU ¡ LRU ¡

0 ¡ 1 ¡ 1 ¡ 0 ¡ 1 ¡ 0 ¡ 0 ¡ 1 ¡

Sequence ¡of ¡reads: ¡a, ¡b, ¡a’, ¡b, ¡a ¡

A’ ¡ 0 ¡ A ¡ a ¡

B ¡was ¡replaced ¡in ¡L2, ¡therefore ¡b ¡has ¡to ¡be ¡ invalidated ¡in ¡L1. ¡

  • Inv. ¡

1 ¡

slide-78
SLIDE 78

When ¡an ¡invalida;on ¡request ¡for ¡a ¡line ¡is ¡received, ¡ ¡ a ¡check ¡is ¡done ¡in ¡L2. ¡If ¡it ¡is ¡not ¡in ¡L2, ¡L1 ¡does ¡not ¡ ¡ need ¡to ¡be ¡disturbed. ¡ ¡ If ¡the ¡line ¡is ¡in ¡L2, ¡a ¡bit ¡can ¡be ¡used ¡to ¡indicate ¡ ¡ if ¡the ¡entry ¡is ¡in ¡L1. ¡

Baer, ¡p. ¡233 ¡

If ¡the ¡line ¡of ¡L2 ¡is ¡larger ¡than ¡the ¡line ¡of ¡L1, ¡then ¡mul;ple ¡ inclusion ¡bits ¡are ¡necessary ¡in ¡each ¡L2 ¡line. ¡ The ¡associa;vity ¡of ¡L2 ¡must ¡be ¡high ¡enough ¡so ¡that ¡ it ¡can ¡simultaneouly ¡map ¡all ¡lines ¡in ¡L1 ¡(see ¡example ¡in ¡book). ¡

Mul;level ¡Inclusion ¡Property ¡– ¡ Support ¡for ¡Invalida;on ¡

slide-79
SLIDE 79

Mul9level ¡Exclusion ¡

  • A ¡block ¡is ¡in ¡either ¡L1 ¡or ¡L2, ¡but ¡not ¡in ¡both. ¡

– Alterna;ve ¡when ¡mul;level ¡inclusion ¡is ¡not ¡

  • enforced. ¡

– L2 ¡is ¡simply ¡a ¡huge ¡vic;m ¡cache ¡for ¡L1 ¡ – To ¡prevent ¡coherency ¡opera;ons ¡from ¡disturbing ¡ the ¡use ¡of ¡L1 ¡by ¡the ¡processor, ¡L1 ¡must ¡be ¡dual ¡

  • tagged. ¡ ¡

Baer, ¡p. ¡234 ¡

slide-80
SLIDE 80

Replacement ¡Algorithms ¡ Varia;ons ¡on ¡LRU ¡

Baer, ¡p. ¡235 ¡

slide-81
SLIDE 81

Tree-­‑Based ¡Algorithm ¡

  • Example: ¡4-­‑way ¡set ¡associa;ve ¡cache. ¡

a ¡ b ¡ c ¡ d ¡

References: ¡ b ¡ ¡c ¡ ¡a ¡ d ¡ b ¡ ¡c ¡ ¡a ¡ d ¡

a ¡ b ¡ c ¡ d ¡

in ¡L2 ¡cache ¡of ¡IBM ¡Power4 ¡

Requires ¡n-­‑1 ¡bits ¡per ¡set ¡for ¡a ¡n-­‑way ¡set-­‑associa;ve ¡cache. ¡ Baer, ¡p. ¡235 ¡

slide-82
SLIDE 82

Half-­‑Random ¡Selec;on ¡

  • Divide ¡entries ¡in ¡a ¡set ¡into ¡two ¡halves ¡

– Use ¡a ¡single ¡bit ¡to ¡remember ¡the ¡LRU ¡half ¡ – Replace ¡randomly ¡from ¡the ¡LRU ¡half ¡

  • Overall ¡performance ¡is ¡as ¡good ¡as ¡LRU ¡
slide-83
SLIDE 83

Impact ¡of ¡L2 ¡Misses ¡-­‑ ¡Example ¡

IPC ¡with ¡no ¡L2 ¡misses: ¡ 2 ¡instruc;ons/cycle ¡ L2 ¡misses: ¡ 1 ¡for ¡every ¡100 ¡instruc;ons ¡ Memory ¡Latency: ¡ 100 ¡cycles ¡ What ¡is ¡the ¡IPC ¡with ¡L2 ¡misses? ¡ CPIwith ¡L2 ¡= ¡CPIorig ¡+ ¡CPIL2 ¡ CPIwith ¡L2 ¡= ¡0.5 ¡+ ¡0.01 ¡× ¡100 ¡= ¡1.5 ¡ IPCwith ¡L2 ¡= ¡1/1.5 ¡= ¡0.67 ¡ What ¡is ¡the ¡percentage ¡IPC ¡ ¡ improvement ¡with ¡10% ¡ ¡ fewer ¡L2 ¡misses? ¡ CPIwith ¡L2 ¡= ¡0.5 ¡+ ¡0.009 ¡× ¡100 ¡= ¡1.4 ¡ IPCwith ¡L2 ¡= ¡1/1.4 ¡= ¡0.71 ¡

%IPCimpr = 0.71− 0.67 0.71 ×100 = 5.6%

Baer, ¡p. ¡236 ¡

slide-84
SLIDE 84

Sector ¡Caches ¡

Smaller ¡area ¡for ¡tags ¡for ¡given ¡capacity. ¡ Smaller ¡miss ¡penalty. ¡ On ¡a ¡miss, ¡replace ¡one ¡subblock ¡and ¡ invalidate ¡all ¡the ¡others ¡

Baer, ¡p. ¡239 ¡

slide-85
SLIDE 85

Sector ¡Caches ¡today ¡

in ¡L3 ¡of ¡IBM ¡Power4 ¡

Tags ¡of ¡L3 ¡are ¡kept ¡inside ¡the ¡chip: ¡less ¡area ¡for ¡tags. ¡ ¡ 8-­‑way ¡set ¡associa;ve ¡cache ¡with ¡512-­‑byte ¡ lines ¡and ¡four ¡(128-­‑byte) ¡subblocks ¡per ¡line. ¡ for ¡tags. ¡ ¡ Subblock ¡is ¡unit ¡of ¡coherence ¡ ⇒ ¡Reduce ¡false ¡sharing ¡

Baer, ¡p. ¡239 ¡

slide-86
SLIDE 86

Non-­‑Uniform ¡Cache ¡Access ¡

With ¡very ¡large ¡L2 ¡caches, ¡the ¡;me ¡to ¡access ¡entries ¡close ¡ ¡ to ¡the ¡processor ¡is ¡shorter ¡than ¡for ¡entries ¡far ¡away ¡from ¡it. ¡ ¡ Divide ¡L2 ¡into ¡banks ¡and ¡connect ¡banks ¡through ¡an ¡ interconnec;on ¡network. ¡

Baer, ¡p. ¡240 ¡

slide-87
SLIDE 87

Non-­‑Uniform ¡Cache ¡Access ¡ (Example) ¡

Each ¡colum ¡correspond ¡to ¡one ¡way ¡ ¡in ¡an ¡n-­‑way ¡associa;ve ¡cache. ¡ Within ¡a ¡column, ¡banks ¡ are ¡searched ¡ ¡ sequen;ally. ¡ Best ¡to ¡have ¡the ¡requested ¡entry ¡(MRU) ¡ in ¡the ¡top ¡banck ¡(closest ¡to ¡processor). ¡ On ¡a ¡hit, ¡swap ¡line ¡with ¡bank ¡above ¡it. ¡ On ¡a ¡miss ¡LRU ¡will ¡be ¡at ¡the ¡borom ¡bank. ¡ New ¡entry ¡end ¡up ¡far ¡from ¡processor. ¡

Baer, ¡p. ¡240 ¡

slide-88
SLIDE 88

IBM ¡Power4 ¡ Each ¡of ¡the ¡two ¡processors ¡ can ¡run ¡two ¡threads ¡ simultaneously ¡ Power4 ¡(1.7 ¡GHz) ¡and ¡Power5 ¡(1.9 ¡GHz) ¡are ¡8-­‑way ¡out-­‑of-­‑order ¡superscalars. ¡ Power6 ¡(5GHz ¡– ¡2007) ¡is ¡in-­‑order ¡– ¡same ¡energy ¡dissipa;on. ¡ Branch ¡Predictor: ¡

  • ­‑ ¡Local ¡predictor ¡
  • ­‑ ¡Global ¡predictor ¡
  • ­‑ ¡Predictor ¡of ¡predictors ¡

Distributed ¡Windows: ¡ 1 ¡queue/instruc;on ¡type ¡ 11 ¡FIFO ¡queues ¡ Up ¡to ¡80 ¡instr. ¡may ¡queue ¡ 80 ¡physical ¡int. ¡reg. ¡ 72 ¡physical ¡FP ¡reg. ¡ 80-­‑instruc;on ¡ROB ¡ load ¡specula;on ¡ Baer, ¡p. ¡241 ¡

slide-89
SLIDE 89

IBM ¡Power4/Power5 ¡ L1 ¡I-­‑Cache: ¡64KB ¡ Direct/2-­‑way ¡ 128-­‑byte ¡lines ¡ LRU ¡– ¡4 ¡sectors ¡ L1 ¡D-­‑Cache: ¡32KB ¡ 2-­‑way/4-­‑way ¡ 128-­‑byte ¡lines ¡ Write-­‑through ¡ LRU ¡ L3 ¡data ¡is ¡in ¡memory ¡in ¡Power4 ¡and ¡in ¡the ¡processor ¡in ¡Power5. ¡ L2: ¡ 1.5 ¡MB/2 ¡MB ¡ 8 ¡way/10way ¡ 128-­‑byte ¡lines ¡ Writeback ¡ Pseudo-­‑LRU ¡ L3: ¡

  • ­‑ ¡32MB/36 ¡MB ¡
  • ­‑ ¡8-­‑way/12-­‑way ¡
  • ­‑ ¡512-­‑byte ¡line ¡
  • ­‑ ¡Writeback ¡
  • ­‑ ¡Replacement ¡??? ¡
  • ­‑ ¡4 ¡sectors ¡

1/1 ¡cycle ¡ 1/1 ¡cycle ¡ 12/13 ¡cycles ¡ L3: ¡123/87 ¡cycles ¡ Memory: ¡351/220 ¡cycles ¡ Baer, ¡p. ¡242 ¡

slide-90
SLIDE 90

IBM ¡Power4/Power5 ¡ Single-­‑ported ¡ 32 ¡bytes/cycle ¡ ≡ ¡1 ¡sector ¡ ≡ ¡8 ¡instruc;ons ¡ ¡ 128-­‑byte ¡lines ¡divided ¡into ¡4 ¡32-­‑byte ¡sectors ¡ ¡ 4-­‑line ¡prefetch ¡buffer ¡ ¡ 4-­‑line ¡prefetch ¡buffer: ¡ Fetched ¡lines ¡go ¡into ¡the ¡buffer. ¡Cri;cal ¡sector ¡ ¡sent ¡to ¡pipeline. ¡ In ¡later ¡cycles ¡(on ¡other ¡misses) ¡the ¡line ¡is ¡transferred ¡to ¡the ¡cache. ¡ ¡ Prefetch: ¡ Hit ¡in ¡prefetch ¡buffer ¡⇒ ¡prefetch ¡next ¡line. ¡ Miss ¡in ¡the ¡prefetch ¡buffer ¡⇒ ¡prefetch ¡two ¡subsequent ¡lines. ¡ 3-­‑port ¡D1 ¡cache: ¡ two ¡8-­‑byte ¡reads ¡

  • ne ¡8-­‑byte ¡write ¡

Baer, ¡p. ¡242 ¡

slide-91
SLIDE 91

IBM ¡Power4/Power5 ¡ 512 ¡KB ¡of ¡data ¡per ¡slice ¡ Duplicated ¡tag ¡array ¡ for ¡coherence ¡(snooping). ¡ Mul,level ¡Inclusion: ¡ L2 ¡tags ¡contain ¡bits ¡ to ¡indicate ¡in ¡which ¡ L1 ¡cache ¡the ¡entry ¡is. ¡ 8-­‑way ¡set ¡associa;ve ¡ 4 ¡banks ¡of ¡SRAM ¡per ¡slice ¡ Each ¡bank ¡may ¡supply ¡32 ¡bytes/cycle ¡to ¡L1 ¡ Replacement: ¡ Tree-­‑based ¡pseudo ¡LRU ¡ Tag ¡array ¡is ¡parity-­‑protected. ¡Data ¡is ¡ECC ¡protected. ¡ Queues ¡in ¡each ¡slice: ¡

  • ¡one ¡store ¡queue ¡for ¡each ¡processor ¡(stores ¡from ¡L1) ¡
  • ¡a ¡writeback ¡queue ¡fro ¡dirty ¡lines ¡(stores ¡to ¡L3) ¡
  • ¡Several ¡MSHRs ¡for ¡pending ¡requests ¡to ¡L3 ¡
  • ¡a ¡queue ¡for ¡snooping ¡requests ¡

Coherence: ¡

  • ¡with ¡L1s ¡ ¡
  • ¡(4 ¡coherency ¡processors ¡per ¡slice) ¡
  • ¡with ¡other ¡chip ¡mul;processors ¡
  • ¡(4 ¡coherency ¡processors ¡per ¡slice) ¡

Two ¡noncacheable ¡units ¡ (one ¡per ¡processor). ¡(p.e. ¡ to ¡handle ¡memory-­‑mapped ¡I/O). ¡ Baer, ¡p. ¡243 ¡

slide-92
SLIDE 92

IBM ¡Power4/Power5 ¡ 4 ¡quadrants; ¡2 ¡banks/quadrant ¡ 4 ¡MB ¡embedded ¡DRAM/bank ¡ Controler: ¡ 4 ¡quadrants; ¡ ¡ 2 ¡coherence ¡processors/quadrant ¡ 1 ¡simple ¡processor/quadrant ¡ ¡ ¡ ¡ ¡ ¡ ¡for ¡writebacks ¡and ¡DMA ¡ Sector ¡cache ¡with ¡4 ¡sectors. ¡ Does ¡not ¡enforce ¡inclusion. ¡ Baer, ¡p. ¡244 ¡

slide-93
SLIDE 93

Prefetching ¡

IBM ¡Power4/Power5 ¡

Hardware ¡prefetching ¡at ¡all ¡levels ¡ 8 ¡streams ¡of ¡sequen;al ¡data ¡can ¡be ¡preteched ¡concurrently ¡ Start ¡prefetching ¡a ¡stream ¡aier ¡4 ¡consecu;ve ¡ ¡cache ¡misses ¡ ¡ in ¡various ¡levels. ¡ A ¡touch ¡instruc;on ¡can ¡accelerate ¡stream ¡detec;on. ¡

Baer, ¡p. ¡245 ¡

slide-94
SLIDE 94

Stream ¡Prefetching ¡

IBM ¡Power4/Power5 ¡

L1: ¡First ¡access ¡to ¡a ¡prefetched ¡line ¡B0 ¡ ⇒ ¡prefetch ¡line ¡B1 ¡= ¡B0 ¡ ¡+ ¡128 ¡from ¡L2 ¡to ¡L1 ¡ ⇒ ¡L2: ¡prefetch ¡line ¡B5 ¡= ¡B0 ¡ ¡+ ¡512 ¡from ¡L3 ¡to ¡L2 ¡

  • ¡

Account ¡for ¡longer ¡latency ¡of ¡L2 ¡ ⇒ ¡L3: ¡Every ¡4th ¡;me: ¡ ¡ ¡ ¡ ¡ ¡prefetch ¡lines ¡B17, ¡B18, ¡B19, ¡B20 ¡from ¡memory ¡toL3 ¡

  • ¡

Account ¡for ¡longer ¡latency ¡of ¡L3 ¡

  • ¡ ¡ ¡ ¡ ¡Account ¡for ¡longer ¡lines ¡in ¡L3 ¡

Prefetching ¡stops ¡at ¡the ¡end ¡of ¡the ¡virtual ¡memory ¡page. ¡

  • ¡Has ¡4KB ¡and ¡16MB ¡pages ¡

Baer, ¡p. ¡245 ¡