All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Wang Nan <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: lizefan@huawei.com, masami.hiramatsu.pt@hitachi.com,
	hpa@zytor.com, wangnan0@huawei.com, ast@kernel.org,
	mingo@kernel.org, linux-kernel@vger.kernel.org, acme@redhat.com,
	tglx@linutronix.de
Subject: [tip:perf/core] perf test: Test the BPF prologue adding infrastructure
Date: Mon, 23 Nov 2015 08:08:08 -0800	[thread overview]
Message-ID: <tip-bbb7d4925a05ecd5bbfdbc1147d402b0db203a5a@git.kernel.org> (raw)
In-Reply-To: <1447675815-166222-13-git-send-email-wangnan0@huawei.com>

Commit-ID:  bbb7d4925a05ecd5bbfdbc1147d402b0db203a5a
Gitweb:     http://git.kernel.org/tip/bbb7d4925a05ecd5bbfdbc1147d402b0db203a5a
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Mon, 16 Nov 2015 12:10:14 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 18 Nov 2015 17:51:04 -0300

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>
---
 tools/perf/tests/.gitignore                 |  1 +
 tools/perf/tests/Build                      |  9 +++++++-
 tools/perf/tests/bpf-script-test-prologue.c | 35 +++++++++++++++++++++++++++++
 tools/perf/tests/bpf.c                      | 34 ++++++++++++++++++++++++++++
 tools/perf/tests/llvm.c                     |  4 ++++
 tools/perf/tests/llvm.h                     |  2 ++
 6 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/.gitignore b/tools/perf/tests/.gitignore
index 489fc9f..bf016c4 100644
--- a/tools/perf/tests/.gitignore
+++ b/tools/perf/tests/.gitignore
@@ -1,2 +1,3 @@
 llvm-src-base.c
 llvm-src-kbuild.c
+llvm-src-prologue.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index f41ebf8..0ff8a97 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -31,7 +31,7 @@ perf-y += sample-parsing.o
 perf-y += parse-no-sample-id-all.o
 perf-y += kmod-path.o
 perf-y += thread-map.o
-perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o
+perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o
 perf-y += bpf.o
 perf-y += topology.o
 
@@ -49,6 +49,13 @@ $(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
 
+$(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c
+	$(call rule_mkdir)
+	$(Q)echo '#include <tests/llvm.h>' > $@
+	$(Q)echo 'const char test_llvm__bpf_test_prologue_prog[] =' >> $@
+	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
+	$(Q)echo ';' >> $@
+
 ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
 perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
 endif
diff --git a/tools/perf/tests/bpf-script-test-prologue.c b/tools/perf/tests/bpf-script-test-prologue.c
new file mode 100644
index 0000000..7230e62
--- /dev/null
+++ b/tools/perf/tests/bpf-script-test-prologue.c
@@ -0,0 +1,35 @@
+/*
+ * 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;
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 6ebfdee..d584422 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -19,6 +19,29 @@ static int epoll_pwait_loop(void)
 	return 0;
 }
 
+#ifdef HAVE_BPF_PROLOGUE
+
+static int llseek_loop(void)
+{
+	int fds[2], i;
+
+	fds[0] = open("/dev/null", O_RDONLY);
+	fds[1] = open("/dev/null", O_RDWR);
+
+	if (fds[0] < 0 || fds[1] < 0)
+		return -1;
+
+	for (i = 0; i < NR_ITERS; i++) {
+		lseek(fds[i % 2], i, (i / 2) % 2 ? SEEK_CUR : SEEK_SET);
+		lseek(fds[(i + 1) % 2], i, (i / 2) % 2 ? SEEK_CUR : SEEK_SET);
+	}
+	close(fds[0]);
+	close(fds[1]);
+	return 0;
+}
+
+#endif
+
 static struct {
 	enum test_llvm__testcase prog_id;
 	const char *desc;
@@ -37,6 +60,17 @@ static struct {
 		&epoll_pwait_loop,
 		(NR_ITERS + 1) / 2,
 	},
+#ifdef HAVE_BPF_PROLOGUE
+	{
+		LLVM_TESTCASE_BPF_PROLOGUE,
+		"Test BPF prologue generation",
+		"[bpf_prologue_test]",
+		"fix kbuild first",
+		"check your vmlinux setting?",
+		&llseek_loop,
+		(NR_ITERS + 1) / 4,
+	},
+#endif
 };
 
 static int do_test(struct bpf_object *obj, int (*func)(void),
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 366e38b..b414763 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -44,6 +44,10 @@ static struct {
 		.source = test_llvm__bpf_test_kbuild_prog,
 		.desc = "Test kbuild searching",
 	},
+	[LLVM_TESTCASE_BPF_PROLOGUE] = {
+		.source = test_llvm__bpf_test_prologue_prog,
+		.desc = "Test BPF prologue generation",
+	},
 };
 
 
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h
index d91d8f4..5150b4d 100644
--- a/tools/perf/tests/llvm.h
+++ b/tools/perf/tests/llvm.h
@@ -6,10 +6,12 @@
 
 extern const char test_llvm__bpf_base_prog[];
 extern const char test_llvm__bpf_test_kbuild_prog[];
+extern const char test_llvm__bpf_test_prologue_prog[];
 
 enum test_llvm__testcase {
 	LLVM_TESTCASE_BASE,
 	LLVM_TESTCASE_KBUILD,
+	LLVM_TESTCASE_BPF_PROLOGUE,
 	__LLVM_TESTCASE_MAX,
 };
 

  parent reply	other threads:[~2015-11-23 16:08 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 12:10 [PATCH 00/13] perf tools: bpf: Improve BPF program ability Wang Nan
2015-11-16 12:10 ` [PATCH 01/13] perf probe: Fix memory leaking on faiulre by clearing all probe_trace_events Wang Nan
2015-11-16 12:10 ` [PATCH 02/13] perf probe: Clear probe_trace_event when add_probe_trace_event() fails Wang Nan
2015-11-16 12:10 ` [PATCH 03/13] perf tools: Allow BPF program attach to uprobe events Wang Nan
2015-11-16 14:14   ` Arnaldo Carvalho de Melo
2015-11-23 16:06   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 04/13] perf tools: Allow BPF program attach to modules Wang Nan
2015-11-23 16:06   ` [tip:perf/core] perf bpf: Allow attaching BPF programs to modules symbols tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 05/13] perf tools: Introduce strtobool() to string.c Wang Nan
2015-11-16 14:17   ` Arnaldo Carvalho de Melo
2015-11-16 14:49     ` Arnaldo Carvalho de Melo
2015-11-16 15:55       ` Arnaldo Carvalho de Melo
2015-11-23 16:04   ` [tip:perf/core] tools: Clone the kernel's strtobool function tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 06/13] perf tools: Allow BPF program config probing options Wang Nan
2015-11-23 16:06   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 07/13] bpf tools: Load a program with different instances using preprocessor Wang Nan
2015-11-16 19:02   ` Arnaldo Carvalho de Melo
2015-11-17  3:53     ` Wangnan (F)
2015-11-23 16:05   ` [tip:perf/core] " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 08/13] perf tools: Add BPF_PROLOGUE config options for further patches Wang Nan
2015-11-23 16:05   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 09/13] perf tools: Compile dwarf-regs.c if CONFIG_BPF_PROLOGUE is on Wang Nan
2015-11-23 16:05   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 10/13] perf tools: Add prologue for BPF programs for fetching arguments Wang Nan
2015-11-23 16:07   ` [tip:perf/core] perf bpf: " tip-bot for He Kuang
2015-11-16 12:10 ` [PATCH 11/13] perf tools: Generate prologue for BPF programs Wang Nan
2015-11-23 16:07   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 12/13] perf test: Test BPF prologue Wang Nan
2015-11-17  1:29   ` Arnaldo Carvalho de Melo
2015-11-17  1:31     ` Wangnan (F)
2015-11-17  4:38     ` Wangnan (F)
2015-11-17 12:20       ` Arnaldo Carvalho de Melo
2015-11-17  8:32     ` [PATCH 0/5] perf tools: Improve BPF support Wang Nan
2015-11-17  8:32       ` [PATCH 1/5] perf test: Fix 2 bugs in 'perf test BPF' Wang Nan
2015-11-17 12:56         ` Arnaldo Carvalho de Melo
2015-11-17 13:01           ` pi3orama
2015-11-17 13:34             ` Arnaldo Carvalho de Melo
2015-11-23 16:08         ` [tip:perf/core] perf test: Fix 'perf test BPF' when it fails to find a suitable vmlinux tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 2/5] perf tools: Use same BPF program if arguments are identical Wang Nan
2015-11-23 16:08         ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 3/5] perf test: Print result for each subtest for llvm Wang Nan
2015-11-17 13:03         ` Arnaldo Carvalho de Melo
2015-11-23 16:09         ` [tip:perf/core] perf test: Print result for each LLVM subtest tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 4/5] perf test: Print result for each subtest for BPF Wang Nan
2015-11-23 16:09         ` [tip:perf/core] perf test: Print result for each BPF subtest tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 5/5] perf test: Mute test cases if verbose == 0 Wang Nan
2015-11-17 13:11         ` Arnaldo Carvalho de Melo
2015-11-23 16:10         ` [tip:perf/core] perf test: Mute test cases error messages " tip-bot for Wang Nan
2015-11-17  8:38     ` [PATCH 12/13] perf test: Test BPF prologue Wangnan (F)
2015-11-17  9:44     ` [PATCH] perf record: Support custom vmlinux path Wang Nan
2015-11-17 12:33       ` Arnaldo Carvalho de Melo
2015-11-17 12:42         ` Arnaldo Carvalho de Melo
2015-11-17 12:45           ` pi3orama
2015-11-19 14:03           ` [PATCH 0/2] perf tools: Builtin options related improvements Wang Nan
2015-11-19 14:03             ` [PATCH 1/2] perf tools: Always give options even it not compiled Wang Nan
2015-11-20 10:54               ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-26  8:05                 ` Wangnan (F)
2015-11-26  9:06                   ` Wangnan (F)
2015-11-19 14:03             ` [PATCH 2/2] perf record: Support custom vmlinux path Wang Nan
2015-11-23 16:08   ` tip-bot for Wang Nan [this message]
2015-11-16 12:10 ` [PATCH 13/13] perf tools: Use same BPF program if arguments are identical Wang Nan
2015-11-17  3:05   ` Wangnan (F)
2015-11-17 13:16     ` Arnaldo Carvalho de Melo
2015-11-16 14:09 ` [PATCH 00/13] perf tools: bpf: Improve BPF program ability Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-bbb7d4925a05ecd5bbfdbc1147d402b0db203a5a@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=ast@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.