ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document ›...

19
ΙΕΡΑΡΧΙΚΗ ΟΡΓΑΝΩΣΗ ΜΝΗΜΗΣ Αρχιτεκτονική Υπολογιστών

Transcript of ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document ›...

Page 1: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

ΙΕΡΑΡΧΙΚΗ ΟΡΓΑΝΩΣΗ ΜΝΗΜΗΣ

Αρχιτεκτονική Υπολογιστών

Page 2: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Τι είναι κρυφή μνήμη (cache)

• Μικρή και γρήγορη μνήμη που χρησιμοποιείται για να μειώσει τον μέσο χρόνο προσπέλασης σε αργή μνήμη

Αρχιτεκτονική Υπολογιστών

Proc/Regs

L1-Cache

L2-Cache

Memory

Disk, Tape, etc.

Bigger Faster

Page 3: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

ΤΟΠΙΚΟΤΗΤΑ

• Χρονική Τοπικότητα (Temporal Locality)– μια λέξη μνήμης που χρησιμοποιήθηκε

πρόσφατα στο παρελθόν, έχει μεγάληπιθανότητα να ξανά χρησιμοποιηθεί σύντομαστο μέλλον.

• Τοπική Τοπικότητα (Spatial Locality):– οι λέξεις κοντά σε μία λέξη που χρησιμοποιήθηκε

πρόσφατα στο παρελθόν έχουν μεγάληπιθανότητα να χρησιμοποιηθούν σύντομα στομέλλον.

Αρχιτεκτονική Υπολογιστών

Page 4: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Παραδείγματα Τοπικότητας

• Προσπελάσεις Δεδομένων– Προσπέλαση των στοιχείων του πίνακα με

τη σειρά (stride-1 reference pattern).

– Προσπέλαση της μεταβλητής sum σε κάθε επανάληψη.

• Προσπελάσεις εντολών– Προσπέλαση εντολών στη σειρά.

– Επανάληψη εντολών σε loop.

sum = 0;

for (i = 0; i<n; i++)

sum += a[i];

return sum;

Spatial locality

Temporal locality

Spatial locality

Temporal locality

Page 5: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

ΜΝΗΜΗ CACHE

• πλήρως προσεταιριστική (fully associative cache) – Κάθε λέξη της κύριας μνήμης μπορεί να

αποθηκευθεί οπουδήποτε στην cache• Μεγαλύτερη ωφέλιμη χωρητικότητα

• μονοσήμαντης απεικόνισης direct mapped cache– Κάθε λέξη της κύριας μνήμης μπορεί να

αποθηκευθεί μόνο σε μία θέση στην cache• Εύκολη αναζήτηση

Αρχιτεκτονική Υπολογιστών

Page 6: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Ορολογία– block: minimum unit of data to move between levels– hit: data requested is in upper level– miss: data requested is not in upper level– hit rate: fraction of memory accesses that are hits (i.e.,

found at upper level)– miss rate: fraction of memory accesses that are not hits

• miss rate = 1 – hit rate

– hit time: time to determine if the access is indeed a hit + time to access and deliver the data from the upper level to the CPU

– miss penalty: time to determine if the access is a miss + time to replace block at upper level with corresponding block at lower level + time to deliver the block to the CPU

Αρχιτεκτονική Υπολογιστών

Page 7: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

DIRECT MAPPED CACHE

Αρχιτεκτονική Υπολογιστών

00001 00101 01001 01101 10001 10101 11001 11101

00

0

Cache

Memory

001

01

0

01

1

100

101

110

11

1

Page 8: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

ΑΝΑΓΝΩΣΗCACHE

• CACHE HIT– Ανάγνωση από

CACHE

• CACHE MISS– Ανάγνωση από

RAM

– Αποθήκευση στην cache

– Ανανέωση Valid & Tag

Αρχιτεκτονική Υπολογιστών

20 10

Byteoffset

Valid Tag DataIndex

0

1

2

1021

1022

1023

Tag

Index

Hit Data

20 32

31

Address (bit positions)12 11 2

Page 9: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Προσεταιριστική Κρυφή Μνήμη

Αρχιτεκτονική Υπολογιστών

1

2Tag

Data

Block # 0 1 2 3 4 5 6 7

Search

Direct mapped

1

2Tag

Data

Set # 0 1 2 3

Search

Set associative

1

2Tag

Data

Search

Fully associativeDirect Mapped 2-way Set Associative Fully Associative

Θέση ενός block μνήμης με address 12 σε μία cache με 8 blocks

με διαφορετικούς βαθμούς προσεταιριστικότητας

12 mod 8 = 4 12 mod 4 = 0

Page 10: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Άμεσης Απεικόνισης (Direct Mapped)

• Κάθε block απεικονίζεται ακριβώς σε 1 θέση της cache

• Cache location = (block address) MOD (# blocks in cache)

Αρχιτεκτονική Υπολογιστών

Page 11: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Πλήρως Προσεταιριστική

• Κάθε block απεικονίζεται σε οποιαδήποτε

• Cache location = any

Αρχιτεκτονική Υπολογιστών

Page 12: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Προσεταιριστική με Σετ

• Κάθε block απεικονίζεται σε ένα υπο-σετ της cache

• Set selection = (block address) MOD (# sets in cache)

Αρχιτεκτονική Υπολογιστών

Page 13: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Εύρεση θέσης σε Direct Mapped

Αρχιτεκτονική Υπολογιστών

Page 14: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Εύρεση θέσης σε 2-way Set Associative

Αρχιτεκτονική Υπολογιστών

Page 15: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Τι συμβαίνει όταν εκτελείται ένα SW?• Need to keep cache consistent with main memory

– Reads are easy - no modifications

– Writes are harder - when do we update main memory?

• Write-Through

– On cache write - always update main memory as well

– Use a write buffer to stockpile writes to main memory for speed

• Write-Back

– On cache write - remember that block is modified (dirty bit)

– Update main memory when dirty block is replaced

– Sometimes need to flush cache (I/O, multiprocessing)

• Write-Allocate

– Bring written block into cache

– Update word in block

– Anticipate further use of block

• No-write Allocate

– Main memory is updated

– Cache contents unmodified Αρχιτεκτονική Υπολογιστών

Page 16: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Βελτιστοποίηση Απόδοσης της Cache

Αρχιτεκτονική Υπολογιστών

Assume:

cache block of 4 words

1 clock cycle to send address to memory address buffer (1 bus trip)

15 clock cycles for each memory data access

1 clock cycle to send data to memory data buffer (1 bus trip)

CPU

Cache

Bus

Memory

a. One-word-wide

memory organization

CPU

Bus

b. Wide memory organization

Memory

Multiplexor

Cache

CPU

Cache

Bus

Memory

bank 1

Memory

bank 2

Memory

bank 3

Memory

bank 0

c. Interleaved memory organization

Miss penalties1 + 4*15 + 4*1 = 65 cycles

1 + 1*15 +1*1 = 17 cycles

4 word wide memory and bus

1 +1*15 + 4*1 = 20 cycles

4 word wide memory only

Proce-

ssor

Memory

bank 0

Memory

bank 2

Memory

bank 3

Memory

bank 1

Bus

Interleaved memory units

compete for bus

Page 17: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Χρήσιμοι σύνδεσμοι

• http://www.ecs.umass.edu/ece/koren/architecture/Cache/tutorial.html

Αρχιτεκτονική Υπολογιστών

Page 18: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Αρχιτεκτονική Υπολογιστών

• Miss-oriented Approach to Memory Access:

–CPIExecution includes ALU and Memory instructions

CycleTimeyMissPenaltMissRateInst

MemAccess

ExecutionCPIICCPUtime

CycleTimeyMissPenaltInst

MemMisses

ExecutionCPIICCPUtime

Απόδοση Cache

• Separating out Memory component entirely

–AMAT = Average Memory Access Time

–CPIALUOps does not include memory instructions

CycleTimeAMATInst

MemAccessCPI

Inst

AluOpsICCPUtime

AluOps

yMissPenaltMissRateHitTimeAMAT

DataDataData

InstInstInst

yMissPenaltMissRateHitTime

yMissPenaltMissRateHitTime

MissRate=MemMiss

es/MemAccess

Page 19: ΙΡΑΡΧΙΚΗ ΟΡΑΝΩΣΗ ΜΝΗΜΗΣ › modules › document › file.php...Ορολογία –block: minimum unit of data to move between levels –hit: data requested is

Αρχιτεκτονική Υπολογιστών

Παράδειγμα

• clock per instruction (CPI) is 1.0 when all memory accesses hit in the cache.

• The only data accesses are loads and stores: 50% of the instructions.

• miss penalty is 25 clock cycles and the miss rate is 2% (Unified instruction cache and data cache),

• how much faster would the computer be if all instructions and data were cache hit?

TimeClockCyclelsMemoryStalCPIIC

TimeClockCyclellsMemeoryStaclesCPUClockCyCPUtime

)(

75.02502.0)5.01(

ICIC

yMissPenaltMissRateInst

MemAccessIClCyclesMemoryStal

When all instructions are hit:

TimeClockCycleIC

TimeClockCycleIC

TimeClockCyclelsMemoryStalCPIICIdealCPUtime

)00.1(

)(_

In reality:

TimeClockCycleIC

TimeClockCycleICIC

TimeClockCyclelsMemoryStalCPIICCacheCPUtime

75.1

)75.00.1(

)(_