CPE 631 Lecture 19 Multiprocessors Aleksandar Milenkovi milenkaece

  • Slides: 45
Download presentation
CPE 631 Lecture 19: Multiprocessors Aleksandar Milenković, milenka@ece. uah. edu Electrical and Computer Engineering

CPE 631 Lecture 19: Multiprocessors Aleksandar Milenković, milenka@ece. uah. edu Electrical and Computer Engineering University of Alabama in Huntsville

CPE 631 AM Review: Small-Scale—Shared Memory n Caches serve to: – Increase bandwidth versus

CPE 631 AM Review: Small-Scale—Shared Memory n Caches serve to: – Increase bandwidth versus bus/memory – Reduce latency of access – Valuable for both private data and shared data n What about cache consistency? Time Event $A $B X (memory) 0 1 1 CPU A: R x 1 2 CPU B: R x 1 1 1 3 CPU A: W x, 0 0 11/22/2020 1 UAH-CPE 631 2

CPE 631 AM What Does Coherency Mean? n Informally: – “Any read of a

CPE 631 AM What Does Coherency Mean? n Informally: – “Any read of a data item must return the most recently written value” – this definition includes both coherence and consistency • coherence: what values can be returned by a read • consistency: when a written value will be returned by a read n Memory system is coherent if – a read(X) by P 1 that follows a write(X) by P 1, with no writes of X by another processor occurring between these two events, always returns the value written by P 1 – a read(X) by P 1 that follows a write(X) by another processor, returns the written value if the read and write are sufficiently separated and no other writes occur between – writes to the same location are serialized: two writes to the same location by any two CPUs are seen in the same order by all CPUs 11/22/2020 UAH-CPE 631 3

CPE 631 AM Potential HW Coherence Solutions n Snooping Solution (Snoopy Bus): – every

CPE 631 AM Potential HW Coherence Solutions n Snooping Solution (Snoopy Bus): – every cache that has a copy of the data also has a copy of the sharing status of the block – Processors snoop to see if they have a copy and respond accordingly – Requires broadcast, since caching information is at processors – Works well with bus (natural broadcast medium) – Dominates for small scale machines (most of the market) n Directory-Based Schemes (discuss later) – Keep track of what is being shared in 1 centralized place (logically) – Distributed memory => distributed directory for scalability (avoids bottlenecks) – Send point-to-point requests to processors via network – Scales better than Snooping – Actually existed BEFORE Snooping-based schemes UAH-CPE 631 11/22/2020 4

CPE 631 AM Basic Snoopy Protocols n Write Invalidate Protocol – A CPU has

CPE 631 AM Basic Snoopy Protocols n Write Invalidate Protocol – A CPU has exclusive access to a data item before it writes that item – Write to shared data: an invalidate is sent to all caches which snoop and invalidate any copies – Read Miss: • Write-through: memory is always up-to-date • Write-back: snoop in caches to find most recent copy n Write Update Protocol (typically write through): – Write to shared data: broadcast on bus, processors snoop, and update any copies – Read miss: memory is always up-to-date n Write serialization: bus serializes requests! – Bus is single point of arbitration 11/22/2020 UAH-CPE 631 5

CPE 631 AM Write Invalidate versus Update n Multiple writes to the same word

CPE 631 AM Write Invalidate versus Update n Multiple writes to the same word with no intervening reads – Update: multiple broadcasts n For multiword cache blocks – Update: each word written in a cache block requires a write broadcast – Invalidate: only the first write to any word in the block requires an invalidation n Update has lower latency between write and read 11/22/2020 UAH-CPE 631 6

CPE 631 AM Snooping Cache Variations Basic Protocol Exclusive Shared Invalid Berkeley Protocol Illinois

CPE 631 AM Snooping Cache Variations Basic Protocol Exclusive Shared Invalid Berkeley Protocol Illinois Protocol Owned Exclusive Private Dirty Private Clean Owned Shared Invalid MESI Protocol Modfied (private, !=Memory) e. Xclusive (private, =Memory) Shared (shared, =Memory) Invalid Owner can update via bus invalidate operation Owner must write back when replaced in cache If read sourced from memory, then Private Clean if read sourced from other cache, then Shared Can write in cache if held private clean or dirty 11/22/2020 UAH-CPE 631 7

CPE 631 AM An Example Snoopy Protocol Invalidation protocol, write-back cache n Each block

CPE 631 AM An Example Snoopy Protocol Invalidation protocol, write-back cache n Each block of memory is in one state: n – Clean in all caches and up-to-date in memory (Shared) – OR Dirty in exactly one cache (Exclusive) – OR Not in any caches n Each cache block is in one state (track these): – Shared : block can be read – OR Exclusive : cache has only copy, its writeable, and dirty – OR Invalid : block contains no data Read misses: cause all caches to snoop bus n Writes to clean line are treated as misses n 11/22/2020 UAH-CPE 631 8

CPE 631 AM Snoopy-Cache State Machine-I State machine for CPU requests for each cache

CPE 631 AM Snoopy-Cache State Machine-I State machine for CPU requests for each cache block CPU Read hit CPU Read Invalid Place read miss on bus Shared (read/only) CPU Write Place Write Miss on bus CPU read miss CPU Read miss Write back block, Place read miss on bus CPU Write Place Write Miss on Bus Exclusive (read/write) CPU read hit CPU write hit 11/22/2020 CPU Write Miss Write back cache block Place write miss on bus UAH-CPE 631 9

CPE 631 AM Snoopy-Cache State Machine-II State machine for bus requests for each cache

CPE 631 AM Snoopy-Cache State Machine-II State machine for bus requests for each cache block Invalid Write miss for this block Write Back Block; (abort memory access) Exclusive (read/write) 11/22/2020 UAH-CPE 631 Write miss for this block Shared (read/only) Read miss for this block Write Back Block; (abort memory access) 10

CPE 631 AM Snoopy-Cache State Machine-III CPU Read hit State machine for CPU requests

CPE 631 AM Snoopy-Cache State Machine-III CPU Read hit State machine for CPU requests for each cache block and for bus requests for each cache block Cache State Write miss for this block Shared CPU Read Invalid (read/only) Place read miss on bus CPU Write Place Write Miss on bus Write miss CPU read miss CPU Read miss for this block Write back block, Place read miss on bus Write Back CPU Write on bus Block; (abort Place Write Miss on Bus memory access) Block Read miss Write Back for this block Block; (abort Exclusive memory access) (read/write) CPU Write Miss CPU read hit Write back cache block CPU write hit Place write miss on bus 11/22/2020 UAH-CPE 631 11

CPE 631 AM Example Processor 1 Assumes initial cache state is invalid and A

CPE 631 AM Example Processor 1 Assumes initial cache state is invalid and A 1 and A 2 map to same cache block, but A 1 != A 2 Processor 2 Bus CPU Read hit Remote Write Invalid Remote Write Back Read miss on bus Write miss on bus Remote Read Write Back Memory Shared CPU Read Miss CPU Write Place Write Miss on Bus Exclusive 11/22/2020 CPU Write Miss CPU read hit Write Back CPU write hit UAH-CPE 631 12

CPE 631 AM Example: Step 1 Assumes initial cache state is invalid and A

CPE 631 AM Example: Step 1 Assumes initial cache state is invalid and A 1 and A 2 map to same cache block, but A 1 != A 2. Active arrow = CPU Read hit Remote Write Invalid Remote Write Back Read miss on bus Write miss on bus Remote Read Write Back Shared CPU Read Miss CPU Write Place Write Miss on Bus Exclusive 11/22/2020 CPU Write Miss CPU read hit Write Back CPU write hit UAH-CPE 631 13

CPE 631 AM Example: Step 2 Assumes initial cache state is invalid and A

CPE 631 AM Example: Step 2 Assumes initial cache state is invalid and A 1 and A 2 map to same cache block, but A 1 != A 2 CPU Read hit Remote Write Invalid Remote Write Back Read miss on bus Write miss on bus Remote Read Write Back Shared CPU Read Miss CPU Write Place Write Miss on Bus Exclusive 11/22/2020 CPU Write Miss CPU read hit Write Back CPU write hit UAH-CPE 631 14

CPE 631 AM Example: Step 3 A 1 Assumes initial cache state is invalid

CPE 631 AM Example: Step 3 A 1 Assumes initial cache state is invalid and A 1 and A 2 map to same cache block, but A 1 != A 2. CPU Read hit Remote Write Invalid Remote Write Back Read miss on bus Write miss on bus Remote Read Write Back Shared CPU Read Miss CPU Write Place Write Miss on Bus Exclusive 11/22/2020 CPU Write Miss CPU read hit Write Back CPU write hit UAH-CPE 631 15

CPE 631 AM Example: Step 4 A 1 A 1 Assumes initial cache state

CPE 631 AM Example: Step 4 A 1 A 1 Assumes initial cache state is invalid and A 1 and A 2 map to same cache block, but A 1 != A 2 CPU Read hit Remote Write Invalid Remote Write Back Read miss on bus Write miss on bus Remote Read Write Back Shared CPU Read Miss CPU Write Place Write Miss on Bus Exclusive 11/22/2020 CPU Write Miss CPU read hit Write Back CPU write hit UAH-CPE 631 16

CPE 631 AM Example: Step 5 A 1 A 1 A 1 Assumes initial

CPE 631 AM Example: Step 5 A 1 A 1 A 1 Assumes initial cache state is invalid and A 1 and A 2 map to same cache block, but A 1 != A 2 CPU Read hit Remote Write Invalid Remote Write Back Read miss on bus Write miss on bus Remote Read Write Back Shared CPU Read Miss CPU Write Place Write Miss on Bus Exclusive 11/22/2020 CPU Write Miss CPU read hit Write Back CPU write hit UAH-CPE 631 17

CPE 631 AM Implementation Complications n Write Races: – Cannot update cache until bus

CPE 631 AM Implementation Complications n Write Races: – 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 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, allowing two caches to grab block in the Exclusive state • Must track and prevent multiple misses for one block n Must support interventions and invalidations 11/22/2020 UAH-CPE 631 18

CPE 631 AM Implementing Snooping Caches Multiple processors must be on bus, access to

CPE 631 AM Implementing Snooping Caches Multiple processors must be on bus, access to both addresses and data n Add a few new commands to perform coherency, in addition to read and write n Processors continuously snoop on address bus n – If address matches tag, either invalidate or update n Since every bus transaction checks cache tags, could interfere with CPU just to check: – solution 1: duplicate set of tags for L 1 caches just to allow checks in parallel with CPU – solution 2: L 2 cache already duplicate, provided L 2 obeys inclusion with L 1 cache • block size, associativity of L 2 affects L 1 11/22/2020 UAH-CPE 631 19

CPE 631 AM Implementing Snooping Caches Bus serializes writes, getting bus ensures no one

CPE 631 AM Implementing Snooping Caches Bus serializes writes, getting bus ensures no one else can perform memory operation n On a miss in a write back cache, may have the desired copy and its dirty, so must reply n Add extra state bit to cache to determine shared or not n Add 4 th state (MESI) n 11/22/2020 UAH-CPE 631 20

CPE 631 AM MESI: CPU Requests CPU Read hit CPU Read Bus. Rd /

CPE 631 AM MESI: CPU Requests CPU Read hit CPU Read Bus. Rd / No. Sh Invalid CPU Write /Bus. Rd. Ex CPU Read miss Bus. Rd / No. Sh Exclusive CPU read miss Bus. WB, Bus. Rd / No. Sh CPU write hit /CPU read miss Bus. WB, Bus. Rd / Sh CPU read hit CPU write hit Modified (read/write) 11/22/2020 CPU read miss Bus. WB, Bus. Rd / Sh CPU Write Miss Bus. Rd. Ex CPU Write Hit Bus. Inv UAH-CPE 631 Shared CPU Read hit 21

CPE 631 AM MESI: Bus Requests Invalid Bus. Rd. Ex Exclusive Bus. Rd /

CPE 631 AM MESI: Bus Requests Invalid Bus. Rd. Ex Exclusive Bus. Rd / => Sh Bus. Rd. Ex / =>Bus. WB Modified (read/write) 11/22/2020 Bus. Rd / =>Bus. WB UAH-CPE 631 Shared 22

CPE 631 AM Fundamental Issues n 3 Issues to characterize parallel machines – 1)

CPE 631 AM Fundamental Issues n 3 Issues to characterize parallel machines – 1) Naming – 2) Synchronization – 3) Performance: Latency and Bandwidth (covered earlier) 11/22/2020 UAH-CPE 631 23

CPE 631 AM Fundamental Issue #1: Naming n Naming: how to solve large problem

CPE 631 AM Fundamental Issue #1: Naming n Naming: how to solve large problem fast – – what data is shared how it is addressed what operations can access data how processes refer to each other Choice of naming affects code produced by a compiler; via load where just remember address or keep track of processor number and local virtual address for msg. passing n Choice of naming affects replication of data; via load in cache memory hierarchy or via SW replication and consistency n 11/22/2020 UAH-CPE 631 24

CPE 631 AM Fundamental Issue #1: Naming n Global physical address space: any processor

CPE 631 AM Fundamental Issue #1: Naming n Global physical address space: any processor can generate, address and access it in a single operation – memory can be anywhere: virtual addr. translation handles it Global virtual address space: if the address space of each process can be configured to contain all shared data of the parallel program n Segmented shared address space: locations are named <process number, address> uniformly for all processes of the parallel program n 11/22/2020 UAH-CPE 631 25

CPE 631 AM Fundamental Issue #2: Synchronization To cooperate, processes must coordinate n Message

CPE 631 AM Fundamental Issue #2: Synchronization To cooperate, processes must coordinate n Message passing is implicit coordination with transmission or arrival of data n Shared address => additional operations to explicitly coordinate: e. g. , write a flag, awaken a thread, interrupt a processor n 11/22/2020 UAH-CPE 631 26

CPE 631 AM Summary: Parallel Framework n Layers: – Programming Model: Programming Model Communication

CPE 631 AM Summary: Parallel Framework n Layers: – Programming Model: Programming Model Communication Abstraction Interconnection SW/OS Interconnection HW • Multiprogramming : lots of jobs, no communication • Shared address space: communicate via memory • Message passing: send and receive messages • Data Parallel: several agents operate on several data sets simultaneously and then exchange information globally and simultaneously (shared or message passing) – Communication Abstraction: • Shared address space: e. g. , load, store, atomic swap • Message passing: e. g. , send, receive library calls • Debate over this topic (ease of programming, scaling) => many hardware designs 1: 1 programming model 11/22/2020 UAH-CPE 631 27

CPE 631 AM Larger MPs Separate Memory per Processor n Local or Remote access

CPE 631 AM Larger MPs Separate Memory per Processor n Local or Remote access via memory controller n One Cache Coherency solution: non-cached pages n Alternative: directory per cache that tracks state of every block in every cache n – Which caches have a copies of block, dirty vs. clean, . . . n Info per memory block vs. per cache block? – PLUS: In memory => simpler protocol (centralized/one location) – MINUS: In memory => directory is ƒ(memory size) vs. ƒ(cache size) n Prevent directory as bottleneck? distribute directory entries with memory, each keeping track of which Procs have copies of their blocks 11/22/2020 UAH-CPE 631 28

CPE 631 AM Distributed Directory MPs M P 0 P 1 Pn C C

CPE 631 AM Distributed Directory MPs M P 0 P 1 Pn C C C IO M IO . . . M IO Interconnection Network C - Cache M - Memory IO - Input/Output 11/22/2020 UAH-CPE 631 29

CPE 631 AM Directory Protocol n Similar to Snoopy Protocol: Three states – Shared:

CPE 631 AM Directory Protocol n Similar to Snoopy Protocol: Three states – Shared: ≥ 1 processors have data, memory up-to-date – Uncached (no processor has it; not valid in any cache) – Exclusive: 1 processor (owner) has data; memory out-of-date In addition to cache state, must track which processors have data when in the shared state (usually bit vector, 1 if processor has copy) n Keep it simple(r): n – Writes to non-exclusive data => write miss – Processor blocks until access completes – Assume messages received and acted upon in order sent 11/22/2020 UAH-CPE 631 30

CPE 631 AM Directory Protocol n No bus and don’t want to broadcast: –

CPE 631 AM Directory Protocol n No bus and don’t want to broadcast: – interconnect no longer single arbitration point – all messages have explicit responses n Terms: typically 3 processors involved – Local node where a request originates – Home node where the memory location of an address resides – Remote node has a copy of a cache block, whether exclusive or shared n Example messages on next slide: P = processor number, A = address 11/22/2020 UAH-CPE 631 31

CPE 631 AM Directory Protocol Messages Message type Content Read miss Source Destination Msg

CPE 631 AM Directory Protocol Messages Message type Content Read miss Source Destination Msg Local cache Home directory P, A Processor P reads data at address A; make P a read sharer and arrange to send data back Write miss Local cache Home directory P, A Processor P writes data at address A; make P the exclusive owner and arrange to send data back Invalidate Home directory Remote caches A Invalidate a shared copy at address A. Fetch Home directory Remote cache A Fetch the block at address A and send it to its home directory Fetch/Invalidate Home directory Remote cache A Fetch the block at address A and send it to its home directory; invalidate the block in the cache Data value reply Home directory Local cache Data Return a data value from the home memory (read miss response) Data write-back Remote cache Home directory A, Data Write-back a data value for address A (invalidate response) 11/22/2020 UAH-CPE 631 32

CPE 631 AM State Transition Diagram for an Individual Cache Block in a Directory

CPE 631 AM State Transition Diagram for an Individual Cache Block in a Directory Based System n n n States identical to snoopy case; transactions very similar Transitions caused by read misses, write misses, invalidates, data fetch requests Generates read miss & write miss msg to home directory Write misses that were broadcast on the bus for snooping => explicit invalidate & data fetch requests Note: on a write, a cache block is bigger, so need to read the full cache block 11/22/2020 UAH-CPE 631 33

CPE 631 AM CPU -Cache State Machine CPU Read hit State machine Invalidate for

CPE 631 AM CPU -Cache State Machine CPU Read hit State machine Invalidate for CPU Shared Invalid requests (read/only) CPU Read for each Send Read Miss memory block message CPU read miss: n Invalid state Send Read Miss CPU Write: Send Write Miss if in Write Miss message msg to h. d. memory Fetch/Invalidate to home directory n send Data Write Back message to home directory Exclusive (read/writ) CPU read hit CPU write hit 11/22/2020 Fetch: send Data Write Back message to home directory CPU read miss: send Data Write Back message and read miss to home directory CPU write miss: send Data Write Back message and Write Miss to home UAH-CPE 631 directory 34

CPE 631 AM State Transition Diagram for the Directory Same states & structure as

CPE 631 AM State Transition Diagram for the Directory Same states & structure as the transition diagram for an individual cache n 2 actions: update of directory state & send msgs to statisfy requests n Tracks all copies of memory block. n Also indicates an action that updates the sharing set, Sharers, as well as sending a message. n 11/22/2020 UAH-CPE 631 35

CPE 631 AM Directory State Machine State machine Read miss: Sharers = {P} for

CPE 631 AM Directory State Machine State machine Read miss: Sharers = {P} for Directory send Data Value requests for each Uncached Reply memory block n Uncached state Write Miss: if in memory n Data Write Back: Sharers = {} (Write back block) Write Miss: Sharers = {P}; send Fetch/Invalidate; send Data Value Reply msg to remote cache 11/22/2020 Sharers = {P}; send Data Value Reply msg Read miss: Sharers += {P}; send Data Value Reply Shared (read only) Write Miss: send Invalidate to Sharers; then Sharers = {P}; send Data Value Reply msg Read miss: Sharers += {P}; Exclusive send Fetch; (read/writ) send Data Value Reply msg to remote cache (Write back block) UAH-CPE 631 36

CPE 631 AM Example Directory Protocol n Message sent to directory causes two actions:

CPE 631 AM Example Directory Protocol n Message sent to directory causes two actions: – Update the directory – More messages to satisfy request n Block is in Uncached state: the copy in memory is the current value; only possible requests for that block are: – Read miss: requesting processor sent data from memory &requestor made only sharing node; state of block made Shared. – Write miss: requesting processor is sent the value & becomes the Sharing node. The block is made Exclusive to indicate that the only valid copy is cached. Sharers indicates the identity of the owner. n Block is Shared => the memory value is up-to-date: – Read miss: requesting processor is sent back the data from memory & requesting processor is added to the sharing set. – Write miss: requesting processor is sent the value. All processors in the set Sharers are sent invalidate messages, & Sharers is set to identity of requesting processor. The state of the block is made Exclusive. 11/22/2020 UAH-CPE 631 37

CPE 631 AM Example Directory Protocol n Block is Exclusive: current value of the

CPE 631 AM Example Directory Protocol n Block is Exclusive: current value of the block is held in the cache of the processor identified by the set Sharers (the owner) => three possible directory requests: – Read miss: owner processor sent data fetch message, causing state of block in owner’s cache to transition to Shared and causes owner to send data to directory, where it is written to memory & sent back to requesting processor. Identity of requesting processor is added to set Sharers, which still contains the identity of the processor that was the owner (since it still has a readable copy). State is shared. – Data write-back: owner processor is replacing the block and hence must write it back, making memory copy up-to-date (the home directory essentially becomes the owner), the block is now Uncached, and the Sharer set is empty. – Write miss: block has a new owner. A message is sent to old owner causing the cache to send the value of the block to the directory from which it is sent to the requesting processor, which becomes the new owner. Sharers is set to identity of new owner, and state of block is made Exclusive. 11/22/2020 UAH-CPE 631 38

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory P 2: Write

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory P 2: Write 20 to A 1 and A 2 map to the same cache block 11/22/2020 UAH-CPE 631 39

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory P 2: Write

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory P 2: Write 20 to A 1 and A 2 map to the same cache block 11/22/2020 UAH-CPE 631 40

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory P 2: Write

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory P 2: Write 20 to A 1 and A 2 map to the same cache block 11/22/2020 UAH-CPE 631 41

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory A 1 P

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory A 1 P 2: Write 20 to A 1 Write Back A 1 and A 2 map to the same cache block 11/22/2020 UAH-CPE 631 42

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory A 1 P

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory A 1 P 2: Write 20 to A 1 and A 2 map to the same cache block 11/22/2020 UAH-CPE 631 43

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory A 1 P

CPE 631 AM Example Processor 1 Processor 2 Interconnect Directory Memory A 1 P 2: Write 20 to A 1 and A 2 map to the same cache block 11/22/2020 UAH-CPE 631 44

CPE 631 AM Implementing a Directory We assume operations atomic, but they are not;

CPE 631 AM Implementing a Directory We assume operations atomic, but they are not; reality is much harder; must avoid deadlock when run out of buffers in network (see Appendix I) – The devil is in the details n Optimizations: n – read miss or write miss in Exclusive: send data directly to requestor from owner vs. 1 st to memory and then from memory to requestor 11/22/2020 UAH-CPE 631 45