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

stapdyn porting systemtap onto dyninst
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

1

stapdyn: Porting SystemTap

  • nto Dyninst

Josh Stone & David Smith Performance Tools @ Red Hat April 29, 2013

slide-2
SLIDE 2

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

2

slide-3
SLIDE 3

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
slide-4
SLIDE 4

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
slide-5
SLIDE 5

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) }

slide-6
SLIDE 6

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

6

SystemTap runtime modes

stap (user privileges) Analyze the user script foo.stp Generate kernel source foo.c Compile kernel module foo.ko Load & Run foo.ko staprun (root privileges) Generate user source foo.c Compile user module foo.so Load & Run foo.so stapdyn (user privileges) mode

slide-7
SLIDE 7

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.
slide-8
SLIDE 8

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

8

child process foo.so SHM child process foo.so SHM

High-level view of stapdyn

libdyninstAPI.so stapdyn (user privileges) foo.so Shared Memory globals synchronization data transport target process foo.so SHM child process foo.so SHM create/ attach fork/exec

slide-9
SLIDE 9

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

9

Probe implementations

Examples of different probe points in Kernel and Dyninst modes

slide-10
SLIDE 10

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

10

Probe the beginning and end of everything

Kernel

  • Called directly in-kernel
  • Runs when the module

loads and unloads Dyninst

  • Called directly in stapdyn
  • Runs when stapdyn

starts and finishes begin end error

slide-11
SLIDE 11

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

11

Probe a specific process address

Kernel

  • Uses uprobes
  • Inserts a breakpoint
  • Runs in the process'

context, but transitions to ring-0 Dyninst

  • Direct instrumentation
  • fileOffsetToAddr()
  • insertSnippet()
  • Runs in-process, no ring
  • r context switches at all

process.function[.call|.inline] process.statement process.mark

slide-12
SLIDE 12

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

12

Probe when a function returns

Kernel

  • Uses uretprobes
  • Breakpoint on entry
  • Replaces stack PC with

a “trampoline” location

  • Runs in the process'

context, but transitions to ring-0, twice Dyninst

  • Direct instrumentation
  • fileOffsetToAddr()
  • getFunction()
  • findPoint(locExit)
  • insertSnippet()
  • Runs in-process, no ring
  • r context switches at all

process.function.return

slide-13
SLIDE 13

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

13

Probe the beginning and end of a process

Kernel

  • Uses utrace / tracepoints
  • On all forks and execs,

it's an end and a begin

  • On exit, it's just an end
  • Runs in the process'

context, already ring-0 for kernel setup Dyninst

  • processCreate()
  • processAttach()
  • Callbacks for postFork,

Exec, and Exit

  • RPC oneTimeCode()

process.begin process.end

slide-14
SLIDE 14

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

14

Probe the beginning and end of a thread

Kernel

  • Uses utrace / tracepoints
  • A clone() is a begin
  • A sys_exit, is an end
  • Runs in the process'

context, already ring-0 for kernel setup Dyninst

  • Uses threadEvent

callbacks

  • RPC oneTimeCode()

process.thread.begin process.thread.end

slide-15
SLIDE 15

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

15

Probe periodically

Kernel

  • Uses hrtimers
  • Runs in no specific

context Dyninst

  • POSIX timer
  • timer_create()
  • Runs directly in stapdyn

timer.{hz,s,ms,us,ns}

slide-16
SLIDE 16

PARADYN WEEK 2013 | JOSH STONE & DAVID SMITH

16

Unimplemented probes

Impossible: kernel.* kprobe.* module.* netfilter.* perf.* (?) Maybe possible: process.syscall timer.profile procfs.* (similar)

slide-17
SLIDE 17

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

slide-18
SLIDE 18

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
slide-19
SLIDE 19

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>