Cache Coherence. Bryan Mills, PhD. Slides provided by Rami Melhem

Similar documents
Cache Coherence. Introduction to High Performance Computing Systems (CS1645) Esteban Meneses. Spring, 2014

Performance study example ( 5.3) Performance study example

Chapter 5. Multiprocessors and Thread-Level Parallelism

Multiprocessor Cache Coherence. Chapter 5. Memory System is Coherent If... From ILP to TLP. Enforcing Cache Coherence. Multiprocessor Types

Introduction to Multiprocessors (Part II) Cristina Silvano Politecnico di Milano

1. Memory technology & Hierarchy

COEN-4730 Computer Architecture Lecture 08 Thread Level Parallelism and Coherence

Lecture 25: Multiprocessors. Today s topics: Snooping-based cache coherence protocol Directory-based cache coherence protocol Synchronization

Multiprocessors & Thread Level Parallelism

Shared Memory SMP and Cache Coherence (cont) Adapted from UCB CS252 S01, Copyright 2001 USB

Computer Architecture. A Quantitative Approach, Fifth Edition. Chapter 5. Multiprocessors and Thread-Level Parallelism

ESE 545 Computer Architecture Symmetric Multiprocessors and Snoopy Cache Coherence Protocols CA SMP and cache coherence

Computer Architecture

Lecture 10: Cache Coherence: Part I. Parallel Computer Architecture and Programming CMU , Spring 2013

Memory Hierarchy in a Multiprocessor

Chapter 5. Multiprocessors and Thread-Level Parallelism

Thread- Level Parallelism. ECE 154B Dmitri Strukov

Cache Coherence. (Architectural Supports for Efficient Shared Memory) Mainak Chaudhuri

Suggested Readings! What makes a memory system coherent?! Lecture 27" Cache Coherency! ! Readings! ! Program order!! Sequential writes!! Causality!

Lecture 25: Multiprocessors

Lecture 10: Cache Coherence: Part I. Parallel Computer Architecture and Programming CMU /15-618, Spring 2015

Processor Architecture

Computer Architecture

EC 513 Computer Architecture

CMSC 611: Advanced. Distributed & Shared Memory

EN2910A: Advanced Computer Architecture Topic 05: Coherency of Memory Hierarchy Prof. Sherief Reda School of Engineering Brown University

Foundations of Computer Systems

Cache Coherence. CMU : Parallel Computer Architecture and Programming (Spring 2012)

Overview: Shared Memory Hardware. Shared Address Space Systems. Shared Address Space and Shared Memory Computers. Shared Memory Hardware

Overview: Shared Memory Hardware

Computer Systems Architecture

Scalable Cache Coherence

CMSC 611: Advanced Computer Architecture

Cache Coherence. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T.

Cache Coherence. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T.

ECSE 425 Lecture 30: Directory Coherence

Module 9: Addendum to Module 6: Shared Memory Multiprocessors Lecture 17: Multiprocessor Organizations and Cache Coherence. The Lecture Contains:

ECE 485/585 Microprocessor System Design

Multiprocessor Cache Coherency. What is Cache Coherence?

4 Chip Multiprocessors (I) Chip Multiprocessors (ACS MPhil) Robert Mullins

CMSC 411 Computer Systems Architecture Lecture 21 Multiprocessors 3

Lecture 24: Multiprocessing Computer Architecture and Systems Programming ( )

Flynn s Classification

Module 9: "Introduction to Shared Memory Multiprocessors" Lecture 16: "Multiprocessor Organizations and Cache Coherence" Shared Memory Multiprocessors

CS 152 Computer Architecture and Engineering. Lecture 19: Directory-Based Cache Protocols

Multicore Workshop. Cache Coherency. Mark Bull David Henty. EPCC, University of Edinburgh

COMP Parallel Computing. CC-NUMA (1) CC-NUMA implementation

10 Parallel Organizations: Multiprocessor / Multicore / Multicomputer Systems

Lecture 11: Cache Coherence: Part II. Parallel Computer Architecture and Programming CMU /15-618, Spring 2015

Review: Multiprocessor. CPE 631 Session 21: Multiprocessors (Part 2) Potential HW Coherency Solutions. Bus Snooping Topology

Cache Coherence in Scalable Machines

Lecture 18: Coherence Protocols. Topics: coherence protocols for symmetric and distributed shared-memory multiprocessors (Sections

MULTIPROCESSORS AND THREAD-LEVEL PARALLELISM (PART 1)

Handout 3 Multiprocessor and thread level parallelism

Multiple Issue and Static Scheduling. Multiple Issue. MSc Informatics Eng. Beyond Instruction-Level Parallelism

CS 152 Computer Architecture and Engineering

Lecture 20: Multi-Cache Designs. Spring 2018 Jason Tang

Lecture 8: Snooping and Directory Protocols. Topics: split-transaction implementation details, directory implementations (memory- and cache-based)

MULTIPROCESSORS AND THREAD-LEVEL. B649 Parallel Architectures and Programming

Aleksandar Milenkovich 1

MULTIPROCESSORS AND THREAD-LEVEL PARALLELISM. B649 Parallel Architectures and Programming

Scalable Multiprocessors

Lecture 30: Multiprocessors Flynn Categories, Large vs. Small Scale, Cache Coherency Professor Randy H. Katz Computer Science 252 Spring 1996

Page 1. Lecture 12: Multiprocessor 2: Snooping Protocol, Directory Protocol, Synchronization, Consistency. Bus Snooping Topology

Aleksandar Milenkovic, Electrical and Computer Engineering University of Alabama in Huntsville

Portland State University ECE 588/688. Cache Coherence Protocols

CS252 Spring 2017 Graduate Computer Architecture. Lecture 12: Cache Coherence

CS 152 Computer Architecture and Engineering. Lecture 19: Directory-Based Cache Protocols

Parallel Computer Architecture Lecture 5: Cache Coherence. Chris Craik (TA) Carnegie Mellon University

Limitations of parallel processing

Lecture 24: Board Notes: Cache Coherency

Lecture 18: Coherence and Synchronization. Topics: directory-based coherence protocols, synchronization primitives (Sections

Midterm Exam 02/09/2009

3/13/2008 Csci 211 Lecture %/year. Manufacturer/Year. Processors/chip Threads/Processor. Threads/chip 3/13/2008 Csci 211 Lecture 8 4

Page 1. SMP Review. Multiprocessors. Bus Based Coherence. Bus Based Coherence. Characteristics. Cache coherence. Cache coherence

Lecture 7: PCM Wrap-Up, Cache coherence. Topics: handling PCM errors and writes, cache coherence intro

CSC 631: High-Performance Computer Architecture

Lecture 1: Introduction

Shared Symmetric Memory Systems

Computer Architecture and Engineering CS152 Quiz #5 April 27th, 2016 Professor George Michelogiannakis Name: <ANSWER KEY>

Chapter-4 Multiprocessors and Thread-Level Parallelism

Scalable Cache Coherent Systems Scalable distributed shared memory machines Assumptions:

Parallel Architecture. Hwansoo Han

CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture. Lecture 18 Cache Coherence

Lecture 24: Virtual Memory, Multiprocessors

Scalable Cache Coherence

Chapter Seven. Idea: create powerful computers by connecting many smaller ones

ECE/CS 757: Homework 1

CS 152 Computer Architecture and Engineering. Lecture 19: Directory-Based Cache Protocols

Scalable Cache Coherent Systems

CMSC Computer Architecture Lecture 15: Memory Consistency and Synchronization. Prof. Yanjing Li University of Chicago

Scalable Cache Coherence. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Parallel Computers. CPE 631 Session 20: Multiprocessors. Flynn s Tahonomy (1972) Why Multiprocessors?

The Cache Write Problem

Lecture 24: Thread Level Parallelism -- Distributed Shared Memory and Directory-based Coherence Protocol

EN2910A: Advanced Computer Architecture Topic 05: Coherency of Memory Hierarchy

EITF20: Computer Architecture Part 5.2.1: IO and MultiProcessor

Lecture 3: Snooping Protocols. Topics: snooping-based cache coherence implementations

Lecture-22 (Cache Coherence Protocols) CS422-Spring

CS433 Homework 6. Problem 1 [15 points] Assigned on 11/28/2017 Due in class on 12/12/2017

Transcription:

Cache Coherence Bryan Mills, PhD Slides provided by Rami Melhem

Cache coherence Programmers have no control over caches and when they get updated. x = 2; /* initially */ y0 eventually ends up = 2 y1 eventually ends up = 6 z1 =??? Copyright 2010, Elsevier Inc. All rights Reserved

The problem of cache coherence in SMPs Different caches may contain different value for the same memory location. Processor Cache Processor Cache Processor Cache Single bus Memory I/O Time Event Cache Contents for CPU A Cache Contents for CPU B Memory Contents for locahon X 0 1 1 CPU A Reads X X = 1 1 2 CPU B reads X X = 1 X = 1 1 3 CPU A stores 0 into X X = 0 X = 1 0 if write through 1 if write back

Do not cache shared data Approaches to cache coherence Do not cache writeable shared data Use snoopy caches (if connected by a bus) If no shared bus, then Use broadcast to emulate shared bus Use directory-based protocols (to communicate only with concerned parties, not with everybody directory keeps track of concerned parties) P1 P2 Pn network/bus Memory

Snooping cache coherence protocols Processor Processor Processor Snoop tag Cache tag and data Snoop tag Cache tag and data Snoop tag Cache tag and data Single bus Memory I/O Each processor monitors the activity on the bus On a read, all caches check to see if they have a copy of the requested block. If yes, they may have to supply the data. On a write, all caches check to see if they have a copy of the data. If yes, they either invalidate the local copy, or update it with the new value. Can have either write back or write through policy (the former is usually more efficient, but harder to maintain coherence).

An Example Snoopy Protocol InvalidaHon protocol for write- back caches Each block of memory can be: Clean in one or more caches and up- to- date in memory, or Dirty in exactly one cache, or Uncached: not in any caches Correspondingly, we record the state of each block in a cache as: Invalid : block contains no valid data, Shared : a clean block (can be shared by other caches), or Exclusive/Modified: a dirty block (cannot be in any other cache) MSI protocol = Modified/shared/invalid Makes sure that if a block is dirty in one cache, it is not valid in any other cache and that a read request gets the most updated data

An Example Snoopy Protocol A read miss to a block in a cache, C1, generates a bus transaction -- if another cache,c2, has the block exclusively, it has to write back the block before memory supplies it. C1 gets the data from the bus and the block becomes shared in both caches. A write hit to a shared block in C1 forces a write back -- all other caches that have the block should invalidate that block the block becomes exclusive in C1. A write hit to an exclusive block does not generate a write back or change of state. A write miss (to an invalid block) in C1 generates a bus transaction If a cache, C2, has the block as shared, it invalidates it If a cache, C2, has the block in exclusive, it writes back the block and changes it state in C2 to invalid. If no cache supplies the block, the memory will supply it. When C1 gets the block, it sets its state to exclusive

Assumes that blocks B1 and B2 map to same cache location L. Initially neither B1 or B2 is cached Block size = one word Event P1 writes 10 to B1 (write miss) P1 reads B1 (read hit) P2 reads B1 (read miss) P2 writes 20 to B1 (write hit) P2 writes 40 to B2 (write miss) P1 reads B1 (read miss) L = invalid L ß B1 = 10 (exclusive) L ß B1 = 10 (exclusive) L ß B1 = 10 (shared) L = invalid L = invalid Example In P1 s cache L ß B1 = 20 (shared) L = invalid L = invalid L = invalid In P2 s cache L ß B1 = 10 (shared) L ß B1 = 20 (exclusive) B1 is written back L ß B2 = 40 (exclusive) L ß B2 = 40 (exclusive)

Example (cont.) Event P1 writes 30 to B1 (write hit) P2 writes 50 to B1 (write miss) P1 reads B1 (read miss) P2 reads B2 (read miss) P1 writes 60 to B2 (write miss) In P1 s cache L ß B1 = 20 (shared) L ß B1 = 30 (exclusive) L ß invalid L ß B1 = 50 (shared) L ß B1 = 50 (shared) L ß B2 = 50 (exclusive) L ß B2 = 40 (exclusive) L ß B2 = 40 (exclusive) B2 is written back L ß B1 = 50 (exclusive) B1 is written back L ß B1 = 50 (shared) L ß B2 = 40 (shared) L = invalid In P2 s cache Describe the messages that show up on the bus after each event Message types: read request, write request, write back

Hierarchical Snooping P P P P L1 L1 L1 L1 L2 B1 L2 B1 B2 Main Memory (Mp) B1 busses follow standard snooping protocol to keep L1 copies consistent with the content of its shared L2 The B2 bus keeps copies in L2 consistent with memory A change of state of a cache line in L2 can be triggered by a transaction on one of the two busses (B1 or B2) and may require propagation to the other bus.

Directory-based Coherence Assumes a shared memory space which is physically distributed P0 Memory P1 Memory Pn Memory Shared memory Network Idea: Implement a directory that keeps track of where each copy of a block is cached and its state in each cache (note that with snooping, the state of a block was kept only in the cache). Processors must consult directory before loading blocks from memory to cache When a block in memory is updated (written), the directory is consulted to either update or invalidate other cached copies. Eliminates the overhead of broadcasting/snooping (bus bandwidth) Hence, scales up to numbers of processors that would saturate a single bus. But is slower in terms of latency

Directory-based Coherence The memory and the directory can be centralized P0 P1 Pn Network Mem Dir Mem Dir Shared memory Mem Dir Or distributed P0 P1 Pn Mem Dir Mem Dir Mem Dir Shared memory Network AlternaHvely, the memory may be distributed but the directory can be centralized. Or the memory may be centralized but the directory can be distributed

Distributed directory- based coherence P0 P1 Pn Mem Dir Mem Dir Mem Dir Network The location (home) of each memory block is determined by its address. A controller decides if access is Local or Remote As in snooping caches, the state of every block in every cache is tracked in that cache (exclusive/dirty, shared/clean, invalid) to avoid the need for write through and unnecessary write back. In addition, with each block in memory, a directory entry keeps track of where the block is cached. Accordingly, a block can be in one of the following states: Uncached: no processor has it (not valid in any cache) Shared/clean: cached in one or more processors and memory is up-to-date Exclusive/dirty: one processor (owner) has data; memory out-of-date

Enforcing coherence Coherence is enforced by exchanging messages between nodes Three types of nodes may be involved Local requestor node (L): the node that reads or write the cache block Home node (H): the node that stores the block in its memory - - may be the same as L Remote nodes (R): other nodes that have a cached copy of the requested block. When L encounters a Read Hit, it just reads the data When L encounters a Read Miss, it sends a message to the home node, H, of the requested block three cases may arise: The directory indicates that the block is not cached The directory indicates that the block is shared/clean and may supply the list of sharers The directory indicates that the block is exclusive

What happens on a read miss? (when block is invalid in local cache) (a) Read miss to a clean or uncached block -- L sends request to H -- H sends the block to L -- state of block is shared in directory -- state of block is shared in L L 1 Request to Home node Return data 2 H (b) Read miss to a block that is exclusive (in another cache) -- L sends request to H -- H informs L about the block owner, R -- L requests the block from R -- R send the block to L -- L and R set the state of block to shared -- R informs H that it should change the state of the block to shared L 3 4 Request to owner R Return data 1 Request to Home node Return owner 4 2 Revise entry H

What happens on a write miss? (when block is invalid in local cache) (a) Write miss to an uncached block -- similar to a read miss to an uncached block except that the state of the block is set to exclusive (b) Write miss to an block that is exclusive in another cache -- similar to a read miss to an exclusive block except that the state of the block is set to exclusive (c) Write miss to a shared block -- L sends request to H -- H sets the state to exclusive -- H sends the block to L -- H sends to L the list of other sharers -- L sets the block s state to exclusive -- L sends invalidating messages to each sharers (R) -- R sets block s state to invalid L 3 Invalidate ack ack 4 4 R R 3 Invalidate 1 Request to Home node Return sharers and data 2 H

What happens on a write hit? (when block is shared or exclusive in local cache) (a) If the block is exclusive in L, just write the data (b) If the block is shared in L -- L sends a request to H to have the block as exclusive -- H sets the state to exclusive -- H informs L of the block s other sharers -- L sets the block s state to exclusive -- L sends invalidating messages to each sharers (R) -- R sets block s state to invalid 3 Invalidate R ack L 4 4 ack R 3 Invalidate 1 Request to Home node Return sharers and data 2 H A degree of complexity that we will ignore: We need a busy state to handle simultaneous requests to the same block. For example, if there are two writes to the same block it has to be serialized.

The MESI protocol As described earlier, a block can have three states (specified in the directory) Invalid or Uncached : no processor has it (not valid in any cache) Shared/clean: cached in one or more processors and memory is up- to- date Modified/dirty: one processor (owner) has data; memory out- of- date The MESI protocol divides the Exclusive state to two states Invalid or uncached: no processor has it (not valid in any cache) Shared: cached in more than one processors and memory is up- to- date Exclusive: one processor (owner) has data and it is clean Modified: one processor (owner) has data, but it is dirty If MESI is implemented using a directory, then the informahon kept for each block in the directory is the same as the three state protocol: Shared in MESI = shared/clean but more than one sharer Exclusive in MESI = shared/clean but only one sharer Modified in MESI = Exclusive/Modified/dirty However, at each cached copy, a dishnchon is made between shared and exclusive.

The MESI protocol On a read miss (local block is invalid), load the block and change its state to exclusive if it was uncached in memory shared if it was already shared, modified or exclusive - if it was modified, get the clean copy from the owner - if was modified or exclusive, change the copy at the previous owner to shared On a write miss, load the block and mark it modified Invalidate other cached copies (if any) On a write hit to a modified block, do nothing On a write hit to an exclusive block change the block to modified On a write hit to a shared block change the block to modified and invalidate the other cached copies. When a modified block is evicted, write it back.

The MESI protocol If MESI is implemented as a snooping protocol, then the main advantage over the three state protocol is when a read to an uncached block is followed by a write to that block. After the uncached block is read, it is marked exclusive Note that, when writing to a shared block, the transaction has to be posted on the bus so that other sharers invalidate their copies. But when writing to an exclusive block, there is no need to post the transaction on the bus Hence, by distinguishing between shared and exclusive states, we can avoid bus transactions when writing on an exclusive block. However, now a cache that has an exclusive block has to monitor the bus for any read to that block. Such a read will change the state to shared. This advantage disappears in a directory protocol since after a write onto an exclusive block, the directory has to be notified to change the state to modified.

Cache organization in multicore systems Shared L2 systems Private L2 systems P P P P P P P P L1 L1 L1 L1 L1 L1 L1 L1 L2 Memory controller L2 L2 L2 L2 System interconnect Memory controller Memory system Memory system Examples: Intel Core Duo PenHum Uses MESI (Modified, Exclusive, Shared, Invalid) cache coherence protocol to keep the L1 data coherent Examples: AMD Dual Core Opteron Uses MOESI (M + Owned + ESI) cache coherence protocol to keep the L2 data coherent (L1 is inclusive to L2)

Consistency Models Strong consistency: Enforces a total ordering among memory operations by different processors. Simple conceptual model (multitasking single CPU). Potentially has high performance penalization. Weak consistency: Allows out-of-order execution within individual processors. Programmers must be aware of consistency models and adapt the code to it. Allows more concurrency and improves performance.

Sequential Consistency Requirements: Memory operations must be atomic. There is a serialization (interleaving) of all memory operations from all processors where: Example: Memory operations from the same processor execute in program order. A read of variable X returns the latest value written to variable X.

Sequential Consistency Requirements: Memory operations must be atomic. There is a serialization (interleaving) of all memory operations from all processors where: Memory operations from the same processor execute in program order. A read of variable X returns the latest value written to variable X. Example: Can t R(Y)0 without W(Y)5

Sequential Consistency (examples) Processor 1 Processor 2 W(Y)5 R(Y)5 W(X)0 W(X)1 W(Y)0 R(X)0 R(Y)0 Processor 1 Processor 2 Processor 3 W(Z)1 R(Z)1 R(X)7 W(X)0 W(X)7 W(Y)9 R(Y)9

Sequential Consistency (examples) Processor 1 Processor 2 W(Y)5 R(Y)5 W(X)0 W(X)1 W(Y)0 R(X)0 R(Y)0 W(Y)5, R(Y)5, W(X)1, W(X)0, W(Y)0, R(X)0, R(Y)0 Processor 1 Processor 2 Processor 3 W(Z)1 R(Z)1 R(X)7 W(X)0 W(X)7 W(Y)9 R(Y)9 W(Z)1, W(X)0, R(Z)1, W(X)7, R(X)7, W(Y)9, R(Y)9