Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Universität Karlsruhe (TH) Forschungsuniversität · gegründet 1825 Lehrstuhl für Programmiersysteme Fakultät für Informatik Software Transactional Memory:

Ähnliche Präsentationen


Präsentation zum Thema: "Universität Karlsruhe (TH) Forschungsuniversität · gegründet 1825 Lehrstuhl für Programmiersysteme Fakultät für Informatik Software Transactional Memory:"—  Präsentation transkript:

1 Universität Karlsruhe (TH) Forschungsuniversität · gegründet 1825 Lehrstuhl für Programmiersysteme Fakultät für Informatik Software Transactional Memory: Bibliotheken und Spracherweiterungen Andreas Zwinkau IPD, Lehrstuhl Prof. Tichy

2 Wo liegt das Problem?

3 Lehrstuhl für Programmiersysteme Fakultät für Informatik 3 Zeit Das Blockadeproblem

4 Lehrstuhl für Programmiersysteme Fakultät für Informatik 4 Zeit Das Blockadeproblem Nicht blockierend

5 Lehrstuhl für Programmiersysteme Fakultät für Informatik 5 Zeit Das Blockadeproblem blockierend

6 Lehrstuhl für Programmiersysteme Fakultät für Informatik 6 Leistungsvergleich Quelle: Robert Ennals, Software Transactional Memory Should Not Be Obstruction-Free Bei variierendem Wettstreit in Rot-Schwarz-Bäumen sind blockierende Transaktionen schneller

7 Lehrstuhl für Programmiersysteme Fakultät für Informatik 7 Das Seiteneffektproblem

8 Lehrstuhl für Programmiersysteme Fakultät für Informatik 8 Das Seiteneffektproblem Siehe: Tim Harris, Exceptions and side-effects in atomic blocks Wann soll IO stattfinden? Wann darf ein Bankautomat das Geld auswerfen? Transaktion Ausgabe SQL Commit

9 Lehrstuhl für Programmiersysteme Fakultät für Informatik 9 Dynamic STM2 Java Bibliothek Flexibel Kein „lock-in“ auf eine Strategie Komponenten austauschbar Blockadefrei Also Blockadeproblem

10 10 Ein Blick unter die Haube

11 Lehrstuhl für Programmiersysteme Fakultät für Informatik 11 DSTM2: Schnittstelle @atomic public interface Node { int getValue (); void setValue ( int value ); Node getNext (); void setNext ( Node value ); } class INode implements Node {...}

12 Lehrstuhl für Programmiersysteme Fakultät für Informatik 12 DSTM2: Fabrik Factory factory = dstm2.Thread.makeFactory(INode.class); Ersetze „new INode“ durch „factory.create()“ ! Die Fabrik kapselt die INode Klasse, damit der Zugriff auf Attribute gepuffert und damit transaktional wird.

13 Lehrstuhl für Programmiersysteme Fakultät für Informatik 13 DSTM2: Transaktion INode intSet = factory.create() result = dstm2.Thread.doit(new Callable () { public Boolean call() { return intSet.insert(value); } }); So sieht der Einsatz der transaktionalen Klasse aus

14 Lehrstuhl für Programmiersysteme Fakultät für Informatik 14 Multicore RunTime C/C++ Bibliothek Leistung! Nicht blockadefrei Also auch kein Blockadeproblem Fortgeschrittene Funktionalität Verschachtelte Transaktionen Signale

15 15 Leistung

16 Lehrstuhl für Programmiersysteme Fakultät für Informatik 16 Multicore RunTime: Hashtabelle Quelle: Bratin Saha et al, McRT-STM: A High Performance Software Transactional Memory System for a Multi-Core Runtime

17 Lehrstuhl für Programmiersysteme Fakultät für Informatik 17 Multicore RunTime: Verkettete Liste Quelle: Bratin Saha et al, McRT-STM: A High Performance Software Transactional Memory System for a Multi-Core Runtime

18 18 Und nun? Spracherweiterungen!

19 Lehrstuhl für Programmiersysteme Fakultät für Informatik 19 Übersetzung atomic ( condition ) { statements ; } boolean done = false; while (!done) { STMStart(); try { if ( condition ) { statements ; done = STMCommit(); } else { STMWait(); } } catch (Throwable t) { done = STMCommit(); if (done) { throw t; }}} So übersetzt die Harris-Fraser-STM

20 Lehrstuhl für Programmiersysteme Fakultät für Informatik 20 Das Seiteneffektproblem public class ExampleOutput { static PrintStream out = new PrintStream( new AtomicOutputStream(System.out)); static void print_sum(int x, int y) { atomic { int result = x + y; out.println("Result is " + result); } Callback! Quelle: Tim Harris, Exceptions and side-effects in atomic blocks

21 Lehrstuhl für Programmiersysteme Fakultät für Informatik 21 ATOMOΣ Java-ähnlich Minus synchronized Plus STM Verschachtelte Transaktionen Streng atomar

22 Lehrstuhl für Programmiersysteme Fakultät für Informatik 22 ATOMOΣ: Barriere synchronized (lock) { count++; if (count != thread_count) { lock.wait(); } else { lock.notifyAll(); } atomic { count++; } atomic { if (count != thread_count){ watch count; retry; } Implementation einer Barriere in herkömmlichem Java und in ATOMOΣ mit transaktionalem Speicher

23 Lehrstuhl für Programmiersysteme Fakultät für Informatik 23 ATOMOΣ: watch void watch (Address a) { VM_Thread.getCurrentThread().watchSet.add(a); } Die watch-Funktion fügt eine Speicheradresse dem watchset des aktuellen Threads hinzu.

24 Lehrstuhl für Programmiersysteme Fakultät für Informatik 24 ATOMOΣ: retry void retry() { [...] for (int i=0,s=watchSet.size();i<s;i++) { Address a = (Address)watchSet.get(i); open { thread.schedulerAddress = a; thread.schedulerWatch = true; } open {if(thread.schedulerWatch) for(;;);} } [...] } Die retry-Funktion startet eine Transaktion neu, sobald sich eine Variable im watch set ändert.

25 25 Optimierungen

26 Lehrstuhl für Programmiersysteme Fakultät für Informatik 26 StarJIT Existierende Optimierungen ermöglichen Neue semantische Konstrukte durch Prüfvariablen garantieren Globale Optimierungen Unveränderbare Variablen in Transaktionen ignorieren Stackvariablen ignorieren Codeerzeugung Optimierter Assemblercode für Transaktionen Quelle: Ali-Reza Adl-Tabatabai, Brian T. Lewis, Vijay Menon, Brian R. Murphy, Bratin Saha, and Tatiana Shpeisman, Compiler and runtime support for efficient software transactional memory

27 Lehrstuhl für Programmiersysteme Fakultät für Informatik 27 STM Haskell Main = do {... ; atomic( do { x <- delete t1 A; insert t2 A x });... } atomic :: STM a -> IO a Typisierung von „atomic“ Verhinderung von Seiteneffekten ; ist ein Operator atomic (readPort p1 `orElse` readPort p2) Alternativer Operator „orElse“

28 28 „Ein echter Ferrari !!!“

29 Lehrstuhl für Programmiersysteme Fakultät für Informatik 29 Danke für's Zuhören! Fragen?

30 Lehrstuhl für Programmiersysteme Fakultät für Informatik 30 Backupfolien...

31 Lehrstuhl für Programmiersysteme Fakultät für Informatik 31 ATOMOΣ: open Public void createOrder () { atomic { Order order = new Order(); order.setID(generateID());... } public int generateID { atomic { return id++; }} public int generateID { open { return id++; }}

32 Lehrstuhl für Programmiersysteme Fakultät für Informatik 32 Multicore RunTime: Sendmail Quelle: Bratin Saha et al, McRT-STM: A High Performance Software Transactional Memory System for a Multi-Core Runtime

33 Lehrstuhl für Programmiersysteme Fakultät für Informatik 33 public static T doIt(Callable xaction) { T result = null ; while (! Thread.stop ) { beginTransaction (); try { xaction.call result = xaction.call (); } catch (AbortedException d) { } catch (Exception e) { throw new PanicException("Unhandled exception " + e ); } if (commitTransaction ()) { return result ; }}} DSTM2: Doit Implementation


Herunterladen ppt "Universität Karlsruhe (TH) Forschungsuniversität · gegründet 1825 Lehrstuhl für Programmiersysteme Fakultät für Informatik Software Transactional Memory:"

Ähnliche Präsentationen


Google-Anzeigen