University of Maryland The New Dyninst Event Model James Waskiewicz.

Slides:



Advertisements
Similar presentations
Paradyn Project Paradyn / Dyninst Week Madison, Wisconsin May 2-4, 2011 ProcControlAPI and StackwalkerAPI Integration into Dyninst Todd Frederick and Dan.
Advertisements

OPERATING SYSTEMS Threads
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Chapter 4 – Threads (Pgs 153 – 174). Threads  A "Basic Unit of CPU Utilization"  A technique that assists in performing parallel computation by setting.
University of Maryland Paradyn as a Strict Dyninst Client James Waskiewicz.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Lecture 3 Threads Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Paradyn Project Paradyn / Dyninst Week Madison, Wisconsin April 12-14, 2010 Binary Rewriting with Dyninst Madhavi Krishnan and Dan McNulty.
Operating System Concepts
Lecture 4 Page 1 CS 111 Online Modularity and Memory Clearly, programs must have access to memory We need abstractions that give them the required access.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Chapter 4 – Thread Concepts
Threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Threads and Cooperation
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Chapter 4: Threads.
Why Threads Are A Bad Idea (for most purposes)
CS510 Operating System Foundations
Chapter 4: Threads.
Processes Creation and Threads
Chapter 4: Threads.
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
Chapter 4: Threads.
Presentation transcript:

University of Maryland The New Dyninst Event Model James Waskiewicz

University of Maryland Motivation: the series Several years in the making: Paradyn separation requires… DyninstAPI support for threads –Among other things Supporting threads (a la Paradyn) requires… –Asynchronous event handling, which requires… Solving the multi-event-source problem –Eg. Listen for and handle events coming from Socket / file descriptor System call ( wait() ) –Solution: use threads Just a can of worms … Or Pandora’s box?

University of Maryland Overall Design Concerns Keep thread stuff out of the way –Don’t want to “pollute” dyninst code with synchronization primitives –Dyninst is already hard to fix when broken Keep threading issues modular Try to keep existing code thread- context free –In other words, most dyninst code should be able to run successfully no matter what thread executes it. –There can be some tricky situations here (inferior RPCs for example) –Obvious exceptions in signal handling

University of Maryland The Plan: The 3 thread model 3 threads –(1) User Interface Thread API user’s mutator –(1) Synchronous Event Thread Eg. Loop on waitpid() –(1) Asynchronous Event Thread Eg. Loop on select() And a mailbox –Hide internal threads by forcing non UI threads to “mail” events to the UI thread. Eg. ensure that user-supplied callbacks are only executed on the UI thread.

University of Maryland The Plan: The 3 thread model UI ThreadMutatee 1 Mailbox Synchronous Event Thread waitpid() poll() Asynchronous Event Thread select() Mutatee 2 Mutatee N

University of Maryland But there’s a problem (linux) Ptrace() may only be called by one thread, period. –But we really want all threads to be able to issue ptrace() commands Process::pause() Write/readDataSpace() Solution: Add another thread –Solely responsible for accepting and handling requests for calling ptrace() –And sometimes waitpid() and fork() …

University of Maryland The Plan: The 4 thread model UI ThreadMutatee 1 Mailbox Synchronous Event Thread waitpid() poll() Asynchronous Event Thread select() Mutatee 2 Mutatee N Ptracer (DBI) Thread

University of Maryland But there’s another problem (windows) Restrictive OS level debugging API –The thread that starts the mutatee process is the only thread that is allowed to call WaitNextDebugEvent() Solution: add N threads ! –N = number of mutatees This is actually a good idea –One “listener” thread per process Elegant in terms of code modularity A nice simple concept: a thread that starts a process and receives events from it until termination/detach Handles events as they occur.

University of Maryland The Plan: The (n+3) thread model UI Thread Mailbox Synchronous Event Thread 1 waitpid() Poll() Asynchronous Event Thread select() Mutatee 2 Ptracer (DBI) Thread Mutatee 1 Mutatee N Synchronous Event Thread 2 waitpid() Poll() Synchronous Event Thread N waitpid() Poll()

University of Maryland But there’s another problem: recursion Dyninst is full of recursive event patterns –ie. An event that causes another event, and needs to wait for its completion Best solution will involve encapsulating this behavior into a “natural” structure –Either that or re-architect many functional elements of dyninst –And don’t forget: add more threads! Solution: decouple event handling concept into: –Event generation One dedicated thread (per process) –Event handling Multiple possible threads (thread pool) Number of threads depends on recursion depth This is a bit nasty –Could probably be done using the mailbox’s recursive callback features, but… They’re complicated too, and need more thought

University of Maryland The Plan: The (2n+3+x) thread model UI Thread Mailbox Signal Generator Thread 1 Asynchronous Event Thread select() Mutatee 2 Ptracer (DBI) Thread Mutatee 1 Mutatee N SH Signal Generator Thread 1 SH Signal Generator Thread 1 SH

University of Maryland A simple example: full stop UI Thread issues stopExecution () –Sends SIGSTOP to mutatee –Blocks inside waitForStop() UI Thread kill (SIGSTOP) Mutatee Signal Generator Thread Signal Handler Thread Event Gate Wait for event: evtProcessStop block

University of Maryland A simple example: full stop Mutatee Stops –Notifes parent process of SIGSTOP –This is received by SignalGenerator, which is listening for mutatee events UI Thread kill (SIGSTOP) Mutatee Signal Generator Thread Signal Handler Thread SIGSTOP Event Gate Wait for event: evtProcessStop block

University of Maryland A simple example: full stop Signal Generator decodes SIGSTOP and assigns event –Creates an Event with platform independent type evtProcessStop –Assigns Event to available SignalHandler Thread UI Thread kill (SIGSTOP) Mutatee Signal Generator Thread Signal Handler Thread SIGSTOP evtProcessStop Event Gate Wait for event: evtProcessStop block

University of Maryland A simple example: full stop Signal Hander handles evtProcessStop –Platform independent code for handling evtProcessStop –Signal waiting EventGates that evtProcessStop happened UI Thread kill (SIGSTOP) Mutatee Signal Generator Thread Signal Handler Thread SIGSTOP evtProcessStop Event Gate Wait for event: evtProcessStop Signal event: evtProcessStop block

University of Maryland A simple example: full stop Event Gate receives target event –Release UI Thread from block UI Thread kill (SIGSTOP) Mutatee Signal Generator Thread Signal Handler Thread SIGSTOP evtProcessStop Event Gate Wait for event: evtProcessStop Signal event: evtProcessStop resume block

University of Maryland A (slightly) more complex example User registers a DynLibrary Callback –When a library is loaded, insert some instrumentation UI Thread Mutatee Signal Generator Thread SH - 0 CB Manager register callback Mailbox SH - 1

University of Maryland A (slightly) more complex example Continue mutatee execution –Wait for it to exit –Mutatee runs UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox kill (SIGCONT) SH - 1 Event Gate

University of Maryland A (slightly) more complex example Eventually, mutatee executes dlopen() –Stops, sending SIGTRAP to mutator UI Thread Mutatee Signal Generator Thread SH - 0 SIGTRAP Block until exit event CB Manager register callback Continue execution Mailbox kill (SIGCONT) dlopen() SH - 1 Event Gate

University of Maryland A (slightly) more complex example SignalGenerator Decodes SIGTRAP –Analyzes runtime link maps, finds new library –Sends an evtLoadLibrary Event to a Signal Handler UI Thread Mutatee Signal Generator Thread SH - 0 SIGTRAP evtLoadLibrary Block until exit event CB Manager register callback Continue execution Mailbox kill (SIGCONT) dlopen() SH - 1 Event Gate

University of Maryland A (slightly) more complex example SignalHandler handles evtLoadLibrary –Adjusts Dyninst Internal State (platform indep) –Obtains relevant Callback from CBManager –“Executes” loadLibrary callback (zoom in to mailbox) UI Thread Mutatee Signal Generator Thread SH - 0 SIGTRAP evtLoadLibrary Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Event Gate

University of Maryland A (slightly) more complex example Callback Execution (zoom in): –Registers instance of callback with Mailbox (target = UI Thread) –Signals Event Gates that evtLoadLibrary happened –Blocks until completion of callback UI Thread SH - 0 Block until exit event Mailbox Event Gate CB Block until CB complete Signal evtLoadLibrary Register CB

University of Maryland A (slightly) more complex example UI Thread, signalled, wakes up –Checks mailbox and finds callback with target_thread == UIThread –But the Event does not match target –Executes callback (zoom back out… ) UI Thread SH - 0 Block until exit event Mailbox Event Gate CB Block until CB complete Signal evtLoadLibrary Register CB Wake up, Execute Callbacks CB

University of Maryland A (slightly) more complex example But the callback triggers another event –InsertSnippet needs to allocate memory before insertion –Issues inferiorMalloc RPC and blocks for its completion UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate block

University of Maryland A (slightly) more complex example Mutatee issues malloc() and traps SignalGenerator receives SIGTRAP –Discovers that we just completed a RPC UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate malloc() block SIGTRAP

University of Maryland A (slightly) more complex example SignalGenerator sees that SH-0 is busy (blocked) –Assigns evtRPCSignal event to SH-1 UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate malloc() block SIGTRAP evtRPCSignal

University of Maryland A (slightly) more complex example SH -1 handles RPC completion event –Manages Dyninst internal state (RPC Manager) –Signals Event Gates that evtRPCSignal happened UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate malloc() block SIGTRAP evtRPCSignal

University of Maryland A (slightly) more complex example EventGate waiting for evtRPCSignal wakes up –Releases UI thread from RPC block UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate malloc() block SIGTRAP evtRPCSignal

University of Maryland A (slightly) more complex example Callback finishes executing –Inserts instrumentation in newly malloc()’d space –SH-0 is released from blocking state UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate malloc() resume SIGTRAP evtRPCSignal

University of Maryland A (slightly) more complex example UI Thread resumes blocking for process exit –Inserts instrumentation in newly malloc()’d space –SH-0 is released from blocking state UI Thread Mutatee Signal Generator Thread SH - 0 Block until exit event CB Manager register callback Continue execution Mailbox dlopen() SH - 1 Inferior Malloc RPC Insert: resume block Event Gate malloc()

University of Maryland A (slightly) more complex example Finally, Mutatee Exits –evtProcessExit propagates through Event Handling –UI Thread is released from block UI Thread Mutatee Signal Generator Thread SH - 0 resume Block until exit event CB Manager register callback Continue execution Mailbox dlopen() exit() SH - 1 Event Gate malloc() evtProcessExit Signal event: evtProcessExit

University of Maryland Thread Inflation aside… Good things have emerged too… Unified Dyninst event concept –All event oriented subsystems operate on the same generic event concept Well, its really just a new c++ class Unified Dyninst event handling –Event handling framework is now platform independent –Dyninst takes uniform actions when specific events occur, across platforms More or less But more than before

University of Maryland Implications (future features) Finer grained Callback APIs –We currently have callbacks for events like LoadLibrary Process Exit Thread Creation –Now possible (and easy) to expose generic event callback to user Eg. Execute func() when mutatee receives signal S Eg. Execte func() when mutatee issues dlclose()

University of Maryland Implications (future features) Spin-off “Debugger API” library –Separate out code for process control, signal handling, other debugger-like operations into shared library –Requires solving some complex problems: Eg. How to deal with RPCs How much gets spun off? –This is a hard question to answer –Related RPC and shared-object subsytems are heavily intertwined. –Where to draw the line?