1. 28 Nov, 2015 1 commit
    • Namhyung Kim's avatar
      perf hists: Do not skip elided fields when processing samples · e72655d9
      Namhyung Kim authored
      If user gives a filter, perf marks the corresponding column elided and
      omits the output.  But it should process and aggregates samples using
      the field, otherwise samples will be aggregated as if the column was not
      there resulted in incorrect output.
      
      For example, I'd like to set a filter on native_write_msr_safe.  The
      original overhead of the function is negligible.
      
        $ perf report | grep native_write_msr_safe
            0.00%  swapper  [kernel.vmlinux]  native_write_msr_safe
            0.00%  perf     [kernel.vmlinux]  native_write_msr_safe
      
      However adding -S option gives different output.
      
        $ perf report -S native_write_msr_safe --percentage absolute | \
        > grep -e swapper -e perf
           51.47%  swapper  [kernel.vmlinux]
            4.14%  perf     [kernel.vmlinux]
      
      Since it aggregated samples using comm and dso only.  In fact, the above
      values are same when it sorts with -s comm,dso.
      
        $ perf report -s comm,dso | grep -e swapper -e perf
           51.47%  swapper  [kernel.vmlinux]
            4.14%  perf     [kernel.vmlinux]
      
      This resulted in TUI failure with -ERANGE since it tries to increase
      sample hit count for annotation with wrong symbols due to incorrect
      aggregation.
      
      This patch fixes it not to skip elided fields when comparing samples in
      order to insert them to the hists.
      
      Commiter note:
      
      After the patch, with a different workloads:
      
        # perf report --show-total-period -S native_write_msr_safe --stdio
        #
        # symbol: native_write_msr_safe
        #
        # Samples: 455  of event 'cycles:pp'
        # Event count (approx.): 134787489
        #
        # Overhead Period Command         Shared Object
        # ........ ...... ............... ................
        #
             0.22% 293081 qemu-system-x86 [vmlinux]
             0.19% 255914 swapper         [vmlinux]
             0.00%   2054 Timer           [vmlinux]
             0.00%   1021 firefox         [vmlinux]
             0.00%      2 perf            [vmlinux]
      
        # perf report --show-total-period | grep native_write_msr_safe
        Failed to open /tmp/perf-14838.map, continuing without symbols
             0.22% 293081 qemu-system-x86 [vmlinux]  [k] native_write_msr_safe
             0.19% 255914 swapper         [vmlinux]  [k] native_write_msr_safe
             0.00%   2054 Timer           [vmlinux]  [k] native_write_msr_safe
             0.00%   1021 firefox         [vmlinux]  [k] native_write_msr_safe
             0.00%      2 perf            [vmlinux]  [k] native_write_msr_safe
        #
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1448645559-31167-2-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e72655d9
  2. 27 Nov, 2015 6 commits
    • Namhyung Kim's avatar
      perf report: Show error message when processing sample fails · 25b1606b
      Namhyung Kim authored
      Currently when perf fails to process samples for some reason, it doesn't
      show any message about the failure.  This is very inconvenient for users
      especially on TUI as screen is reset after the failure.
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1448645559-31167-1-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      25b1606b
    • Arnaldo Carvalho de Melo's avatar
      perf list: Robustify event printing routine · e37df6c7
      Arnaldo Carvalho de Melo authored
      When a43eec30 ("bpf: introduce bpf_perf_event_output() helper") added
      PERF_COUNT_SW_BPF_OUTPUT we ended up with a new entry in the event_symbols_sw
      array that wasn't initialized, thus set to NULL, fix print_symbol_events()
      to check for that case so that we don't crash if this happens again.
      
        (gdb) bt
        #0  __match_glob (ignore_space=false, pat=<optimized out>, str=<optimized out>) at util/string.c:198
        #1  strglobmatch (str=<optimized out>, pat=pat@entry=0x7fffffffe61d "stall") at util/string.c:252
        #2  0x00000000004993a5 in print_symbol_events (type=1, syms=0x872880 <event_symbols_sw+160>, max=11, name_only=false, event_glob=0x7fffffffe61d "stall")
            at util/parse-events.c:1615
        #3  print_events (event_glob=event_glob@entry=0x7fffffffe61d "stall", name_only=false) at util/parse-events.c:1675
        #4  0x000000000042c79e in cmd_list (argc=1, argv=0x7fffffffe390, prefix=<optimized out>) at builtin-list.c:68
        #5  0x00000000004788a5 in run_builtin (p=p@entry=0x871758 <commands+120>, argc=argc@entry=2, argv=argv@entry=0x7fffffffe390) at perf.c:370
        #6  0x0000000000420ab0 in handle_internal_command (argv=0x7fffffffe390, argc=2) at perf.c:429
        #7  run_argv (argv=0x7fffffffe110, argcp=0x7fffffffe11c) at perf.c:473
        #8  main (argc=2, argv=0x7fffffffe390) at perf.c:588
        (gdb) p event_symbols_sw[PERF_COUNT_SW_BPF_OUTPUT]
        $4 = {symbol = 0x0, alias = 0x0}
        (gdb)
      
      A patch to robustify perf to not segfault when the next counter gets added in
      the kernel will follow this one.
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      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://lkml.kernel.org/n/tip-57wysblcjfrseb0zg5u7ek10@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e37df6c7
    • Arnaldo Carvalho de Melo's avatar
      perf list: Add support for PERF_COUNT_SW_BPF_OUT · bae9cc41
      Arnaldo Carvalho de Melo authored
      When PERF_COUNT_SW_BPF_OUTPUT was added to the kernel we should've
      added it to tools/perf, where it is used just to list events.
      
      This ended up causing a segfault in commands like "perf list stall".
      
      Fix it by adding that new software counter.
      
      A patch to robustify perf to not segfault when the next counter gets
      added in the kernel will follow this one.
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      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://lkml.kernel.org/n/tip-uya354upi3eprsey6mi5962d@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      bae9cc41
    • Jiri Olsa's avatar
      perf test: 'unwind' test should create kernel maps · 9bdcede5
      Jiri Olsa authored
      The 'perf test unwind' is failing because it forgot to create the kernel
      maps, fix it.
      
      After the patch:
      
        # perf test unwind
        40: Test dwarf unwind         : Ok
      Reported-and-Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lkml.kernel.org/r/20151127082121.GA24503@krava.brq.redhat.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9bdcede5
    • Michael Petlan's avatar
      perf buildid-list: Show running kernel build id fix · c4e07949
      Michael Petlan authored
      The --kernel option of perf buildid-list tool should show the running
      kernel buildid.  The functionality has been lost during other changes of
      the related code.
      
      The build_id__sprintf() function should return length of the build-id
      string,  but it was the length of the build-id raw data instead. Due to
      that, some return value checking caused that the final string was not
      printed out.
      
      With this patch the build_id__sprintf() returns the correct value, so
      the --kernel option works again.
      
      Before:
      
      	# perf buildid-list --kernel
      	#
      
      After:
      
      	# perf buildid-list --kernel
      	972c1edab5bdc06cc224af45d510af662a3c6972
      	#
      Signed-off-by: default avatarMichael Petlan <mpetlan@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      LPU-Reference: 1448632089.24573.114.camel@redhat.com
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c4e07949
    • Ingo Molnar's avatar
      Merge tag 'perf-core-for-mingo' of... · 3f3b1a46
      Ingo Molnar authored
      Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
      
      Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
      
      User visible changes:
      
        - Add 'vmlinux.debug' to the vmlinux search path (Ekaterina Tumanova)
      
        - Do not show sample_(type|period) in the perf_event_attr dump when using
          -v with 'perf stat' (Jiri Olsa)
      
        - Display the WEIGHT sample bit, when set, in 'perf evlist -v' (Jiri Olsa)
      
        - Honour --hide-unresolved in 'report', will honour it as well in 'top'
          when --hide-unresolved gets supported in that tool (Namhyung Kim)
      
        - Fix freeze wit h--call-graph 'flat/folded' due to not properly
          reinitializing the callchain rb_tree (Namhyumg Kim)
      
        - Set dso->long_name when a module name is passed as a parameter
          to tools like 'perf probe' but the 'struct dso' associated to that module
          still doesn't have the full path for the module, just the '[name]' one
          obtained from /proc/modules (Wang Nan)
      
        - Fix anon_hugepage mmaps detection using scanf on /proc/PID/smaps (Yannick Brosseau)
      
      Infrastructure changes:
      
        - Add helper function for updating bpf maps elements (He Kuang)
      
        - Fix traceevents plugins build race (Jiri Olsa)
      
        - Add the $OUTPUT path prefix with 'fixdep' (Jiri Olsa)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      3f3b1a46
  3. 26 Nov, 2015 14 commits
  4. 25 Nov, 2015 3 commits
    • Wang Nan's avatar
      tools lib bpf: Don't do a feature check when cleaning · d8ad6a15
      Wang Nan authored
      Before this patch libbpf always do feature check even when cleaning.
      
      For example:
      
        $ cd kernel/tools/lib/bpf
        $ make
      
        Auto-detecting system features:
        ...                        libelf: [ on  ]
        ...                           bpf: [ on  ]
      
          CC       libbpf.o
          CC       bpf.o
          LD       libbpf-in.o
          LINK     libbpf.a
          LINK     libbpf.so
        $ make clean
          CLEAN    libbpf
          CLEAN    core-gen
        $ make clean
      
        Auto-detecting system features:
        ...                        libelf: [ on  ]
        ...                           bpf: [ on  ]
      
          CLEAN    libbpf
          CLEAN    core-gen
        $
      
      Although the first 'make clean' doesn't show feature check result, it
      still does the check. No output because check result is similar to
      FEATURE-DUMP.libbpf.
      
      This patch uses same method as perf to turn off feature checking when
      'make clean'.
      Reported-and-Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Jiri Olsa <jolsa@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/1448372181-151723-3-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d8ad6a15
    • Wang Nan's avatar
      tools build: Clean CFLAGS and LDFLAGS for fixdep · 5725dd8f
      Wang Nan authored
      Sometimes passing variables to tools/build is dangerous. For example, on
      my platform there is a gcc problem (gcc 4.8.1):
      
      It passes the stackprotector-all feature check:
      
        $ gcc -fstack-protector-all -c ./test.c
        $ echo $?
        0
      
      But requires LDFLAGS support if separate compiling and linking:
        $ gcc -fstack-protector-all -c ./test.c
        $ gcc ./test.o
        ./test.o: In function `main':
        test.c:(.text+0xb): undefined reference to `__stack_chk_guard'
        test.c:(.text+0x21): undefined reference to `__stack_chk_guard'
        collect2: error: ld returned 1 exit status
        $ gcc -fstack-protector-all ./test.o
        $ echo $?
        0
        $ gcc ./test.o -lssp
        $ echo $?
        0
        $
      
      In this environment building perf throws an error:
      
        $ make
          BUILD:   Doing 'make -j24' parallel build
        config/Makefile:344: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
        config/Makefile:403: No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev
        config/Makefile:418: slang not found, disables TUI support. Please install slang-devel or libslang-dev
        config/Makefile:432: GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev
        config/Makefile:564: No bfd.h/libbfd found, please install binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling
        config/Makefile:606: No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev
          CC       fixdep.o
          LD       fixdep-in.o
          LINK     fixdep
        fixdep-in.o: In function `parse_dep_file':
        /kernel/tools/build/fixdep.c:47: undefined reference to `__stack_chk_guard'
        /kernel/tools/build/fixdep.c:117: undefined reference to `__stack_chk_guard'
        fixdep-in.o: In function `main':
        /kernel-hydrogen/tools/build/fixdep.c:156: undefined reference to `__stack_chk_guard'
        /kernel/tools/build/fixdep.c:168: undefined reference to `__stack_chk_guard'
        collect2: error: ld returned 1 exit status
        make[2]: *** [fixdep] Error 1
        make[1]: *** [fixdep] Error 2
        make: *** [all] Error 2
      
      This is because the CFLAGS used in building perf pollutes the CFLAGS
      used for fixdep, passing -fstack-protector-all to buiold fixdep which is
      obviously not required. Since fixdep is a small host side tool, we
      should keep its CFLAGS/LDFLAGS simple and clean.
      
      This patch clears the CFLAGS and LDFLAGS passed when building fixdep, so
      such gcc problem won't block the perf build process.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      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/1448372181-151723-2-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5725dd8f
    • Masami Hiramatsu's avatar
      perf probe: Fix to free temporal Dwarf_Frame correctly · 4d3b1626
      Masami Hiramatsu authored
      The commit 05c8d802 ("perf probe: Fix to free temporal Dwarf_Frame")
      tried to fix the memory leak of Dwarf_Frame, but it released the frame
      at wrong point. Since the dwarf_frame_cfa(frame, &pf->fb_ops, &nops) can
      return an address inside the frame data structure to pf->fb_ops, we can
      not release the frame before using pf->fb_ops.
      
      This reverts the commit and releases the frame afterwards (right before
      returning from call_probe_finder) correctly.
      Reported-and-Tested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Reported-by: default avatarMichael Petlan <mpetlan@redhat.com>
      Signed-off-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.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: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: 05c8d802 ("perf probe: Fix to free temporal Dwarf_Frame")
      LPU-Reference: 20151125103432.1473.31009.stgit@localhost.localdomain
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      4d3b1626
  5. 24 Nov, 2015 1 commit
    • Ingo Molnar's avatar
      Merge tag 'perf-core-for-mingo' of... · 9327ca73
      Ingo Molnar authored
      Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
      
      Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
      
      User visible changes:
      
        - Allow callchain order (caller, callee) to the libdw and libunwind based DWARF
          unwinders (Jiri Olsa)
      
        - Add missing parent_val initialization in the callchain code, fixing a
          SEGFAULT when using callchains with 'perf top' (Jiri Olsa)
      
        - Add initial 'perf config' command, for now just with a --list command to the
          contents of the configuration file in use and a basic man page describing
          its format, commands for doing edits and detailed documentation are being
          reviewed and proof-read. (Taeung Song)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      9327ca73
  6. 23 Nov, 2015 15 commits
    • Steven Rostedt's avatar
      tools lib traceevent: Fix output of %llu for 64 bit values read on 32 bit machines · 32abc2ed
      Steven Rostedt authored
      When a long value is read on 32 bit machines for 64 bit output, the
      parsing needs to change "%lu" into "%llu", as the value is read
      natively.
      
      Unfortunately, if "%llu" is already there, the code will add another "l"
      to it and fail to parse it properly.
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: stable@vger.kernel.org
      Link: http://lkml.kernel.org/r/20151116172516.4b79b109@gandalf.local.homeSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      32abc2ed
    • Jiri Olsa's avatar
      perf callchain: Add missing parent_val initialization · 646a6e84
      Jiri Olsa authored
      Adding missing parent_val callchain_node initialization.
      It's causing segfault in perf top:
      
        $ sudo perf top -g
        perf: Segmentation fault
        -------- backtrace --------
        free_callchain_node(+0x29) in perf [0x4a4b3e]
        free_callchain(+0x29) in perf [0x4a5a83]
        hist_entry__delete(+0x126) in perf [0x4c6649]
        hists__delete_entry(+0x6e) in perf [0x4c66dc]
        hists__decay_entries(+0x7d) in perf [0x4c6776]
        perf_top__sort_new_samples(+0x7c) in perf [0x436a78]
        hist_browser__run(+0xf2) in perf [0x507760]
        perf_evsel__hists_browse(+0x1da) in perf [0x507c8d]
        perf_evlist__tui_browse_hists(+0x3e) in perf [0x5088cf]
        display_thread_tui(+0x7f) in perf [0x437953]
        start_thread(+0xc5) in libpthread-2.21.so [0x7f7068fbb555]
        __clone(+0x6d) in libc-2.21.so [0x7f7066fc3b9d]
        [0x0]
      Reported-and-Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: 4b3a3212 ("perf hists browser: Support flat callchains")
      Link: http://lkml.kernel.org/r/20151121102355.GA17313@krava.localSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      646a6e84
    • Taeung Song's avatar
      perf config: Add initial man page · 7d685243
      Taeung Song authored
      Add perf-config document to describe the perf configuration and a
      'list’ subcommand.
      Signed-off-by: default avatarTaeung Song <treeze.taeung@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lkml.kernel.org/r/63AD9B57-7B8C-46F8-8F18-0FFEB9A6A1BC@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7d685243
    • Taeung Song's avatar
      perf tools: Add 'perf config' command · 30862f2c
      Taeung Song authored
      The perf configuration file contains many variables to change various
      aspects of each of its tools, including output, disk usage, etc.
      
      But looking at the state of configuration is difficult and there's no
      documentation about config variables except for the variables in
      perfconfig.example exist.
      
      So this patch adds a 'perf-config' command with a '--list' option.
      
          perf config [options]
      
          display current perf config variables.
          # perf config -l | --list
      Signed-off-by: default avatarTaeung Song <treeze.taeung@gmail.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/1447768424-17327-1-git-send-email-treeze.taeung@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      30862f2c
    • Jiri Olsa's avatar
      perf callchain: Add order support for libdw DWARF unwinder · 8bd508b0
      Jiri Olsa authored
      As reported by Milian, currently for DWARF unwind (both libdw and
      libunwind) we display callchain in callee order only.
      
      Adding the support to follow callchain order setup to libdw DWARF
      unwinder, so we could get following output for report:
      
        $ perf record --call-graph dwarf ls
        ...
      
        $ perf report --no-children --stdio
      
          21.12%  ls       libc-2.21.so      [.] __strcoll_l
                       |
                       ---__strcoll_l
                          mpsort_with_tmp
                          mpsort_with_tmp
                          mpsort_with_tmp
                          sort_files
                          main
                          __libc_start_main
                          _start
      
        $ perf report --stdio --no-children -g caller
      
          21.12%  ls       libc-2.21.so      [.] __strcoll_l
                       |
                       ---_start
                          __libc_start_main
                          main
                          sort_files
                          mpsort_with_tmp
                          mpsort_with_tmp
                          mpsort_with_tmp
                          __strcoll_l
      Reported-and-Tested-by: default avatarMilian Wolff <milian.wolff@kdab.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jan Kratochvil <jkratoch@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20151119130119.GA26617@krava.brq.redhat.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8bd508b0
    • Jiri Olsa's avatar
      perf test: Add callchain order setup for DWARF unwinder test · 8dc0564d
      Jiri Olsa authored
      Adding callchain order setup for DWARF unwinder test. The test now runs
      unwinder for both callee and caller orders.
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarMilian Wolff <milian.wolff@kdab.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/r/1447772739-18471-4-git-send-email-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8dc0564d
    • Jiri Olsa's avatar
      perf callchain: Add order support for libunwind DWARF unwinder · cb1dc22d
      Jiri Olsa authored
      As reported by Milian, currently for DWARF unwind (both libdw and
      libunwind) we display callchain in callee order only.
      
      Adding the support to follow callchain order setup to libunwind DWARF
      unwinder, so we could get following output for report:
      
        $ perf record --call-graph dwarf ls
        ...
        $ perf report --no-children --stdio
      
          39.26%  ls       libc-2.21.so      [.] __strcoll_l
                       |
                       ---__strcoll_l
                          mpsort_with_tmp
                          mpsort_with_tmp
                          sort_files
                          main
                          __libc_start_main
                          _start
                          0
      
        $ perf report -g caller --no-children --stdio
          ...
          39.26%  ls       libc-2.21.so      [.] __strcoll_l
                       |
                       ---0
                          _start
                          __libc_start_main
                          main
                          sort_files
                          mpsort_with_tmp
                          mpsort_with_tmp
                          __strcoll_l
      Based-on-patch-by: default avatarMilian Wolff <milian.wolff@kdab.com>
      Reported-and-Tested-by: default avatarMilian Wolff <milian.wolff@kdab.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/r/20151118075247.GA5416@krava.brq.redhat.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cb1dc22d
    • Jiri Olsa's avatar
      perf callchain: Move initial entry call into get_entries function · b26b218a
      Jiri Olsa authored
      Moving initial entry call into get_entries function so all entries
      processing is on one place. It will be useful for next change that adds
      ordering logic.
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarMilian Wolff <milian.wolff@kdab.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/r/1447772739-18471-2-git-send-email-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b26b218a
    • Andi Kleen's avatar
      perf/x86: Handle multiple umask bits for BDW CYCLE_ACTIVITY.* · b7883a1c
      Andi Kleen authored
      The earlier constraint fix for Broadwell CYCLE_ACTIVITY.*
      forced umask 8 to counter 2. For this it used UEVENT,
      to match the complete umask.
      
      The event list for Broadwell has an additional
      STALLS_L1D_PENDIND event that uses umask 8, but also
      sets other bits in the umask.  The earlier strict umask match
      didn't handle this case.
      
      Add a new UBIT_EVENT constraint macro that only matches
      the specified bits in the umask. Then use that macro
      to handle CYCLE_ACTIVITY.* on Broadwell.
      
      The documented event also uses cmask, but there's no
      need to let the event scheduler know about the cmask,
      as the scheduling restriction is only tied to the umask.
      Reported-by: default avatarGrant Ayers <ayers@cs.stanford.edu>
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Link: http://lkml.kernel.org/r/1447719667-9998-1-git-send-email-andi@firstfloor.org
      [ Filled in the missing email address of Grant Ayers - hopefully I got the right one. ]
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b7883a1c
    • Takao Indoh's avatar
      perf, x86: Stop Intel PT before kdump starts · da06a43d
      Takao Indoh authored
      This patch stops Intel PT logging and saves its registers in memory
      before kdump is started. This feature is needed to prevent Intel PT from
      overwriting its log buffer after panic, and saved registers are needed to
      find the last position where Intel PT wrote data.
      
      After the crash dump is captured by kdump, users can retrieve the log buffer
      from the vmcore and use it to investigate bad kernel behavior.
      Signed-off-by: default avatarTakao Indoh <indou.takao@jp.fujitsu.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Alexander Shishkin<alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: H.Peter Anvin <hpa@zytor.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Link: http://lkml.kernel.org/r/1446614553-6072-3-git-send-email-indou.takao@jp.fujitsu.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      da06a43d
    • Takao Indoh's avatar
      perf/x86/intel/pt: Add interface to stop Intel PT logging · 24cc12b1
      Takao Indoh authored
      This patch add a function for external components to stop Intel PT.
      Basically this function is used when kernel panic occurs. When it is
      called, the intel_pt driver disables Intel PT and saves its registers
      using pt_event_stop(), which is also used by pmu.stop handler.
      
      This function stops Intel PT on the CPU where it is working, therefore
      users of it need to call it for each CPU to stop all logging.
      Signed-off-by: default avatarTakao Indoh <indou.takao@jp.fujitsu.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Alexander Shishkin<alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: H.Peter Anvin <hpa@zytor.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Link: http://lkml.kernel.org/r/1446614553-6072-2-git-send-email-indou.takao@jp.fujitsu.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      24cc12b1
    • Andi Kleen's avatar
      perf/x86: Add option to disable reading branch flags/cycles · b16a5b52
      Andi Kleen authored
      With LBRv5 reading the extra LBR flags like mispredict, TSX, cycles is
      not free anymore, as it has moved to a separate MSR.
      
      For callstack mode we don't need any of this information; so we can
      avoid the unnecessary MSR read. Add flags to the perf interface where
      perf record can request not collecting this information.
      
      Add branch_sample_type flags for CYCLES and FLAGS. It's a bit unusual
      for branch_sample_types to be negative (disable), not positive (enable),
      but since the legacy ABI reported the flags we need some form of
      explicit disabling to avoid breaking the ABI.
      
      After we have the flags the x86 perf code can keep track if any users
      need the flags. If noone needs it the information is not collected.
      
      This cuts down the cost of LBR callstack on Skylake significantly.
      Profiling a kernel build with LBR call stack the average run time of
      the PMI handler drops by 43%.
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: acme@kernel.org
      Cc: jolsa@kernel.org
      Link: http://lkml.kernel.org/r/1445366797-30894-2-git-send-email-andi@firstfloor.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b16a5b52
    • Andi Kleen's avatar
      perf/x86: Optimize stack walk user accesses · 75925e1a
      Andi Kleen authored
      Change the perf user stack walking to use the new
      __copy_from_user_nmi(), and split each access into word sized transfer
      sizes. This allows to inline the complete access and optimize it all
      into a single load.
      
      The main advantage is that this avoids the overhead of double page
      faults.  When normal copy_from_user() fails it reexecutes the copy to
      compute an accurate number of non copied bytes. This leads to
      executing the expensive page fault twice.
      
      While walking stacks having a fault at some point is relatively common
      (typically when some part of the program isn't compiled with frame
      pointers), so this is a large overhead.
      
      With the optimized copies we avoid this problem because they only do
      all accesses once. And of course they're much faster too when the
      access does not fault because they're just single instructions instead
      of complex function calls.
      
      While profiling a kernel build with -g, the patch brings down the
      average time of the PMI handler from 966ns to 552ns (-43%).
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mike Galbraith <efault@gmx.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Link: http://lkml.kernel.org/r/1445551641-13379-2-git-send-email-andi@firstfloor.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      75925e1a
    • Andi Kleen's avatar
      x86: Add an inlined __copy_from_user_nmi() variant · 10013ebb
      Andi Kleen authored
      Add a inlined __ variant of copy_from_user_nmi. The inlined variant allows
      the user to:
      
       - batch the access_ok() check for multiple accesses
      
       - avoid having a pagefault_disable/enable() on every access if the
         caller already ensures disabled page faults due to its context.
      
       - get all the optimizations in copy_*_user() for small constant sized
         transfers
      
      It is just a define to __copy_from_user_inatomic().
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/1445551641-13379-1-git-send-email-andi@firstfloor.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      10013ebb
    • Ingo Molnar's avatar
      Merge tag 'perf-core-for-mingo' of... · 8c2accc8
      Ingo Molnar authored
      Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
      
      Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
      
      User visible changes:
      
        - Allows BPF scriptlets specify arguments to be fetched using
          DWARF info, using a prologue generated at compile/build time (He Kuang, Wang Nan)
      
        - Allow attaching BPF scriptlets to module symbols (Wang Nan)
      
        - Allow attaching BPF scriptlets to userspace code using uprobe (Wang Nan)
      
        - BPF programs now can specify 'perf probe' tunables via its section name,
          separating key=val values using semicolons (Wang Nan)
      
      Testing some of these new BPF features:
      
        Use case: get callchains when receiving SSL packets, filter then in the
                  kernel, at arbitrary place.
      
        # cat ssl.bpf.c
        #define SEC(NAME) __attribute__((section(NAME), used))
      
        struct pt_regs;
      
        SEC("func=__inet_lookup_established hnum")
        int func(struct pt_regs *ctx, int err, unsigned short port)
        {
                return err == 0 && port == 443;
        }
      
        char _license[] SEC("license") = "GPL";
        int  _version   SEC("version") = LINUX_VERSION_CODE;
        #
        # perf record -a -g -e ssl.bpf.c
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.787 MB perf.data (3 samples) ]
        # perf script | head -30
        swapper     0 [000] 58783.268118: perf_bpf_probe:func: (ffffffff816a0f60) hnum=0x1bb
      	 8a0f61 __inet_lookup_established (/lib/modules/4.3.0+/build/vmlinux)
      	 896def ip_rcv_finish (/lib/modules/4.3.0+/build/vmlinux)
      	 8976c2 ip_rcv (/lib/modules/4.3.0+/build/vmlinux)
      	 855eba __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
      	 8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
      	 8572a8 process_backlog (/lib/modules/4.3.0+/build/vmlinux)
      	 856b11 net_rx_action (/lib/modules/4.3.0+/build/vmlinux)
      	 2a284b __do_softirq (/lib/modules/4.3.0+/build/vmlinux)
      	 2a2ba3 irq_exit (/lib/modules/4.3.0+/build/vmlinux)
      	 96b7a4 do_IRQ (/lib/modules/4.3.0+/build/vmlinux)
      	 969807 ret_from_intr (/lib/modules/4.3.0+/build/vmlinux)
      	 2dede5 cpu_startup_entry (/lib/modules/4.3.0+/build/vmlinux)
      	 95d5bc rest_init (/lib/modules/4.3.0+/build/vmlinux)
      	1163ffa start_kernel ([kernel.vmlinux].init.text)
      	11634d7 x86_64_start_reservations ([kernel.vmlinux].init.text)
      	1163623 x86_64_start_kernel ([kernel.vmlinux].init.text)
      
        qemu-system-x86  9178 [003] 58785.792417: perf_bpf_probe:func: (ffffffff816a0f60) hnum=0x1bb
      	 8a0f61 __inet_lookup_established (/lib/modules/4.3.0+/build/vmlinux)
      	 896def ip_rcv_finish (/lib/modules/4.3.0+/build/vmlinux)
      	 8976c2 ip_rcv (/lib/modules/4.3.0+/build/vmlinux)
      	 855eba __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
      	 8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
      	 856660 netif_receive_skb_internal (/lib/modules/4.3.0+/build/vmlinux)
      	 8566ec netif_receive_skb_sk (/lib/modules/4.3.0+/build/vmlinux)
      	   430a br_handle_frame_finish ([bridge])
      	   48bc br_handle_frame ([bridge])
      	 855f44 __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
      	 8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
        #
      
          Use 'perf probe' various options to list functions, see what variables can
          be collected at any given point, experiment first collecting without a filter,
          then filter, use it together with 'perf trace', 'perf top', with or without
          callchains, if it explodes, please tell us!
      
        - Introduce a new callchain mode: "folded", that will list per line
          representations of all callchains for a give histogram entry, facilitating
          'perf report' output processing by other tools, such as Brendan Gregg's
          flamegraph tools (Namhyung Kim)
      
        E.g:
      
       # perf report | grep -v ^# | head
          18.37%     0.00%  swapper  [kernel.kallsyms]   [k] cpu_startup_entry
                          |
                          ---cpu_startup_entry
                             |
                             |--12.07%--start_secondary
                             |
                              --6.30%--rest_init
                                        start_kernel
                                        x86_64_start_reservations
                                        x86_64_start_kernel
        #
      
       Becomes, in "folded" mode:
      
       # perf report -g folded | grep -v ^# | head -5
           18.37%     0.00%  swapper [kernel.kallsyms]   [k] cpu_startup_entry
         12.07% cpu_startup_entry;start_secondary
          6.30% cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel
           16.90%     0.00%  swapper [kernel.kallsyms]   [k] call_cpuidle
         11.23% call_cpuidle;cpu_startup_entry;start_secondary
          5.67% call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel
           16.90%     0.00%  swapper [kernel.kallsyms]   [k] cpuidle_enter
         11.23% cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary
          5.67% cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel
           15.12%     0.00%  swapper [kernel.kallsyms]   [k] cpuidle_enter_state
        #
      
         The user can also select one of "count", "period" or "percent" as the first column.
      
      Infrastructure changes:
      
        - Fix multiple leaks found with Valgrind and a refcount
          debugger (Masami Hiramatsu)
      
        - Add further 'perf test' entries for BPF and LLVM (Wang Nan)
      
        - Improve 'perf test' to suport subtests, so that the series of tests
          performed in the LLVM and BPF main tests appear in the default 'perf test'
          output (Wang Nan)
      
        - Move memdup() from tools/perf to tools/lib/string.c (Arnaldo Carvalho de Melo)
      
        - Adopt strtobool() from the kernel into tools/lib/ (Wang Nan)
      
        - Fix selftests_install tools/ Makefile rule (Kevin Hilman)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      8c2accc8