[tip:perf/urgent] perf test: Enhance the LLVM test: update basic BPF test program

2015-11-07 Thread tip-bot for Wang Nan
Commit-ID:  b31de018a6284a25e0fdfeb028e724f8417ec3b1
Gitweb: http://git.kernel.org/tip/b31de018a6284a25e0fdfeb028e724f8417ec3b1
Author: Wang Nan 
AuthorDate: Fri, 6 Nov 2015 13:49:41 +
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 6 Nov 2015 17:49:24 -0300

perf test: Enhance the LLVM test: update basic BPF test program

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(_table, );
  int new_flag;
  if (!flag)
  return 0;
  /* flip flag and store back */
  new_flag = !*flag;
  bpf_map_update_elem(_table, , _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: Wang Nan 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1446817783-86722-6-git-send-email-wangn...@huawei.com
Signed-off-by: He Kuang 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/Build|   9 ++-
 tools/perf/tests/bpf-script-example.c |   4 ++
 tools/perf/tests/llvm.c   | 131 ++
 tools/perf/tests/llvm.h   |  16 +
 4 files changed, 129 insertions(+), 31 deletions(-)

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 50de225..6c095b3 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -31,9 +31,16 @@ perf-y += sample-parsing.o
 perf-y += parse-no-sample-id-all.o
 perf-y += 

[tip:perf/urgent] perf test: Enhance the LLVM test: update basic BPF test program

2015-11-07 Thread tip-bot for Wang Nan
Commit-ID:  b31de018a6284a25e0fdfeb028e724f8417ec3b1
Gitweb: http://git.kernel.org/tip/b31de018a6284a25e0fdfeb028e724f8417ec3b1
Author: Wang Nan 
AuthorDate: Fri, 6 Nov 2015 13:49:41 +
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 6 Nov 2015 17:49:24 -0300

perf test: Enhance the LLVM test: update basic BPF test program

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(_table, );
  int new_flag;
  if (!flag)
  return 0;
  /* flip flag and store back */
  new_flag = !*flag;
  bpf_map_update_elem(_table, , _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: Wang Nan 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1446817783-86722-6-git-send-email-wangn...@huawei.com
Signed-off-by: He Kuang 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/Build|   9 ++-
 tools/perf/tests/bpf-script-example.c |   4 ++
 tools/perf/tests/llvm.c   | 131 ++
 tools/perf/tests/llvm.h   |  16 +
 4 files changed, 129 insertions(+), 31 deletions(-)

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index