1. 24 11月, 2015 4 次提交
  2. 20 11月, 2015 14 次提交
    • N
      perf hists browser: Support flat callchains · 4b3a3212
      Namhyung Kim 提交于
      The flat callchain mode is to print all chains in a single, simple
      hierarchy so make it easy to see.
      
      Currently perf report --tui doesn't show flat callchains properly.  With
      flat callchains, only leaf nodes are added to the final rbtree so it
      should show entries in parent nodes.  To do that, add parent_val list to
      struct callchain_node and show them along with the (normal) val list.
      
      For example, consider following callchains with '-g graph'.
      
        $ perf report -g graph
        - 39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
             intel_idle
             cpuidle_enter_state
             cpuidle_enter
             call_cpuidle
           - cpu_startup_entry
                28.63% start_secondary
              - 11.30% rest_init
                   start_kernel
                   x86_64_start_reservations
                   x86_64_start_kernel
      
      Before:
        $ perf report -g flat
        - 39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
             28.63% start_secondary
           - 11.30% rest_init
                start_kernel
                x86_64_start_reservations
                x86_64_start_kernel
      
      After:
        $ perf report -g flat
        - 39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
           - 28.63% intel_idle
                cpuidle_enter_state
                cpuidle_enter
                call_cpuidle
                cpu_startup_entry
                start_secondary
           - 11.30% intel_idle
                cpuidle_enter_state
                cpuidle_enter
                call_cpuidle
                cpu_startup_entry
                start_kernel
                x86_64_start_reservations
                x86_64_start_kernel
      Signed-off-by: NNamhyung Kim <namhyung@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1447047946-1691-8-git-send-email-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4b3a3212
    • N
      perf report: Add callchain value option · f2af0086
      Namhyung Kim 提交于
      Now -g/--call-graph option supports how to display callchain values.
      Possible values are 'percent', 'period' and 'count'.  The percent is
      same as before and it's the default behavior.  The period displays the
      raw period value rather than the percentage.  The count displays the
      number of occurrences.
      
        $ perf report --no-children --stdio -g percent
        ...
          39.93%  swapper  [kernel.vmlinux]  [k] intel_idel
                  |
                  ---intel_idle
                     cpuidle_enter_state
                     cpuidle_enter
                     call_cpuidle
                     cpu_startup_entry
                     |
                     |--28.63%-- start_secondary
                     |
                      --11.30%-- rest_init
      
        $ perf report --no-children --show-total-period --stdio -g period
        ...
          39.93%   13018705  swapper  [kernel.vmlinux]  [k] intel_idel
                  |
                  ---intel_idle
                     cpuidle_enter_state
                     cpuidle_enter
                     call_cpuidle
                     cpu_startup_entry
                     |
                     |--9334403-- start_secondary
                     |
                      --3684302-- rest_init
      
        $ perf report --no-children --show-nr-samples --stdio -g count
        ...
          39.93%     80  swapper  [kernel.vmlinux]  [k] intel_idel
                  |
                  ---intel_idle
                     cpuidle_enter_state
                     cpuidle_enter
                     call_cpuidle
                     cpu_startup_entry
                     |
                     |--57-- start_secondary
                     |
                      --23-- rest_init
      Signed-off-by: NNamhyung Kim <namhyung@kernel.org>
      Acked-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1447047946-1691-6-git-send-email-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f2af0086
    • N
      perf callchain: Add count fields to struct callchain_node · 5e47f8ff
      Namhyung Kim 提交于
      It's to track the count of occurrences of the callchains.
      Signed-off-by: NNamhyung Kim <namhyung@kernel.org>
      Acked-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1447047946-1691-5-git-send-email-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5e47f8ff
    • N
      perf callchain: Abstract callchain print function · 5ab250ca
      Namhyung Kim 提交于
      This is a preparation to support for printing other type of callchain
      value like count or period.
      Signed-off-by: NNamhyung Kim <namhyung@kernel.org>
      Tested-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1447047946-1691-4-git-send-email-namhyung@kernel.org
      [ renamed new _sprintf_ operation to _scnprintf_ ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5ab250ca
    • N
      perf report: Support folded callchain mode on --stdio · 26e77924
      Namhyung Kim 提交于
      Add new call chain option (-g) 'folded' to print callchains in a line.
      The callchains are separated by semicolons, and preceded by (absolute)
      percent values and a space.
      
      For example, the following 20 lines can be printed in 3 lines with the
      folded output mode:
      
        $ perf report -g flat --no-children | grep -v ^# | head -20
            60.48%  swapper  [kernel.vmlinux]  [k] intel_idle
                    54.60%
                       intel_idle
                       cpuidle_enter_state
                       cpuidle_enter
                       call_cpuidle
                       cpu_startup_entry
                       start_secondary
      
                    5.88%
                       intel_idle
                       cpuidle_enter_state
                       cpuidle_enter
                       call_cpuidle
                       cpu_startup_entry
                       rest_init
                       start_kernel
                       x86_64_start_reservations
                       x86_64_start_kernel
      
        $ perf report -g folded --no-children | grep -v ^# | head -3
            60.48%  swapper  [kernel.vmlinux]  [k] intel_idle
        54.60% intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary
        5.88% intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel
      
      This mode is supported only for --stdio now and intended to be used by
      some scripts like in FlameGraphs[1].  Support for other UI might be
      added later.
      
      [1] http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.htmlRequested-and-Tested-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Signed-off-by: NNamhyung Kim <namhyung@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1447047946-1691-2-git-send-email-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      26e77924
    • M
      perf machine: Fix machine__findnew_module_map to put dso · 566c69c3
      Masami Hiramatsu 提交于
      Fix machine__findnew_module_map to drop the reference to the dso because
      it is already referenced by both machine__findnew_module_dso() and
      map__new2().
      
      Refcnt debugger shows:
      
        ==== [1] ====
        Unreclaimed dso: 0x1ffd980
        Refcount +1 => 1 at
          ./perf(dso__new+0x1ff) [0x4a62df]
          ./perf(__dsos__addnew+0x29) [0x4a6e19]
          ./perf() [0x4b8b91]
          ./perf(modules__parse+0xfc) [0x4a9d5c]
          ./perf() [0x4b8460]
          ./perf(machine__create_kernel_maps+0x150) [0x4bb550]
          ./perf(machine__new_host+0xfa) [0x4bb75a]
          ./perf(init_probe_symbol_maps+0x93) [0x506623]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1345a8eaf5]
          ./perf() [0x4220a9]
      
      This map_groups__insert(0x4b8b91) already gets a reference to the new
      dso:
      
        ----
        eu-addr2line -e ./perf -f 0x4b8b91
        map_groups__insert inlined at util/machine.c:586 in
        machine__create_module
        util/map.h:207
        ----
      
      So this dso refcnt will be released when map_groups gets released.
      
        [snip]
        Refcount +1 => 2 at
          ./perf(dso__get+0x34) [0x4a65f4]
          ./perf() [0x4b8b35]
          ./perf(modules__parse+0xfc) [0x4a9d5c]
          ./perf() [0x4b8460]
          ./perf(machine__create_kernel_maps+0x150) [0x4bb550]
          ./perf(machine__new_host+0xfa) [0x4bb75a]
          ./perf(init_probe_symbol_maps+0x93) [0x506623]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1345a8eaf5]
          ./perf() [0x4220a9]
      
      Here, machine__findnew_module_dso(0x4b8b35) gets the dso (and stores it
      in a local variable):
      
        ----
        # eu-addr2line -e ./perf -f 0x4b8b35
        machine__findnew_module_dso inlined at util/machine.c:578 in
        machine__create_module
        util/machine.c:514
        ----
      
        Refcount +1 => 3 at
          ./perf(dso__get+0x34) [0x4a65f4]
          ./perf(map__new2+0x76) [0x4be1c6]
          ./perf() [0x4b8b4f]
          ./perf(modules__parse+0xfc) [0x4a9d5c]
          ./perf() [0x4b8460]
          ./perf(machine__create_kernel_maps+0x150) [0x4bb550]
          ./perf(machine__new_host+0xfa) [0x4bb75a]
          ./perf(init_probe_symbol_maps+0x93) [0x506623]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1345a8eaf5]
          ./perf() [0x4220a9]
      
      But also map__new2() gets the dso which will be put when the map is
      released.
      
      So, we have to drop the constructor reference obtained in
      machine__findnew_module_dso().
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064035.30709.58824.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      566c69c3
    • M
      perf tools: Fix machine__create_kernel_maps to put kernel dso refcount · 1154c957
      Masami Hiramatsu 提交于
      Fix machine__create_kernel_maps() to put kernel dso because the dso has
      been gotten via __machine__create_kernel_maps().
      
      Refcnt debugger shows:
        ==== [0] ====
        Unreclaimed dso: 0x3036ab0
        Refcount +1 => 1 at
          ./perf(dso__new+0x1ff) [0x4a62df]
          ./perf(__dsos__addnew+0x29) [0x4a6e19]
          ./perf(dsos__findnew+0xd1) [0x4a7181]
          ./perf(machine__findnew_kernel+0x27) [0x4a5e17]
          ./perf() [0x4b8cf2]
          ./perf(machine__create_kernel_maps+0x28) [0x4bb428]
          ./perf(machine__new_host+0xfa) [0x4bb74a]
          ./perf(init_probe_symbol_maps+0x93) [0x506613]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffa6809eaf5]
          ./perf() [0x4220a9]
        [snip]
        Refcount +1 => 2 at
          ./perf(dsos__findnew+0x7e) [0x4a712e]
          ./perf(machine__findnew_kernel+0x27) [0x4a5e17]
          ./perf() [0x4b8cf2]
          ./perf(machine__create_kernel_maps+0x28) [0x4bb428]
          ./perf(machine__new_host+0xfa) [0x4bb74a]
          ./perf(init_probe_symbol_maps+0x93) [0x506613]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffa6809eaf5]
          ./perf() [0x4220a9]
        [snip]
        Refcount -1 => 1 at
          ./perf(dso__put+0x2f) [0x4a664f]
          ./perf(machine__delete+0xfe) [0x4b93ee]
          ./perf(exit_probe_symbol_maps+0x28) [0x5066b8]
          ./perf() [0x45628a]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffa6809eaf5]
          ./perf() [0x4220a9]
      
      Actually, dsos__findnew gets the dso before returning it, so the dso
      user (in this case machine__create_kernel_maps) has to put the dso after
      used.
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064033.30709.98954.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1154c957
    • M
      perf tools: Fix __dsos__addnew to put dso after adding it to the list · 82de26ab
      Masami Hiramatsu 提交于
      __dsos__addnew should drop the constructor reference to dso after adding
      it to the list, because __dsos__add() will get a reference that will be
      kept while it is in the list.
      
      This fixes DSO leaks when entries are removed to the list and the refcount
      never gets to zero.
      
      Refcnt debugger shows:
        ==== [0] ====
        Unreclaimed dso: 0x2fccab0
        Refcount +1 => 1 at
          ./perf(dso__new+0x1ff) [0x4a62df]
          ./perf(__dsos__addnew+0x29) [0x4a6e19]
          ./perf(dsos__findnew+0xd1) [0x4a7281]
          ./perf(machine__findnew_kernel+0x27) [0x4a5e17]
          ./perf() [0x4b8df2]
          ./perf(machine__create_kernel_maps+0x28) [0x4bb528]
          ./perf(machine__new_host+0xfa) [0x4bb84a]
          ./perf(init_probe_symbol_maps+0x93) [0x506713]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f46df132af5]
          ./perf() [0x4220a9]
        Refcount +1 => 2 at
          ./perf(__dsos__addnew+0xfb) [0x4a6eeb]
          ./perf(dsos__findnew+0xd1) [0x4a7281]
          ./perf(machine__findnew_kernel+0x27) [0x4a5e17]
          ./perf() [0x4b8df2]
          ./perf(machine__create_kernel_maps+0x28) [0x4bb528]
          ./perf(machine__new_host+0xfa) [0x4bb84a]
          ./perf(init_probe_symbol_maps+0x93) [0x506713]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f46df132af5]
          ./perf() [0x4220a9]
        Refcount +1 => 3 at
          ./perf(dsos__findnew+0x7e) [0x4a722e]
          ./perf(machine__findnew_kernel+0x27) [0x4a5e17]
          ./perf() [0x4b8df2]
          ./perf(machine__create_kernel_maps+0x28) [0x4bb528]
          ./perf(machine__new_host+0xfa) [0x4bb84a]
          ./perf(init_probe_symbol_maps+0x93) [0x506713]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f46df132af5]
          ./perf() [0x4220a9]
        [snip]
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064031.30709.81460.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      82de26ab
    • M
      perf tools: Fix to put new map after inserting to map_groups in dso__load_sym · 8d5c340d
      Masami Hiramatsu 提交于
      Fix dso__load_sym to put the map object which is already
      insterted to kmaps.
      
      Refcnt debugger shows
        ==== [0] ====
        Unreclaimed map: 0x39113e0
        Refcount +1 => 1 at
          ./perf(map__new2+0xb5) [0x4be155]
          ./perf(dso__load_sym+0xee1) [0x503461]
          ./perf(dso__load_vmlinux+0xbf) [0x4aa6df]
          ./perf(dso__load_vmlinux_path+0x8c) [0x4aa83c]
          ./perf() [0x50528a]
          ./perf(convert_perf_probe_events+0xd79) [0x50ac29]
          ./perf() [0x45600f]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f152368baf5]
          ./perf() [0x4220a9]
        Refcount +1 => 2 at
          ./perf(maps__insert+0x9a) [0x4bfffa]
          ./perf(dso__load_sym+0xf89) [0x503509]
          ./perf(dso__load_vmlinux+0xbf) [0x4aa6df]
          ./perf(dso__load_vmlinux_path+0x8c) [0x4aa83c]
          ./perf() [0x50528a]
          ./perf(convert_perf_probe_events+0xd79) [0x50ac29]
          ./perf() [0x45600f]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f152368baf5]
          ./perf() [0x4220a9]
        Refcount -1 => 1 at
          ./perf(map_groups__exit+0x94) [0x4bed04]
          ./perf(machine__delete+0xb0) [0x4b9300]
          ./perf(exit_probe_symbol_maps+0x28) [0x506608]
          ./perf() [0x45628a]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f152368baf5]
          ./perf() [0x4220a9]
      
      This means that the dso__load_sym calls map__new2 and maps_insert, both
      of them bump the map refcount, but map_groups__exit will drop just one
      reference.
      
      Fix it by dropping the refcount after inserting it into kmaps.
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064026.30709.50038.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8d5c340d
    • M
      perf tools: Make perf_exec_path() always return malloc'd string · c4068f51
      Masami Hiramatsu 提交于
      Since system_path() returns malloc'd string if given path is not an
      absolute path, perf_exec_path() sometimes returns a static string and
      sometimes returns a malloc'd string depending on the environment
      variables or command options.
      
      This may cause a memory leak because the caller can not unconditionally
      free the returned string.
      
      This fixes perf_exec_path() and system_path() to always return a
      malloc'd string, so the caller can always free it.
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151119060453.14210.65666.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c4068f51
    • M
      perf machine: Fix to destroy kernel maps when machine exits · ebe9729c
      Masami Hiramatsu 提交于
      Actually machine__exit forgot to call machine__destroy_kernel_maps.
      
      This fixes some memory leaks on map as below.
      
      Without this fix.
        ----
        ./perf probe vfs_read
        Added new event:
          probe:vfs_read       (on vfs_read)
      
        You can now use it in all perf tools, such as:
      
                perf record -e probe:vfs_read -aR sleep 1
      
        REFCNT: BUG: Unreclaimed objects found.
        REFCNT: Total 4 objects are not reclaimed.
           To see all backtraces, rerun with -v option
        ----
      With this fix.
        ----
        ./perf probe vfs_read
        Added new event:
          probe:vfs_read       (on vfs_read)
      
        You can now use it in all perf tools, such as:
      
                perf record -e probe:vfs_read -aR sleep 1
      
        REFCNT: BUG: Unreclaimed objects found.
        REFCNT: Total 2 objects are not reclaimed.
           To see all backtraces, rerun with -v option
        ----
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064024.30709.43577.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ebe9729c
    • M
      perf machine: Fix machine__destroy_kernel_maps to drop vmlinux_maps references · e96e4078
      Masami Hiramatsu 提交于
      Fix machine__destroy_kernel_maps() to drop vmlinux_maps references
      before filling it with NULL.
      
      Refcnt debugger shows
        ==== [1] ====
        Unreclaimed map: 0x36b1070
        Refcount +1 => 1 at
          ./perf(map__new2+0xb5) [0x4bdec5]
          ./perf(machine__create_kernel_maps+0x72) [0x4bb152]
          ./perf(machine__new_host+0xfa) [0x4bb41a]
          ./perf(init_probe_symbol_maps+0x93) [0x5062d3]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1fc9fc4af5]
          ./perf() [0x4220a9]
        Refcount +1 => 2 at
          ./perf(maps__insert+0x9a) [0x4bfd6a]
          ./perf(machine__create_kernel_maps+0xc3) [0x4bb1a3]
          ./perf(machine__new_host+0xfa) [0x4bb41a]
          ./perf(init_probe_symbol_maps+0x93) [0x5062d3]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1fc9fc4af5]
          ./perf() [0x4220a9]
        Refcount -1 => 1 at
          ./perf(map_groups__exit+0x94) [0x4bea74]
          ./perf(machine__delete+0x3d) [0x4b91fd]
          ./perf(exit_probe_symbol_maps+0x28) [0x506378]
          ./perf() [0x45628a]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1fc9fc4af5]
          ./perf() [0x4220a9]
      
      map__new2() returns map with refcnt = 1, and also map_groups__insert
      gets it again in__machine__create_kernel_maps().
      
      machine__destroy_kernel_maps() calls map_groups__remove() to
      decrement the refcnt, but before decrement it again (corresponding
      to map__new2), it makes vmlinux_maps[type] = NULL. And this may
      cause a refcnt leak.
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064022.30709.3897.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e96e4078
    • M
      perf machine: Fix machine__findnew_module_map to put registered map · 9afcb420
      Masami Hiramatsu 提交于
      Fix machine object to drop the reference to the map object after it
      inserted it into machine->kmaps.
      
      refcnt debugger shows what happened:
        ----
        ==== [2] ====
        Unreclaimed map: 0x346f750
        Refcount +1 => 1 at
          ./perf(map__new2+0xb5) [0x4bdea5]
          ./perf() [0x4b8aaf]
          ./perf(modules__parse+0xfc) [0x4a9cbc]
          ./perf() [0x4b83c0]
          ./perf(machine__create_kernel_maps+0x148) [0x4bb208]
          ./perf(machine__new_host+0xfa) [0x4bb3fa]
          ./perf(init_probe_symbol_maps+0x93) [0x5062b3]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5373899af5]
          ./perf() [0x4220a9]
        Refcount +1 => 2 at
          ./perf(maps__insert+0x9a) [0x4bfd4a]
          ./perf() [0x4b8acb]
          ./perf(modules__parse+0xfc) [0x4a9cbc]
          ./perf() [0x4b83c0]
          ./perf(machine__create_kernel_maps+0x148) [0x4bb208]
          ./perf(machine__new_host+0xfa) [0x4bb3fa]
          ./perf(init_probe_symbol_maps+0x93) [0x5062b3]
          ./perf() [0x455ffa]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5373899af5]
          ./perf() [0x4220a9]
        Refcount -1 => 1 at
          ./perf(map_groups__exit+0x94) [0x4bea54]
          ./perf(machine__delete+0x3d) [0x4b91ed]
          ./perf(exit_probe_symbol_maps+0x28) [0x506358]
          ./perf() [0x45628a]
          ./perf(cmd_probe+0x6c) [0x4566bc]
          ./perf() [0x47abc5]
          ./perf(main+0x610) [0x421f90]
          /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5373899af5]
          ./perf() [0x4220a9]
        ----
      
      This pattern clearly shows that the refcnt of the map is acquired twice
      by map__new2 and maps__insert but released onlu once at
      map_groups__exit, when we purge its maps rbtree.
      
      Since maps__insert already reference counted the map, we have to drop
      the constructor (map__new2) reference count right after inserting it.
      
      These happened in machine__findnew_module_map, as below.
      
        ----
        # eu-addr2line -e ./perf -f 0x4b8aaf
        machine__findnew_module_map inlined at util/machine.c:1046
        in machine__create_module
        util/machine.c:582
        # eu-addr2line -e ./perf -f 0x4b8acb
        map_groups__insert inlined at util/machine.c:585
        in machine__create_module
        util/map.h:208
        ----
      
      (note that both are at util/machine.c:58X which is
       machine__findnew_module_map)
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064020.30709.40499.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9afcb420
    • M
      perf probe: Fix to free temporal Dwarf_Frame · 05c8d802
      Masami Hiramatsu 提交于
      Since dwarf_cfi_addrframe returns malloc'd Dwarf_Frame object, it has to
      be freed after it is used.
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/20151118064011.30709.65674.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      05c8d802
  3. 19 11月, 2015 7 次提交
    • W
      perf bpf: Use same BPF program if arguments are identical · d35b3289
      Wang Nan 提交于
      This patch allows creating only one BPF program for different
      'probe_trace_event'(tev) entries generated by one
      'perf_probe_event'(pev) if their prologues are identical.
      
      This is done by comparing the argument list of different tev instances,
      and the maps type of prologue and tev using a mapping array. This patch
      utilizes qsort to sort the tevs. After sorting, tevs with identical
      argument lists will be grouped together.
      
      Test result:
      
      Sample BPF program:
      
        #define SEC(NAME) __attribute__((section(NAME), used))
        SEC("inlines=no;"
            "func=SyS_dup? oldfd")
        int func(void *ctx)
        {
            return 1;
        }
      
      It would probe at SyS_dup2 and SyS_dup3, obtaining oldfd as its
      argument.
      
      The following cmdline shows a BPF program being loaded into the kernel
      by perf:
      
       # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog
      
      Before this patch:
      
        # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog
        [1] 24858
        lrwx------ 1 root root 64 Nov 14 04:09 3 -> anon_inode:bpf-prog
        lrwx------ 1 root root 64 Nov 14 04:09 4 -> anon_inode:bpf-prog
        ...
      
      After this patch:
      
        # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog
        [1] 25699
        lrwx------ 1 root root 64 Nov 14 04:10 3 -> anon_inode:bpf-prog
        ...
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447749170-175898-3-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d35b3289
    • W
      perf bpf: Generate prologue for BPF programs · a08357d8
      Wang Nan 提交于
      This patch generates a prologue for each 'struct probe_trace_event' for
      fetching arguments for BPF programs.
      
      After bpf__probe(), iterate over each program to check whether prologues are
      required. If none of the 'struct perf_probe_event' programs will attach to have
      at least one argument, simply skip preprocessor hooking. For those who a
      prologue is required, call bpf__gen_prologue() and paste the original
      instruction after the prologue.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-12-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a08357d8
    • H
      perf bpf: Add prologue for BPF programs for fetching arguments · bfc077b4
      He Kuang 提交于
      This patch generates a prologue for a BPF program which fetches arguments for
      it.  With this patch, the program can have arguments as follow:
      
        SEC("lock_page=__lock_page page->flags")
        int lock_page(struct pt_regs *ctx, int err, unsigned long flags)
        {
       	 return 1;
        }
      
      This patch passes at most 3 arguments from r3, r4 and r5. r1 is still the ctx
      pointer. r2 is used to indicate if dereferencing was done successfully.
      
      This patch uses r6 to hold ctx (struct pt_regs) and r7 to hold stack pointer
      for result. Result of each arguments first store on stack:
      
       low address
       BPF_REG_FP - 24  ARG3
       BPF_REG_FP - 16  ARG2
       BPF_REG_FP - 8   ARG1
       BPF_REG_FP
       high address
      
      Then loaded into r3, r4 and r5.
      
      The output prologue for offn(...off2(off1(reg)))) should be:
      
           r6 <- r1			// save ctx into a callee saved register
           r7 <- fp
           r7 <- r7 - stack_offset	// pointer to result slot
           /* load r3 with the offset in pt_regs of 'reg' */
           (r7) <- r3			// make slot valid
           r3 <- r3 + off1		// prepare to read unsafe pointer
           r2 <- 8
           r1 <- r7			// result put onto stack
           call probe_read		// read unsafe pointer
           jnei r0, 0, err		// error checking
           r3 <- (r7)			// read result
           r3 <- r3 + off2		// prepare to read unsafe pointer
           r2 <- 8
           r1 <- r7
           call probe_read
           jnei r0, 0, err
           ...
           /* load r2, r3, r4 from stack */
           goto success
      err:
           r2 <- 1
           /* load r3, r4, r5 with 0 */
           goto usercode
      success:
           r2 <- 0
      usercode:
           r1 <- r6	// restore ctx
           // original user code
      
      If all of arguments reside in register (dereferencing is not
      required), gen_prologue_fastpath() will be used to create
      fast prologue:
      
           r3 <- (r1 + offset of reg1)
           r4 <- (r1 + offset of reg2)
           r5 <- (r1 + offset of reg3)
           r2 <- 0
      
      P.S.
      
      eBPF calling convention is defined as:
      
      * r0		- return value from in-kernel function, and exit value
                        for eBPF program
      * r1 - r5	- arguments from eBPF program to in-kernel function
      * r6 - r9	- callee saved registers that in-kernel function will
                        preserve
      * r10		- read-only frame pointer to access stack
      
      Committer note:
      
      At least testing if it builds and loads:
      
        # cat test_probe_arg.c
        struct pt_regs;
      
        __attribute__((section("lock_page=__lock_page page->flags"), used))
        int func(struct pt_regs *ctx, int err, unsigned long flags)
        {
        	return 1;
        }
      
        char _license[] __attribute__((section("license"), used)) = "GPL";
        int _version __attribute__((section("version"), used)) = 0x40300;
        # perf record -e ./test_probe_arg.c usleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.016 MB perf.data ]
        # perf evlist
        perf_bpf_probe:lock_page
        #
      Signed-off-by: NHe Kuang <hekuang@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-11-git-send-email-wangnan0@huawei.comSigned-off-by: NWang Nan <wangnan0@huawei.com>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      bfc077b4
    • W
      perf bpf: Allow BPF program config probing options · 03e01f56
      Wang Nan 提交于
      By extending the syntax of BPF object section names, this patch allows users to
      config probing options like what they can do in 'perf probe'.
      
      The error message in 'perf probe' is also updated.
      
      Test result:
      
      For following BPF file test_probe_glob.c:
      
        # cat test_probe_glob.c
        __attribute__((section("inlines=no;func=SyS_dup?"), used))
      
        int func(void *ctx)
        {
      	  return 1;
        }
      
        char _license[] __attribute__((section("license"), used)) = "GPL";
        int _version __attribute__((section("version"), used)) = 0x40300;
        #
        # ./perf record  -e ./test_probe_glob.c ls /
        ...
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.013 MB perf.data ]
        # ./perf evlist
        perf_bpf_probe:func_1
        perf_bpf_probe:func
      
      After changing "inlines=no" to "inlines=yes":
      
        # ./perf record  -e ./test_probe_glob.c ls /
        ...
        [ perf record: Woken up 2 times to write data ]
        [ perf record: Captured and wrote 0.013 MB perf.data ]
        # ./perf evlist
        perf_bpf_probe:func_3
        perf_bpf_probe:func_2
        perf_bpf_probe:func_1
        perf_bpf_probe:func
      
      Then test 'force':
      
      Use following program:
      
        # cat test_probe_force.c
        __attribute__((section("func=sys_write"), used))
      
        int funca(void *ctx)
        {
      	  return 1;
        }
      
        __attribute__((section("force=yes;func=sys_write"), used))
      
        int funcb(void *ctx)
        {
        	return 1;
        }
      
        char _license[] __attribute__((section("license"), used)) = "GPL";
        int _version __attribute__((section("version"), used)) = 0x40300;
        #
      
        # perf record -e ./test_probe_force.c usleep 1
        Error: event "func" already exists.
         Hint: Remove existing event by 'perf probe -d'
             or force duplicates by 'perf probe -f'
             or set 'force=yes' in BPF source.
        event syntax error: './test_probe_force.c'
                             \___ Probe point exist. Try 'perf probe -d "*"' and set 'force=yes'
      
        (add -v to see detail)
        ...
      
      Then replace 'force=no' to 'force=yes':
      
        # vim test_probe_force.c
        # perf record -e ./test_probe_force.c usleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.017 MB perf.data ]
        # perf evlist
        perf_bpf_probe:func_1
        perf_bpf_probe:func
        #
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-7-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      03e01f56
    • W
      perf bpf: Allow attaching BPF programs to modules symbols · 5dbd16c0
      Wang Nan 提交于
      By extending the syntax of BPF object section names, this patch allows
      users to attach BPF programs to symbols in modules. For example:
      
        SEC("module=i915;"
            "parse_cmds=i915_parse_cmds")
        int parse_cmds(void *ctx)
        {
            return 1;
        }
      
      The implementation is very simple: like what 'perf probe' does, for module,
      fill 'uprobe' field in 'struct perf_probe_event'. Other parts will be done
      automatically.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kaixu Xia <xiakaixu@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-5-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5dbd16c0
    • W
      perf bpf: Allow BPF program attach to uprobe events · 361f2b1d
      Wang Nan 提交于
      This patch adds a new syntax to the BPF object section name to support
      probing at uprobe event. Now we can use BPF program like this:
      
        SEC(
        "exec=/lib64/libc.so.6;"
        "libcwrite=__write"
        )
        int libcwrite(void *ctx)
        {
            return 1;
        }
      
      Where, in section name of a program, before the main config string, we
      can use 'key=value' style options. Now the only option key is "exec",
      for uprobes.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-4-git-send-email-wangnan0@huawei.com
      [ Changed the separator from \n to ; ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      361f2b1d
    • A
      tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c · 4ddd3274
      Arnaldo Carvalho de Melo 提交于
      That will contain more string functions with counterparts, sometimes
      verbatim copies, in the kernel.
      Acked-by: NWang Nan <wangnan0@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lkml.kernel.org/n/tip-rah6g97kn21vfgmlramorz6o@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4ddd3274
  4. 13 11月, 2015 6 次提交
    • W
      perf probe: Clear probe_trace_event when add_probe_trace_event() fails · 092b1f0b
      Wang Nan 提交于
      When probing with a glob, errors in add_probe_trace_event() won't be
      passed to debuginfo__find_trace_events() because it would be modified by
      probe_point_search_cb(). It causes a segfault if perf fails to find an
      argument for a probe point matched by the glob. For example:
      
        # ./perf probe -v -n 'SyS_dup? oldfd'
        probe-definition(0): SyS_dup? oldfd
        symbol:SyS_dup? file:(null) line:0 offset:0 return:0 lazy:(null)
        parsing arg: oldfd into oldfd
        1 arguments
        Looking at the vmlinux_path (7 entries long)
        Using /lib/modules/4.3.0-rc4+/build/vmlinux for symbols
        Open Debuginfo file: /lib/modules/4.3.0-rc4+/build/vmlinux
        Try to find probe point from debuginfo.
        Matched function: SyS_dup3
        found inline addr: 0xffffffff812095c0
        Probe point found: SyS_dup3+0
        Searching 'oldfd' variable in context.
        Converting variable oldfd into trace event.
        oldfd type is long int.
        found inline addr: 0xffffffff812096d4
        Probe point found: SyS_dup2+36
        Searching 'oldfd' variable in context.
        Failed to find 'oldfd' in this function.
        Matched function: SyS_dup3
        Probe point found: SyS_dup3+0
        Searching 'oldfd' variable in context.
        Converting variable oldfd into trace event.
        oldfd type is long int.
        Matched function: SyS_dup2
        Probe point found: SyS_dup2+0
        Searching 'oldfd' variable in context.
        Converting variable oldfd into trace event.
        oldfd type is long int.
        Found 4 probe_trace_events.
        Opening /sys/kernel/debug/tracing//kprobe_events write=1
        Writing event: p:probe/SyS_dup3 _text+2135488 oldfd=%di:s64
        Segmentation fault (core dumped)
        #
      
      This patch ensures that add_probe_trace_event() doesn't touches
      tf->ntevs and tf->tevs if those functions fail.
      
      After the patch:
      
        # perf probe  'SyS_dup? oldfd'
        Failed to find 'oldfd' in this function.
        Added new events:
          probe:SyS_dup3       (on SyS_dup? with oldfd)
          probe:SyS_dup3_1     (on SyS_dup? with oldfd)
          probe:SyS_dup2       (on SyS_dup? with oldfd)
      
        You can now use it in all perf tools, such as:
      
      	perf record -e probe:SyS_dup2 -aR sleep 1
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447417761-156094-3-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      092b1f0b
    • M
      perf probe: Fix memory leaking on failure by clearing all probe_trace_events · 0196e787
      Masami Hiramatsu 提交于
      Fix memory leaking on the debuginfo__find_trace_events() failure path
      which frees an array of probe_trace_events but doesn't clears all the
      allocated sub-structures and strings.
      
      So, before doing zfree(tevs), clear all the array elements which may
      have allocated resources.
      Reported-by: NWang Nan <wangnan0@huawei.com>
      Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447417761-156094-2-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0196e787
    • A
      perf buildid-list: Requires ordered events · 1216b65c
      Adrian Hunter 提交于
      'perf buildid-list' processes events to determine hits (i.e. with-hits
      option).  That may not work if events are not sorted in order. i.e. MMAP
      events must be processed before the samples that depend on them so that
      sample processing can 'hit' the DSO to which the MMAP refers.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/1447408112-1920-3-git-send-email-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1216b65c
    • A
      perf symbols: Fix dso lookup by long name and missing buildids · e266a753
      Adrian Hunter 提交于
      Commit 4598a0a6 ("perf symbols: Improve DSO long names lookup speed
      with rbtree") Added a tree to lookup dsos by long name.  That tree gets
      corrupted whenever a dso long name is changed because the tree is not
      updated.
      
      One effect of that is buildid-list does not work with the 'with-hits'
      option because dso lookup fails and results in two structs for the same
      dso.  The first has the buildid but no hits, the second has hits but no
      buildid. e.g.
      
      Before:
      
        $ tools/perf/perf record ls
        arch     certs    CREDITS  Documentation  firmware  include
        ipc      Kconfig  lib      Makefile       net       REPORTING-BUGS
        scripts  sound    usr      block          COPYING   crypto
        drivers  fs       init     Kbuild         kernel    MAINTAINERS
        mm       README   samples  security       tools     virt
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.012 MB perf.data (11 samples) ]
        $ tools/perf/perf buildid-list
        574da826c66538a8d9060d393a8866289bd06005 [kernel.kallsyms]
        30c94dc66a1fe95180c3d68d2b89e576d5ae213c /lib/x86_64-linux-gnu/libc-2.19.so
        $ tools/perf/perf buildid-list -H
        574da826c66538a8d9060d393a8866289bd06005 [kernel.kallsyms]
        0000000000000000000000000000000000000000 /lib/x86_64-linux-gnu/libc-2.19.so
      
      After:
      
        $ tools/perf/perf buildid-list -H
        574da826c66538a8d9060d393a8866289bd06005 [kernel.kallsyms]
        30c94dc66a1fe95180c3d68d2b89e576d5ae213c /lib/x86_64-linux-gnu/libc-2.19.so
      
      The fix is to record the root of the tree on the dso so that
      dso__set_long_name() can update the tree when the long name changes.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Don Zickus <dzickus@redhat.com>
      Cc: Douglas Hatch <doug.hatch@hp.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Scott J Norton <scott.norton@hp.com>
      Cc: Waiman Long <Waiman.Long@hp.com>
      Fixes: 4598a0a6 ("perf symbols: Improve DSO long names lookup speed with rbtree")
      Link: http://lkml.kernel.org/r/1447408112-1920-2-git-send-email-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e266a753
    • A
      perf symbols: Allow forcing reading of non-root owned files by root · 2059fc7a
      Arnaldo Carvalho de Melo 提交于
      When the root user tries to read a file owned by some other user we get:
      
        # ls -la perf.data
        -rw-------. 1 acme acme 20032 Nov 12 15:50 perf.data
        # perf report
        File perf.data not owned by current user or root (use -f to override)
        # perf report -f | grep -v ^# | head -2
          30.96%  ls       [kernel.vmlinux]  [k] do_set_pte
          28.24%  ls       libc-2.20.so      [.] intel_check_word
        #
      
      That wasn't happening when the symbol code tried to read a JIT map,
      where the same check was done but no forcing was possible, fix it.
      Reported-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Tested-by: NBrendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://permalink.gmane.org/gmane.linux.kernel.perf.user/2380Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      2059fc7a
    • A
      perf symbols: Rebuild rbtree when adjusting symbols for kcore · 866548dd
      Adrian Hunter 提交于
      Normally symbols are read from the DSO and adjusted, if need be, so that
      the symbol start matches the file offset in the DSO file (we want the
      file offset because that is what we know from MMAP events). That is done
      by dso__load_sym() which inserts the symbols *after* adjusting them.
      
      In the case of kcore, the symbols have been read from kallsyms and the
      symbol start is the memory address. The symbols have to be adjusted to
      match the kcore file offsets. dso__split_kallsyms_for_kcore() does that,
      but now the adjustment is being done *after* the symbols have been
      inserted. It appears dso__split_kallsyms_for_kcore() was assuming that
      changing the symbol start would not change the order in the rbtree -
      which is, of course, not guaranteed.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: NWang Nan <wangnan0@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/563CB241.2090701@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      866548dd
  5. 12 11月, 2015 3 次提交
  6. 07 11月, 2015 4 次提交
    • W
      perf test: Add 'perf test BPF' · ba1fae43
      Wang Nan 提交于
      This patch adds BPF testcase for testing BPF event filtering.
      
      By utilizing the result of 'perf test LLVM', this patch compiles the
      eBPF sample program then test its ability. The BPF script in 'perf test
      LLVM' lets only 50% samples generated by epoll_pwait() to be captured.
      This patch runs that system call for 111 times, so the result should
      contain 56 samples.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446817783-86722-8-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ba1fae43
    • W
      perf bpf: Improve BPF related error messages · d3e0ce39
      Wang Nan 提交于
      A series of bpf loader related error codes were introduced to help error
      reporting. Functions were improved to return these new error codes.
      
      Functions which return pointers were adjusted to encode error codes into
      return value using the ERR_PTR() interface.
      
      bpf_loader_strerror() was improved to convert these error messages to
      strings. It checks the error codes and calls libbpf_strerror() and
      strerror_r() accordingly, so caller don't need to consider checking the
      range of the error code.
      
      In bpf__strerror_load(), print kernel version of running kernel and the
      object's 'version' section to notify user how to fix his/her program.
      
      v1 -> v2:
       Use macro for error code.
      
       Fetch error message based on array index, eliminate for-loop.
      
       Print version strings.
      
      Before:
      
        # perf record -e ./test_kversion_nomatch_program.o sleep 1
        event syntax error: './test_kversion_nomatch_program.o'
                             \___ Failed to load program: Validate your program and check 'license'/'version' sections in your object
        SKIP
      
        After:
      
        # perf record -e ./test_kversion_nomatch_program.o ls
        event syntax error: './test_kversion_nomatch_program.o'
                             \___ 'version' (4.4.0) doesn't match running kernel (4.3.0)
        SKIP
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446818289-87444-1-git-send-email-wangnan0@huawei.com
      [ Add 'static inline' to bpf__strerror_prepare_load() when LIBBPF is disabled ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d3e0ce39
    • W
      perf tools: Make fetch_kernel_version() publicly available · 07bc5c69
      Wang Nan 提交于
      There are 2 places in llvm-utils.c which find kernel version information
      through uname. This patch extracts the uname related code into a
      fetch_kernel_version() function and puts it into util.h so it can be
      reused.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446818135-87310-1-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      07bc5c69
    • W
      bpf tools: Improve libbpf error reporting · 6371ca3b
      Wang Nan 提交于
      In this patch, a series of libbpf specific error numbers and
      libbpf_strerror() are introduced to help reporting errors.
      
      Functions are updated to pass correct the error number through the
      CHECK_ERR() macro.
      
      All users of bpf_object__open{_buffer}() and bpf_program__title() in
      perf are modified accordingly. In addition, due to the error codes
      changing, bpf__strerror_load() is also modified to use them.
      
      bpf__strerror_head() is also changed accordingly so it can parse libbpf
      errors. bpf_loader_strerror() is introduced for that purpose, and will
      be improved by the following patch.
      
      load_program() is improved not to dump log buffer if it is empty. log
      buffer is also used to deduce whether the error was caused by an invalid
      program or other problem.
      
      v1 -> v2:
      
       - Using macro for error code.
      
       - Fetch error message based on array index, eliminate for-loop.
      
       - Use log buffer to detect the reason of failure. 3 new error code
         are introduced to replace LIBBPF_ERRNO__LOAD.
      
      In v1:
      
        # perf record -e ./test_ill_program.o ls
        event syntax error: './test_ill_program.o'
                             \___ Failed to load program: Validate your program and check 'license'/'version' sections in your object
        SKIP
      
        # perf record -e ./test_kversion_nomatch_program.o ls
        event syntax error: './test_kversion_nomatch_program.o'
                             \___ Failed to load program: Validate your program and check 'license'/'version' sections in your object
        SKIP
      
        # perf record -e ./test_big_program.o ls
        event syntax error: './test_big_program.o'
                             \___ Failed to load program: Validate your program and check 'license'/'version' sections in your object
        SKIP
      
        In v2:
      
        # perf record -e ./test_ill_program.o ls
        event syntax error: './test_ill_program.o'
                             \___ Kernel verifier blocks program loading
        SKIP
      
        # perf record -e ./test_kversion_nomatch_program.o
        event syntax error: './test_kversion_nomatch_program.o'
                             \___ Incorrect kernel version
        SKIP
        (Will be further improved by following patches)
      
        # perf record -e ./test_big_program.o
        event syntax error: './test_big_program.o'
                             \___ Program too big
        SKIP
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446817783-86722-2-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6371ca3b
  7. 06 11月, 2015 2 次提交