Transactional Memory Lecturer: Danny Hendler. 2 2 From the New York Times…

Slides:



Advertisements
Similar presentations
Time-based Transactional Memory with Scalable Time Bases Torvald Riegel, Christof Fetzer, Pascal Felber Presented By: Michael Gendelman.
Advertisements

Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
CS 162 Memory Consistency Models. Memory operations are reordered to improve performance Hardware (e.g., store buffer, reorder buffer) Compiler (e.g.,
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Transactional Locking Nir Shavit Tel Aviv University (Joint work with Dave Dice and Ori Shalev)
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.
Transactional Memory: Architectural Support for Lock- Free Data Structures Herlihy & Moss Presented by Robert T. Bauer.
CS6290 Synchronization. Synchronization Shared counter/sum update example –Use a mutex variable for mutual exclusion –Only one processor can own the mutex.
Transactional Memory (TM) Evan Jolley EE 6633 December 7, 2012.
PARALLEL PROGRAMMING with TRANSACTIONAL MEMORY Pratibha Kona.
Transactional Memory Yujia Jin. Lock and Problems Lock is commonly used with shared data Priority Inversion –Lower priority process hold a lock needed.
1 Lecture 21: Transactional Memory Topics: consistency model recap, introduction to transactional memory.
The Performance of Spin Lock Alternatives for Shared-Memory Microprocessors Thomas E. Anderson Presented by David Woodard.
1 MetaTM/TxLinux: Transactional Memory For An Operating System Hany E. Ramadan, Christopher J. Rossbach, Donald E. Porter and Owen S. Hofmann Presenter:
Lock vs. Lock-Free memory Fahad Alduraibi, Aws Ahmad, and Eman Elrifaei.
1 Lecture 23: Transactional Memory Topics: consistency model recap, introduction to transactional memory.
1 Lecture 21: Synchronization Topics: lock implementations (Sections )
CS510 Concurrent Systems Class 2 A Lock-Free Multiprocessor OS Kernel.
1 Lecture 20: Protocols and Synchronization Topics: distributed shared-memory multiprocessors, synchronization (Sections )
Why The Grass May Not Be Greener On The Other Side: A Comparison of Locking vs. Transactional Memory Written by: Paul E. McKenney Jonathan Walpole Maged.
Memory Consistency Models Some material borrowed from Sarita Adve’s (UIUC) tutorial on memory consistency models.
An Introduction to Software Transactional Memory
Synchronization (Barriers) Parallel Processing (CS453)
Software Transactional Memory for Dynamic-Sized Data Structures Maurice Herlihy, Victor Luchangco, Mark Moir, William Scherer Presented by: Gokul Soundararajan.
Programming Paradigms for Concurrency Part 2: Transactional Memories Vasu Singh
CS510 Concurrent Systems Jonathan Walpole. A Lock-Free Multiprocessor OS Kernel.
Multi-core systems System Architecture COMP25212 Daniel Goodman Advanced Processor Technologies Group.
Concurrency, Mutual Exclusion and Synchronization.
Reduced Hardware NOrec: A Safe and Scalable Hybrid Transactional Memory Alexander Matveev Nir Shavit MIT.
1 Hardware Transactional Memory (Herlihy, Moss, 1993) Some slides are taken from a presentation by Royi Maimon & Merav Havuv, prepared for a seminar given.
Software Transactional Memory Yoav Cohen Seminar in Distributed Computing Spring 2007 Yoav Cohen Seminar in Distributed Computing Spring 2007.
A Qualitative Survey of Modern Software Transactional Memory Systems Virendra J. Marathe Michael L. Scott.
Transactional Memory Lecturer: Danny Hendler.  Speeding up uni-processors is harder and harder  Intel, Sun (RIP), AMD, IBM now focusing on “multi-core”
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Caltech CS184 Spring DeHon 1 CS184b: Computer Architecture (Abstractions and Optimizations) Day 12: May 3, 2003 Shared Memory.
Anshul Kumar, CSE IITD CSL718 : Multiprocessors Synchronization, Memory Consistency 17th April, 2006.
Anshul Kumar, CSE IITD ECE729 : Advance Computer Architecture Lecture 26: Synchronization, Memory Consistency 25 th March, 2010.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Wait-Free Multi-Word Compare- And-Swap using Greedy Helping and Grabbing Håkan Sundell PDPTA 2009.
Fundamentals of Parallel Computer Architecture - Chapter 71 Chapter 7 Introduction to Shared Memory Multiprocessors Yan Solihin Copyright.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Consistency Oblivious Programming Hillel Avni Tel Aviv University.
Software Transactional Memory Should Not Be Obstruction-Free Robert Ennals Presented by Abdulai Sei.
A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy Slides by Vincent Rayappa.
1 Lecture 19: Scalable Protocols & Synch Topics: coherence protocols for distributed shared-memory multiprocessors and synchronization (Sections )
1 Lecture 4: Transaction Serialization and Concurrency Control Advanced Databases CG096 Nick Rossiter [Emma-Jane Phillips-Tait]
Concurrent Computing Seminar Introductory Lecture Instructor: Danny Hendler
Ch4. Multiprocessors & Thread-Level Parallelism 4. Syn (Synchronization & Memory Consistency) ECE562 Advanced Computer Architecture Prof. Honggang Wang.
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
ECE 1747: Parallel Programming Short Introduction to Transactions and Transactional Memory (a.k.a. Speculative Synchronization)
Novel Paradigms of Parallel Programming Prof. Smruti R. Sarangi IIT Delhi.
Multiprocessors – Locks
Maurice Herlihy, Victor Luchangco, Mark Moir, William N. Scherer III
Maurice Herlihy and J. Eliot B. Moss,  ISCA '93
Outline Introduction Centralized shared-memory architectures (Sec. 5.2) Distributed shared-memory and directory-based coherence (Sec. 5.4) Synchronization:
Part 2: Software-Based Approaches
Atomic Operations in Hardware
Atomic Operations in Hardware
Challenges in Concurrent Computing
A Qualitative Survey of Modern Software Transactional Memory Systems
Lecture 6: Transactions
Lecture: Coherence and Synchronization
Software Transactional Memory Should Not be Obstruction-Free
Lecturer: Danny Hendler
CS333 Intro to Operating Systems
Lecture 23: Transactional Memory
Lecture: Coherence and Synchronization
Lecture 18: Coherence and Synchronization
Presentation transcript:

Transactional Memory Lecturer: Danny Hendler

2 2 From the New York Times…

3 Moore’s law Exponential growth in computing power

4  Speeding up uni-processors is harder and harder  Intel, Sun, AMD, IBM now focusing on “multi- core” architectures  Already, most computers are multiprocessors How can we write correct and efficient algorithms for multiprocessors ? The Future of Computing

5 A fundamental problem of thread-level parallelism. Account[i] = Account[i]-X; Account[j] = Account[j]+X;.... Account[i] = Account[i]-X; Account[j] = Account[j]+X;... Thread A Thread B But what if execution is concurrent? Must avoid race conditions

6 Inter-thread synch. alternatives

7

8

9

10 Transactional Memory: What is a transaction? A transaction is a sequence of memory reads and writes, executed by a single thread, that either commits or aborts If a transaction commits, all the reads and writes appear to have executed atomically If a transaction aborts, none of its stores take effect Transaction operations aren't visible until they commit (if they do)

11 Transactions properties: A transaction satisfies the following key property: Atomicity: Each transaction either commits (its changes seem to take effect atomically) or aborts (its changes have no effect).

12 Transactional Memory Goals A new multiprocessor architecture The goal: Implementing lock-free synchronization that is – efficient – easy to use compared with conventional techniques based on mutual exclusion Implemented by hardware support (such as straightforward extensions to multiprocessor cache- coherence protocols) and / or by software mechanisms

13 A Usage Example Locks: Lock(L[i]); Lock(L[j]); Account[i] = Account[i] – X; Account[j] = Account[j] + X; Unlock(L[j]); Unlock(L[i]); Transactional Memory: atomic { Account[i] = Account[i] – X; Account[j] = Account[j] + X; }; Account[i] = Account[i]-X; Account[j] = Account[j]+X;

14 Transactions execute in commit order ld 0xdddd... st 0xbeef Transaction A Time ld 0xbeef Transaction C ld 0xbeef Re-execute with new data Commit ld 0xdddd... ld 0xbbbb Transaction B Commit Violation! 0xbeef Taken from a presentation by Royi Maimon & Merav Havuv, prepared for a seminar given by Prof. Yehuda Afek. Transactions interaction Two transactions conflict if the write-set of one intersects with the data-set of the other

15 Software Transaction Memory (Nir Shavit and Dan Touitou, '95) No TM hardware support required Non-blocking –Memory locations acquired in increasing order –Help the transaction that fails you Shared memory operations required: –Read & Write –Load-link / store-conditional (LL / SC) Static transactions only (to permit 2-phase locking)

16 Usage example: kCAS kCAS(size, DataSet[], old[], new[]) { 1.BeginTransaction 2. for (i=0 to size) 3. if Read-transctional(DataSet[i] ≠ old[i]) 4. return-code=Failure 5. ExitTransaction 6. for (i=0 to size) 7. Write-transactional(DataSet[i], New[i]) 8. return-code=Success 9.EndTransaction }

17 Load-linked / store-conditional (LL/SC) Change a value only if a previously read variable was not written in the interim. Load-linked(w) - return the value of w Store-conditional(w,v) by p – writes v and returns success if no write/SC was applied to o since p’s last load-linked operation on o. Otherwise, it returns fail.

18 Shavit/Touitou STM: Data Structures Memory Ownerships executing status version Size addr[] oldValues[] Rec 1 Rec 2 Rec n executing status version Size addr[] oldValues[] executing status version Size addr[] oldValues[] Each process owns a single transaction record

Basic ideas Changes are tentative until transaction commits LL/SC verifies ‘old’ processes do not overwrite completed transactions Helping: A failed transaction helps the transaction that failed it 19

Transaction record executing status version size addr[] oldValues[] calc Data-set size Data-set addresses, in increasing order Contains old values of dataset once transaction succeeds Incremented every new transaction Only help transaction that are still executing Function to apply to data-set {NONE,SUCCESS, FAILURE}

A typical use of LL/SC and version field LL(trans.field) … if (version != trans.version) return SC(trans.field, newval);

22 The startTransaction procedure Status StartTransaction(TransactionBody Calc, MemAddr[] DataSet) 1.Initialize(Rec i, DataSet) 2.Rec i.calc=Calc 3.Rec i.executing=true 4.Transaction(Rec i, Rec i.version, true) // true – called by tran. owner 5.Rec i.executing=false // Disable helping 6.Rec i.version++ 7.if rec i.status=SUCCESS 8. return (SUCCESS, Rec i.oldValues) 9.Else 10. return Failure Code to execute in transaction Addresses that may be accessed

The Transaction procedure Transaction(rec, version, isInitiator) 1.AquireOwnerships(rec, version) // Try to capture memory ownership 2.(status, failaddr) = LL(rec.status) // Status set by Aquire 3.if (status == NONE) // did not fail 4. if (version ≠ rec.version) // Transaction already completed 5. return 6. SC(rec.status(SUCCESS) 7.(status, failaddr) = LL(rec.status) // failaddr is index of non-acquired mem 8.if (status == SUCCESS) 9. AgreeOldValues(rec,version) // Copy old values to record 10. NewValues=calc (rec.OldValues) // Calculate new values – apply transact. 11. UpdateMemory(rec, version, NewValues) // Write back to memory 12. ReleaseOwnership(rec, version) // Release memory’s ownerships 13.else … true – called by initiator false – called by helper

24 The Transaction procedure Transaction(rec, version, isInitiator) … 13.else // In case of failure 14. ReleaseOwnerships(rec, version) 15. if IsInitiator // Help only the transaction that failed mine 16. failtran=ownerships[failaddr] // Find whom to help 17. if (failtran == Nobody) 18. return // That transaction already completed 19. else 20. failversion=failtran.version 21. if (failtran.executing) // only help an executing transaction 22. Transaction(failtran, failversion, false) // help once

25 The AcquireOwnerships procedure AcquireOwnerships(rec,version) 1.transize=rec.size // transaction size 2.for j=1 to transize do 3. while true do 4. location=rec.addr[j] // address of next memory cell 5. if LL(rec.status ≠ NONE) 6. return // Transaction already completed 7. owner=LL(ownerships[rec.addr[j]) // find out who owns this cell 8. if (rec.version ≠ version) return // Transaction already completed 9. if (owner=rec) exit while loop // go to next cell 10. if (owner=nobody) // memory cell free 11. if SC(rec.status, NONE) // if status did not change 12. if SC(ownerships[location], rec) // if managed to acquire cell 13. exit while loop // go to next cell 14. else // this transaction fails 15. SC(rec.status, (Failure, j) ) 16. return

The AgreeOldValues procedure AgreeOldValues(rec,version) 1.transize=rec.size 2.for (j=1 to transize) 3. location=rec.addr[j] 4. LL(rec.oldValues[j]) 5. if (rec.version ≠ version) return 6. SC(rec.oldValues[j], Memory[location])

The ReleaseOwnership procedure ReleaseOwnership(rec,version) 1.transize=rec.size 2.for (j=1 to transize) 3. location=rec.addr[j] 4. if (LL(ownerships[location]) = rec) 5. if (rec.version ≠ version) return // Transaction completed 6. SC(ownerships[location], nobody)

Many new STM implementations DSTM Dynamic transactions Obstruction free Contention managers RSTM Object-based implementation for C++ SXM STM package for C# Locking-based STM Scheduling-based STM …