1. 18 Nov, 2015 11 commits
    • Wang Nan's avatar
      perf bpf: Allow BPF program config probing options · 03e01f56
      Wang Nan authored
      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: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      03e01f56
    • Wang Nan's avatar
      perf bpf: Allow attaching BPF programs to modules symbols · 5dbd16c0
      Wang Nan authored
      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: default avatarWang 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5dbd16c0
    • Wang Nan's avatar
      perf bpf: Allow BPF program attach to uprobe events · 361f2b1d
      Wang Nan authored
      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: default avatarWang 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      361f2b1d
    • Wang Nan's avatar
      perf bpf: Compile dwarf-regs.c if CONFIG_BPF_PROLOGUE is on · 30433a3a
      Wang Nan authored
      regs_query_register_offset() in dwarf-regs.c is required by BPF
      prologue.  This patch compiles it if CONFIG_BPF_PROLOGUE is on to avoid
      build failure when CONFIG_BPF_PROLOGUE is on but CONFIG_DWARF is not
      set.
      Signed-off-by: default avatarHe Kuang <hekuang@huawei.com>
      Acked-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-10-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      30433a3a
    • Wang Nan's avatar
      perf bpf: Add BPF_PROLOGUE config options for further patches · 1c0ed632
      Wang Nan authored
      If both LIBBPF and DWARF are detected, it is possible to create prologue
      for eBPF programs to help them access kernel data. HAVE_BPF_PROLOGUE and
      CONFIG_BPF_PROLOGUE are added as flags for this feature.
      
      PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET is introduced in commit
      63ab024a ("perf tools:
      regs_query_register_offset() infrastructure"), which indicates that an
      architecture supports converting name of a register to its offset in
      'struct pt_regs'. Without this support, BPF_PROLOGUE should be turned
      off.
      Signed-off-by: default avatarWang 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-9-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1c0ed632
    • Wang Nan's avatar
      bpf tools: Load a program with different instances using preprocessor · b580563e
      Wang Nan authored
      This patch is a preparation for BPF prologue support which allows
      generating a series of BPF bytecode for fetching kernel data before
      calling program code. With the newly introduced multiple instances
      support, perf is able to create different prologues for different kprobe
      points.
      
      Before this patch, a bpf_program can be loaded into kernel only once,
      and get the only resulting fd. What this patch does is to allow creating
      and loading different variants of one bpf_program, then fetching their
      fds.
      
      Here we describe the basic idea in this patch. The detailed description
      of the newly introduced APIs can be found in comments in the patch body.
      
      The key of this patch is the new mechanism in bpf_program__load().
      Instead of loading BPF program into kernel directly, it calls a
      'pre-processor' to generate program instances which would be finally
      loaded into the kernel based on the original code. To enable the
      generation of multiple instances, libbpf passes an index to the
      pre-processor so it know which instance is being loaded.
      
      Pre-processor should be called from libbpf's user (perf) using
      bpf_program__set_prep(). The number of instances and the relationship
      between indices and the target instance should be clear when calling
      bpf_program__set_prep().
      
      To retrieve a fd for a specific instance of a program,
      bpf_program__nth_fd() is introduced. It returns the resulting fd
      according to index.
      Signed-off-by: default avatarHe Kuang <hekuang@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: He Kuang <hekuang@huawei.com>
      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-8-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarWang Nan <wangnan0@huawei.com>
      [ Enclosed multi-line if/else blocks with {}, (*func_ptr)() -> func_ptr() ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b580563e
    • Wang Nan's avatar
      tools: Clone the kernel's strtobool function · 7d85c434
      Wang Nan authored
      Copying it to tools/lib/string.c, the counterpart to the kernel's
      lib/string.c.
      
      This is preparation for enhancing BPF program configuration, which will
      allow config string like 'inlines=yes'.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Jonathan Cameron <jic23@cam.ac.uk>
      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-6-git-send-email-wangnan0@huawei.com
      [ Copied it to tools/lib/string.c instead, to make it usable by other tools/ ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7d85c434
    • Arnaldo Carvalho de Melo's avatar
      tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c · 4ddd3274
      Arnaldo Carvalho de Melo authored
      That will contain more string functions with counterparts, sometimes
      verbatim copies, in the kernel.
      Acked-by: default avatarWang 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      4ddd3274
    • Kevin Hilman's avatar
      tools: Fix selftests_install Makefile rule · 9a13c658
      Kevin Hilman authored
      Fix copy/paste error in selftests_install rule which was copy-pasted
      from the clean rule but not properly changed.
      Signed-off-by: default avatarKevin Hilman <khilman@linaro.org>
      Cc: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Pali Rohar <pali.rohar@gmail.com>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Roberta Dobrescu <roberta.dobrescu@gmail.com>
      Cc: Shuah Khan <shuahkh@osg.samsung.com>
      Cc: linaro-kernel@lists.linaro.org
      Link: http://lkml.kernel.org/r/1447797261-1775-1-git-send-email-khilman@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9a13c658
    • Arnaldo Carvalho de Melo's avatar
      perf test: Fix build of BPF and LLVM on older glibc libraries · 916d4092
      Arnaldo Carvalho de Melo authored
        $ rpm -q glibc
        glibc-2.12-1.166.el6_7.1.x86_64
      
      <SNIP>
          CC       /tmp/build/perf/tests/llvm.o
        cc1: warnings being treated as errors
        tests/llvm.c: In function ‘test_llvm__fetch_bpf_obj’:
        tests/llvm.c:53: error: declaration of ‘index’ shadows a global declaration
        /usr/include/string.h:489: error: shadowed declaration is here
      <SNIP>
          CC       /tmp/build/perf/tests/bpf.o
        cc1: warnings being treated as errors
        tests/bpf.c: In function ‘__test__bpf’:
        tests/bpf.c:149: error: declaration of ‘index’ shadows a global declaration
        /usr/include/string.h:489: error: shadowed declaration is here
      <SNIP>
      
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: pi3orama@163.com
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Fixes: b31de018 ("perf test: Enhance the LLVM test: update basic BPF test program")
      Fixes: ba1fae43 ("perf test: Add 'perf test BPF'")
      Link: http://lkml.kernel.org/n/tip-akpo4r750oya2phxoh9e3447@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      916d4092
    • Ingo Molnar's avatar
      Merge tag 'perf-urgent-for-mingo' of... · e15bf88a
      Ingo Molnar authored
      Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
      
      Pull perf/urgent fixes from Arnaldo Carvalho de Melo:
      
        - Do not change the key of an object in a rbtree, this time it was
          the one for DSOs lookup by its long_name, and the noticed symptom was
          with 'perf buildid-list --with-hits' (Adrian Hunter)
      
        - 'perf inject' is a pipe, events it doesn't touch should be passed
          on, PERF_RECORD_LOST wasn't, fix it (Adrian Hunter)
      
        - Make 'perf buildid-list' request event ordering, as it needs to
          first get the mmap events to be able to mark wich DSOs had hits
          (Adrian Hunter)
      
        - Fix memory leaks on failure in 'perf probe' (Masami Hiramatsu, Wang Nan)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      e15bf88a
  2. 13 Nov, 2015 6 commits
    • Wang Nan's avatar
      perf probe: Clear probe_trace_event when add_probe_trace_event() fails · 092b1f0b
      Wang Nan authored
      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: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      092b1f0b
    • Masami Hiramatsu's avatar
      perf probe: Fix memory leaking on failure by clearing all probe_trace_events · 0196e787
      Masami Hiramatsu authored
      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: default avatarWang Nan <wangnan0@huawei.com>
      Signed-off-by: default avatarMasami 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0196e787
    • Adrian Hunter's avatar
      perf inject: Also re-pipe lost_samples event · d8145b3e
      Adrian Hunter authored
      perf inject must re-pipe all events otherwise they get dropped from the
      output file.
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/1447408112-1920-4-git-send-email-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d8145b3e
    • Adrian Hunter's avatar
      perf buildid-list: Requires ordered events · 1216b65c
      Adrian Hunter authored
      '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: default avatarAdrian 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1216b65c
    • Adrian Hunter's avatar
      perf symbols: Fix dso lookup by long name and missing buildids · e266a753
      Adrian Hunter authored
      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: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: default avatarArnaldo 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e266a753
    • Ingo Molnar's avatar
      Merge tag 'perf-urgent-for-mingo' of... · 2a49f02a
      Ingo Molnar authored
      Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
      
      Pull perf/urgent fixes from Arnaldo Carvalho de Melo:
      
        - Fix 'd' hotkey for filtering by DSO in the top/report
          TUI browser (Arnaldo Carvalho de Melo)
      
        - Allow forcing reading of non-root owned /tmp/perf-PID JIT
          symbol maps (Arnaldo Carvalho de Melo)
      
        - Rebuild rbtree when adjusting symbols for kcore (Adrian Hunter)
      
        - Actually install tmon in the tools/ install rule (Kamal Mostafa)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      2a49f02a
  3. 12 Nov, 2015 8 commits
  4. 11 Nov, 2015 5 commits
  5. 09 Nov, 2015 2 commits
  6. 08 Nov, 2015 1 commit
    • Ingo Molnar's avatar
      Merge tag 'perf-core-for-mingo-2' of... · bad9bc2d
      Ingo Molnar authored
      Merge tag 'perf-core-for-mingo-2' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
      
      Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
      
      Fixes:
      
        - libbpf error reporting improvements, using a strerror interface to
          more precisely tell the user about problems with the provided
          scriptlet, be it in C or as a ready made object file (Wang Nan)
      
        - Do not be case sensitive when searching for matching 'perf test'
          entries (Arnaldo Carvalho de Melo)
      
        - Inform the user about objdump failures in 'perf annotate' (Andi Kleen)
      
      Infrastructure changes:
      
        - Improve the LLVM 'perf test' entry, introduce a new ones for
          BPF and kbuild tests to check the environment used by clang to
          compile .c scriptlets (Wang Nan)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      bad9bc2d
  7. 06 Nov, 2015 7 commits
    • Arnaldo Carvalho de Melo's avatar
      perf test: Do not be case sensitive when searching for matching tests · 345c99a3
      Arnaldo Carvalho de Melo authored
      Before:
      
        # perf test llvm
        # perf test LLVM
        35: Test LLVM searching and compiling                        : Ok
        #
      
      After
      
        # perf test llvm
        35: Test LLVM searching and compiling                        : Ok
        #
      
      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://lkml.kernel.org/n/tip-c1u05npqbf6epse17ovfejoj@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      345c99a3
    • Wang Nan's avatar
      perf test: Add 'perf test BPF' · ba1fae43
      Wang Nan authored
      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: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ba1fae43
    • Wang Nan's avatar
      perf test: Enhance the LLVM tests: add kbuild test · 7af3f3d5
      Wang Nan authored
      This patch adds a kbuild testcase to check whether kernel headers can be
      correctly found.
      
      For example:
        # mv /lib/modules/4.3.0-rc5{,.bak}
        # perf test LLVM
      
          38: Test LLVM searching and compiling                        : Skip
      
        # perf test -v LLVM
        ...
        <stdin>:11:10: fatal error: 'uapi/linux/fs.h' file not found
        #include <uapi/linux/fs.h>
                ^
        1 error generated.
        ERROR:	unable to compile -
        Hint:	Check error message shown above.
        Hint:	You can also pre-compile it into .o using:
           		 clang -target bpf -O2 -c -
      	 with proper -I and -D options.
        Failed to compile test case: 'Test kbuild searching'
        test child finished with -2
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo 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-7-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7af3f3d5
    • Wang Nan's avatar
      perf test: Enhance the LLVM test: update basic BPF test program · b31de018
      Wang Nan authored
      This patch replaces the original toy BPF program with the previously
      introduced bpf-script-example.c. Dynamically embeddeding it into
      'llvm-src-base.c'.
      
      The newly introduced BPF program attaches a BPF program to
      'sys_epoll_pwait()'. perf itself never use that syscall, so further test
      can verify their result with it. The program would generate 1 sample in
      every 2 calls of epoll_pwait() system call.
      
      Since the resulting BPF object is useful per se for further tests,
      test_llvm__fetch_bpf_obj() is introduced for creating BPF objects from
      source. The LLVM test was rewritten to use it.
      
      Committer note:
      
      Running it:
      
        [root@zoo wb]# perf test -v LLVM
        35: Test LLVM searching and compiling                        :
        --- start ---
        test child forked, pid 17740
        Kernel build dir is set to /lib/modules/4.3.0-rc1+/build
        set env: KBUILD_DIR=/lib/modules/4.3.0-rc1+/build
        unset env: KBUILD_OPTS
        include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.9.2/include -I/home/git/linux/arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated  -I/home/git/linux/include -Iinclude -I/home/git/linux/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/home/git/linux/include/uapi -Iinclude/generated/uapi -include /home/git/linux/include/linux/kconfig.h
        set env: NR_CPUS=4
        set env: LINUX_VERSION_CODE=0x40300
        set env: CLANG_EXEC=/usr/libexec/icecc/bin/clang
        set env: CLANG_OPTIONS=-xc
        set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.9.2/include -I/home/git/linux/arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated  -I/home/git/linux/include -Iinclude -I/home/git/linux/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/home/git/linux/include/uapi -Iinclude/generated/uapi -include /home/git/linux/include/linux/kconfig.h
        set env: WORKING_DIR=/lib/modules/4.3.0-rc1+/build
        set env: CLANG_SOURCE=-
        llvm compiling command template: echo '/*
         * bpf-script-example.c
         * Test basic LLVM building
         */
        #ifndef LINUX_VERSION_CODE
        # error Need LINUX_VERSION_CODE
        # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
        #endif
        #define BPF_ANY 0
        #define BPF_MAP_TYPE_ARRAY 2
        #define BPF_FUNC_map_lookup_elem 1
        #define BPF_FUNC_map_update_elem 2
      
        static void *(*bpf_map_lookup_elem)(void *map, void *key) =
      	  (void *) BPF_FUNC_map_lookup_elem;
        static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
      	  (void *) BPF_FUNC_map_update_elem;
      
        struct bpf_map_def {
      	  unsigned int type;
      	  unsigned int key_size;
      	  unsigned int value_size;
      	  unsigned int max_entries;
        };
      
        #define SEC(NAME) __attribute__((section(NAME), used))
        struct bpf_map_def SEC("maps") flip_table = {
      	  .type = BPF_MAP_TYPE_ARRAY,
      	  .key_size = sizeof(int),
      	  .value_size = sizeof(int),
      	  .max_entries = 1,
        };
      
        SEC("func=sys_epoll_pwait")
        int bpf_func__sys_epoll_pwait(void *ctx)
        {
      	  int ind =0;
      	  int *flag = bpf_map_lookup_elem(&flip_table, &ind);
      	  int new_flag;
      	  if (!flag)
      		  return 0;
      	  /* flip flag and store back */
      	  new_flag = !*flag;
      	  bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
      	  return new_flag;
        }
        char _license[] SEC("license") = "GPL";
        int _version SEC("version") = LINUX_VERSION_CODE;
        ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
        test child finished with 0
        ---- end ----
        Test LLVM searching and compiling: Ok
        [root@zoo wb]#
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo 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-6-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarHe Kuang <hekuang@huawei.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b31de018
    • Wang Nan's avatar
      perf bpf: Improve BPF related error messages · d3e0ce39
      Wang Nan authored
      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: default avatarWang Nan <wangnan0@huawei.com>
      Tested-by: default avatarArnaldo 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d3e0ce39
    • Wang Nan's avatar
      perf tools: Make fetch_kernel_version() publicly available · 07bc5c69
      Wang Nan authored
      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: default avatarWang 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      07bc5c69
    • Wang Nan's avatar
      bpf tools: Add new API bpf_object__get_kversion() · 45825d8a
      Wang Nan authored
      bpf_object__get_kversion() can be used to fetch value of object's
      'version' section. Following patch will use it for error reporting.
      Signed-off-by: default avatarWang 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/1446817783-86722-3-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      45825d8a