linux/tools/perf/tests
Wang Nan bbb7d4925a perf test: Test the BPF prologue adding infrastructure
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: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo 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: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-11-18 17:51:04 -03:00
..
attr perf tests: Fix attr tests 2015-04-08 10:49:53 -03:00
.gitignore perf test: Test the BPF prologue adding infrastructure 2015-11-18 17:51:04 -03:00
attr.c perf test: Keep test result clean if '-v' not set 2015-11-03 11:45:40 -03:00
attr.py perf tools: Remove EOL whitespaces 2015-01-21 13:24:31 -03:00
bp_signal_overflow.c perf tools: Enable close-on-exec flag on perf file descriptor 2014-07-18 09:09:34 +02:00
bp_signal.c perf tools: Enable close-on-exec flag on perf file descriptor 2014-07-18 09:09:34 +02:00
bpf-script-example.c perf test: Enhance the LLVM test: update basic BPF test program 2015-11-06 17:49:24 -03:00
bpf-script-test-kbuild.c perf test: Enhance the LLVM tests: add kbuild test 2015-11-06 17:49:50 -03:00
bpf-script-test-prologue.c perf test: Test the BPF prologue adding infrastructure 2015-11-18 17:51:04 -03:00
bpf.c perf test: Test the BPF prologue adding infrastructure 2015-11-18 17:51:04 -03:00
Build perf test: Test the BPF prologue adding infrastructure 2015-11-18 17:51:04 -03:00
builtin-test.c perf test: Do not be case sensitive when searching for matching tests 2015-11-06 17:50:04 -03:00
code-reading.c perf test: Keep test result clean if '-v' not set 2015-11-03 11:45:40 -03:00
dso-data.c perf tools: Reference count struct dso 2015-06-08 10:31:40 -03:00
dwarf-unwind.c perf tests: Move x86 tests into arch directory 2015-10-05 16:55:43 -03:00
evsel-roundtrip-name.c perf tools: Add parse_events_error interface 2015-04-29 10:37:58 -03:00
evsel-tp-sched.c perf evsel: Propagate error info from tp_format 2015-09-15 09:48:33 -03:00
fdarray.c tools lib fd array: Allow associating an integer cookie with each entry 2014-09-25 16:46:55 -03:00
hists_common.c perf tools: Reference count struct dso 2015-06-08 10:31:40 -03:00
hists_common.h perf tests: Define and use symbolic names for fake symbols 2014-06-01 14:35:11 +02:00
hists_cumulate.c perf callchain: Allow disabling call graphs per event 2015-08-12 13:20:28 -03:00
hists_filter.c perf test: Add entry for hists socket filter 2015-09-14 13:04:10 -03:00
hists_link.c perf machine: Protect the machine->threads with a rwlock 2015-05-08 16:19:27 -03:00
hists_output.c perf hists: Reducing arguments of hist_entry_iter__add() 2015-05-27 12:21:43 -03:00
keep-tracking.c perf test: Keep test result clean if '-v' not set 2015-11-03 11:45:40 -03:00
kmod-path.c perf tools: Deal with kernel module names in '[]' correctly 2015-06-03 10:02:38 -03:00
llvm.c perf test: Test the BPF prologue adding infrastructure 2015-11-18 17:51:04 -03:00
llvm.h perf test: Test the BPF prologue adding infrastructure 2015-11-18 17:51:04 -03:00
make perf tools: Allow shuffling the build tests 2015-11-05 11:39:54 -03:00
mmap-basic.c perf evsel: Propagate error info from tp_format 2015-09-15 09:48:33 -03:00
mmap-thread-lookup.c perf tools: Add reference counting for thread_map object 2015-06-25 15:15:50 -03:00
openat-syscall-all-cpus.c perf test: Silence tracepoint event failures 2015-10-19 14:57:49 -03:00
openat-syscall-tp-fields.c perf test: Silence tracepoint event failures 2015-10-19 14:57:49 -03:00
openat-syscall.c perf test: Silence tracepoint event failures 2015-10-19 14:57:49 -03:00
parse-events.c perf test: Suppress libtraceevent warnings 2015-10-19 14:58:10 -03:00
parse-no-sample-id-all.c perf tools: Move pr_* debug macros into debug object 2014-07-17 12:58:39 -03:00
perf-record.c perf evlist: Introduce poll method for common code idiom 2014-09-25 16:46:55 -03:00
perf-targz-src-pkg perf tools: Add test for building detached source tarballs 2014-01-13 10:06:26 -03:00
pmu.c perf tools: Add term support for parse_events_error 2015-04-29 10:38:01 -03:00
python-use.c perf tests: Check python path on attr and binding test 2013-01-24 16:40:10 -03:00
sample-parsing.c perf tests: Fix typo in sample-parsing.c 2015-01-22 17:03:01 -03:00
sw-clock.c perf tests: Fix software clock events test setting maps 2015-09-15 11:04:49 -03:00
switch-tracking.c perf test: Keep test result clean if '-v' not set 2015-11-03 11:45:40 -03:00
task-exit.c perf tests: Fix task exit test setting maps 2015-09-15 11:03:58 -03:00
tests.h perf test: Add 'perf test BPF' 2015-11-06 17:50:03 -03:00
thread-map.c perf test: Check for refcnt in thread_map test 2015-07-21 14:20:32 -03:00
thread-mg-share.c perf tools: Use atomic.h for the map_groups refcount 2015-05-15 15:20:44 -03:00
topology.c perf cpu_map: Add data arg to cpu_map__build_map callback 2015-10-19 18:04:01 -03:00
vmlinux-kallsyms.c perf machine: Add method for common kernel_map(FUNCTION) operation 2015-09-30 18:34:29 -03:00