debugging programs that use atomic blocks and transactional memory
DESCRIPTION
Debugging Programs that use Atomic Blocks and Transactional Memory. Ferad Zyulkyarov 1,2 , Tim Harris 3 , Osman S. Unsal 1 , Adrián Cristal 1 , Mateo Valero 1,2. 1 BSC-Microsoft Research Centre 2 Universitat Politècnica de Catalunya 3 Microsoft Research Cambridge. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/1.jpg)
Ferad Zyulkyarov1,2, Tim Harris3, Osman S. Unsal1, Adrián Cristal1, Mateo Valero1,2
1BSC-Microsoft Research Centre2Universitat Politècnica de Catalunya
3Microsoft Research Cambridge
15th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming09-14 January 2010 – Bangalore
Debugging Programs that use Atomic Blocks and Transactional Memory
![Page 2: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/2.jpg)
2
Our Motivation
• It is difficult to debug transactional applications with existing debuggers
• Existing debuggers are not aware of atomic blocks and transactional memory– Lessons learnt from developing complex TM
applications such as Atomic Quake[1] and Quake TM [2].
[1] Zyulkyarov et al. “Atomic Quake: Using Transactional Memory in an Interactive Multiplayer Game Server“, PPoPP'09[2] Gajinov et al. “QuakeTM: Parallelizing a Complex Serial Application Using Transactional Memory “, ICS'09
![Page 3: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/3.jpg)
Overview
• Debugging atomic blocks atomically• Examining the TM state• Managing the TM state at debug-time• Conflict point discovery• Design and implementation
3
![Page 4: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/4.jpg)
Debugging at the Level of Atomic Blocks
• Debugger is extended with the semantics of atomic blocks– Atomicity – atomic blocks are treated as
single instruction– Isolation – the user does not observe
intermediate results of concurrently running transactions
• Hides the low level implementation details of atomic blocks (TM or lock inference)
4
![Page 5: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/5.jpg)
Atomicity in Debugging• Step over atomic blocks as if single instruction.• Good for debugging sync errors at granularity of atomic
blocks vs. individual statements inside the atomic blocks.
5
<statement 1><statement 2><statement 3>atomic { <statement 4> <statement 5> <statement 6> <statement 7>}<statement 8><statement 9>
<statement 1><statement 2><statement 3>atomic { <statement 4> <statement 5> <statement 6> <statement 7>}<statement 8><statement 9>
Current Debugger TM Aware Debugger
![Page 6: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/6.jpg)
Using Existing Debuggers
6
SV_LinkEdict1 atomic {2 InitializeBoundingBox(ent);3 SV_FindTouchedLeafs(ent, sv.worldmodel->nodes);4 node = FindNewLocation(ent, sv_areanode);5 InsertLinkBefore(&ent->area, &node->trigger_edicts);6 } // end atomic
sv_areanode
Want to move from A to B and take the keys.
Compute the bounding box. Find the leafs the
bounding box maps to.
Find location BAnother player took the keys
before us.
Change the location and take the keys.
Conflict. Rollback.
Re-execute.
![Page 7: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/7.jpg)
Using TM Aware Debugger
7
SV_LinkEdict1 atomic {2 InitializeBoundingBox(ent);3 SV_FindTouchedLeafs(ent, sv.worldmodel->nodes);4 node = FindNewLocation(ent, sv_areanode);5 InsertLinkBefore(&ent->area, &node->trigger_edicts);6 } // end atomic
sv_areanode
Moved from A to B and took the keys.
![Page 8: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/8.jpg)
Isolation in Debugging• What if we want to debug wrong code within atomic
block?– Put breakpoint inside atomic block.– Validate the transaction– Step within the transaction.
• The user does not observe intermediate results of concurrently running transactions– Switch transaction to irrevocable mode after validation.
8
atomic { <statement 1> <statement 2> <statement 3> <statement 4>}
![Page 9: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/9.jpg)
Debugging Wrong Code Inside Atomic Blocks
• Why isolation is important?
9
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 5 6
![Page 10: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/10.jpg)
Example Importance of Isolation
10
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 5 64
InsertSorted(4)
![Page 11: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/11.jpg)
Example Importance of Isolation
11
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 5 6
4
![Page 12: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/12.jpg)
Example Importance of Isolation
12
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 3 6
4
Another transaction changed the value to 3. The current TX will be
doomed and operate on invalid data.
![Page 13: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/13.jpg)
Example Importance of Isolation
13
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 3 6
4
Confuse the user because of consuming speculative values and not detecting conflict.
![Page 14: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/14.jpg)
Why Isolate Speculative State?
14
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 3 6
4
Confuse the user because of consuming speculative values and not detecting conflict.
![Page 15: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/15.jpg)
Why Isolate Speculative State?
15
InsertSorted(object value) { Node n = new Node(value); atomic { Node previous = FindPrevious(value); n.Next = previous.Next; previous.Next = n; }}
1 3 6
4Conflict.Rollback.
Re-execute.
![Page 16: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/16.jpg)
• Debugging atomic blocks atomically• Examining the TM state• Managing the TM state at debug-time• Conflict point discovery• Design and implementation
16
![Page 17: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/17.jpg)
Debugging at the Level of Transactions
• Assumes that atomic blocks are implemented with transactional memory.
• Examine the internal state of the TM– Read/write set, re-executions, status
• TM specific watch points– Break when conflict happens– Filters
• Concurrent work with Herlihy and Lev [PACT’ 09].
17
![Page 18: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/18.jpg)
Querying the TM State
18
atomic { <statement 1> <statement 2> <statement 3> <statement 4>}
Read Set0x30FA000x30FE160x320B0A0x4A11F8
Write Set0x30FE160x3AEE0D0x4A1124
Status: Active
Re-executions: 1Query TM
StatePriority: 1Nesting: 1
![Page 19: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/19.jpg)
TM Specific Watchpoints
19
atomic { <statement 1> <statement 2> <statement 3> <statement 4>}
Conflict Information
Conflicting Threads: T1, T2Address: 0x84D2F0Symbol: reservation@04Readers: T1Writers: T2
Break when conflict happens
Filter: Break ifAddress = reservation@04Thread = T2
AND
![Page 20: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/20.jpg)
• Debugging atomic blocks atomically• Examining the TM state• Managing the TM state at debug-time• Conflict point discovery• Design and implementation
20
![Page 21: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/21.jpg)
Managing Transactions at Debug-Time
• At the level of atomic blocks– Debug time atomic blocks– Splitting atomic blocks
• At the level of transactions– Changing the state of TM system (i.e. adding
and removing entries from read/write set, change the status, abort)
• Analogous to the functionality of existing debuggers to change the CPU state
21
![Page 22: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/22.jpg)
Debug Time Atomic Blocks
• Create and remove atomic blocks while debugging.
• Useful to investigate and patch synchronization errors such as data races, atomicity, and order violation.
• User marks the places that should execute atomically.
22
![Page 23: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/23.jpg)
Example Debug Time Atomic Bblocks
23
<statement 1><statement 2><statement 3><statement 4><statement 5><statement 6><statement 7><statement 8><statement 9><statement 10><statement 11><statement 12><statement 13><statement 14>
![Page 24: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/24.jpg)
Example Debug Time Atomic Bblocks
24
<statement 1><statement 2><statement 3>StartDebugAtomic<statement 4><statement 5><statement 6><statement 7><statement 8><statement 9>EndDebugAtomic<statement 10><statement 11><statement 12><statement 13><statement 14>
User marks the startand the end of thetransactions
![Page 25: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/25.jpg)
Data Race
25
Thread 1
atomic { local = counter; local++; counter = local;}
Thread 2
atomic { local = counter; local++;}counter = local;
StartDebugAtomicatomic { local = counter; local++;}counter = local;EndDebugAtomic
![Page 26: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/26.jpg)
Split Atomic Block
• Useful to find unnecessarily large atomic blocks or searching for data races
26
atomic { s1;
s2;}
atomic { s1;<split> s2;}
atomic { s1;}
atomic { s2;}
![Page 27: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/27.jpg)
• Debugging atomic blocks atomically• Examining the TM state• Managing the TM state at debug-time• Conflict point discovery• Design and implementation
27
![Page 28: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/28.jpg)
Conflict Point Discovery
28
• TM applications have unanticipated overheads– Problem raised by Pankratius [talk at ICSE’09]
and Rossbach et al. [PPoPP’10]• Tells the users at which source lines how
many conflicts happen.– Useful to profile and optimize TM applications.
• More comprehensive than Reach Points Gajinov et al. [ICS’ 09]
![Page 29: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/29.jpg)
Example OutputFile:Line #Conf. Method LineHashtable.cs:51 152 Add If (_container[hashCode]…
Hashtable.cs:48 62 Add uint hashCode = HashSdbm(…
Hashtable.cs:53 5 Add _container[hashCode] = n …
Hashtable.cs:83 5 Add while (entry != null) …
ArrayList.cs:79 3 Contains for (int i = 0; i < count; i++ )
ArrayList.cs:52 1 Add if (count == capacity – 1) …
29
![Page 30: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/30.jpg)
Optimizing Genome
30
![Page 31: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/31.jpg)
• Debugging atomic blocks atomically• Examining the TM state• Managing the TM state at debug-time• Conflict point discovery• Design and implementation
31
![Page 32: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/32.jpg)
Design
32
Debugger Process
WinDbg
TmDbgExt
DbgEng
Target Process
Program
TmTargetDbg
StmLib
ShowRead set
Implements debugger commands
such as setting watchpoints, query
and modify the STM.
Wrapper around the STM to hide its implementation
details.
Function call on the target process.
![Page 33: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/33.jpg)
Conclusion
• New principles and approaches for debugging TM applications– Debugging at the level of atomic blocks– Debugging at the level of transactions– Managing transactions at debug-time
• Conflict point discovery– Optimized Genome
• Generic and decoupled design
33
![Page 34: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/34.jpg)
Край
Slides available at www.bscmsrc.eu
![Page 35: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/35.jpg)
Backup Slides
35
![Page 36: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/36.jpg)
Implementing Conflict Point Discovery
36
atomic { a = 5;}
Addr: 01 : StartAtomic();02 : OpenObjForWrite(a);03 : a = 5;04 : CommitAtomic();
Obj. Addr.
0x40D8E2
…
…
Ret. Addr Counter
0x03 152
… …
… …
CompilerInstrumentation
Conflict
DbgEng
Addr = 0x03
Hashtable.cs:51
Translate tosource line
Return Addr.
0x03
…
…
Log the address of a for conflict
detection.
To know where conflict happens log the return
address of OpenObjForRead.
![Page 37: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/37.jpg)
Internal Breakpoint
• Debugger breakpoint used to implement– Atomicity– Watchpoints– Splitting atomic blocks– Debug time atomic blocks
37
![Page 38: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/38.jpg)
Breakpoint-time Callback• Distinguishes ordinary
breakpoints from internal breakpoints
• Overrides the debugger behavior of suspending the target process
• May execute complementary actions
38
![Page 39: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/39.jpg)
Example Use of Internal Breakpoint
39
atomic{ <statement 1> <statement 2> <statement 3> <statement 4> <statement 5> <statement 6> <statement 7> <statement 8>}
Internal Breakpoint -> StartAtomic()
-> Commit()
Stepping over atomic block as if a single instruction
![Page 40: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/40.jpg)
Atomicity Violations
40
initially a = b = 0; Thread 1 Thread 2
1 atomic{2 a++;3 } atomic {4 a++;5 atomic{ }6 b--;7 assert(a + b == 0);8 }
![Page 41: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/41.jpg)
Atomicity Violations
41
initially a = b = 0; Thread 1 Thread 2
StartDebugAomic1 atomic{2 a++;3 } atomic {4 a++;5 atomic{ }6 b--;7 assert(a + b == 0);8} EndDebugAtomic
![Page 42: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/42.jpg)
Extending the Scope of Atomic Blocks
• We can build over debug time transactions to allow users to extend the scope of existing compile time atomic blocks.
42
<statement 1><statement 2>atomic { <statement 3> <statement 4>}<statement 5><statement 6><statement 7>
<statement 1><statement 2>atomic { <statement 3> <statement 4> <statement 5> <statement 6>}<statement 7>
<statement 1><statement 2>StartDebugTx <statement 3> <statement 4> <statement 5> <statement 6>EndDebugTx<statement 7>
We want How we do
![Page 43: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/43.jpg)
Shrinking the Scope
• The implementation of shrinking the scope of atomic blocks might be tricky for STMs because of the code instrumentation.
43
<statement 1><statement 2>atomic { <statement 3> <statement 4> <statement 5> <statement 6>}<statement 7>
<statement 1><statement 2><statement 3>atomic { <statement 4> <statement 5>}<statement 6><statement 7>
<statement 1><statement 2>StartTx - Ignore <statement 3>StartDebugTx <statement 4> <statement 5>EndDebugTx <statement 6>EndTx - Ignore<statement 7>
We want How we do
![Page 44: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/44.jpg)
Debugging Wrong Code Inside Atomic Blocks?
44
SV_LinkEdict1 atomic {2 InitializeBoundingBox(ent);3 SV_FindTouchedLeafs(ent, sv.worldmodel->nodes);4 node = FindNewLocation(ent, sv_areanode);5 InsertLinkBefore(&ent->area, &node->trigger_edicts);6 } // end atomic
InsertLinkBefore(object value) { Node n = new Node(value); atomic { AddNode(n); RightRotate(ParentOf(n)); FixColors(); }}
![Page 45: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/45.jpg)
Isolating Speculative State
45
5
4Insert(3)
5
4
3
Insert(object value) { Node n = new Node(value); atomic { AddNode(n); RightRotate(ParentOf(n)); FixColors(); }}
3
![Page 46: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/46.jpg)
Isolating Speculative State
46
5
4Insert(3)
5
2
3
Insert(object value) { Node n = new Node(value); atomic { AddNode(n); RightRotate(ParentOf(n)); FixColors(); }}
Another transaction changed the value to
2.The current TX will be doomed and operate
on invalid data.
![Page 47: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/47.jpg)
Insert(object value) { Node n = new Node(value); atomic { AddNode(n); RightRotate(ParentOf(n)); FixColors(); }}
Isolating Speculative State
47
5
2
32
3
RotateRight
5
Mislead the user because of consuming speculative values and not detecting
conflict.
![Page 48: Debugging Programs that use Atomic Blocks and Transactional Memory](https://reader035.vdocuments.net/reader035/viewer/2022062520/56815fd7550346895dced962/html5/thumbnails/48.jpg)
Isolating Speculative State
48
5
2
3
FixColors
5
2
3
Insert(object value) { Node n = new Node(value); atomic { AddNode(n); RightRotate(ParentOf(n)); FixColors(); }}
Conflict.Rollback.
Re-execute.