Outline

• MP Motivation EEL 5764 Graduate Computer • SISD v. SIMD v. MIMD Architecture • Centralized vs. • Challenges to Parallel Programming • Consistency, Coherency, Write Serialization Chapter 4 - Multiprocessors and TLP • Snoopy Ann Gordon-Ross • Directory-based protocols and examples Electrical and Computer Engineering University of Florida

http://www.ann.ece.ufl.edu/

These slides are provided by: David Patterson Electrical Engineering and Computer Sciences, University of California, Berkeley Modifications/additions have been made from the originals 11/11/09 2

Uniprocessor Performance (SPECint) - Déjà vu all over again? Revisited….yet again 3X “… today’s processors … are nearing an impasse as technologies approach From Hennessy and Patterson, the speed of light..” : A Quantitative Approach, 4th edition, 2006! David Mitchell, The Transputer: The Time Is Now (1989) • Transputer had bad timing (Uniprocessor performance!) " Procrastination rewarded: 2X seq. perf. / 1.5 years • “We are dedicating all of our future product development to multicore designs. … This is a sea change in computing” Paul Otellini, President, Intel (2005) • All companies switch to MP (2X CPUs / 2 yrs) " Procrastination penalized: 2X sequential perf. / 5 yrs

Manufacturer/Year! AMD/’05! Intel/’06! IBM/’04! Sun/’05! Processors/chip! 2! 2! 2! 8! • VAX : 25%/year 1978 to 1986 Threads/! !1 !2 !2 !4 • RISC + : 52%/year 1986 to 2002 11/11/09 3 Threads/chip11/11/09 ! 2 4 4 32 4 • RISC + x86: ??%/year 2002 to present ! ! ! ! Other Factors Pushing Multiprocessors Other Factors Pushing Multiprocessors • Growth in data-intensive applications • Lessons learned: – Data bases, file servers, … – Improved understanding in how to use – Inherently parallel - SMT can’t fully exploit multiprocessors effectively • Growing interest in servers, server perf. » Especially in servers where significant natural TLP – Internet – Advantages in replication rather than unique • Increasing desktop perf. less important design (outside of graphics) » In uniprocessor, redesign every few years = – Don’t need to run Word any faster tremendous R&D • Or many designs for different customer demands (Celeron – But near unbounded performance increase has lead to vs. Pentium) terrible programming » Shift efforts to multiprocessor • Simple add more processors for more performance

11/11/09 5 11/11/09 6

M.J. Flynn, "Very High-Speed Computers", Outline Flynn’s Taxonomy Proc. of the IEEE, V 54, 1900-1909, Dec. 1966.

• MP Motivation • Flynn divided the world into two streams in 1966 = instruction and data • SISD v. SIMD v. MIMD Single Instruction Single Single Instruction Multiple • Centralized vs. Distributed Memory Data (SISD) Data SIMD • Challenges to Parallel Programming (Uniprocessor) (single PC: Vector, CM-2) • Consistency, Coherency, Write Serialization Multiple Instruction Single Multiple Instruction Multiple Data (MISD) Data MIMD • Snoopy Cache (????) (Clusters, SMP servers) • Directory-based protocols and examples • SIMD " Data Level Parallelism • MIMD " Level Parallelism • MIMD popular because – Flexible: N pgms and 1 multithreaded pgm – Cost-effective: same MPU in desktop & MIMD

11/11/09 7 11/11/09 8 Outline Back to Basics

• MP Motivation • A parallel computer is… – … a collection of processing elements that cooperate and • SISD v. SIMD v. MIMD communicate to solve large problems fast. • Centralized vs. Distributed Memory • How do we build a parallel architecture? • Challenges to Parallel Programming – Computer Architecture + Communication Architecture • 2 classes of multiprocessors WRT memory: • Consistency, Coherency, Write Serialization 1. Centralized Memory Multiprocessor • Snoopy Cache • Take a single design and just keep adding more • Directory-based protocols and examples processors/cores • few dozen processor chips (and < 100 cores) in 2006 • Small enough to share single, centralized memory • But interconnect is becoming a bottleneck….. 2. Physically Distributed-Memory multiprocessor • Can have larger number chips and cores • BW demands are met by distributing memory among processors 11/11/09 9 11/11/09 10

Centralized vs. Distributed Memory Centralized Memory Multiprocessor

Intel AMD • Also called symmetric multiprocessors (SMPs) Scale • main memory has a symmetric relationship to all processors P Pn 1 P1 Pn • All processors see same access time to memory • Reducing interconnect bottleneck $ $ $ $ Mem Mem • Large caches " single memory can satisfy memory demands Interconnection network of small number of processors Interconnection network Mem Mem • How big can the design realistically be? • Scale to a few dozen processors by using a switch and by Centralized Memory Distributed Memory using many memory banks • Scaling beyond that is technically conceivable but….it All memory is far Close memory and far memory becomes less attractive as the number of processors sharing centralized memory increases

Logically connected but • Longer wires = longer latency on different banks • Higher load = higher power • More contention = bottleneck for shared resource

11/11/09 11 11/11/09 12 2 Models for Communication and Distributed Memory Multiprocessor Memory Architecture 1. message-passing multiprocessors • Distributed memory is a “must have” for • Communication occurs by explicitly passing messages among big designs the processors 2. multiprocessors • Pros: • Communication occurs through a shared address space (via • Cost-effective way to scale memory bandwidth loads and stores): either • If most accesses are to local memory • UMA ( time) for shared address, • Reduces latency of local memory accesses centralized memory MP • NUMA (Non Uniform Memory Access time multiprocessor) for • Cons: shared address, distributed memory MP • Communicating data between processors more complex • More complicated • Software aware • In past, confusion whether “sharing” means sharing physical memory (Symmetric MP) or • Must change software to take advantage of increased memory BW sharing address space

11/11/09 13 11/11/09 14

Outline Challenges of Parallel Processing

• MP Motivation • First challenge is % of program inherently • SISD v. SIMD v. MIMD sequential • Centralized vs. Distributed Memory • Suppose 80X from 100 processors. What fraction of original program can be • Challenges to Parallel Programming sequential? • Consistency, Coherency, Write Serialization a. 10% • Snoopy Cache b. 5% • Directory-based protocols and examples c. 1% d. <1%

11/11/09 15 11/11/09 16 Amdahl’s Law Answers Challenges of Parallel Processing

• Second challenge is long latency to remote memory • Suppose 32 CPU MP, 2GHz, 200 ns remote memory (400 clock cycles), all local accesses hit and base CPI is 0.5. • What is the performance impact if 0.2% instructions involve remote access? a. 1.5X b. 2.0X c. 2.5X 11/11/09 17 11/11/09 18

CPI Equation Challenges of Parallel Processing

• CPI = Base CPI + 1. Need new advances in algorithms Remote request rate • Application parallelism x Remote request cost 2. New programming languages • CPI = 0.5 + 0.2% x 400 = 0.5 + 0.8 = 1.3 • Hard to program parallel applications • No communication is 1.3/0.5 or 2.6 faster 3. How to deal with long remote latency than 0.2% instructions involve local impact access • both by architect and by the programmer – For example, reduce frequency of remote accesses either by » Caching shared data (HW) » Restructuring the data layout to make more accesses local (SW)

11/11/09 19 11/11/09 20 Symmetric Shared-Memory Architectures Outline - UMA • MP Motivation • From multiple boards on a shared bus to • SISD v. SIMD v. MIMD multiple processors inside a single chip • Centralized vs. Distributed Memory • Equal access time for all processors to • Challenges to Parallel Programming memory via shared bus • Consistency, Coherency, Write Serialization • Each processor will cache both • Snoopy Cache – Private data are used by a single processor – Shared data are used by multiple processors • Directory-based protocols and examples • Advantage of caching shared data – Reduces latency to shared data, memory bandwidth for shared data, and interconnect bandwidth – But adds cache coherence problem

11/11/09 21 11/11/09 22

Example Cache Coherence Problem Not Just Cache Coherency….

P1 P2 P3 • Getting single variable values coherent isn’t the u = ? u = ? 3 only issue 4 $ $ 5 $ – Coherency alone doesn’t lead to correct program execution u :5 u :5 u = 7 • Also deals with synchronization of different variables that interact – Shared data values not only need to be coherent but order of I/O devices access to those values must be protected 1 2 u :5

Memory

– Processors see different values for u after event 3 – With write back caches, depends on which cache flushes first » Processes accessing main memory may see very stale value – Unacceptable for programming, and its frequent!

11/11/09 23 11/11/09 24 This should see value Example Intuitive Memory Model written immediately

P1 P2 P • Reading an address should return the last value /*Assume initial value of A and flag is 0*/ L1 written to that address /*spin idly*/ 100:67 A = 1; while (flag == 0); – Easy in uniprocessors L2 flag = 1; print A; 100:35 – In multiprocessors, more complicated than just seeing Memory the last value written • expect memory to respect order between accesses to » How do you define write Disk 100:34 order between different different locations issued by a given process processes – to preserve orders among accesses to same location by different processes • Too vague and simplistic; 2 issues • Coherence is not enough! 1. Coherence defines values returned by a read 2. Consistency determines when a written value will be returned – pertains only to single location by a read Pn P1 • Coherence defines behavior to same location, Consistency defines behavior to other locations Conceptual Picture Mem 11/11/09 25 11/11/09 26

Defining Coherent Memory System Write Consistency

1. Preserve Program Order: A read by processor P to • For now assume location X that follows a write by P to X, with no writes of X by another processor occurring between the write and 1. A write does not complete (and allow the next the read by P, always returns the value written by P write to occur) until all processors have seen the 2. Coherent view of memory: Read by a processor to effect of that write location X that follows a write by another processor to X 2. The processor does not change the order of any returns the written value if the read and write are sufficiently separated in time (hardware recognition write with respect to any other memory access time) and no other writes to X occur between the two " if a processor writes location A followed by accesses location B, any processor that sees the new 3. Write serialization: 2 writes to same location by any 2 value of B must also see the new value of A processors are seen in the same order by all processors – If not, a processor could keep value 1 since saw as last write • These restrictions allow the processor to reorder – For example, if the values 1 and then 2 are written to a reads, but forces the processor to finish writes location, processors can never read the value of the in program order location as 2 and then later read it as 1

11/11/09 27 11/11/09 28 Outline Basic Schemes for Enforcing Coherence

• MP Motivation • Problem = Program on multiple processors will • SISD v. SIMD v. MIMD normally have copies of the same data in several caches • Centralized vs. Distributed Memory • Rather than trying to avoid sharing in SW, • Challenges to Parallel Programming SMPs use a HW protocol to maintain coherent caches • Consistency, Coherency, Write Serialization through: • Snoopy Cache – Migration - data can be moved to a local cache and used there in a transparent fashion • Directory-based protocols and examples » Reduces both latency to access shared data that is allocated remotely and bandwidth demand on the shared memory – Replication – for shared data being simultaneously read, since caches make a copy of data in local cache » Reduces both latency of access and contention for read shared data

11/11/09 29 11/11/09 30

2 Classes of Cache Coherence Protocols Snooping Cache-Coherence Protocols

1. Snooping — Every cache with a copy of data also has a copy of sharing status of block, but no centralized state State Address is kept Data • All caches are accessible via some broadcast medium (a bus or switch) • All cache controllers monitor or snoop on the medium to determine whether or not they have a copy of a block that is requested on a bus or switch access • Each processors cache controller “snoops” all transactions on • Emphasis for now with systems because they are small the shared medium (bus or switch) enough – Attractive solution with common broadcast bus 2. Directory based — Sharing status of a block of physical – Only interested in relevant transaction – take action to ensure coherence memory is kept in just one location, the directory » invalidate, update, or supply value • Old method revisited to deal with future larger systems – depends on state of the block and the protocol • Moving from bus topology to switch topology • Either get exclusive access before write via write invalidate or update all copies on write • Advantages: – Distributed model – Only a slightly more complicated state machine 11/11/09 31 11/11/09 32 – Doesn’t cost much WRT hw Architectural Building Blocks - What Example: Write-thru Invalidate do we need? • Cache block state transition diagram P1 P2 P3 u = ? – FSM specifying how state of block changes u = ? 3 » invalid, valid, dirty 7 $ $ 7 $ – Logically need FSM for each cache block, not how it is implemented but u :5 u :5 u = 7 we will envision this scenario • Broadcast Medium (e.g., bus) – Logically single set of wires connect several devices

I/O devices – Protocol: arbitration, command/addr, data 1 2 u :5 " Every device observes every transaction u = 7 • Broadcast medium enforces serialization of read or write Memory accesses " Write serialization – 1st processor to get medium invalidates others copies • Must invalidate before step 3 – Implies cannot complete write until it obtains bus • Could just broadcast new data value, all caches update to • Also need method to find up-to-date copy of cache block reflect – If write-back, copy may be in anther processors L1 cache – Write update uses more bandwidth - too much – all recent MPUs use write invalidate 11/11/09 33 11/11/09 34

How to locate up-to-date copy of data Cache Resources for WB Snooping

• Write-through: • Normal cache tags can be used for snooping – Reads always get up-to-date copy from memory • Valid bit per block makes invalidation easy – Write through simpler if enough memory BW • Reads • Write-back harder – Most recent copy can be in any cache – misses easy since rely on snooping – Lower memory bandwidth – Processors respond if they have dirty data from a read – Most multiprocessors use write-back miss • Can use same snooping mechanism • Writes – Need to know if know whether any other copies of the block 1. Snoop every address placed on the bus are cached 2. If a processor has dirty copy of requested cache » No other copies " No need to place write on bus for WB block, it provides it in response to a read request » Other copies " Need to place invalidate on bus and aborts the memory access – Complexity from retrieving cache block from a processor cache, which can take longer than retrieving it from memory 11/11/09 (which is optimized) 35 11/11/09 36 Cache Resources for WB Snooping Example Protocol - Start Simple

• Need one extra state bit to track whether a cache • Snooping coherence protocol is usually block is shared implemented by incorporating a finite-state – Write to Shared block " Need to place invalidate on controller in each node bus and mark cache block as exclusive (if an option) • Logically, think of a separate controller – No further invalidations will be sent for that block associated with each cache block – This processor called owner of cache block – That is, snooping operations or cache requests for different – Owner then changes state from shared to unshared (or blocks can proceed independently exclusive) • In implementations, a single controller allows multiple operations to distinct blocks to proceed in interleaved fashion – that is, one operation may be initiated before another is completed, even through only one cache access or one bus access is allowed at time

11/11/09 37 11/11/09 38

Write-through Invalidate Protocol Is 2-state Protocol Coherent?

PrRd/ -- • Processor only observes state of memory system by issuing • 2 states per block in each cache PrWr / BusWr memory operations – as in uniprocessor V – If processor only does ALU operations, doesn’t see see state of – Hardware state bits associated with BusWr / - memory blocks that are in the cache • Assume bus transactions and memory operations are atomic – other blocks can be seen as being in and a one-level cache invalid (not-present) state in that cache PrRd / BusRd – one bus transaction complete before next one starts • Writes invalidate all other cache I – processor waits for memory operation to complete before issuing next – with one-level cache, assume invalidations applied during bus transaction copies (write no-alloc) PrWr / BusWr • All writes go to bus + atomicity – can have multiple simultaneous readers – Writes serialized by order in which they appear on bus (bus order) of block,but write invalidates them => invalidations applied to caches in bus order State Tag Data State Tag Data • How to insert reads in this order? – Important since processors see writes through reads, so determines PrRd: Processor Read P1 Pn whether write serialization is satisfied PrWr: Processor Write – But read hits may happen independently and do not appear on bus or $ $ BusRd: Bus Read Bus enter directly in bus order BusWr: Bus Write Mem I/O devices • Let’s understand other ordering issues 11/11/09 39 11/11/09 40 Ordering Example Write Back Snoopy Protocol

• Look at invalidation protocol with a write-back cache – Snoops every address on bus – If cache has a dirty copy of requested block, provides that block in response to the read request and aborts the memory access • Each memory block is in one state: – Clean in all caches and up-to-date in memory (Shared) – OR Dirty in exactly one cache (Exclusive) – OR Not in any caches • Each cache block is in one state (track these): • Writes establish a partial ordering for the reads – Shared : block can be read • Doesn’t constrain ordering of reads, though – OR Exclusive : cache has only copy, its writeable, and dirty shared-medium (bus) will order read misses too – OR Invalid : block contains no data (in uniprocessor cache too) – any order among reads between writes is fine, • Read misses: cause all caches to snoop bus as long as in program order • Writes to clean blocks are treated as misses

11/11/09 41 11/11/09 42

Write-Back State Machine - CPU Write-Back State Machine- Bus request CPU Read hit • State machine • State machine for bus requests Write miss for CPU requests CPU Read Shared for each Shared for each Invalid for this block Invalid (read/only) cache block (read/only) cache block Place read miss on bus

CPU Write CPU Read miss Place Write CPU read miss Place read miss Miss on bus Write back block, on bus Write miss Place read miss CPU Write for this block on bus Place Write Miss on Bus Write Back Read miss Block; (abort for this block Cache Block memory access) Write Back State Exclusive Block; (abort memory access) (read/write) Exclusive CPU read hit (read/write) CPU write hit CPU Write Miss Write back cache block 11/11/09 Place write miss on bus 43 11/11/09 44 Write-back State Machine - Putting Example it all Together CPU Read hit • State machine Write miss for CPU requests for this block for each Shared CPU Read cache block and Invalid (read/only) Place read miss for bus requests for each CPU Write on bus cache block Place Write Miss on bus Write miss CPU read miss CPU Read miss for this block Write back block, Place read miss Write Back Place read miss on bus Block; (abort on bus CPU Write memory access) Place Write Miss on Bus

Cache Block Read miss Write Back • Assumes A1 and A2 map to same cache location but are not in the same memory State Exclusive for this block Block; (abort block memory access) (read/write) * Initial cache state is invalid CPU read hit CPU Write Miss * Assume write allocate CPU write hit Write back cache block 11/11/09 Place write miss on bus 45 11/11/09 46

Example Example

• Assumes A1 and A2 map to same cache location but are not in the same memory • Assumes A1 and A2 map to same cache location but are not in the same memory block block * Initial cache state is invalid * Initial cache state is invalid * Assume write allocate * Assume write allocate

11/11/09 47 11/11/09 48 Example Example

Goes to shared because it is clean

• Assumes A1 and A2 map to same cache location but are not in the same memory • Assumes A1 and A2 map to same cache location but are not in the same memory block block * Initial cache state is invalid * Initial cache state is invalid * Assume write allocate * Assume write allocate

11/11/09 49 11/11/09 50

Example Implementation Complications • Write Races - Who writes first?? – Cannot update cache until bus is obtained » Otherwise, another processor may get bus first, and then write the same cache block! – Two step process: » Arbitrate for bus » Place miss on bus and complete operation – If write miss occurs to block while waiting for bus, handle miss (invalidate may be needed) and then restart. – Split transaction bus: » Bus transaction is not atomic: can have multiple outstanding transactions for a block » Multiple misses can interleave, • Assumes A1 and A2 map to same cache location but are not in the same memory allowing two caches to grab block in the Exclusive state block » Must track and prevent multiple misses for one block * Initial cache state is invalid * Assume write allocate • Must support interventions and invalidations

11/11/09 51 11/11/09 52 Limitations in Symmetric Shared-Memory Performance of Symmetric Shared-Memory Multiprocessors and Snooping Protocols Multiprocessors • Single memory accommodate all CPUs even • Cache performance is combination of though there may be multiple memory banks 1. Uniprocessor cache miss traffic • Bus-based 2. Traffic caused by communication – must support both coherence traffic & » Results in invalidations and subsequent cache misses normal memory traffic • 4th C: coherence miss – Solution: – Joins Compulsory, Capacity, Conflict » Multiple buses or interconnection networks – How significant are coherence misses? (cross bar or small point-to-point)

11/11/09 53 11/11/09 54

Coherency Misses Example: True v. False Sharing v. Hit?

1. True sharing misses • Assume x1 and x2 in same cache block, different • Processes must share data for communication or addresses in that block. processing P1 and P2 both read x1 and x2 before. • Types: • Invalidates due to 1st write to shared block Time P1 P2 True, False, Hit? Why? • Reads by another CPU of modified block in different cache • Miss would still occur if block size were 1 word 1 Write x1 Hit, invalidate x1/x2 in P2 2. False sharing misses 2 Read x2 • When a block is invalidated because some word in the block, False miss; x1 irrelevant to P2 other than the one being read, is written into 3 Write x1 • Invalidation does not cause a new value to be Hit, invalidate x1/x2 in P2 communicated, but only causes an extra cache miss • Block is shared, but no word in block is actually shared 4 Write x2 False miss; x1 irrelevant to P2 " miss would not occur if block size were 1 word • Larger block sizes lead to more false sharing misses 5 Read x2 True miss

11/11/09 55 11/11/09 56 MP Performance 4 Processor MP Performance 2MB Cache Commercial Workload: OLTP, Decision Commercial Workload: OLTP, Decision Support (Database), Search Engine Support (Database), Search Engine

True and false sharing increase as number of True and false sharing CPUs increase. This will doesn’t change much become more as cache size increases significant in the future as we move to many more processors

11/11/09 57 11/11/09 58

Outline A Cache Coherent System Must:

• Coherence • Provide set of states, state transition diagram, and actions • Write Consistency • Manage coherence protocol • Snooping – (0) Determine when to invoke coherence protocol • Building Blocks – (a) Find info about state of block in other caches to determine action • Snooping protocols and examples » whether need to communicate with other cached copies • Coherence traffic and Performance on MP – (b) Locate the other copies – (c) Communicate with those copies (invalidate/update) • Directory-based protocols and examples • (0) is done the same way on all systems – state of the line is maintained in the cache – protocol is invoked if an “access fault” occurs on the line • Different approaches (snoopy and directory based) distinguished by (a) to (c)

11/11/09 59 11/11/09 60 Bus-based Coherence Scalable Approach: Directories

• All of (a), (b), (c) done through broadcast on bus • Every memory block has associated directory – faulting processor sends out a “search” information – others respond to the search probe and take necessary – keeps track of copies of cached blocks and their states action – on a miss, find directory entry, look it up, and communicate • Conceptually simple, but broadcast doesn’t only with the nodes that have copies if necessary » Presence bit keeps track of which processors have it. Use bit scale with p vector to save space – on bus, bus bandwidth doesn’t scale » Minimizes traffic, don’t just broadcast for each access – on scalable network, every fault leads to at least p network » Minimizes processing, not all processors have to check every transactions address – in scalable networks, communication with directory and • Scalable coherence, how do we keep track as copies is through network transactions the number of processors gets larger • Many alternatives for organizing directory – can have same cache states and state transition diagram information – different mechanisms to manage protocol - directory based

11/11/09 61 11/11/09 62

Basic Operation of Directory Directory Protocol

• Similar to Snoopy Protocol: Three states similar to snoopy – Shared: ! 1 processors have data, memory up-to-date • k processors. – Uncached (no processor has it; not valid in any cache) • With each cache-block in memory: – Exclusive: 1 processor (owner) has data; k presence-bits, 1 dirty-bit memory out-of-date • With each cache-block in cache: • In addition to cache state, must track which processors 1 valid bit, and 1 dirty (owner) bit have data when in the shared state (usually bit vector, 1 if processor has copy) - presence vector

• Example: • Keep it simple(r): – Writes to non-exclusive data – Read from main memory by processor i: => write miss » If dirty-bit OFF then { read from main memory; turn p[i] ON; } – Processor blocks until access completes » if dirty-bit ON then { recall line from dirty proc; update memory; – Assume messages received and acted upon in order sent (not turn dirty-bit OFF; turn p[i] ON; supply recalled data to i} realistic but we will assume) – Write to main memory by processor i: » If dirty-bit OFF then {send invalidations to all caches that have the block; turn dirty-bit ON; turn p[i] ON; ... } 11/11/09 63 11/11/09 64 State Transition Diagram for One Cache CPU -Cache State Machine CPU Read hit Block in Directory Based System • State machine for CPU requests for each Invalidate memory block Shared • States identical to snoopy case; Invalid (read/only) • Invalid state CPU Read transactions very similar. if in memory Send Read Miss • Transitions caused by read misses, write message CPU read miss: misses, invalidates, data fetch requests CPU Write: Send Read Miss Send Write Miss CPU Write: Send msg to h.d. Write Miss message Invalidate to home directory send Data Write Back message to home directory Fetch: send Data Write Back message to home directory CPU read miss: send Data Exclusive Write Back message and read miss to home directory (read/write) CPU read hit CPU write miss: CPU write hit send Data Write Back message 11/11/09 65 11/11/09 and Write Miss to home directory66

Directory State Machine Read miss: State Transition Diagram for Directory Sharers += {P}; send Data Value Reply • State machine Read miss: for Directory requests for each Sharers = {P} • Same states & structure as the transition memory block send Data Value Reply Shared diagram for an individual cache • Uncached state Uncached (read only) • 2 actions: update of directory state & if in memory send messages to satisfy requests Write Miss: Write Miss: Sharers = {P}; • Tracks all copies of memory block send Invalidate Data Write Back: send Data to Sharers; • Also indicates an action that updates the Sharers = {} Value Reply then Sharers = {P}; (Write back block) msg sharing set, Sharers, as well as sending send Data Value a message Reply msg Write Miss: Read miss: send Invalidate; send Fetch; Sharers = {P}; Exclusive Sharers += {P}; send Data Value Reply (read/write) send Data Value Reply msg to cache msg to cache 11/11/09 67 11/11/09 (Write back block) 68 Example Example

Processor 1 Processor 2 Interconnect Directory Memory Processor 1 Processor 2 Interconnect Directory Memory

P2: Write 20 to A1 P2: Write 20 to A1

• Assumes A1 and A2 map to same cache location but are not in the same memory • Assumes A1 and A2 map to same cache location but are not in the same memory block block * Initial cache state is invalid * Initial cache state is invalid * Assume write allocate * Assume write allocate

11/11/09 69 11/11/09 70

Example Example

Processor 1 Processor 2 Interconnect Directory Memory Processor 1 Processor 2 Interconnect Directory Memory

A1 {P1}A1

P2: Write 20 to A1 P2: Write 20 to A1

Write Back • Assumes A1 and A2 map to same cache location but are not in the same memory • Assumes A1 and A2 map to same cache location but are not in the same memory block block * Initial cache state is invalid * Initial cache state is invalid * Assume write allocate * Assume write allocate

11/11/09 71 11/11/09 72 Example Example

Processor 1 Processor 2 Interconnect Directory Memory Processor 1 Processor 2 Interconnect Directory Memory

A1 {P1}A1 A1 {P1}A1

P2: Write 20 to A1 P2: Write 20 to A1

• Assumes A1 and A2 map to same cache location but are not in the same memory • Assumes A1 and A2 map to same cache location but are not in the same memory block block * Initial cache state is invalid * Initial cache state is invalid * Assume write allocate * Assume write allocate

11/11/09 73 11/11/09 74

Implementing a Directory Example Directory Protocol (1st Read)

E • We assume operations atomic, but they are not; Read pA reality is much harder; must avoid S when run out of bufffers in network (see P1: pA Dir M Appendix E) R/reply ctrl U • Optimizations: – read miss or write miss in Exclusive: send data directly to requestor from owner vs. 1st to memory and then from memory to requestor

E E

S S $ P1 $ P2 R/req I ld vA -> rd pA I 11/11/09 75 11/11/09 76 Example Directory Protocol (Read Share) Example Directory Protocol (Wr to shared)

E E

RX/invalidate&reply S S P1: pA R/_ Dir M P1: pA EX R/_ Dir M P2: pA R/reply ctrl P2: pA R/reply ctrl U U Inv ACK reply xD(pA) Invalidate pA Req_to_update pA

E E E W/req E E W/_ W/req E S S S S R/_ $ P1 R/_ $ P2 R/_ $ P1 R/_ $ P2 R/req R/req R/req Inv/_ R/req I ld vA -> rd pA I I st vA -> wr pA II ld vA -> rd pA 11/11/09 77 11/11/09 78

Example Directory Protocol (Wr to Ex)

DE RU/_ RX/invalidate&reply S P1: pA R/_ Dir M R/reply ctrl U Read_toUpdate pA Inv pA Reply xD(pA) Write_back pA

E W/req E E W/req E W/_ W/_ W/req E W/req E S S R/_ $ P1 R/_ $ P2 Inv/_ R/req Inv/_ R/req II I st vA -> wr pA 11/11/09 79