stapdyn porting systemtap onto dyninst
play

stapdyn: Porting SystemTap onto Dyninst Josh Stone & David - PowerPoint PPT Presentation

stapdyn: Porting SystemTap onto Dyninst Josh Stone & David Smith Performance Tools @ Red Hat April 29, 2013 1 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH 2 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH stapdyn: Porting SystemTap


  1. stapdyn: Porting SystemTap onto Dyninst Josh Stone & David Smith Performance Tools @ Red Hat April 29, 2013 1 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  2. 2 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  3. stapdyn: Porting SystemTap onto Dyninst ● Motivation for porting to Dyninst ● Overview of SystemTap operation ● Porting all the probe types ● Porting the runtime and tapset ● Wish list for Dyninst 3 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  4. Motivation ● User Privilege ● Attach to one's own processes freely ● No setuid helper necessary ● Performance ● Run instrumentation directly ● Stability ● We always strive for probe safety, but... ● Only participating processes are at risk 4 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  5. Anatomy of a SystemTap script global foo function total(p, n) { return (foo[p] += n) } probe process.function("foo") { t = total(pid(), $var->member) if (t > 1000) printf("%s(%d) total %d\n", execname(), pid(), t) } 5 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  6. SystemTap runtime modes staprun (root privileges) stap (user privileges) Load & Run Generate Compile kernel source kernel module foo.c foo.ko foo.ko Analyze the user script mode stapdyn (user privileges) foo.stp Generate Compile Load & Run user source user module foo.c foo.so foo.so 6 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  7. Contents of a generated module ● Every compiled “foo.so” contains: ● Metadata describing the probe types and locations ● Instrumentation entry functions for each probe type ● Code for the user's functions and probe handlers ● Runtime code for shared memory, data output, etc. 7 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  8. High-level view of stapdyn target process stapdyn (user privileges) create/ foo.so attach libdyninstAPI.so foo.so SHM fork/exec child process child process child process Shared Memory foo.so foo.so globals foo.so synchronization data transport SHM SHM SHM 8 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  9. Probe implementations Examples of different probe points in Kernel and Dyninst modes 9 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  10. Probe the beginning and end of everything begin end error Dyninst Kernel ● Called directly in stapdyn ● Called directly in-kernel ● Runs when stapdyn ● Runs when the module starts and finishes loads and unloads 10 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  11. Probe a specific process address process.function[.call|.inline] process.statement process.mark Dyninst Kernel ● Direct instrumentation ● Uses uprobes ● Inserts a breakpoint ● fileOffsetToAddr() ● Runs in the process' ● insertSnippet() context, but transitions to ● Runs in-process, no ring ring-0 or context switches at all 11 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  12. Probe when a function returns process.function.return Dyninst Kernel ● Direct instrumentation ● Uses uretprobes ● fileOffsetToAddr() ● Breakpoint on entry ● Replaces stack PC with ● getFunction() a “trampoline” location ● findPoint(locExit) ● Runs in the process' ● insertSnippet() context, but transitions to ● Runs in-process, no ring ring-0, twice or context switches at all 12 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  13. Probe the beginning and end of a process process.begin process.end Dyninst Kernel ● Uses utrace / tracepoints ● processCreate() ● processAttach() ● On all forks and execs, it's an end and a begin ● Callbacks for postFork , ● On exit, it's just an end Exec , and Exit ● Runs in the process' ● RPC oneTimeCode() context, already ring-0 for kernel setup 13 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  14. Probe the beginning and end of a thread process.thread.begin process.thread.end Dyninst Kernel ● Uses threadEvent ● Uses utrace / tracepoints callbacks ● A clone() is a begin ● RPC oneTimeCode() ● A sys_exit, is an end ● Runs in the process' context, already ring-0 for kernel setup 14 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  15. Probe periodically timer.{hz,s,ms,us,ns} Dyninst Kernel ● POSIX timer ● Uses hrtimers ● Runs in no specific ● timer_create() context ● Runs directly in stapdyn 15 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  16. Unimplemented probes Impossible: Maybe possible: kernel.* process.syscall kprobe.* timer.profile module.* procfs.* (similar) netfilter.* perf.* (?) 16 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  17. Porting the runtime and tapsets ● Much is shared code, forked for different APIs ● Userspace APIs are more stable than the kernel's ● Runtime changes locking, shared memory, transport ● Tapset functions also change ● cpu(): smp_processor_id() vs. sched_getcpu() ● Most tapset probepoints don't really translate ● scheduler.* syscall.* vfs.* So far, the userspace code is not really Dyninst-specific 17 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  18. Dyninst wishlist ● Cooperation with exception handling ● Instrumentation confuses the unwinder ● Fuller register access ● Currently missing 32-bit x86 ● Direct pt_regs would be nice ● Hook system calls (e.g. PTRACE_SYSCALL) ● Support for ARM and AArch64 ● Use elfutils' libdw instead of libdwarf 18 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

  19. http://sourceware.org/systemtap systemtap@sourceware.org Josh Stone <jistone@redhat.com> David Smith <dsmith@redhat.com> 19 PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend