Global and high-contention operations: Barriers, reductions, and highly-contended locks Katie Coons April 6, 2006.

Slides:



Advertisements
Similar presentations
1 Lecture 20: Synchronization & Consistency Topics: synchronization, consistency models (Sections )
Advertisements

1 Synchronization A parallel computer is a collection of processing elements that cooperate and communicate to solve large problems fast. Types of Synchronization.
Synchronization without Contention
The University of Adelaide, School of Computer Science
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Multiprocessors—Synchronization. Synchronization Why Synchronize? Need to know when it is safe for different processes to use shared data Issues for Synchronization:
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Synchronization without Contention John M. Mellor-Crummey and Michael L. Scott+ ECE 259 / CPS 221 Advanced Computer Architecture II Presenter : Tae Jun.
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
Synchron. CSE 471 Aut 011 Some Recent Medium-scale NUMA Multiprocessors (research machines) DASH (Stanford) multiprocessor. –“Cluster” = 4 processors on.
The Performance of Spin Lock Alternatives for Shared-Memory Microprocessors Thomas E. Anderson Presented by David Woodard.
1 Lecture 21: Synchronization Topics: lock implementations (Sections )
Synchronization Todd C. Mowry CS 740 November 1, 2000 Topics Locks Barriers Hardware primitives.
CS252/Patterson Lec /28/01 CS 213 Lecture 10: Multiprocessor 3: Directory Organization.
1 Lecture 20: Protocols and Synchronization Topics: distributed shared-memory multiprocessors, synchronization (Sections )
Synchronization (Barriers) Parallel Processing (CS453)
The Performance of Spin Lock Alternatives for Shared-Memory Multiprocessors THOMAS E. ANDERSON Presented by Daesung Park.
Fundamentals of Parallel Computer Architecture - Chapter 91 Chapter 9 Hardware Support for Synchronization Yan Solihin Copyright.
Caltech CS184 Spring DeHon 1 CS184b: Computer Architecture (Abstractions and Optimizations) Day 12: May 3, 2003 Shared Memory.
Jeremy Denham April 7,  Motivation  Background / Previous work  Experimentation  Results  Questions.
Cache Coherence Protocols 1 Cache Coherence Protocols in Shared Memory Multiprocessors Mehmet Şenvar.
CALTECH cs184c Spring DeHon CS184c: Computer Architecture [Parallel and Multithreaded] Day 10: May 8, 2001 Synchronization.
Caltech CS184 Spring DeHon 1 CS184b: Computer Architecture (Abstractions and Optimizations) Day 22: May 20, 2005 Synchronization.
1 Lecture 19: Scalable Protocols & Synch Topics: coherence protocols for distributed shared-memory multiprocessors and synchronization (Sections )
1 Global and high-contention operations: Barriers, reductions, and highly- contended locks Katie Coons April 6, 2006.
1 Synchronization “A parallel computer is a collection of processing elements that cooperate and communicate to solve large problems fast.” Types of Synchronization.
Synchronization Todd C. Mowry CS 740 November 24, 1998 Topics Locks Barriers.
Multiprocessors – Locks
Outline Introduction Centralized shared-memory architectures (Sec. 5.2) Distributed shared-memory and directory-based coherence (Sec. 5.4) Synchronization:
Background on the need for Synchronization
Lecture 21 Synchronization
Synchronization Feb 2017 Topics Locks Barriers
Prof John D. Kubiatowicz
Lecture 19: Coherence and Synchronization
Lecture 5: Synchronization
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Lecture 18: Coherence and Synchronization
Reactive Synchronization Algorithms for Multiprocessors
Multiprocessor Cache Coherency
The University of Adelaide, School of Computer Science
CMSC 611: Advanced Computer Architecture
Example Cache Coherence Problem
The University of Adelaide, School of Computer Science
CS510 Concurrent Systems Jonathan Walpole.
Cache Coherence Protocols 15th April, 2006
Designing Parallel Algorithms (Synchronization)
Lecture 5: Snooping Protocol Design Issues
Shared Memory Systems Miodrag Bolic.
Lecture 21: Synchronization and Consistency
Lecture: Coherence and Synchronization
CS 213 Lecture 11: Multiprocessor 3: Directory Organization
Hardware-Software Trade-offs in Synchronization and Data Layout
Lecture 25: Multiprocessors
CS533 Concepts of Operating Systems
Lecture 4: Synchronization
CS510 Concurrent Systems Jonathan Walpole.
The University of Adelaide, School of Computer Science
Lecture 17 Multiprocessors and Thread-Level Parallelism
Lecture 24: Multiprocessors
Lecture: Coherence, Synchronization
Lecture: Coherence Topics: wrap-up of snooping-based coherence,
Lecture 17 Multiprocessors and Thread-Level Parallelism
Lecture 21: Synchronization & Consistency
Lecture: Coherence and Synchronization
Lecture 19: Coherence and Synchronization
Lecture 18: Coherence and Synchronization
The University of Adelaide, School of Computer Science
Lecture 10: Directory-Based Examples II
Lecture 17 Multiprocessors and Thread-Level Parallelism
Presentation transcript:

Global and high-contention operations: Barriers, reductions, and highly-contended locks Katie Coons April 6, 2006

Synchronization Operations Locks Point-to-point event synchronization Barriers Global event notification Dynamic work distribution

Locks - Desirable Characteristics and Potential Tradeoffs Low latency to acquire lock High bandwidth Minimal traffic at all stages Low storage cost Fairness - FIFO lock granting Perform well with distributed memory

Test&set Lock Acquire method: test&set returns 0, sets to 1 Waiting algorithm: spin on test&set until it returns 0 Release algorithm: set to 0

Disadvantages Excessive traffic Unfair Separate primitives needed for different operations Exponential backoff only helps somewhat

Test-and-test&set Spin waiting protocol Spins on the read only Generates less bus traffic, but still O(p2) Failed attempts generate invalidations

Contended test&set spin locks P1 holds the lock, P2 and P3 spin on the same variable P1 releases the lock, P2 and P3 read miss

Contended test&set spin locks P2 and P3 try to reread lock - lock is temporarily unlocked P2 and P3 attempt to test&set the lock to gain exclusive access

Contended test&set spin locks Causes additional invalidations and cache interference Return to a), but now P2 has the lock

Load-linked, Store-conditional LL - Loads variable to register SC - Writes register to memory only if no intervening writes to that location occurred Together, they implement an atomic r-m-w Goals: Test with reads only No invalidations on failure Single primitive for variety of r-m-w operations

LL, SC Lock Implementation lock: ll r1, location ; read the value bnz r1, lock ; loop if not free sc location, #1 ; try to store beqz lockit ; start over if ; unsuccessful unlock: st location, #0 ; release the lock lock: ll r1, location ; read the value bnz r1, lock ; loop if not free sc location, #1 ; try to store beqz lockit ; start over if ; unsuccessful unlock: st location, #0 ; release the lock SC fails if 1) Detects another write before bus request or 2) Loses bus arbitration

Load-linked, Store-conditional Advantages No bus traffic while spinning Generates no invalidations on store failure Primitive for various operations (test&set, fetch&op, compare&swap) Improved traffic for lock acquisition - O(p) Not scalable - when lock is released the processors spinning on the load-locked operations will miss on the location and rush to the bus with read transactions. O(p) is better than test-and-test&set case, which is O(p^2) for traffic.

Load-linked, Store-conditional Disadvantages Heavy traffic when lock is released. Invalidates caches for all waiting processors O(p) traffic per lock acquisition (could do better) Not fair Traffic is better, but not at a minimum.

Contended Locks Problem: Release all waiting processors, but only one will get the lock! Solution: Notify only one processor

Ticket Lock Two counters: next-ticket and now-serving Algorithm Acquire method: atomic fetch&increment on next-ticket provides unique my-ticket Waiting algorithm: check now-serving until it equals my-ticket Release method: increment now-serving

Ticket Lock Advantages: Drawbacks: Decreased traffic on lock release Constant, small storage Fair Low latency with cacheable fetch&increment Drawbacks: Traffic still not O(1) on release Improved traffic: Only one read attempt upon release of the lock. Not significantly different from LL-SC, but you save the one invalidation and a set of read misses when one processor succeeds in its SC. Storage: Only need to save now_serving and ticket_number Fair: FIFO order by fetch&increment operation (primary difference between this and simple LL-SC) Invalidations and read misses of now-serving on release Read traffic problem on release: All processes waiting on same now-serving Proposed solution - backoff proportional to difference between ticket-number and now-serving.

Array-Based Lock Acquire method: atomic fetch&increment provides unique location (address) Waiting algorithm: check location for ready, if not ready, check until a read miss occurs Release method: write to the next location in the array Release causes the next waiting processor to have a read miss

Array-Based Lock Advantages: Disadvantages: Only one invalidate on a release Fair Similar uncontended latency No backoff needed Disadvantages: O(p) rather than O(1) space Complications with distributed memory Space is usually not a big problem since p is usually small.

Synchronization with Distributed Memory Interconnect not centralized Disjoint processors coordinate in parallel Complicates synchronization primitives Physically distributed memory Synchronization variable allocation important Varies with cache implementation If the cache caches nonlocal shared data, it’s not as important.

Synchronization with Distributed Memory Memory bandwidth Limits scalability Hot spot references are most severe cause Memory latency Limits performance Requires good cache and memory locality

Array-Based Locks and Distributed Memory Problems O(p) storage Impossible to always spin on local memory Spinning on remote locations undesirable Increases traffic Increases contention

Software Queuing Lock Goals: Distributed linked list of waiters Reduce space requirements Always spin on locally allocated variables Distributed linked list of waiters Each node points to following node Tail pointer to last waiter

Software Queuing Lock

Software Queuing Lock Atomic changes to tail pointer Atomic fetch&store Returns current value of 1st operand Sets it to second operand Returns only on success Determines FIFO ordering for acquisition

Software Queuing Lock Atomic check for last processor Atomic compare&swap Compares first two operands If equal, set first to third, return true If not equal, return false Difficult to implement (3 operands) - use LL,SC

Software Queuing Lock Advantages Space proportional to waiting processes FIFO granting order Processes spin on local variables Preferred lock for shared address space, distributed memory with no coherent caching Array-based lock is proportional to number of processes in program, which is potentially more How do you know where to write to?

Queue on Lock Bit (QOLB) Hardware primitive Incorporated in IEEE SCI protocol List of waiters in cache tags of spinning processors DASH - directory pointers approximate QOLB waiting list

Atomic Counter Increment Performance Time per increment (usec)

Atomic Counter Increment Network Usage Est. Network Messages per Increment Constant for granting and Fetch&Op locks

Point-to-Point Event Synchronization Producer-consumer synchronization Software algorithms use flags - P1 tells P2 that a value is ready for P2 to use: P1 P2 a = f(x); // set a while (flag is 0) flag = 1; do nothing; b = g(a); // use a

Full-Empty Bits Word-level, producer-consumer synchronization: A full-empty bit is associated with each word in memory Producer writes only if the full-empty bit is empty, and leaves it set to full Consumer reads only if the full-empty bit is set to full, and leaves it set to empty

Full-Empty Bits Advantages: Disadvantages: J-machine? M-machine? Full-empty bit preserves atomicity Hardware support for fine-grained producer-consumer synchronization Disadvantages: Inflexible Imposes synchronization on all accesses Hardware cost J-machine? M-machine? Flexibility - doesn’t lend itself well to single-producer, multiple-consumer synchronization Doesn’t lend well to case where a producer updates a value multiple times before consumer consumes it.

Global (Barrier) Event Synchronization No processes can go beyond the barrier until all processes have reached the barrier Arrival Wait for release Release

Centralized Barrier Single, shared counter, and flag Counter: Number of arrived processes, increment on arrival to get my-number p = Total number of processes If my-number = p, set release flag Otherwise, busy-wait on release flag Increments must be mutually exclusive - atomic fetch&increment

Centralized Barrier Inefficient Counter: incremented atomically by each arriving processor Flag: all arrived processors busy-wait on the same flag Correctness Problem: Consecutively entering the same barrier (use sense reversal)

Centralized Barrier Latency: critical path proportional to p Traffic: about 3p bus transactions Storage: low cost (1 counter, 1 flag) Fairness: same processor may always be last to exit the barrier (unfair) Key problems: latency and traffic, especially with distributed memory!

Barriers and Distributed Memory Why do we need better barrier algorithms for distributed memory? Traffic, contention Even bigger problem without cache coherence Parallelization of communication now possible Fine-grained parallelism often means frequent communication and synchronization On a bus-based machine, the bus serializes all communication anyway, but now that’s not a problem.

Barriers and Distributed Memory Is special hardware support needed? CM-5, special “control” network for barriers, reductions, broadcasts CRAY T3D, M-machine Potentially significant overhead in a large system Are sophisticated software algorithms enough?

Software Combining Trees Little Contention Contention Flat Tree-structured

Software Combining Trees Same process for release Critical path length is O(logkp) O(p) for centralized barrier O(p) for any barrier on a centralized bus Disadvantages: Remote spinning problem Heavy network traffic while spinning

Tree Barriers with Local Spinning “Tournament barrier” Predetermine which processor moves up The other processor spins on a local variable P-node tree A leaf writes to its parent’s arrival array A parent waits for all arrivals, then writes to its parent’s arrival array Separate arrival and release tree ok

Tree Barriers with Local Spinning Separate arrival, release branching factor Larger branching factor => more contention Smaller branching factor => more network transactions Suited to scalable machines without coherent caching

Global Event Notification Example uses: Producer-consumer synchronization Communicate global data to consumers (new global min/max, for example) Invalidation-based coherence - sufficient for low-frequency writes Update protocol - reduces communication latency, prevents remote read misses for consuming processors Getting rid of remote read misses increases utilization

Update-writes Consumer doesn’t fetch data from producers cache Used for: Small data items (coherence messages per word, not per cache line) Items the consumer already has cached Well-suited to implementing barrier release

Barrier Synchronization with Update Write and Fetch&Op

Barrier Synchronization Without Fetch&Op

Dynamic Work Distribution Allocate work to load-balance system, often using task queues Mutual exclusion => multiple remote memory accesses per update Instead, support Fetch&Op Fetch&Op operations can often be parallelized (combining tree)

Parallel Prefix Synchronize by combining information Distribute a result based on that combination Carry-lookahead operator is an example Can calculate any associative function (sum, maximum, concatenate) in O(log n) time

Parallel Prefix - Upward Sweep Each node saves the value from its rightmost child… … and passes a combined result to its parent

Parallel Prefix - Downward Sweep Combine values, send to left child Pass data directly to right child

Synchronization and Fine-Grained Parallelism How do these techniques apply to transactional memory? How do they differ for message-passing vs. shared memory? What mechanisms are worth implementing in hardware to support fine-grained parallelism?

Questions?