[tip:perf/urgent] perf bpf: Add struct bpf_map struct

2018-08-18 Thread tip-bot for Arnaldo Carvalho de Melo
Commit-ID:  7402e543a74a08ae630234012356ff5cf947bd61
Gitweb: https://git.kernel.org/tip/7402e543a74a08ae630234012356ff5cf947bd61
Author: Arnaldo Carvalho de Melo 
AuthorDate: Mon, 6 Aug 2018 09:02:26 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2018 15:55:54 -0300

perf bpf: Add struct bpf_map struct

A helper structure used by eBPF C program to describe map attributes to
elf_bpf loader, to be used initially by the special __bpf_stdout__ map
used to print strings into the perf ring buffer in BPF scripts, e.g.:

Using the upcoming stdio.h and puts() macros to use the __bpf_stdout__
map to add strings to the ring buffer:

  # cat tools/perf/examples/bpf/hello.c
  #include 

  int syscall_enter(openat)(void *args)
  {
  puts("Hello, world\n");
  return 0;
  }

  license(GPL);
  #
  # cat ~/.perfconfig
  [llvm]
dump-obj = true
  # perf trace -e openat,tools/perf/examples/bpf/hello.c/call-graph=dwarf/ cat 
/etc/passwd > /dev/null
  LLVM: dumping tools/perf/examples/bpf/hello.o
 0.016 ( ): __bpf_stdout__:Hello, world
 0.018 ( 0.010 ms): cat/9079 openat(dfd: CWD, filename: /etc/ld.so.cache, 
flags: CLOEXEC   ) = 3
 0.057 ( ): __bpf_stdout__:Hello, world
 0.059 ( 0.011 ms): cat/9079 openat(dfd: CWD, filename: /lib64/libc.so.6, 
flags: CLOEXEC   ) = 3
 0.417 ( ): __bpf_stdout__:Hello, world
 0.419 ( 0.009 ms): cat/9079 openat(dfd: CWD, filename: /etc/passwd 
   ) = 3
  #
  # file tools/perf/examples/bpf/hello.o
  tools/perf/examples/bpf/hello.o: ELF 64-bit LSB relocatable, *unknown arch 
0xf7* version 1 (SYSV), not stripped
   # readelf -SW tools/perf/examples/bpf/hello.o
  There are 10 section headers, starting at offset 0x208:

  Section Headers:
[Nr] Name  TypeAddress  OffSize   ES 
Flg Lk Inf Al
[ 0]   NULL 00 00 00
  0   0  0
[ 1] .strtab   STRTAB   000188 7f 00
  0   0  1
[ 2] .text PROGBITS 40 00 00  
AX  0   0  4
[ 3] syscalls:sys_enter_openat PROGBITS 40 
88 00  AX  0   0  8
[ 4] .relsyscalls:sys_enter_openat REL  000178 
10 10  9   3  8
[ 5] maps  PROGBITS c8 1c 00  
WA  0   0  4
[ 6] .rodata.str1.1PROGBITS e4 0e 01 
AMS  0   0  1
[ 7] license   PROGBITS f2 04 00  
WA  0   0  1
[ 8] version   PROGBITS f8 04 00  
WA  0   0  4
[ 9] .symtab   SYMTAB   000100 78 18
  1   1  8
  Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
p (processor specific)
# readelf -s tools/perf/examples/bpf/hello.o

  Symbol table '.symtab' contains 5 entries:
   Num:Value  Size TypeBind   Vis  Ndx Name
 0:  0 NOTYPE  LOCAL  DEFAULT  UND
 1:  0 NOTYPE  GLOBAL DEFAULT5 __bpf_stdout__
 2:  0 NOTYPE  GLOBAL DEFAULT7 _license
 3:  0 NOTYPE  GLOBAL DEFAULT8 _version
 4:  0 NOTYPE  GLOBAL DEFAULT3 syscall_enter_openat
  #

Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-81fg60om2ifnatsybzwmi...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/include/bpf/bpf.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
index 2873cdde293f..1f632b56bb34 100644
--- a/tools/perf/include/bpf/bpf.h
+++ b/tools/perf/include/bpf/bpf.h
@@ -4,6 +4,20 @@
 
 #include 
 
+/*
+ * A helper structure used by eBPF C program to describe map attributes to
+ * elf_bpf loader, taken from tools/testing/selftests/bpf/bpf_helpers.h:
+ */
+struct bpf_map {
+unsigned int type;
+unsigned int key_size;
+unsigned int value_size;
+unsigned int max_entries;
+unsigned int map_flags;
+unsigned int inner_map_idx;
+unsigned int numa_node;
+};
+
 #define SEC(NAME) __attribute__((section(NAME),  used))
 
 #define probe(function, vars) \


[tip:perf/urgent] perf bpf: Add struct bpf_map struct

2018-08-18 Thread tip-bot for Arnaldo Carvalho de Melo
Commit-ID:  7402e543a74a08ae630234012356ff5cf947bd61
Gitweb: https://git.kernel.org/tip/7402e543a74a08ae630234012356ff5cf947bd61
Author: Arnaldo Carvalho de Melo 
AuthorDate: Mon, 6 Aug 2018 09:02:26 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2018 15:55:54 -0300

perf bpf: Add struct bpf_map struct

A helper structure used by eBPF C program to describe map attributes to
elf_bpf loader, to be used initially by the special __bpf_stdout__ map
used to print strings into the perf ring buffer in BPF scripts, e.g.:

Using the upcoming stdio.h and puts() macros to use the __bpf_stdout__
map to add strings to the ring buffer:

  # cat tools/perf/examples/bpf/hello.c
  #include 

  int syscall_enter(openat)(void *args)
  {
  puts("Hello, world\n");
  return 0;
  }

  license(GPL);
  #
  # cat ~/.perfconfig
  [llvm]
dump-obj = true
  # perf trace -e openat,tools/perf/examples/bpf/hello.c/call-graph=dwarf/ cat 
/etc/passwd > /dev/null
  LLVM: dumping tools/perf/examples/bpf/hello.o
 0.016 ( ): __bpf_stdout__:Hello, world
 0.018 ( 0.010 ms): cat/9079 openat(dfd: CWD, filename: /etc/ld.so.cache, 
flags: CLOEXEC   ) = 3
 0.057 ( ): __bpf_stdout__:Hello, world
 0.059 ( 0.011 ms): cat/9079 openat(dfd: CWD, filename: /lib64/libc.so.6, 
flags: CLOEXEC   ) = 3
 0.417 ( ): __bpf_stdout__:Hello, world
 0.419 ( 0.009 ms): cat/9079 openat(dfd: CWD, filename: /etc/passwd 
   ) = 3
  #
  # file tools/perf/examples/bpf/hello.o
  tools/perf/examples/bpf/hello.o: ELF 64-bit LSB relocatable, *unknown arch 
0xf7* version 1 (SYSV), not stripped
   # readelf -SW tools/perf/examples/bpf/hello.o
  There are 10 section headers, starting at offset 0x208:

  Section Headers:
[Nr] Name  TypeAddress  OffSize   ES 
Flg Lk Inf Al
[ 0]   NULL 00 00 00
  0   0  0
[ 1] .strtab   STRTAB   000188 7f 00
  0   0  1
[ 2] .text PROGBITS 40 00 00  
AX  0   0  4
[ 3] syscalls:sys_enter_openat PROGBITS 40 
88 00  AX  0   0  8
[ 4] .relsyscalls:sys_enter_openat REL  000178 
10 10  9   3  8
[ 5] maps  PROGBITS c8 1c 00  
WA  0   0  4
[ 6] .rodata.str1.1PROGBITS e4 0e 01 
AMS  0   0  1
[ 7] license   PROGBITS f2 04 00  
WA  0   0  1
[ 8] version   PROGBITS f8 04 00  
WA  0   0  4
[ 9] .symtab   SYMTAB   000100 78 18
  1   1  8
  Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
p (processor specific)
# readelf -s tools/perf/examples/bpf/hello.o

  Symbol table '.symtab' contains 5 entries:
   Num:Value  Size TypeBind   Vis  Ndx Name
 0:  0 NOTYPE  LOCAL  DEFAULT  UND
 1:  0 NOTYPE  GLOBAL DEFAULT5 __bpf_stdout__
 2:  0 NOTYPE  GLOBAL DEFAULT7 _license
 3:  0 NOTYPE  GLOBAL DEFAULT8 _version
 4:  0 NOTYPE  GLOBAL DEFAULT3 syscall_enter_openat
  #

Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-81fg60om2ifnatsybzwmi...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/include/bpf/bpf.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
index 2873cdde293f..1f632b56bb34 100644
--- a/tools/perf/include/bpf/bpf.h
+++ b/tools/perf/include/bpf/bpf.h
@@ -4,6 +4,20 @@
 
 #include 
 
+/*
+ * A helper structure used by eBPF C program to describe map attributes to
+ * elf_bpf loader, taken from tools/testing/selftests/bpf/bpf_helpers.h:
+ */
+struct bpf_map {
+unsigned int type;
+unsigned int key_size;
+unsigned int value_size;
+unsigned int max_entries;
+unsigned int map_flags;
+unsigned int inner_map_idx;
+unsigned int numa_node;
+};
+
 #define SEC(NAME) __attribute__((section(NAME),  used))
 
 #define probe(function, vars) \