tree: 4e588056693a1707d5d2c6600d5be9e9dd659fb0 [path history] [tgz]
  1. android/
  2. arm64/
  3. bin/
  4. powerpc/
  5. x86/
  6. .gitignore
  7. Android.bp
  8. bashreadline.bpf.c
  9. bashreadline.c
  10. bashreadline.h
  11. bindsnoop.bpf.c
  12. bindsnoop.c
  13. bindsnoop.h
  14. biolatency.bpf.c
  15. biolatency.c
  16. biolatency.h
  17. biopattern.bpf.c
  18. biopattern.c
  19. biopattern.h
  20. biosnoop.bpf.c
  21. biosnoop.c
  22. biosnoop.h
  23. biostacks.bpf.c
  24. biostacks.c
  25. biostacks.h
  26. bitesize.bpf.c
  27. bitesize.c
  28. bitesize.h
  29. bits.bpf.h
  30. blk_types.h
  31. cachestat.bpf.c
  32. cachestat.c
  33. core_fixes.bpf.h
  34. cpudist.bpf.c
  35. cpudist.c
  36. cpudist.h
  37. cpufreq.bpf.c
  38. cpufreq.c
  39. cpufreq.h
  40. drsnoop.bpf.c
  41. drsnoop.c
  42. drsnoop.h
  43. drsnoop_example.txt
  44. errno_helpers.c
  45. errno_helpers.h
  46. execsnoop.bpf.c
  47. execsnoop.c
  48. execsnoop.h
  49. exitsnoop.bpf.c
  50. exitsnoop.c
  51. exitsnoop.h
  52. filelife.bpf.c
  53. filelife.c
  54. filelife.h
  55. filetop.bpf.c
  56. filetop.c
  57. filetop.h
  58. fsdist.bpf.c
  59. fsdist.c
  60. fsdist.h
  61. fsslower.bpf.c
  62. fsslower.c
  63. fsslower.h
  64. funclatency.bpf.c
  65. funclatency.c
  66. funclatency.h
  67. gethostlatency.bpf.c
  68. gethostlatency.c
  69. gethostlatency.h
  70. hardirqs.bpf.c
  71. hardirqs.c
  72. hardirqs.h
  73. kernel.config
  74. klockstat.bpf.c
  75. klockstat.c
  76. klockstat.h
  77. ksnoop.bpf.c
  78. ksnoop.c
  79. ksnoop.h
  80. llcstat.bpf.c
  81. llcstat.c
  82. llcstat.h
  83. Makefile
  84. map_helpers.c
  85. map_helpers.h
  86. maps.bpf.h
  87. mountsnoop.bpf.c
  88. mountsnoop.c
  89. mountsnoop.h
  90. numamove.bpf.c
  91. numamove.c
  92. offcputime.bpf.c
  93. offcputime.c
  94. offcputime.h
  95. oomkill.bpf.c
  96. oomkill.c
  97. oomkill.h
  98. opensnoop.bpf.c
  99. opensnoop.c
  100. opensnoop.h
  101. readahead.bpf.c
  102. readahead.c
  103. readahead.h
  104. README.md
  105. runqlat.bpf.c
  106. runqlat.c
  107. runqlat.h
  108. runqlen.bpf.c
  109. runqlen.c
  110. runqlen.h
  111. runqslower.bpf.c
  112. runqslower.c
  113. runqslower.h
  114. runqslower_example.txt
  115. softirqs.bpf.c
  116. softirqs.c
  117. softirqs.h
  118. solisten.bpf.c
  119. solisten.c
  120. solisten.h
  121. stat.h
  122. statsnoop.bpf.c
  123. statsnoop.c
  124. statsnoop.h
  125. syscall_helpers.c
  126. syscall_helpers.h
  127. syscount.bpf.c
  128. syscount.c
  129. syscount.h
  130. tcpconnect.bpf.c
  131. tcpconnect.c
  132. tcpconnect.h
  133. tcpconnlat.bpf.c
  134. tcpconnlat.c
  135. tcpconnlat.h
  136. tcprtt.bpf.c
  137. tcprtt.c
  138. tcprtt.h
  139. tcpsynbl.bpf.c
  140. tcpsynbl.c
  141. tcpsynbl.h
  142. trace_helpers.c
  143. trace_helpers.h
  144. uprobe_helpers.c
  145. uprobe_helpers.h
  146. vfsstat.bpf.c
  147. vfsstat.c
  148. vfsstat.h
libbpf-tools/README.md

Useful links

Building

To build libbpf-based tools, simply run make. This will build all the listed tools/applications. All the build artifacts, by default, go into .output subdirectory to keep source code and build artifacts completely separate. The only exception is resulting tool binaries, which are put in a current directory. make clean will clean up all the build artifacts, including generated binaries.

Given that the libbpf package might not be available across wide variety of distributions, all libbpf-based tools are linked statically against a version of libbpf that BCC links against (from submodule under src/cc/libbpf). This results in binaries with minimal amount of dependencies (libc, libelf, and libz are linked dynamically, though, given their widespread availability). If your build fails because the libbpf submodule is outdated, try running git submodule update --init --recursive.

Tools are expected to follow a simple naming convention:

  • .c contains userspace C code of a tool.
  • .bpf.c contains BPF C code, which gets compiled into BPF ELF file. This ELF file is used to generate BPF skeleton .skel.h, which is subsequently is included from .c.
  • .h can optionally contain any types and constants, shared by both BPF and userspace sides of a tool.

For such cases, simply adding name to Makefile's APPS variable will ensure this tool is built alongside others.

For more complicated applications, some extra Makefile rules might need to be created. For such cases, it is advised to put application into a dedicated subdirectory and link it from main Makefile.

vmlinux.h generation

vmlinux.h contains all kernel types, both exported and internal-only. BPF CO-RE-based applications are expected to include this file in their BPF program C source code to avoid dependency on kernel headers package.

For more reproducible builds, vmlinux.h header file is pre-generated and checked in along the other sources. This is done to avoid dependency on specific user/build server's kernel configuration, because vmlinux.h generation depends on having a kernel with BTF type information built-in (which is enabled by CONFIG_DEBUG_INFO_BTF=y Kconfig option See below).

vmlinux.h is generated from upstream Linux version at particular minor version tag. E.g., vmlinux_505.h is generated from v5.5 tag. Exact set of types available in compiled kernel depends on configuration used to compile it. To generate present vmlinux.h header, default configuration was used, with only extra CONFIG_DEBUG_INFO_BTF=y option enabled.

Given different kernel version can have incompatible type definitions, it might be important to use vmlinux.h of a specific kernel version as a "base" version of header. To that extent, all vmlinux.h headers are versioned by appending suffix to a file name. There is always a symbolic link vmlinux.h, that points to whichever version is deemed to be default (usually, latest).

bpftool

bpftool is a universal tool used for inspection of BPF resources, as well as providing various extra BPF-related facilities, like code-generation of BPF program skeletons. The latter functionality is heavily used by these tools to load and interact with BPF programs.

Given bpftool package can't yet be expected to be available widely across many distributions, bpftool binary is checked in into BCC repository in bin/ subdirectory. Once bpftool package is more widely available, this can be changed in favor of using pre-packaged version of bpftool.

Re-compiling your Kernel with CONFIG_DEBUG_INFO_BTF=y

libbpf probes to see if your sys fs exports the file /sys/kernel/btf/vmlinux (from Kernel 5.5+) or if you have the ELF version in your system code Please note the ELF file could exist without the BTF info in it. Your Kconfig should contain the options below

  1. Compile options
CONFIG_DEBUG_INFO_BTF=y
CONFIG_DEBUG_INFO=y
  1. Also, make sure that you have pahole 1.13 (or preferably 1.16+) during the kernel build (it comes from dwarves package). Without it, BTF won't be generated, and on older kernels you'd get only warning, but still would build kernel successfully