• 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
bpf-loader.c 13.5 KB