1. 11 Dec, 2015 9 commits
    • Wang Nan's avatar
      perf tools: Clear struct machine during machine__init() · 93b0ba3c
      Wang Nan authored
      There are so many test cases use stack allocated 'struct machine'.
      Including:
        test__hists_link
        test__hists_filter
        test__mmap_thread_lookup
        test__thread_mg_share
        test__hists_output
        test__hists_cumulate
      
      Also, in non-test code (for example, machine__new_host()) there are
      code use 'malloc()' to alloc struct machine.
      
      These are dangerous operations, cause some tests fail or hung in
      machines__exit(). For example, in
      
       machines__exit ->
         machine__destroy_kernel_maps ->
           map_groups__remove ->
             maps__remove ->
               pthread_rwlock_wrlock
      
      a incorrectly initialized lock causes unintended behavior.
      
      This patch memset(0) that structure in machine__init() to ensure all
      fields in 'struct machine' are initialized to zero.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1449541544-67621-17-git-send-email-wangnan0@huawei.com
      [ Use memset, see 'man bzero' ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      93b0ba3c
    • Wang Nan's avatar
      perf script: Add support for PERF_TYPE_BREAKPOINT · 27cfef00
      Wang Nan authored
      Useful for getting stack traces for hardware breakpoint events.
      
      Test result:
      
      Before this patch:
       # ~/perf record -g -e mem:0x600980 ./sample
       [ perf record: Woken up 1 times to write data ]
       [ perf record: Captured and wrote 0.011 MB perf.data (12 samples) ]
      
       # ~/perf script
      
       # ~/perf script -F comm,tid,pid,time,event,ip,sym,dso
       sample 22520/22520 97457.836294: mem:0x600980:
                5a4ad8 __clear_user (/lib/modules/4.3.0-rc4+/build/vmlinux)
       ...
                3f41ba sys_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
                979395 return_from_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
          7f1b59719cf7 [unknown] ([unknown])
      
       sample 22520/22520 97457.836648: mem:0x600980:
                   532 main (/home/w00229757/DataBreakpoints/sample)
                 21bd5 __libc_start_main (/tmp/oxygen_root-root/lib64/libc-2.18.so)
       ...
      
      After this patch:
       # ~/perf script
       sample 22520 97457.836294: mem:0x600980:
                         5a4ad8 __clear_user (/lib/modules/4.3.0-rc4+/build/vmlinux)
       ...
                         3f41ba sys_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
                         979395 return_from_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
                   7f1b59719cf7 [unknown] ([unknown])
      
       sample 22520 97457.836648: mem:0x600980:
                            532 main (/home/w00229757/DataBreakpoints/sample)
                          21bd5 __libc_start_main (/tmp/oxygen_root-root/lib64/libc-2.18.so)
      
      Committer note:
      
      So, further testing, lets do it for a kernel global variable,
      tcp_hashinfo:
      
        # grep -w tcp_hashinfo /proc/kallsyms
        ffffffff8202fc00 B tcp_hashinfo
        #
      
      Note: allow specifying mem:tcp_hashinfo:
      
        # perf record -g -e mem:0xffffffff81c65ac0 -a
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.790 MB perf.data ]
        #
        # perf evlist
        mem:0xffffffff8202fc00
        # perf evlist -v
        mem:0xffffffff8202fc00: type: 5, size: 112, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CALLCHAIN|CPU, disabled: 1, inherit: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, bp_type: 3, { bp_addr, config1 }: 0xffffffff8202fc00, { bp_len, config2 }: 0x4
        #
      
      Then, after this patch:
      
        # perf script
        swapper 0 [000] 171036.986988: mem:0xffffffff8202fc00:
          8a0fb5 __inet_lookup_established (/lib/modules/4.3.0+/build/vmlinux)
          8bc09d tcp_v4_early_demux (/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)
          804c27 cpuidle_enter (/lib/modules/4.3.0+/build/vmlinux)
          2ded22 call_cpuidle (/lib/modules/4.3.0+/build/vmlinux)
          2defb6 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)
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1449541544-67621-16-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      27cfef00
    • Wang Nan's avatar
      perf data: Add u32_hex data type · 26812d46
      Wang Nan authored
      Add hexadecimal u32 to base data type, which is useful for raw output
      because raw data is u32 aligned.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: David S. Miller <davem@davemloft.net>
      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/1449541544-67621-12-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      26812d46
    • Wang Nan's avatar
      tools lib bpf: Fetch map names from correct strtab · 77ba9a5b
      Wang Nan authored
      Namhyung Kim pointed out a potential problem in original code that it
      fetches names of maps from section header string table, which is used
      to store section names.
      
      Original code doesn't cause error because of a LLVM behavior that, it
      combines shstrtab into strtab. For example:
      
       $ echo 'int func() {return 0;}' | x86_64-oe-linux-clang -x c -o temp.o -c -
       $ readelf -h ./temp.o
       ELF Header:
         Magic:   7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
         ...
         Section header string table index: 1
       $ readelf -S ./temp.o
       There are 10 section headers, starting at offset 0x288:
      
       Section Headers:
         [Nr] Name              Type             Address           Offset
              Size              EntSize          Flags  Link  Info  Align
         [ 0]                   NULL             0000000000000000  00000000
              0000000000000000  0000000000000000           0     0     0
         [ 1] .strtab           STRTAB           0000000000000000  00000230
              0000000000000051  0000000000000000           0     0     1
              ...
       $ readelf -p .strtab ./temp.o
      
       String dump of section '.strtab':
         [     1]  .text
         [     7]  .comment
         [    10]  .bss
         [    15]  .note.GNU-stack
         [    25]  .rela.eh_frame
         [    34]  func
         [    39]  .strtab
         [    41]  .symtab
         [    49]  .data
         [    4f]  -
      
       $ readelf -p .shstrtab ./temp.o
       readelf: Warning: Section '.shstrtab' was not dumped because it does not exist!
      
      Where, 'section header string table index' points to '.strtab', and
      symbol names are also stored there.
      
      However, in case of gcc:
      
       $ echo 'int func() {return 0;}' | gcc -x c -o temp.o -c -
       $ readelf -p .shstrtab ./temp.o
      
       String dump of section '.shstrtab':
         [     1]  .symtab
         [     9]  .strtab
         [    11]  .shstrtab
         [    1b]  .text
         [    21]  .data
         [    27]  .bss
         [    2c]  .comment
         [    35]  .note.GNU-stack
         [    45]  .rela.eh_frame
       $ readelf -p .strtab ./temp.o
      
       String dump of section '.strtab':
         [     1]  func
      
      They are separated sections.
      
      Although original code doesn't cause error, we'd better use canonical
      method for fetching symbol names to avoid potential behavior changing.
      This patch learns from readelf's code, fetches string from sh_link
      of .symbol section.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Reported-and-Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1449541544-67621-3-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      77ba9a5b
    • Wang Nan's avatar
      tools lib bpf: Check return value of strdup when reading map names · 973170e6
      Wang Nan authored
      Commit 561bbcca ("tools lib bpf:
      Extract and collect map names from BPF object file") forgets checking
      return value of strdup(). This patch fixes it. It also checks names
      pointer before strcmp() for safety.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Fixes: 561bbcca ("tools lib bpf: Extract and collect map names from BPF object file")
      Link: http://lkml.kernel.org/r/1449541544-67621-2-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      973170e6
    • Namhyung Kim's avatar
      perf top: Cleanup condition in perf_top__record_precise_ip() · beefb8d0
      Namhyung Kim authored
      The 'he' cannot be NULL since it's caller hist_iter__top_callback() is
      called only if iter->he is not NULL (see hist_entry_iter__add).  So
      setting 'sym' before the condition to simplify the code.
      
      Also make it clearer that the top->symbol_filter_entry check is only
      meaningful on stdio mode (i.e. when use_browser is 0).
      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/1449802616-16170-4-git-send-email-namhyung@kernel.org
      [ Complete the simplification replacing one more he->ms.sym with sym ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      beefb8d0
    • Namhyung Kim's avatar
      perf top: Fix annotation on --stdio · 448f13b2
      Namhyung Kim authored
      The ui__has_annotation() inside perf_top__record_precise_ip() should be
      removed since it returns true only for TUI (and when sort key has
      symbol).  However the 'perf top --stdio' also supports annotation for a
      symbol which was specified by 's' key action.
      
      Actually it already does the necessary checks before calling the
      function.  So it's ok to get rid of the check here.
      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/1449802616-16170-3-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      448f13b2
    • Namhyung Kim's avatar
      perf top: Access hists->lock only if needed · 151ee834
      Namhyung Kim authored
      The perf_top__record_precise_ip() releases and regrabs the
      he->hists->lock because it can sleep if there's an error.  But it should
      be done conditionally as it slows down the fast path.
      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/1449802616-16170-2-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      151ee834
    • Namhyung Kim's avatar
      perf top: Do not convert address for perf_top__record_precise_ip() · 64226bcf
      Namhyung Kim authored
      We call map->unmap_ip() before the function and call map->map_ip()
      inside the function.  This is meaningless and look strange since only
      one of the two checks 'map'.  Let's use al->addr directly.
      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/1449802616-16170-1-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      64226bcf
  2. 10 Dec, 2015 12 commits
  3. 09 Dec, 2015 11 commits
  4. 08 Dec, 2015 3 commits
  5. 07 Dec, 2015 5 commits