Top Banner
1

CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Oct 10, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

CS211Advanced Computer Architecture

L07 Memory II

Chundong WangSeptember 28th, 2020

CS211@ShanghaiTech 1

Page 2: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Assignments

• HW1• Due today

• HW2• Assigned today• Due at 23:59:59, Monday, 19th October 2020

• Paper Reading 3• Assigned today• One paper only• Due at 23:59:59, Monday, 26th October 2020

• Lab 1• Assigned today• A report and source codes both required• Due at 23:59:59, Monday, 9th November 2020

CS211@ShanghaiTech 2

Admin

Page 3: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Quiz 2

• ( ) 1. Not all potential data hazards can be handled by forwarding (also known as bypassing).

• ( ) 2. The Write-After-Read (WAR) and Write-After-Write (WAW) hazards are impossible in the classic 5-stage pipeline,

i.e., Instruction Fetch/Instruction Decode/Execute/Memory Access/Write Back.

• ( ) 3. Using separate instruction and data caches helps to eliminate structural hazards in the classic 5-stage pipeline.

• ( ) 4. A breakpoint used by programmers for debugging can be viewed as a synchronous, user-requested exception.

CS211@ShanghaiTech 3

T

T

T

T

Page 4: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Quiz 2

• ( ) 1. Not all potential data hazards can be handled by forwarding (also known as bypassing).

• ( ) 2. The Write-After-Read (WAR) and Write-After-Write (WAW) hazards are impossible in the classic 5-stage pipeline,

i.e., Instruction Fetch/Instruction Decode/Execute/Memory Access/Write Back.

• ( ) 3. Using separate instruction and data caches helps to eliminate structural hazards in the classic 5-stage pipeline.

• ( ) 4. A breakpoint used by programmers for debugging can be viewed as a synchronous, user-requested exception.

CS211@ShanghaiTech 4

T

T

T

T

Data-dependencer3 ← r1 op r2 Read-after-Write r5 ← r3 op r4 (RAW) hazard

Anti-dependencer3 ← r1 op r2 Write-after-Read r1 ← r4 op r5 (WAR) hazard

Output-dependencer3 ← r1 op r2 Write-after-Write r3 ← r6 op r7 (WAW) hazard

Page 5: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Previously in CS211: Sectored Caches• Divide a block into subblocks (or sectors)

• Have separate valid and dirty bits for each sector• When is this useful? (Think writes…)• How many subblocks do you transfer on a read?

++ No need to transfer the entire cache block into the cache(A write simply validates and updates a subblock)

++ More freedom in transferring subblocks into the cache (a cache block does not need to be in the cache fully)

-- More complex design-- May not exploit spatial locality fully when used for reads

tagsubblockvsubblockv subblockvd d dCS211@ShanghaiTech 5

Page 6: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Previously in CS211: Instruction vs. Data Caches

• Unified:+ Dynamic sharing of cache space between instructions and data-- Instructions and data can thrash each other (i.e., no guaranteed

space for either)-- I and D are accessed in different places in the pipeline. Where do we

place the unified cache for fast access?

• First level caches are almost always split • Mainly for the last reason above

• Second and higher levels are almost always unified

CS211@ShanghaiTech 6

Page 7: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Previously in CS211: Multi-level Caching in a Pipelined Design

• First-level caches (instruction and data)• Decisions very much affected by cycle time• Small, lower associativity• Tag store and data store accessed in parallel

• Second-level caches• Decisions need to balance hit rate and access latency• Usually large and highly associative; latency not as important• Tag store and data store accessed serially

• Serial vs. Parallel access of levels• Serial: Second level cache accessed only if first-level misses• Second level does not see the same accesses as the first

• First level acts as a filter

CS211@ShanghaiTech 7

Page 8: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Case Study: ARM Cortex-A53 Cache Systems• L1 I-Cache is 8KB to 64 KB, has 64B cache lines,

is 2-way set associative, and has a 128-bit read interface to L2

• L1 D-Cache is 8KB to 64 KB, has 64B cache lines, is 4-way set associative, has a 128-bit read interface to L2, and a 256-bit write interface to L2

• L2 Cache is 128KB to 2 MB, has 64B cache lines, and is 16-way set associative

• Both the L1 D cache and L2 use a write-back policy defaulting to allocate on write.

• LRU approximation in all the caches

Processor

L1 I-cache L1 D-cache

L2 cache

Main memory

CS211@ShanghaiTech 8

Page 9: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Case Study: Intel Core i7 6700

• L1 I-Cache is 32KB, has 64B cache lines, is 8-way set associative• L1 D-Cache 32KB, has 64B cache lines, is 8-way set associative• L1 I-Cache and D-Cache have Pseudo-LRU replacement• L2 Cache is 256KB, has 64B cache lines, is 4-way set associative• L2 Cache has Pseudo-LRU replacement• L3 Cache is 8MB, 2MB per core, has 64B cache lines, is 16-way set

associative• L3 Cache has Pseudo-LRU replacement but with an ordered

selection algorithm• The block replaced is always the lowest numbered way whose access

bit is off

CS211@ShanghaiTech 9

Page 10: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Cache Inclusion Policy

CS211@ShanghaiTech 10

Page 11: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Inclusive

L2

L1

Initial state Read A miss; load A into L1 and L2

A

A

Read B miss; load B into L1 and L2

A

A B

B

Evict A from L1 due to cache replacement

A

B

B

Evict B from L2 due to cache replacement

A

B

B

A

Back invalidation

CS211@ShanghaiTech 11

Page 12: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Exclusive

L2

L1

Initial state Read A miss; load A into L1

A

Read B miss; load B into L1

A B

Evict A from L1 due to cache replacement and place in L2

BA

A

CS211@ShanghaiTech 12

Page 13: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Non-inclusive

L2

L1

Initial state Read A miss; load A into L1 and L2

A

A

Read B miss; load B into L1 and L2

A

A B

B

Evict A from L1 due to cache replacement

A

B

B

Evict B from L2 due to cache replacement

A

B

B

A

CS211@ShanghaiTech 13

Page 14: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Cache Inclusion Policy

• Multi-level caches are designed depending upon if data in one cache level are also in other cache levels

• Inclusive Policy• Same data in all levels

• Exclusive Policy• Data in only one cache

• Exclusive policy increases effective amount of caching, but:• If data in L2 but not L1, then block is moved from L2 to L1• If this causes an eviction from L1, then victim cache block moved to L2

• Non-inclusive policy is a blend of inclusive and exclusive policies

CS211@ShanghaiTech 14

Page 15: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Inclusive, or not?

• Inclusive cache eases coherence• Updating a cache block in L1 entails an update in inclusive LLC.• A non-inclusive LLC, say L2 cache, which needs to evict a block, must ask L1

cache if it has the block, because such information is not present in LLC.

• Non-inclusive cache yields higher performance though, why?• No back invalidation• More data can be cached

CS211@ShanghaiTech 15

Page 16: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

‘Sneaky’ LRU for Inclusive Cache

Inclusive LLC

L1

A

A B

B

CPU Core

A is frequently used A is frequently hit in L1 cache. It is MRU in L1 cache.

In LLC, A is not frequently hit

In LLC, A is LRUA is evicted for replacement, in both L1 and L2

As a result, MRU block that should be retained might be evicted, which causes performance penalty.

Link: https://doi.org/10.1109/MICRO.2010.52

What if LLC is non-inclusive?

CS211@ShanghaiTech 16

Page 17: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Main Memory

CS211@ShanghaiTech 17

Page 18: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Modern Virtual Memory SystemsIllusion of a large, private, uniform store

18

Protection & Privacyseveral users, each with their private address space and one or more shared address spaces

Demand PagingProvides the ability to run programs larger than the primary memory

Hides differences in machine configurations

The price is address translation on each memory reference

OS

useri

PrimaryMemory

SecondaryStorage

VA PAmappingTLB

Page 19: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Recap: Hierarchical Page Table

19

Level 1 Page Table

Level 2Page Tables

Data Pages

page in primary memory page in secondary memory

Root of CurrentPage Table

p1

offset

p2

Virtual Address from CPU

(ProcessorRegister, satp in

RISC-V)

PTE of a nonexistent page

p1 p2 offset01112212231

10-bitL1 index

10-bit L2 index

Phys

ical

Mem

ory

RISC-V Sv32 Virtual Memory Scheme

Page 20: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Page-Based Virtual-Memory Machine(Hardware Page-Table Walk)

20

• Assumes page tables held in untranslated physical memory

PCInst. TLB

Inst. Cache D Decode E M

Data Cache W+

Page Fault?Protection violation?

Page Fault?Protection violation?

Data TLB

Main Memory (DRAM)

Memory ControllerPhysical Address

Physical Address

Physical Address

Physical Address

Page-Table Base Register

Virtual Address Physical

Address

Virtual Address

Hardware Page Table Walker

Miss? Miss?

Physical address used to access cache

Page 21: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

The Main Memory System

• Main memory is a critical component of all computing systems: server, mobile, embedded, desktop, sensor

Processorand caches

Main Memory Storage (SSD/HDD)

CS211@ShanghaiTech 21

In-memory database Social networks In-memory analytics Data centers

Page 22: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

The Main Memory System

• Main memory is a critical component of all computing systems: server, mobile, embedded, desktop, sensor

• Main memory system must scale (in size, technology, efficiency, cost, and management algorithms) to maintain performance growth and technology scaling benefits

Processorand caches

Main Memory Storage (SSD/HDD)

CS211@ShanghaiTech 22

Page 23: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Main Memory

• Major Trends Affecting Main Memory• The Memory Scaling Problem and Solution Directions

• New Memory Architectures• Enabling Emerging Technologies

• How Can We Do Better?

CS211@ShanghaiTech 23

Page 24: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Major Trends Affecting Main Memory (II)

• Need for main memory capacity, bandwidth, QoS increasing • Multi-core: increasing number of cores• Data-intensive applications: increasing demand/hunger for data• Consolidation: cloud computing, GPUs, mobile, heterogeneity

• Main memory energy/power is a key system design concern

• DRAM technology scaling is ending

CS211@ShanghaiTech 24

Page 25: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Example: The Memory Capacity Gap

• Memory capacity per core expected to drop by 30% every two years• Trends worse for memory bandwidth per core!

Core count doubling ~ every 2 years DRAM DIMM capacity doubling ~ every 3 years

CS211@ShanghaiTech 25

Page 26: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Major Trends Affecting Main Memory (III)

• Need for main memory capacity, bandwidth, QoS increasing

• Main memory energy/power is a key system design concern• ~40-50% energy spent in off-chip memory hierarchy [Lefurgy, IEEE

Computer 2003] • DRAM consumes power even when not used (periodic refresh)

• DRAM technology scaling is ending

CS211@ShanghaiTech 26

Page 27: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Major Trends Affecting Main Memory (IV)

• Need for main memory capacity, bandwidth, QoS increasing

• Main memory energy/power is a key system design concern

• DRAM technology scaling is ending • ITRS projects DRAM will not scale easily below X nm • Scaling has provided many benefits:

• higher capacity (density), lower cost, lower energy

CS211@ShanghaiTech 27

Page 28: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Main Memory

• Major Trends Affecting Main Memory• The Memory Scaling Problem and Solution Directions

• New Memory Architectures• Enabling Emerging Technologies

• How Can We Do Better?

CS211@ShanghaiTech 28

Page 29: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

The DRAM Scaling Problem

• DRAM stores charge in a capacitor (charge-based memory)• Capacitor must be large enough for reliable sensing• Access transistor should be large enough for low leakage and high

retention time• Scaling beyond 40-35nm (2013) is challenging [ITRS, 2009]

• DRAM capacity, cost, and energy/power hard to scale

CS211@ShanghaiTech 29

Page 30: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Solution 1: Fix DRAM

• Overcome DRAM shortcomings with• System-DRAM co-design• Novel DRAM architectures, interface, functions• Better waste management (efficient utilization)

• Key issues to tackle• Enable reliability at low cost• Reduce energy• Improve latency and bandwidth• Reduce waste (capacity, bandwidth, latency)• Enable computation close to data

CS211@ShanghaiTech 30

Page 31: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Solution 1: Fix DRAM• Liu+, “RAIDR: Retention-Aware Intelligent DRAM Refresh,” ISCA 2012.

• Kim+, “A Case for Exploiting Subarray-Level Parallelism in DRAM,” ISCA 2012.

• Lee+, “Tiered-Latency DRAM: A Low Latency and Low Cost DRAM Architecture,” HPCA 2013.

• Liu+, “An Experimental Study of Data Retention Behavior in Modern DRAM Devices,” ISCA 2013.

• Seshadri+, “RowClone: Fast and Efficient In-DRAM Copy and Initialization of Bulk Data,” MICRO 2013.

• Pekhimenko+, “Linearly Compressed Pages: A Main Memory Compression Framework,” MICRO 2013.

• Chang+, “Improving DRAM Performance by Parallelizing Refreshes with Accesses,” HPCA 2014.

• Khan+, “The Efficacy of Error Mitigation Techniques for DRAM Retention Failures: A Comparative Experimental Study,” SIGMETRICS 2014.

• Luo+, “Characterizing Application Memory Error Vulnerability to Optimize Data Center Cost,” DSN 2014.

• Kim+, “Flipping Bits in Memory Without Accessing Them: An Experimental Study of DRAM Disturbance Errors,” ISCA 2014.

• Lee+, “Adaptive-Latency DRAM: Optimizing DRAM Timing for the Common-Case,” HPCA 2015.

• Qureshi+, “AVATAR: A Variable-Retention-Time (VRT) Aware Refresh for DRAM Systems,” DSN 2015.

• Meza+, “Revisiting Memory Errors in Large-Scale Production Data Centers: Analysis and Modeling of New Trends from the Field,” DSN 2015.

• Kim+, “Ramulator: A Fast and Extensible DRAM Simulator,” IEEE CAL 2015.

• Seshadri+, “Fast Bulk Bitwise AND and OR in DRAM,” IEEE CAL 2015.

• Ahn+, “A Scalable Processing-in-Memory Accelerator for Parallel Graph Processing,” ISCA 2015.

• Ahn+ “PIM-Enabled Instructions: A Low-Overhead, Locality-Aware Processing-in-Memory Architecture,” ISCA 2015.

• Avoid DRAM:• Seshadri+, “The Evicted-Address Filter: A Unified Mechanism to Address Both Cache Pollution and Thrashing,” PACT 2012.• Pekhimenko+, “Base-Delta-Immediate Compression: Practical Data Compression for On-Chip Caches,” PACT 2012.• Seshadri+, “The Dirty-Block Index,” ISCA 2014.• Pekhimenko+, “Exploiting Compressed Block Size as an Indicator of Future Reuse,” HPCA 2015.• Vijaykumar+, “A Case for Core-Assisted Bottleneck Acceleration in GPUs: Enabling Flexible Data Compression with Assist Warps,” ISCA

2015.

CS211@ShanghaiTech 31

Page 32: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Solution 2: Emerging Memory Technologies• Some emerging resistive memory technologies seem more scalable than DRAM

(and they are non-volatile)• Example 1: Phase Change Memory

• Expected to scale to 9nm (2022 [ITRS])• Expected to be denser than DRAM: can store multiple bits/cell

• Example 2: Intel Optane DC Memory• Commercially available, in terabytes

• But, emerging technologies have shortcomings as well• Can they be enabled to replace/augment/surpass DRAM?

Lee+, “Architecting Phase Change Memory as a Scalable DRAM Alternative,” ISCA’09, CACM’10, Micro’10.

Meza+, “Enabling Efficient and Scalable Hybrid Memories,” IEEE Comp. Arch. Letters 2012.

Yoon, Meza+, “Row Buffer Locality Aware Caching Policies for Hybrid Memories,” ICCD 2012.

Kultursay+, “Evaluating STT-RAM as an Energy-Efficient Main Memory Alternative,” ISPASS 2013.

Meza+, “A Case for Efficient Hardware-Software Cooperative Management of Storage and Memory,” WEED 2013.

Lu+, “Loose Ordering Consistency for Persistent Memory,” ICCD 2014.

Zhao+, “FIRM: Fair and High-Performance Memory Control for Persistent Memory Systems,” MICRO 2014.

Yoon, Meza+, “Efficient Data Mapping and Buffering Techniques for Multi-Level Cell Phase-Change Memories,” ACM TACO 2014.

… … CS211@ShanghaiTech 32

Page 33: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Solution 3: Hybrid Memory Systems

Meza+, “Enabling Efficient and Scalable Hybrid Memories,” IEEE Comp. Arch. Letters, 2012.Yoon, Meza et al., “Row Buffer Locality Aware Caching Policies for Hybrid Memories,” ICCD 2012 Best Paper Award.… …

CPUDRAMCtrl

Fast, small, leaky, volatile,

high-costLarge, non-volatile, low-cost

Slow, wears out, high active energy

NVM CtrlDRAM Technology X (e.g., PCM, Intel Optane)

Hardware/software manage data allocation and movement to achieve the best of multiple technologies

CS211@ShanghaiTech 33

Page 34: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Some Promising Directions

• New memory architectures• Rethinking DRAM• A lot of hope in fixing DRAM

• Enabling emerging NVM technologies • Hybrid memory systems • Single-level memory and storage• A lot of hope in hybrid memory systems and single-level stores

CS211@ShanghaiTech 34

Page 35: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Virtual Memory and Cache Interaction

CS211@ShanghaiTech 35

Page 36: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Cache-VM Interaction

CPU

TLB

cache

lowerhier.

physical cache

CPU

cache

TLB

lowerhier.

virtual (L1) cache

VA

PA

CPU

cache TLB

lowerhier.

virtual-physical cache

VA

PA

VA

PA

CS211@ShanghaiTech 36

Page 37: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Address Translation and Caching

• When do we do the address translation?• Before or after accessing the L1 cache?

• In other words, is the cache virtually addressed or physically addressed?

• Virtual versus physical cache

• What are the issues with a virtually addressed cache?

• Synonym problem:• Two different virtual addresses can map to the same physical

address same physical address can be present in multiple locations in the cache can lead to inconsistency in data

CS211@ShanghaiTech 37

Block offsetSet IndexTag

Address

Page 38: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Homonyms and Synonyms

• Homonym: Same VA can map to two different PAs• Why?

• VA is in different processes

• Synonym: Different VAs can map to the same PA• Why?

• Different pages can share the same physical frame within or across processes• Reasons: shared libraries, shared data, copy-on-write pages within the same process, …

• Do homonyms and synonyms create problems when we have a cache?

• Is the cache virtually or physically addressed?

CS211@ShanghaiTech 38

Page 39: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Virtually-Indexed Physically-Tagged• If C≤(page_size × associativity), the cache index bits come only from

page offset (same in VA and PA)• If both cache and TLB are on chip

• index both arrays concurrently using VA bits• check cache tag (physical) against TLB output at the end

VPN Page Offset

TLB

PPN

Index offset

physicalcache

tag data=

cache hit?TLB hit?CS211@ShanghaiTech 39

Page 40: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Virtually-Indexed Physically-Tagged• If C>(page_size × associativity), the cache index bits include VPN ⇒

Synonyms can cause problems• Different VAs mapped to the same physical address• The same physical address can exist in two locations

• Solutions?

VPN Page Offset

TLB

PPN

Index

physicalcache

tag data=

cache hit?TLB hit?

a?

CS211@ShanghaiTech 40

offset

Page 41: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Some Solutions to the Synonym Problem

• Limit cache size to (page size × associativity)• get index from page offset

• On a write to a block, search all possible indices that can contain the same physical block, and update/invalidate

• Used in Alpha 21264, MIPS R10K

• Restrict page placement in OS• make sure index(VA) = index(PA)• Called page coloring• Used in many SPARC processors

CS211@ShanghaiTech 41

Page 42: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

PIPT and VIVT

• Physically indexed, physically tagged (PIPT) caches use the physical address for both the index and the tag.

• Simple to implement but slow, as the physical address must be looked up (which could involve a TLB miss and access to main memory) before that address can be looked up in the cache.

• Virtually indexed, virtually tagged (VIVT) caches use the virtual address for both the index and the tag.

• Potentially much faster lookups.• Problems when several different virtual addresses may refer to the same

physical address• Addresses would be cached separately despite referring to the same memory, causing

coherency problems.• Additionally, there is a problem that virtual-to-physical mappings can change,

which would require clearing cache blocks• Can we have PIVT?

CS211@ShanghaiTech 42

Page 43: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Conclusion

• Case studies for cache• Cache inclusion• Main memory• Interaction between cache and memory

CS211@ShanghaiTech 43

Page 44: CS211 Advanced Computer Architecture L01 Introduction · CS211@ShanghaiTech 3 T T T T. Quiz 2 • ( ) 1. Not all potential data hazards can be handled by forwarding (also known as

Acknowledgements

• These slides contain materials developed and copyright by:• Prof. Onur Mutlu (ETH Zurich)• Prof. Zhi Wang (FSU)• Prof. Jason Tang (UMBC)• Prof. Krste Asanović (UC Berkeley)

CS211@ShanghaiTech 44