1. 20 11月, 2015 3 次提交
    • W
      perf test: Print result for each BPF subtest · 77a0cf68
      Wang Nan 提交于
      This patch prints each sub-tests results for BPF testcases.
      
      Before:
      
        # ./perf test BPF
        37: Test BPF filter                                          : Ok
      
      After:
      
        # ./perf test BPF
        37: Test BPF filter                                          :
        37.1: Test basic BPF filtering                               : Ok
        37.2: Test BPF prologue generation                           : Ok
      
      When a failure happens:
      
        # cat ~/.perfconfig
        [llvm]
            clang-path = "/bin/false"
        # ./perf test BPF
        37: Test BPF filter                                          :
        37.1: Test basic BPF filtering                               : Skip
        37.2: Test BPF prologue generation                           : Skip
      Suggested-and-Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447749170-175898-5-git-send-email-wangnan0@huawei.com
      [ Fixed up not to use .func in an anonymous union ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      77a0cf68
    • W
      perf test: Print result for each LLVM subtest · e8c6d500
      Wang Nan 提交于
      Currently 'perf test llvm' and 'perf test BPF' have multiple sub-tests,
      but the result is provided in only one line:
      
        # perf test LLVM
        35: Test LLVM searching and compiling                        : Ok
      
      This patch introduces sub-tests support, allowing 'perf test' to report
      result for each sub-tests:
      
        # perf test LLVM
        35: Test LLVM searching and compiling                        :
        35.1: Basic BPF llvm compiling test                          : Ok
        35.2: Test kbuild searching                                  : Ok
        35.3: Compile source for BPF prologue generation test        : Ok
      
      When a failure happens:
      
        # cat ~/.perfconfig
        [llvm]
             clang-path = "/bin/false"
        # perf test LLVM
        35: Test LLVM searching and compiling                        :
        35.1: Basic BPF llvm compiling test                          : FAILED!
        35.2: Test kbuild searching                                  : Skip
        35.3: Compile source for BPF prologue generation test        : Skip
      
      And:
      
        # rm ~/.perfconfig
        # ./perf test LLVM
        35: Test LLVM searching and compiling                        :
        35.1: Basic BPF llvm compiling test                          : Skip
        35.2: Test kbuild searching                                  : Skip
        35.3: Compile source for BPF prologue generation test        : Skip
      
      Skip by user:
      
        # ./perf test -s 1,`seq -s , 3 42`
         1: vmlinux symtab matches kallsyms                          : Skip (user override)
         2: detect openat syscall event                              : Ok
        ...
        35: Test LLVM searching and compiling                        : Skip (user override)
        ...
      Suggested-and-Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447749170-175898-4-git-send-email-wangnan0@huawei.com
      [ Changed so that func is not on an anonymous union ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e8c6d500
    • A
      perf tests: Pass the subtest index to each test routine · 721a1f53
      Arnaldo Carvalho de Melo 提交于
      Some tests have sub-tests we want to run, so allow passing this.
      
      Wang tried to avoid having to touch all tests, but then, having the
      test.func in an anonymous union makes the build fail on older compilers,
      like the one in RHEL6, where:
      
        test a = {
      	.func = foo,
        };
      
      fails.
      
      To fix it leave the func pointer in the main structure and pass the subtest
      index to all tests, end result function is the same, but we have just one
      function pointer, not two, with and without the subtest index as an argument.
      
      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-5genj0ficwdmelpoqlds0u4y@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      721a1f53
  2. 19 11月, 2015 15 次提交
    • W
      perf bpf: Use same BPF program if arguments are identical · d35b3289
      Wang Nan 提交于
      This patch allows creating only one BPF program for different
      'probe_trace_event'(tev) entries generated by one
      'perf_probe_event'(pev) if their prologues are identical.
      
      This is done by comparing the argument list of different tev instances,
      and the maps type of prologue and tev using a mapping array. This patch
      utilizes qsort to sort the tevs. After sorting, tevs with identical
      argument lists will be grouped together.
      
      Test result:
      
      Sample BPF program:
      
        #define SEC(NAME) __attribute__((section(NAME), used))
        SEC("inlines=no;"
            "func=SyS_dup? oldfd")
        int func(void *ctx)
        {
            return 1;
        }
      
      It would probe at SyS_dup2 and SyS_dup3, obtaining oldfd as its
      argument.
      
      The following cmdline shows a BPF program being loaded into the kernel
      by perf:
      
       # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog
      
      Before this patch:
      
        # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog
        [1] 24858
        lrwx------ 1 root root 64 Nov 14 04:09 3 -> anon_inode:bpf-prog
        lrwx------ 1 root root 64 Nov 14 04:09 4 -> anon_inode:bpf-prog
        ...
      
      After this patch:
      
        # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | grep bpf-prog
        [1] 25699
        lrwx------ 1 root root 64 Nov 14 04:10 3 -> anon_inode:bpf-prog
        ...
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447749170-175898-3-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d35b3289
    • W
      perf test: Fix 'perf test BPF' when it fails to find a suitable vmlinux · ad0dd7ae
      Wang Nan 提交于
      Two bugs in 'perf test BPF' are found when testing BPF prologue without
      vmlinux:
      
       # mv /lib/modules/4.3.0-rc4+/build/vmlinux{,.bak}
       # ./perf test BPF
       37: Test BPF filter             :Failed to find the path for kernel: No such file or directory
       Ok
      
      Test BPF should fail in this case.
      
      After this patch:
      
       # ./perf test BPF
       37: Test BPF filter             :Failed to find the path for kernel: No such file or directory
        FAILED!
       # mv /lib/modules/4.3.0-rc4+/build/vmlinux{.bak,}
       # ./perf test BPF
       37: Test BPF filter             : Ok
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447749170-175898-2-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ad0dd7ae
    • W
      perf test: Test the BPF prologue adding infrastructure · bbb7d492
      Wang Nan 提交于
      This patch introduces a new BPF script to test the BPF prologue adding
      routines. The new script probes at null_lseek, which is the function pointer
      used when we try to lseek on '/dev/null'.
      
      The null_lseek function is chosen because it is used by function pointers, so
      we don't need to consider inlining and LTO.
      
      By extracting file->f_mode, bpf-script-test-prologue.c should know whether the
      file is writable or readonly. According to llseek_loop() and
      bpf-script-test-prologue.c, one fourth of total lseeks should be collected.
      
      Committer note:
      
      Testing it:
      
        # perf test -v BPF
        <SNIP>
        Kernel build dir is set to /lib/modules/4.3.0+/build
        set env: KBUILD_DIR=/lib/modules/4.3.0+/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+/build
        set env: CLANG_SOURCE=-
        llvm compiling command template: echo '/*
         * bpf-script-test-prologue.c
         * Test BPF prologue
         */
        #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 SEC(NAME) __attribute__((section(NAME), used))
      
        #include <uapi/linux/fs.h>
      
        #define FMODE_READ		0x1
        #define FMODE_WRITE		0x2
      
        static void (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
      	  (void *) 6;
      
        SEC("func=null_lseek file->f_mode offset orig")
        int bpf_func__null_lseek(void *ctx, int err, unsigned long f_mode,
      			   unsigned long offset, unsigned long orig)
        {
      	  if (err)
      		  return 0;
      	  if (f_mode & FMODE_WRITE)
      		  return 0;
      	  if (offset & 1)
      		  return 0;
      	  if (orig == SEEK_CUR)
      		  return 0;
      	  return 1;
        }
      
        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 -
        libbpf: loading object '[bpf_prologue_test]' from buffer
        libbpf: section .strtab, size 135, link 0, flags 0, type=3
        libbpf: section .text, size 0, link 0, flags 6, type=1
        libbpf: section .data, size 0, link 0, flags 3, type=1
        libbpf: section .bss, size 0, link 0, flags 3, type=8
        libbpf: section func=null_lseek file->f_mode offset orig, size 112, link 0, flags 6, type=1
        libbpf: found program func=null_lseek file->f_mode offset orig
        libbpf: section license, size 4, link 0, flags 3, type=1
        libbpf: license of [bpf_prologue_test] is GPL
        libbpf: section version, size 4, link 0, flags 3, type=1
        libbpf: kernel version of [bpf_prologue_test] is 40300
        libbpf: section .symtab, size 168, link 1, flags 0, type=2
        bpf: config program 'func=null_lseek file->f_mode offset orig'
        symbol:null_lseek file:(null) line:0 offset:0 return:0 lazy:(null)
        parsing arg: file->f_mode into file, f_mode(1)
        parsing arg: offset into offset
        parsing arg: orig into orig
        bpf: config 'func=null_lseek file->f_mode offset orig' is ok
        Looking at the vmlinux_path (7 entries long)
        Using /lib/modules/4.3.0+/build/vmlinux for symbols
        Open Debuginfo file: /lib/modules/4.3.0+/build/vmlinux
        Try to find probe point from debuginfo.
        Matched function: null_lseek
        Probe point found: null_lseek+0
        Searching 'file' variable in context.
        Converting variable file into trace event.
        converting f_mode in file
        f_mode type is unsigned int.
        Searching 'offset' variable in context.
        Converting variable offset into trace event.
        offset type is long long int.
        Searching 'orig' variable in context.
        Converting variable orig into trace event.
        orig type is int.
        Found 1 probe_trace_events.
        Opening /sys/kernel/debug/tracing//kprobe_events write=1
        Writing event: p:perf_bpf_probe/func _text+4840528 f_mode=+68(%di):u32 offset=%si:s64 orig=%dx:s32
        libbpf: don't need create maps for [bpf_prologue_test]
        prologue: pass validation
        prologue: slow path
        prologue: fetch arg 0, base reg is %di
        prologue: arg 0: offset 68
        prologue: fetch arg 1, base reg is %si
        prologue: fetch arg 2, base reg is %dx
        add bpf event perf_bpf_probe:func and attach bpf program 3
        adding perf_bpf_probe:func
        adding perf_bpf_probe:func to 0x51672c0
        mmap size 1052672B
        Opening /sys/kernel/debug/tracing//kprobe_events write=1
        Opening /sys/kernel/debug/tracing//uprobe_events write=1
        Parsing probe_events: p:perf_bpf_probe/func _text+4840528 f_mode=+68(%di):u32 offset=%si:s64 orig=%dx:s32
        Group:perf_bpf_probe Event:func probe:p
        Writing event: -:perf_bpf_probe/func
        test child finished with 0
        ---- end ----
        Test BPF filter: Ok
        #
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-13-git-send-email-wangnan0@huawei.com
      [ Added tools/perf/tests/llvm-src-prologue.c to .gitignore ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      bbb7d492
    • W
      perf bpf: Generate prologue for BPF programs · a08357d8
      Wang Nan 提交于
      This patch generates a prologue for each 'struct probe_trace_event' for
      fetching arguments for BPF programs.
      
      After bpf__probe(), iterate over each program to check whether prologues are
      required. If none of the 'struct perf_probe_event' programs will attach to have
      at least one argument, simply skip preprocessor hooking. For those who a
      prologue is required, call bpf__gen_prologue() and paste the original
      instruction after the prologue.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-12-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a08357d8
    • H
      perf bpf: Add prologue for BPF programs for fetching arguments · bfc077b4
      He Kuang 提交于
      This patch generates a prologue for a BPF program which fetches arguments for
      it.  With this patch, the program can have arguments as follow:
      
        SEC("lock_page=__lock_page page->flags")
        int lock_page(struct pt_regs *ctx, int err, unsigned long flags)
        {
       	 return 1;
        }
      
      This patch passes at most 3 arguments from r3, r4 and r5. r1 is still the ctx
      pointer. r2 is used to indicate if dereferencing was done successfully.
      
      This patch uses r6 to hold ctx (struct pt_regs) and r7 to hold stack pointer
      for result. Result of each arguments first store on stack:
      
       low address
       BPF_REG_FP - 24  ARG3
       BPF_REG_FP - 16  ARG2
       BPF_REG_FP - 8   ARG1
       BPF_REG_FP
       high address
      
      Then loaded into r3, r4 and r5.
      
      The output prologue for offn(...off2(off1(reg)))) should be:
      
           r6 <- r1			// save ctx into a callee saved register
           r7 <- fp
           r7 <- r7 - stack_offset	// pointer to result slot
           /* load r3 with the offset in pt_regs of 'reg' */
           (r7) <- r3			// make slot valid
           r3 <- r3 + off1		// prepare to read unsafe pointer
           r2 <- 8
           r1 <- r7			// result put onto stack
           call probe_read		// read unsafe pointer
           jnei r0, 0, err		// error checking
           r3 <- (r7)			// read result
           r3 <- r3 + off2		// prepare to read unsafe pointer
           r2 <- 8
           r1 <- r7
           call probe_read
           jnei r0, 0, err
           ...
           /* load r2, r3, r4 from stack */
           goto success
      err:
           r2 <- 1
           /* load r3, r4, r5 with 0 */
           goto usercode
      success:
           r2 <- 0
      usercode:
           r1 <- r6	// restore ctx
           // original user code
      
      If all of arguments reside in register (dereferencing is not
      required), gen_prologue_fastpath() will be used to create
      fast prologue:
      
           r3 <- (r1 + offset of reg1)
           r4 <- (r1 + offset of reg2)
           r5 <- (r1 + offset of reg3)
           r2 <- 0
      
      P.S.
      
      eBPF calling convention is defined as:
      
      * r0		- return value from in-kernel function, and exit value
                        for eBPF program
      * r1 - r5	- arguments from eBPF program to in-kernel function
      * r6 - r9	- callee saved registers that in-kernel function will
                        preserve
      * r10		- read-only frame pointer to access stack
      
      Committer note:
      
      At least testing if it builds and loads:
      
        # cat test_probe_arg.c
        struct pt_regs;
      
        __attribute__((section("lock_page=__lock_page page->flags"), used))
        int func(struct pt_regs *ctx, int err, unsigned long flags)
        {
        	return 1;
        }
      
        char _license[] __attribute__((section("license"), used)) = "GPL";
        int _version __attribute__((section("version"), used)) = 0x40300;
        # perf record -e ./test_probe_arg.c usleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.016 MB perf.data ]
        # perf evlist
        perf_bpf_probe:lock_page
        #
      Signed-off-by: NHe Kuang <hekuang@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-11-git-send-email-wangnan0@huawei.comSigned-off-by: NWang Nan <wangnan0@huawei.com>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      bfc077b4
    • W
      perf bpf: Allow BPF program config probing options · 03e01f56
      Wang Nan 提交于
      By extending the syntax of BPF object section names, this patch allows users to
      config probing options like what they can do in 'perf probe'.
      
      The error message in 'perf probe' is also updated.
      
      Test result:
      
      For following BPF file test_probe_glob.c:
      
        # cat test_probe_glob.c
        __attribute__((section("inlines=no;func=SyS_dup?"), used))
      
        int func(void *ctx)
        {
      	  return 1;
        }
      
        char _license[] __attribute__((section("license"), used)) = "GPL";
        int _version __attribute__((section("version"), used)) = 0x40300;
        #
        # ./perf record  -e ./test_probe_glob.c ls /
        ...
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.013 MB perf.data ]
        # ./perf evlist
        perf_bpf_probe:func_1
        perf_bpf_probe:func
      
      After changing "inlines=no" to "inlines=yes":
      
        # ./perf record  -e ./test_probe_glob.c ls /
        ...
        [ perf record: Woken up 2 times to write data ]
        [ perf record: Captured and wrote 0.013 MB perf.data ]
        # ./perf evlist
        perf_bpf_probe:func_3
        perf_bpf_probe:func_2
        perf_bpf_probe:func_1
        perf_bpf_probe:func
      
      Then test 'force':
      
      Use following program:
      
        # cat test_probe_force.c
        __attribute__((section("func=sys_write"), used))
      
        int funca(void *ctx)
        {
      	  return 1;
        }
      
        __attribute__((section("force=yes;func=sys_write"), used))
      
        int funcb(void *ctx)
        {
        	return 1;
        }
      
        char _license[] __attribute__((section("license"), used)) = "GPL";
        int _version __attribute__((section("version"), used)) = 0x40300;
        #
      
        # perf record -e ./test_probe_force.c usleep 1
        Error: event "func" already exists.
         Hint: Remove existing event by 'perf probe -d'
             or force duplicates by 'perf probe -f'
             or set 'force=yes' in BPF source.
        event syntax error: './test_probe_force.c'
                             \___ Probe point exist. Try 'perf probe -d "*"' and set 'force=yes'
      
        (add -v to see detail)
        ...
      
      Then replace 'force=no' to 'force=yes':
      
        # vim test_probe_force.c
        # perf record -e ./test_probe_force.c usleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.017 MB perf.data ]
        # perf evlist
        perf_bpf_probe:func_1
        perf_bpf_probe:func
        #
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-7-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      03e01f56
    • W
      perf bpf: Allow attaching BPF programs to modules symbols · 5dbd16c0
      Wang Nan 提交于
      By extending the syntax of BPF object section names, this patch allows
      users to attach BPF programs to symbols in modules. For example:
      
        SEC("module=i915;"
            "parse_cmds=i915_parse_cmds")
        int parse_cmds(void *ctx)
        {
            return 1;
        }
      
      The implementation is very simple: like what 'perf probe' does, for module,
      fill 'uprobe' field in 'struct perf_probe_event'. Other parts will be done
      automatically.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kaixu Xia <xiakaixu@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-5-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5dbd16c0
    • W
      perf bpf: Allow BPF program attach to uprobe events · 361f2b1d
      Wang Nan 提交于
      This patch adds a new syntax to the BPF object section name to support
      probing at uprobe event. Now we can use BPF program like this:
      
        SEC(
        "exec=/lib64/libc.so.6;"
        "libcwrite=__write"
        )
        int libcwrite(void *ctx)
        {
            return 1;
        }
      
      Where, in section name of a program, before the main config string, we
      can use 'key=value' style options. Now the only option key is "exec",
      for uprobes.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-4-git-send-email-wangnan0@huawei.com
      [ Changed the separator from \n to ; ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      361f2b1d
    • W
      perf bpf: Compile dwarf-regs.c if CONFIG_BPF_PROLOGUE is on · 30433a3a
      Wang Nan 提交于
      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: NHe Kuang <hekuang@huawei.com>
      Acked-by: NMasami 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: NWang Nan <wangnan0@huawei.com>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      30433a3a
    • W
      perf bpf: Add BPF_PROLOGUE config options for further patches · 1c0ed632
      Wang Nan 提交于
      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: NWang Nan <wangnan0@huawei.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1447675815-166222-9-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1c0ed632
    • W
      bpf tools: Load a program with different instances using preprocessor · b580563e
      Wang Nan 提交于
      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: NHe 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: NWang Nan <wangnan0@huawei.com>
      [ Enclosed multi-line if/else blocks with {}, (*func_ptr)() -> func_ptr() ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b580563e
    • W
      tools: Clone the kernel's strtobool function · 7d85c434
      Wang Nan 提交于
      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: NWang 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: NArnaldo Carvalho de Melo <acme@redhat.com>
      7d85c434
    • A
      tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c · 4ddd3274
      Arnaldo Carvalho de Melo 提交于
      That will contain more string functions with counterparts, sometimes
      verbatim copies, in the kernel.
      Acked-by: NWang Nan <wangnan0@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: http://lkml.kernel.org/n/tip-rah6g97kn21vfgmlramorz6o@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4ddd3274
    • K
      tools: Fix selftests_install Makefile rule · 9a13c658
      Kevin Hilman 提交于
      Fix copy/paste error in selftests_install rule which was copy-pasted
      from the clean rule but not properly changed.
      Signed-off-by: NKevin 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: NArnaldo Carvalho de Melo <acme@redhat.com>
      9a13c658
    • A
      perf test: Fix build of BPF and LLVM on older glibc libraries · 916d4092
      Arnaldo Carvalho de Melo 提交于
        $ 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: NArnaldo Carvalho de Melo <acme@redhat.com>
      916d4092
  3. 13 11月, 2015 10 次提交
  4. 12 11月, 2015 6 次提交
  5. 07 11月, 2015 6 次提交
    • A
      perf test: Do not be case sensitive when searching for matching tests · 345c99a3
      Arnaldo Carvalho de Melo 提交于
      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: NArnaldo Carvalho de Melo <acme@redhat.com>
      345c99a3
    • W
      perf test: Add 'perf test BPF' · ba1fae43
      Wang Nan 提交于
      This patch adds BPF testcase for testing BPF event filtering.
      
      By utilizing the result of 'perf test LLVM', this patch compiles the
      eBPF sample program then test its ability. The BPF script in 'perf test
      LLVM' lets only 50% samples generated by epoll_pwait() to be captured.
      This patch runs that system call for 111 times, so the result should
      contain 56 samples.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446817783-86722-8-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ba1fae43
    • W
      perf test: Enhance the LLVM tests: add kbuild test · 7af3f3d5
      Wang Nan 提交于
      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: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446817783-86722-7-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7af3f3d5
    • W
      perf test: Enhance the LLVM test: update basic BPF test program · b31de018
      Wang Nan 提交于
      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: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446817783-86722-6-git-send-email-wangnan0@huawei.comSigned-off-by: NHe Kuang <hekuang@huawei.com>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b31de018
    • W
      perf bpf: Improve BPF related error messages · d3e0ce39
      Wang Nan 提交于
      A series of bpf loader related error codes were introduced to help error
      reporting. Functions were improved to return these new error codes.
      
      Functions which return pointers were adjusted to encode error codes into
      return value using the ERR_PTR() interface.
      
      bpf_loader_strerror() was improved to convert these error messages to
      strings. It checks the error codes and calls libbpf_strerror() and
      strerror_r() accordingly, so caller don't need to consider checking the
      range of the error code.
      
      In bpf__strerror_load(), print kernel version of running kernel and the
      object's 'version' section to notify user how to fix his/her program.
      
      v1 -> v2:
       Use macro for error code.
      
       Fetch error message based on array index, eliminate for-loop.
      
       Print version strings.
      
      Before:
      
        # perf record -e ./test_kversion_nomatch_program.o sleep 1
        event syntax error: './test_kversion_nomatch_program.o'
                             \___ Failed to load program: Validate your program and check 'license'/'version' sections in your object
        SKIP
      
        After:
      
        # perf record -e ./test_kversion_nomatch_program.o ls
        event syntax error: './test_kversion_nomatch_program.o'
                             \___ 'version' (4.4.0) doesn't match running kernel (4.3.0)
        SKIP
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446818289-87444-1-git-send-email-wangnan0@huawei.com
      [ Add 'static inline' to bpf__strerror_prepare_load() when LIBBPF is disabled ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d3e0ce39
    • W
      perf tools: Make fetch_kernel_version() publicly available · 07bc5c69
      Wang Nan 提交于
      There are 2 places in llvm-utils.c which find kernel version information
      through uname. This patch extracts the uname related code into a
      fetch_kernel_version() function and puts it into util.h so it can be
      reused.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1446818135-87310-1-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      07bc5c69