]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'perf-uprobes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 May 2012 18:39:34 +0000 (11:39 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 May 2012 18:39:34 +0000 (11:39 -0700)
Pull user-space probe instrumentation from Ingo Molnar:
 "The uprobes code originates from SystemTap and has been used for years
  in Fedora and RHEL kernels.  This version is much rewritten, reviews
  from PeterZ, Oleg and myself shaped the end result.

  This tree includes uprobes support in 'perf probe' - but SystemTap
  (and other tools) can take advantage of user probe points as well.

  Sample usage of uprobes via perf, for example to profile malloc()
  calls without modifying user-space binaries.

  First boot a new kernel with CONFIG_UPROBE_EVENT=y enabled.

  If you don't know which function you want to probe you can pick one
  from 'perf top' or can get a list all functions that can be probed
  within libc (binaries can be specified as well):

$ perf probe -F -x /lib/libc.so.6

  To probe libc's malloc():

$ perf probe -x /lib64/libc.so.6 malloc
Added new event:
probe_libc:malloc    (on 0x7eac0)

  You can now use it in all perf tools, such as:

perf record -e probe_libc:malloc -aR sleep 1

  Make use of it to create a call graph (as the flat profile is going to
  look very boring):

$ perf record -e probe_libc:malloc -gR make
[ perf record: Woken up 173 times to write data ]
[ perf record: Captured and wrote 44.190 MB perf.data (~1930712

$ perf report | less

  32.03%            git  libc-2.15.so   [.] malloc
                    |
                    --- malloc

  29.49%            cc1  libc-2.15.so   [.] malloc
                    |
                    --- malloc
                       |
                       |--0.95%-- 0x208eb1000000000
                       |
                       |--0.63%-- htab_traverse_noresize

  11.04%             as  libc-2.15.so   [.] malloc
                     |
                     --- malloc
                        |

   7.15%             ld  libc-2.15.so   [.] malloc
                     |
                     --- malloc
                        |

   5.07%             sh  libc-2.15.so   [.] malloc
                     |
                     --- malloc
                        |
   4.99%  python-config  libc-2.15.so   [.] malloc
          |
          --- malloc
             |
   4.54%           make  libc-2.15.so   [.] malloc
                   |
                   --- malloc
                      |
                      |--7.34%-- glob
                      |          |
                      |          |--93.18%-- 0x41588f
                      |          |
                      |           --6.82%-- glob
                      |                     0x41588f

   ...

  Or:

$ perf report -g flat | less

# Overhead        Command  Shared Object      Symbol
# ........  .............  .............  ..........
#
  32.03%            git  libc-2.15.so   [.] malloc
          27.19%
              malloc

  29.49%            cc1  libc-2.15.so   [.] malloc
          24.77%
              malloc

  11.04%             as  libc-2.15.so   [.] malloc
          11.02%
              malloc

   7.15%             ld  libc-2.15.so   [.] malloc
           6.57%
              malloc

 ...

  The core uprobes design is fairly straightforward: uprobes probe
  points register themselves at (inode:offset) addresses of
  libraries/binaries, after which all existing (or new) vmas that map
  that address will have a software breakpoint injected at that address.
  vmas are COW-ed to preserve original content.  The probe points are
  kept in an rbtree.

  If user-space executes the probed inode:offset instruction address
  then an event is generated which can be recovered from the regular
  perf event channels and mmap-ed ring-buffer.

  Multiple probes at the same address are supported, they create a
  dynamic callback list of event consumers.

  The basic model is further complicated by the XOL speedup: the
  original instruction that is probed is copied (in an architecture
  specific fashion) and executed out of line when the probe triggers.
  The XOL area is a single vma per process, with a fixed number of
  entries (which limits probe execution parallelism).

  The API: uprobes are installed/removed via
  /sys/kernel/debug/tracing/uprobe_events, the API is integrated to
  align with the kprobes interface as much as possible, but is separate
  to it.

  Injecting a probe point is privileged operation, which can be relaxed
  by setting perf_paranoid to -1.

  You can use multiple probes as well and mix them with kprobes and
  regular PMU events or tracepoints, when instrumenting a task."

Fix up trivial conflicts in mm/memory.c due to previous cleanup of
unmap_single_vma().

* 'perf-uprobes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (21 commits)
  perf probe: Detect probe target when m/x options are absent
  perf probe: Provide perf interface for uprobes
  tracing: Fix kconfig warning due to a typo
  tracing: Provide trace events interface for uprobes
  tracing: Extract out common code for kprobes/uprobes trace events
  tracing: Modify is_delete, is_return from int to bool
  uprobes/core: Decrement uprobe count before the pages are unmapped
  uprobes/core: Make background page replacement logic account for rss_stat counters
  uprobes/core: Optimize probe hits with the help of a counter
  uprobes/core: Allocate XOL slots for uprobes use
  uprobes/core: Handle breakpoint and singlestep exceptions
  uprobes/core: Rename bkpt to swbp
  uprobes/core: Make order of function parameters consistent across functions
  uprobes/core: Make macro names consistent
  uprobes: Update copyright notices
  uprobes/core: Move insn to arch specific structure
  uprobes/core: Remove uprobe_opcode_sz
  uprobes/core: Make instruction tables volatile
  uprobes: Move to kernel/events/
  uprobes/core: Clean up, refactor and improve the code
  ...

14 files changed:
1  2 
arch/Kconfig
arch/x86/Kconfig
arch/x86/include/asm/thread_info.h
arch/x86/kernel/Makefile
arch/x86/kernel/signal.c
include/linux/sched.h
kernel/fork.c
kernel/signal.c
kernel/trace/Kconfig
kernel/trace/Makefile
kernel/trace/trace.h
mm/memory.c
mm/mmap.c
tools/perf/util/symbol.c

diff --cc arch/Kconfig
Simple merge
index d6168994e11585814d356b45cc106554f4c3e9ca,8443c50fbbf6eebeb20edbd888cf04c4fe00528e..0b2d5f24c946e7a0ef96571db2e48c9c666136ac
@@@ -81,13 -80,10 +81,13 @@@ config X8
        select CLKEVT_I8253
        select ARCH_HAVE_NMI_SAFE_CMPXCHG
        select GENERIC_IOMAP
 -      select DCACHE_WORD_ACCESS if !DEBUG_PAGEALLOC
 +      select DCACHE_WORD_ACCESS
 +      select GENERIC_SMP_IDLE_THREAD
 +      select HAVE_ARCH_SECCOMP_FILTER
 +      select BUILDTIME_EXTABLE_SORT
  
  config INSTRUCTION_DECODER
-       def_bool (KPROBES || PERF_EVENTS)
+       def_bool (KPROBES || PERF_EVENTS || UPROBES)
  
  config OUTPUT_FORMAT
        string
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc kernel/fork.c
Simple merge
diff --cc kernel/signal.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc mm/memory.c
index 1e77da6d82c1ef8b5c96ede4c7be04c7d38771dd,bf8b4035277da312b53bfcb796fb033faf1f576a..e40f6759ba98b9ebb0ad7af82e6cef6a13382942
@@@ -1307,6 -1307,12 +1307,9 @@@ static void unmap_single_vma(struct mmu
        if (end <= vma->vm_start)
                return;
  
 -      if (vma->vm_flags & VM_ACCOUNT)
 -              *nr_accounted += (end - start) >> PAGE_SHIFT;
 -
+       if (vma->vm_file)
+               uprobe_munmap(vma, start, end);
        if (unlikely(is_pfn_mapping(vma)))
                untrack_pfn_vma(vma, 0, 0);
  
diff --cc mm/mmap.c
Simple merge
Simple merge