platform/upstream/bcc.git
4 years agolibbpf-tools: add bindsnoop
Hengqi Chen [Wed, 12 May 2021 00:43:15 +0000 (08:43 +0800)]
libbpf-tools: add bindsnoop

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
4 years agoSPECS/bcc.spec: add dependencies to libdebuginfod
Andreas Ziegler [Thu, 6 May 2021 07:02:28 +0000 (09:02 +0200)]
SPECS/bcc.spec: add dependencies to libdebuginfod

On Fedora builds we can check the version number and add
build and runtime dependencies to debuginfod for all
currently supported releases (>= 32). Note that the buildbot
only has Fedora 25-28 so it will not try to build libbcc
with debuginfod support as the required packages are not
available on these releases.

For .deb packages there is no easy way to add dependencies
dynamically, so we do not add dependencies to libdebuginfod
there for now. For documentation purposes, however, let's
add a comment indicating which changes are required for
libdebuginfod support for downstream maintainers.

Signed-off-by: Andreas Ziegler <andreas.ziegler@fau.de>
4 years agobcc_elf: add support for debug information from libdebuginfod
Andreas Ziegler [Thu, 29 Apr 2021 10:18:40 +0000 (12:18 +0200)]
bcc_elf: add support for debug information from libdebuginfod

This change adds debuginfod as a new source for debug
information. By using libdebuginfod we can query a server
for a file containing debug information for a given ELF
binary. The environment variable DEBUGINFOD_URLS has to
be defined to an URL for a debuginfod server providing
debug information files for your distribution or the
federating server provided by the elfutils project:

For example, to use the Fedora server, you would need:
$ export DEBUGINFOD_URLS="https://debuginfod.fedoraproject.org/"

Or for the elfutils server which federates to servers for
openSUSE, Void Linux, Debian and Fedora, among others:
$ export DEBUGINFOD_URLS="https://debuginfod.elfutils.org/"

Calls to the debuginfod_find_debuginfo function from
libdebuginfod will fail if the environment variable is not
set, otherwise the library will attempt to download debug
information for a build ID extracted from the binary in
question and store it in a local cache directory.

Fixes iovisor/bpftrace#1774

Signed-off-by: Andreas Ziegler <andreas.ziegler@fau.de>
4 years agolibbpf-tools: add gethostlatency
Hengqi Chen [Sat, 3 Apr 2021 07:35:16 +0000 (15:35 +0800)]
libbpf-tools: add gethostlatency

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
4 years agoUse arch-specific libdir with pkgconfig
Luigi Baldoni [Thu, 6 May 2021 07:37:32 +0000 (09:37 +0200)]
Use arch-specific libdir with pkgconfig

4 years agoupdate debian changelog for release v0.20.0 v0.20.0
Yonghong Song [Thu, 6 May 2021 03:53:54 +0000 (20:53 -0700)]
update debian changelog for release v0.20.0

  * Support for kernel up to 5.12
  * Some basic support for MIPS
  * added bpf_map_lookup_batch and bpf_map_delete_batch support
  * tools/funclatency.py support nested or recursive functions
  * tools/biolatency.py can optionally print out average/total value
  * fix possible marco HAVE_BUILTIN_BSWAP redefine warning for kernel >= 5.10.
  * new tools: virtiostat
  * new libbpf-tools: ext4dist
  * doc update and bug fixes

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agofix llvm compilation errors
Yonghong Song [Thu, 6 May 2021 02:11:13 +0000 (19:11 -0700)]
fix llvm compilation errors

MCContext and InitMCObjectFileInfo name/signatures
are changed due to upstream patch
  https://reviews.llvm.org/D101462
Adjust related codes in bcc_debug.cc properly to resolve
the compilation error for llvm13.

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agosync with latest libbpf repo
Yonghong Song [Thu, 6 May 2021 00:48:18 +0000 (17:48 -0700)]
sync with latest libbpf repo

sync submodule libbpf repo to the following commit:
  c5389a965bc3 sync: latest libbpf changes from kernel

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agobcc/libbpf-tools: Use fentry for vfsstat
Kenta Tada [Wed, 6 Jan 2021 01:26:10 +0000 (10:26 +0900)]
bcc/libbpf-tools: Use fentry for vfsstat

Use fentry like vfsstat.py when it is available.

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
4 years agoloader: include bpf_workaround.h header
Dave Marchevsky [Wed, 5 May 2021 04:31:42 +0000 (21:31 -0700)]
loader: include bpf_workaround.h header

The intent of #3391 was to have `bpf_workaround.h` included after
`bpf.h` when compiling bcc headers. However, that PR only added the file
to the `headers_` map of files that can be included. To actually
include, need to adjust compiler input flags as well.

Fixes: d089013e ("Move HAVE_BUILTIN_BSWAP includes to separate header")
4 years agolibbpf-tools: add offcputime
Wenbo Zhang [Sat, 1 May 2021 04:22:42 +0000 (12:22 +0800)]
libbpf-tools: add offcputime

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agoMove HAVE_BUILTIN_BSWAP includes to separate header
Dave Marchevsky [Fri, 30 Apr 2021 05:00:05 +0000 (22:00 -0700)]
Move HAVE_BUILTIN_BSWAP includes to separate header

As reported in #3366, on newer kernels bcc complains about macro
redefinition when compiling bpf programs:

```
include/linux/compiler-clang.h:46:9: warning: '__HAVE_BUILTIN_BSWAP64__' macro redefined [-Wmacro-redefined]
\#define __HAVE_BUILTIN_BSWAP64__
        ^
<command line>:5:9: note: previous definition is here
\#define __HAVE_BUILTIN_BSWAP64__ 1
```

Since these macros are passed in as `-D` cflags, they appear first
before any \#define statements in code. Since an [upstream kernel
patch](https://lore.kernel.org/linux-csky/20210226161151.2629097-1-arnd@kernel.org/)
added these defines in a kernel header, we see the warning.

This patch moves these definitions to a separate 'virtual' header that's included
after virtual_bpf.h and adds an ifndef guard. As a result, newer kernels
with the patch will not trigger the warning, while older kernels will
not lose the definition.

This should be safe based on my digging - some existing bcc programs use
`__builtin_bswap` methods, but without checking HAVE_BUILTIN_BSWAP.
Macros that may be conditionally defined based on HAVE_BUILTIN_BSWAP,
like those in `bpf_endian.h`, aren't. If a similar macro or struct def
in virtual_bpf.h - or any header it pulls in - changes depending on
HAVE_BUILTIN_BSWAP this could cause problems on older kernels, but I
don't believe that this is the case, or will be based on how
infrequently the defines are checked.

4 years agofeature: support create new map and pin it to bpffs as file(BPF_TABLE_PINNED) (#3382)
zcy [Fri, 30 Apr 2021 04:36:53 +0000 (12:36 +0800)]
feature: support create new map and pin it to bpffs as file(BPF_TABLE_PINNED) (#3382)

Support create a new map and pin it if the pinned file is not available.

Co-authored-by: chenyue.zhou <chenyue.zhou@upai.com>
4 years agoRevert "add macros offsetof and container_of"
Yonghong Song [Thu, 29 Apr 2021 18:54:02 +0000 (11:54 -0700)]
Revert "add macros offsetof and container_of"

This reverts commit cda7acdbddb19a5a258f881711845e41463dabbf.

This will tigger ugly compilation macro redefined warnings:
  $ sudo ./biolatency.py
  In file included from /virtual/main.c:3:
  In file included from include/linux/blkdev.h:5:
  In file included from include/linux/sched.h:12:
  In file included from arch/x86/include/asm/current.h:6:
  In file included from arch/x86/include/asm/percpu.h:45:
  include/linux/kernel.h:992:9: warning: 'container_of' macro redefined [-Wmacro-redefined]
  #define container_of(ptr, type, member) ({                              \
          ^
  /virtual/include/bcc/helpers.h:48:9: note: previous definition is here
  #define container_of(ptr, type, member)                         \
          ^
  1 warning generated.
  Tracing block device I/O... Hit Ctrl-C to end.
Revert now and let us design how to support it better. For example, may
create a different header file to put common kernel macros there to be
used by the program.

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agoenhanced items_delete_batch() in Python to avoid double list creation
Simone Magnani [Wed, 28 Apr 2021 10:04:52 +0000 (12:04 +0200)]
enhanced items_delete_batch() in Python to avoid double list creation

This commit enhances the items_delete_batch() function by accepting a ct.Array instead of a Python list.
This way, the array does not need to be re-created, allowing to directly perform the requested operation.

Signed-off-by: Simone Magnani <simonemagnani.96@gmail.com>
4 years agoadded bpf_update_batch() API support for Python Maps
Simone Magnani [Wed, 28 Apr 2021 09:59:24 +0000 (11:59 +0200)]
added bpf_update_batch() API support for Python Maps

This commit aims at introducing items_update_batch, batch operation to update multiple key-value pairs at the same time.
Doc has been updated accordingly, and a test is provided.

Signed-off-by: Simone Magnani <simonemagnani.96@gmail.com>
4 years agomodified self.max_entries to be available from all the MAP types
Simone Magnani [Wed, 28 Apr 2021 09:50:01 +0000 (11:50 +0200)]
modified self.max_entries to be available from all the MAP types

This commit introduces the self.max_entries attribute both into Queue/Stack maps and to all those whwqo extend TableBase

Signed-off-by: Simone Magnani <simonemagnani.96@gmail.com>
4 years agointroduced Queue/Stack itervalues
Simone Magnani [Wed, 28 Apr 2021 09:47:20 +0000 (11:47 +0200)]
introduced Queue/Stack itervalues

This commit introduces the possibility to iterate over all elements of a Queue/Stack.
To avoid infinite loop, a maximum of MAX_ENTRIES pop() are performed

Signed-off-by: Simone Magnani <simonemagnani.96@gmail.com>
4 years agotools/biolatency: Extend average/total value
edwardwu [Wed, 28 Apr 2021 10:22:48 +0000 (18:22 +0800)]
tools/biolatency: Extend average/total value

Sometimes log2 range is not enough for throughput tuning.
Especially a little difference in performance downgrade.

Also, this extension uses two bpf helper bpf_map_lookup_elem().
It's a cost on embedded system, therefore it's better to be an option.

Signed-off-by: Edward Wu <edwardwu@realtek.com>
4 years agoFix BPF(src_file="foo")
Jerome Marchand [Tue, 27 Apr 2021 13:13:12 +0000 (15:13 +0200)]
Fix BPF(src_file="foo")

Since commit 75f20a15 ("Use string type for comparison to PATH
elements"), src_file isn't working anymore. Somehow, two wrongs
(ArgString __str__() returning a bytes object and joining a bytes and
what was supposed to be a string) did make a right.

It fixes the following error in netqtop and deadlock:
Traceback (most recent call last):
  File "/usr/share/bcc/tools/netqtop", line 207, in <module>
    b = BPF(src_file = EBPF_FILE)
  File "/usr/lib/python3.6/site-packages/bcc/__init__.py", line 335, in __init__
    src_file = BPF._find_file(src_file)
  File "/usr/lib/python3.6/site-packages/bcc/__init__.py", line 255, in _find_file
    t = b"/".join([os.path.abspath(os.path.dirname(argv0.__str__())), filename])
TypeError: sequence item 0: expected a bytes-like object, str found

4 years agotools/funclatency: Should clear() after display that is what we want (#3380)
netedwardwu [Wed, 28 Apr 2021 04:53:26 +0000 (12:53 +0800)]
tools/funclatency: Should clear() after display that is what we want (#3380)

BUG:
funclatency memcpy -i 2
     nsecs               : count     distribution
         0 -> 1          : 0        |                                        |
         2 -> 3          : 0        |                                        |
         4 -> 7          : 0        |                                        |
         8 -> 15         : 0        |                                        |
        16 -> 31         : 0        |                                        |
        32 -> 63         : 0        |                                        |
        64 -> 127        : 0        |                                        |
       128 -> 255        : 0        |                                        |
       256 -> 511        : 0        |                                        |
       512 -> 1023       : 0        |                                        |
      1024 -> 2047       : 0        |                                        |
      2048 -> 4095       : 28       |************                            |
      4096 -> 8191       : 92       |****************************************|

avg = 4265 nsecs, total: 9413985 nsecs, count: 2207

     nsecs               : count     distribution
         0 -> 1          : 0        |                                        |
         2 -> 3          : 0        |                                        |
         4 -> 7          : 0        |                                        |
         8 -> 15         : 0        |                                        |
        16 -> 31         : 0        |                                        |
        32 -> 63         : 0        |                                        |
        64 -> 127        : 0        |                                        |
       128 -> 255        : 0        |                                        |
       256 -> 511        : 0        |                                        |
       512 -> 1023       : 0        |                                        |
      1024 -> 2047       : 0        |                                        |
      2048 -> 4095       : 38       |******                                  |
      4096 -> 8191       : 248      |****************************************|

avg = 4304 nsecs, total: 11066321 nsecs, count: 2571

After long-run, you can see the count above is totally wrong.

Also, display together before together clearing is important for better accuracy.

Signed-off-by: Edward Wu <edwardwu@realtek.com>
4 years agoAdd BPFStackTable::free_symcache() to free the symbol cache for an PID (#3371)
yzhao [Wed, 28 Apr 2021 04:48:34 +0000 (21:48 -0700)]
Add BPFStackTable::free_symcache() to free the symbol cache for an PID (#3371)

This is useful when BPFStackTable is used by a long running program to
limit the memory usage, by removing the cached symbols of an exited
process.

4 years agoadd macros offsetof and container_of
Yonghong Song [Mon, 26 Apr 2021 04:10:35 +0000 (21:10 -0700)]
add macros offsetof and container_of

These are two common kernel macros to manipulate data
structures. Let us add them to helpers.h so bpf program
can use them.

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agoadd bpf_map_lookup_batch and bpf_map_delete_batch in bcc (#3363)
Emilien Gobillot [Sun, 25 Apr 2021 17:18:50 +0000 (19:18 +0200)]
add bpf_map_lookup_batch and bpf_map_delete_batch in bcc (#3363)

 . add bpf_map_lookup_batch and bpf_map_delete_batch in bcc
 . add test_map_batch_ops.py to test batch lookup and delete on map
 . add items_lookup_batch() and items_delete_batch() in the reference guide
 . add keys as an optional argument to items_delete_batch

4 years agolibbpf-tools: fix some minor issues of ext4dist
Kenta Tada [Fri, 2 Apr 2021 14:42:03 +0000 (23:42 +0900)]
libbpf-tools: fix some minor issues of ext4dist

* Fix the check of the existence of module BTFs
* Initialize the global variable

Signed-off-by: Kenta Tada <Kenta.Tada@sony.com>
4 years agolibbpf-tools: add two helpers
Wenbo Zhang [Sat, 24 Apr 2021 00:04:03 +0000 (08:04 +0800)]
libbpf-tools: add two helpers

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agoupdate
chenyue.zhou [Wed, 14 Apr 2021 17:37:07 +0000 (13:37 -0400)]
update

4 years agotools/funclatency: support nested or recursive functions
chenyue.zhou [Tue, 6 Apr 2021 20:55:48 +0000 (16:55 -0400)]
tools/funclatency: support nested or recursive functions

4 years agofix minor typo
chendotjs [Sat, 10 Apr 2021 15:51:11 +0000 (23:51 +0800)]
fix minor typo

4 years agolibbpf-tools: resolve KERNEL_VERSION macro redefined
Hengqi Chen [Tue, 6 Apr 2021 02:14:07 +0000 (10:14 +0800)]
libbpf-tools: resolve KERNEL_VERSION macro redefined

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
4 years agolibbpf-tools: fix for block io tracepoints changed
Hengqi Chen [Sat, 20 Mar 2021 04:18:35 +0000 (12:18 +0800)]
libbpf-tools: fix for block io tracepoints changed

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
4 years agolibbpf: update to latest upstream version
Andrii Nakryiko [Mon, 5 Apr 2021 18:36:56 +0000 (11:36 -0700)]
libbpf: update to latest upstream version

This brings in KERNEL_VERSION macro fix, among few other recent features.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agolibbpf-tools: add libbpf's Linux uapi headers to build
Andrii Nakryiko [Fri, 26 Mar 2021 06:58:19 +0000 (23:58 -0700)]
libbpf-tools: add libbpf's Linux uapi headers to build

Do not rely on up-to-date UAPI headers on the system. Instead use the most
recent ones that are used for libbpf's own build.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agolibbpf-tools: remove unecessary custom NULL definitions
Andrii Nakryiko [Fri, 26 Mar 2021 06:56:40 +0000 (23:56 -0700)]
libbpf-tools: remove unecessary custom NULL definitions

Now that libbpf defines NULL in bpf_helpers.h, there is no need for tools to
re-define NULL.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agolibbpf: update to latest master
Andrii Nakryiko [Fri, 26 Mar 2021 06:48:04 +0000 (23:48 -0700)]
libbpf: update to latest master

Update libbpf to the latest upstream commit.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agolibbpf-tools: use raw_tp sched_switch instead of kprobe
Wenbo Zhang [Fri, 26 Mar 2021 02:53:18 +0000 (10:53 +0800)]
libbpf-tools: use raw_tp sched_switch instead of kprobe

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agosome code cleanups
Roman Sudarikov [Fri, 26 Mar 2021 07:48:47 +0000 (07:48 +0000)]
some code cleanups

4 years agoaddressing review comments
Roman Sudarikov [Wed, 24 Mar 2021 16:01:22 +0000 (16:01 +0000)]
addressing review comments

4 years agolevereging extern Kconfig LINUX_KERNEL_VERSION, adding comments
Roman Sudarikov [Wed, 17 Mar 2021 13:54:22 +0000 (13:54 +0000)]
levereging extern Kconfig LINUX_KERNEL_VERSION, adding comments

4 years agoblock tracepoints no longer have struct request_queue arg
Roman Sudarikov [Mon, 15 Mar 2021 19:31:27 +0000 (19:31 +0000)]
block tracepoints no longer have struct request_queue arg

4 years agolibbpf-tools: add ext4dist
Wenbo Zhang [Fri, 26 Mar 2021 06:01:07 +0000 (14:01 +0800)]
libbpf-tools: add ext4dist

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agodoc: add perf_submit_skb() documentation
FedeParola [Sun, 21 Mar 2021 11:44:36 +0000 (12:44 +0100)]
doc: add perf_submit_skb() documentation

4 years agotools: handle renamed lookup_fast function in dcache tools
Jerome Marchand [Sat, 20 Mar 2021 13:33:59 +0000 (14:33 +0100)]
tools: handle renamed lookup_fast function in dcache tools

The lookup_fast function can be rename lookup_fast.constprop.x by gcc
constant propagation optimization and that breaks dcstat and
dcsnoop. Let's look for both name using a regular expression.

4 years agobcc: Add some basic support for MIPS
Tiezhu Yang [Sat, 20 Mar 2021 01:42:35 +0000 (09:42 +0800)]
bcc: Add some basic support for MIPS

In order to fix the following errors when running bpf program
on the MIPS Loongson64 platform, add some basic support, with
this patch, running hello_world.py can get the expected result.

 root@linux:/home/loongson/bcc# python examples/hello_world.py
 In file included from <built-in>:3:
 In file included from /virtual/include/bcc/helpers.h:51:
 In file included from include/uapi/linux/if_packet.h:5:
 arch/mips/include/uapi/asm/byteorder.h:17:3: error: "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
 # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
   ^
 In file included from <built-in>:3:
 In file included from /virtual/include/bcc/helpers.h:53:
 In file included from include/linux/log2.h:12:
 In file included from include/linux/bitops.h:32:
 In file included from arch/mips/include/asm/bitops.h:19:
 In file included from arch/mips/include/asm/barrier.h:11:
 arch/mips/include/asm/addrspace.h:13:10: fatal error: 'spaces.h' file not found
 #include <spaces.h>
         ^~~~~~~~~~
 2 errors generated.
 Traceback (most recent call last):
   File "examples/hello_world.py", line 12, in <module>
     BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print()
   File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 364, in __init__
     raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
 Exception: Failed to compile BPF module <text>

 root@linux:/home/loongson/bcc# python examples/hello_world.py
 In file included from <built-in>:3:
 In file included from /virtual/include/bcc/helpers.h:53:
 In file included from include/linux/log2.h:12:
 In file included from include/linux/bitops.h:32:
 arch/mips/include/asm/bitops.h:101:3: error: invalid output constraint '+ZC' in asm
                 __bit_op(*m, __INS "%0, %3, %2, 1", "i"(bit), "r"(~0));
                 ^
 arch/mips/include/asm/bitops.h:40:19: note: expanded from macro '__bit_op'
         : "=&r"(__temp), "+" GCC_OFF_SMALL_ASM()(mem)           \
                          ^
 [...]
 arch/mips/include/asm/atomic.h:154:1: error: invalid output constraint '+ZC' in asm
 arch/mips/include/asm/atomic.h:151:2: note: expanded from macro 'ATOMIC_OPS'
         ATOMIC_FETCH_OP(pfx, op, type, c_op, asm_op, ll, sc)
         ^
 arch/mips/include/asm/atomic.h:141:4: note: expanded from macro 'ATOMIC_FETCH_OP'
           "+" GCC_OFF_SMALL_ASM() (v->counter)                          \
           ^
 fatal error: too many errors emitted, stopping now [-ferror-limit=]
 20 errors generated.
 Traceback (most recent call last):
   File "examples/hello_world.py", line 12, in <module>
     BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print()
   File "/usr/lib/python2.7/site-packages/bcc/__init__.py", line 364, in __init__
     raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
 Exception: Failed to compile BPF module <text>

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
4 years agoupdate debian changelog for release v0.19.0 v0.19.0
Yonghong Song [Sat, 20 Mar 2021 02:28:02 +0000 (19:28 -0700)]
update debian changelog for release v0.19.0

  * Support for kernel up to 5.11
  * allow BCC as a cmake subproject
  * add LPORT support in tcpconnlat and tcpconnect
  * added bpf_map_lookup_and_delete_batch support
  * new tools: virtiostat
  * new libbpf-tools: cpufreq, funclatency, cachestat
  * add install target to libbpf-tools
  * a few lua fixes
  * doc update and bug fixes

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agosync with latest libbpf
Yonghong Song [Sat, 20 Mar 2021 00:02:58 +0000 (17:02 -0700)]
sync with latest libbpf

sync with latest libbpf with top commit:
  092a60685625 Makefile: fix install flags order

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agocmake: make "-no-pie" optional
Gary Lin [Fri, 12 Mar 2021 03:32:19 +0000 (11:32 +0800)]
cmake: make "-no-pie" optional

The recent linux distros already support PIE so it shouldn't be a
problem to remove "-no-pie". To avoid issue#782, we make "-no-pie"
optional and enable it by default. For the distro with PIE luajit,
just add the following build option:

   -DENABLE_NO_PIE=OFF

Then, bcc-lua will be built with PIE support.

Signed-off-by: Gary Lin <glin@suse.com>
4 years agoAllow to use BCC as a cmake sub-project
Mariusz Barczak [Tue, 16 Mar 2021 20:44:06 +0000 (21:44 +0100)]
Allow to use BCC as a cmake sub-project

Signed-off-by: Mariusz Barczak <mariusz.barczak@intel.com>
4 years agolibbpf-tools: fix bug report address
Wenbo Zhang [Thu, 11 Mar 2021 09:48:50 +0000 (17:48 +0800)]
libbpf-tools: fix bug report address

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agolibbpf-tools: initialize global variables in cachestat and funclatency
chenhengqi [Tue, 16 Mar 2021 05:58:25 +0000 (13:58 +0800)]
libbpf-tools: initialize global variables in cachestat and funclatency

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
4 years agoFAQ: Update LD_LIBRARY_PATH and PYTHONPATH
Tiezhu Yang [Tue, 16 Mar 2021 12:34:31 +0000 (20:34 +0800)]
FAQ: Update LD_LIBRARY_PATH and PYTHONPATH

libbcc.so is actually installed to /usr/lib64 instead of
/usr/local/lib in my computer system:

$ find /usr -name libbcc.so
/usr/lib64/libbcc.so

And also we can find out bcc-python:

$ find /usr/lib -name bcc
/usr/lib/python2.7/site-packages/bcc

It is better to use one line command to export environment
variable LD_LIBRARY_PATH and PYTHONPATH.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
4 years agolibbpf-tools: fix error handling and cleanup
Wenbo Zhang [Tue, 16 Mar 2021 03:54:54 +0000 (11:54 +0800)]
libbpf-tools: fix error handling and cleanup

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agotools: add option to include 'LPORT' in tcpconnlat, update man pages
suresh kumar [Mon, 15 Mar 2021 03:33:37 +0000 (09:03 +0530)]
tools: add option to include 'LPORT' in tcpconnlat, update man pages

4 years agolibbpf-tools: fix non-C89-compliant for loop variable declarations
Andrii Nakryiko [Mon, 15 Mar 2021 19:55:32 +0000 (12:55 -0700)]
libbpf-tools: fix non-C89-compliant for loop variable declarations

Fix all the found instances of declaring loop variable inside for() construct,
which is not supported in C89 standard, which is what libbpf-tools are trying
to adhere to, both in user-space and BPF source code. It actually causes
compilation errors on some versions of GCC, as reported by customers in
private conversations.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agotools/virtiostat: add filter
zhenwei pi [Wed, 10 Mar 2021 10:36:24 +0000 (18:36 +0800)]
tools/virtiostat: add filter

Add device driver/name filter for virtiostat.

Suggested by Yonghong, also use bpf_probe_read_kernel_str to copy
string from kernel.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
4 years agoIn GCC10.2 suffix '.isra.0' was appended to 'finish_task_switch'
Guodong Xu [Sat, 13 Mar 2021 02:23:47 +0000 (02:23 +0000)]
In GCC10.2 suffix '.isra.0' was appended to 'finish_task_switch'

When buildiing kernel with GCC10 [2] in Debian on an Arm64 machine, it was
found the new "inter-procedural optimization improvements" [1] makes symbol
name 'finish_task_switch' changed to 'finish_task_switch.isra.0'.

Details:
The results, when built with gcc 9.3:
nm ../linux.buildout/kernel/sched/core.o | grep finish_task_switch
0000000000001288 t finish_task_switch

However, when built with gcc 10.2:
nm ../linux.buildout/kernel/sched/core.o | grep finish_task_switch
00000000000012d0 t finish_task_switch.isra.0

The same symbols (with xxx.isra.0 or without, respectively of course) also
appear in final file 'System.map' and in '/proc/kallsyms' when booting. This
negatively impact the tracing tools commonly used in kernel debugging, such
as bcc tools offcputime and runqlat. They hardcode 'finish_task_switch'
(without the .isra.0 suffix) into their scripts.

This patch fix the issue by changing the hardcoded 'finish_task_switch' string
to a python regular expression pattern who can match both the traditional form
'finish_task_switch' and the new gcc10 form 'finish_task_switch.isra.0'
(with single digit at the end). attach_kprobe()'s input parameter 'event_re'
is used for this type of pattern matching.

[1] https://gcc.gnu.org/gcc-10/changes.html
[2] ARCH=arm64 make Image

Signed-off-by: Guodong Xu <guodong.xu@linaro.org>
4 years agotcpstates: forget sockets when connection is closed
Jerome Marchand [Fri, 5 Mar 2021 13:58:06 +0000 (14:58 +0100)]
tcpstates: forget sockets when connection is closed

The adress of struct sock, which are used as the map key, are often
reused. When it happens random duration appears in the MS field for
new connections (CLOSE->SYN_SENT and LISTEN->SYN_RECV
transitions). Let's forget about the socket when the connection is
closed.

4 years agolibbpf-tools: add cachestat
Wenbo Zhang [Thu, 11 Mar 2021 04:44:30 +0000 (12:44 +0800)]
libbpf-tools: add cachestat

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agocleanup the style and unused function in XDP examples
yeya24 [Wed, 10 Mar 2021 20:30:38 +0000 (15:30 -0500)]
cleanup the style and unused function in XDP examples

Signed-off-by: yeya24 <yb532204897@gmail.com>
4 years agotools: add option to include 'LPORT' in tcpconnect otuput (#3301)
suresh2514 [Fri, 12 Mar 2021 04:05:14 +0000 (09:35 +0530)]
tools: add option to include 'LPORT' in tcpconnect otuput (#3301)

add option to include 'LPORT' in tcpconnect otuput and
update man page for tcpconnect and add examples

4 years agoAdd required libfl-dev in Ubuntu Bionic
UENISHI Kota [Mon, 8 Mar 2021 00:40:17 +0000 (09:40 +0900)]
Add required libfl-dev in Ubuntu Bionic

Otherwise the `make` fails with lack of `FlexLexer.h` error.

4 years agoFix abnormal symbol parsing when __irqentry_text_end is before __irqentry_text_start
Edward Wu [Fri, 5 Mar 2021 06:13:30 +0000 (14:13 +0800)]
Fix abnormal symbol parsing when __irqentry_text_end is before __irqentry_text_start

On my ARM64 kernel 5.4 case

Symbol:
ffffffc0100820b8 T __irqentry_text_end
ffffffc0100820b8 T __irqentry_text_start

It will ignore all functions after __irqentry_text_start until __irqentry_text_end.
But this case __irqentry_text_end is before __irqentry_text_start.
So the problem happens.

Signed-off-by: Edward Wu <edwardwu@realtek.com>
4 years agolibbpf-tools: add funclatency
Barret Rhoden [Fri, 26 Feb 2021 20:58:58 +0000 (15:58 -0500)]
libbpf-tools: add funclatency

This is a port of BCC's funclatency.  Usage:

---------
Time functions and print latency as a histogram

Usage: funclatency [-h] [-m|-u] [-p PID] [-d DURATION] [ -i INTERVAL ]
                   [-T] FUNCTION
       Choices for FUNCTION: FUNCTION         (kprobe)
                             LIBRARY:FUNCTION (uprobe a library in -p PID)
                             :FUNCTION        (uprobe the binary of -p PID)

  -m, --milliseconds         Output in milliseconds
  -u, --microseconds         Output in microseconds
  -p, --pid=PID              Process ID to trace
  -d, --duration=DURATION    Duration to trace
  -i, --interval=INTERVAL    Summary interval in seconds
  -T, --timestamp            Print timestamp

  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

Examples:
  ./funclatency do_sys_open         # time the do_sys_open() kernel function
  ./funclatency -m do_nanosleep     # time do_nanosleep(), in milliseconds
  ./funclatency -u vfs_read         # time vfs_read(), in microseconds
  ./funclatency -p 181 vfs_read     # time process 181 only
  ./funclatency -p 181 c:read       # time the read() C library function
  ./funclatency -p 181 :foo         # time foo() from pid 181's userspace
  ./funclatency -i 2 -d 10 vfs_read # output every 2 seconds, for 10s
  ./funclatency -mTi 5 vfs_read     # output every 5 seconds, with timestamps

---------

It supports kprobes and has limited support for uprobes.  Currently, you
cannot uprobe a library unless you provide a PID.  It does not support
wildcard patterns.

Some of the functions for uprobes are useful for other programs, so I
put those in uprobe_helpers.{c,h}.

Signed-off-by: Barret Rhoden <brho@google.com>
4 years agofix a llvm-triggered compilation error
Yonghong Song [Tue, 2 Mar 2021 23:35:09 +0000 (15:35 -0800)]
fix a llvm-triggered compilation error

Upstream (llvm13) patch
  https://reviews.llvm.org/D97223
changed function signature for CreateAtomicRMW().
The error message:
  /home/yhs/work/bcc/src/cc/frontends/b/codegen_llvm.cc:
     In member function ‘ebpf::StatusTuple ebpf::cc::CodegenLLVM
        ::emit_atomic_add(ebpf::cc::MethodCallExprNode*)’:
  /home/yhs/work/bcc/src/cc/frontends/b/codegen_llvm.cc:720:75:
     error: no matching function for call to
        ‘llvm::IRBuilder<>::CreateAtomicRMW(llvm::AtomicRMWInst::BinOp,
         llvm::Value*&, llvm::Value*&, llvm:: AtomicOrdering)’
       AtomicRMWInst::Add, lhs, rhs, AtomicOrdering::SequentiallyConsistent);
                                                                           ^
  In file included from /home/yhs/work/bcc/src/cc/frontends/b/codegen_llvm.cc:31:
  /home/yhs/work/llvm-project/llvm/build/install/include/llvm/IR/IRBuilder.h:1721:18:
      note: candidate:
  ‘llvm::AtomicRMWInst* llvm::IRBuilderBase::CreateAtomicRMW(llvm::AtomicRMWInst::BinOp,
      llvm::Value*, llvm::Value*, llvm::MaybeAlign, llvm::AtomicOrdering,
      llvm::SyncScope::ID)’
   AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr,
                  ^~~~~~~~~~~~~~~
  /home/yhs/work/llvm-project/llvm/build/install/include/llvm/IR/IRBuilder.h:1721:18: note:
  candidate expects 6 arguments, 4 provided

Fixed the issue with correct arguments.

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agobiotop and biosnoop: save __data_len at blk_start_request
Andreas Gerstmayr [Thu, 25 Feb 2021 18:33:08 +0000 (19:33 +0100)]
biotop and biosnoop: save __data_len at blk_start_request

Commit 95c9229ea9f029a1b9e8dcbe86fc67f037c0dfa2 replaced the
blk_account_io_completion kprobe with blk_account_io_done. Unfortunately
the req->__data_len field is 0 in blk_account_io_done, therefore we need
to save the __data_len field in blk_start_request

Resolves #3099

4 years agofix wakeuptime's raw_tp: get awakened task from ctx not current
Wenbo Zhang [Mon, 1 Mar 2021 14:31:27 +0000 (22:31 +0800)]
fix wakeuptime's raw_tp: get awakened task from ctx not current

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agoUse string type for comparison to PATH elements
Jonathan Giddy [Sun, 28 Feb 2021 16:47:37 +0000 (16:47 +0000)]
Use string type for comparison to PATH elements

4 years agoINSTALL.md: Update and simplify the install steps for Debian from source
Tiezhu Yang [Mon, 1 Mar 2021 12:40:35 +0000 (20:40 +0800)]
INSTALL.md: Update and simplify the install steps for Debian from source

The current install steps for Debian from source is out of date,
use the distribution name sid instead of jessie, stretch, buster
due to the latter always change, update and simplify the install
steps like other distributions which is clear and always right.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
4 years agoIncrease storage size of usdt constant to 64 bits
Richard Sanger [Wed, 3 Feb 2021 01:56:22 +0000 (14:56 +1300)]
Increase storage size of usdt constant to 64 bits

Systemtap defines argument size as either 1, 2, 4, or 8 bytes
signed or unsigned. Thus the constant variable should be stored in
a long long instead of an int to ensure at least 8 bytes size.

4 years agoTypo
Sevan Janiyan [Thu, 25 Feb 2021 22:23:23 +0000 (22:23 +0000)]
Typo

4 years agoEnable kernel headers through /sys/kern/kheaders.tar.xz
Sevan Janiyan [Wed, 24 Feb 2021 21:59:23 +0000 (21:59 +0000)]
Enable kernel headers through /sys/kern/kheaders.tar.xz

It's required by BCC. Opted to make it built-in rather than a module in the snippet.

4 years agoAdded helpers for BPF_PERCPU_HASH
Lénaïc Huard [Thu, 25 Feb 2021 14:26:46 +0000 (15:26 +0100)]
Added helpers for BPF_PERCPU_HASH

4 years agoAllow python usdt attachment with pid -1
Yonghong Song [Mon, 22 Feb 2021 17:26:29 +0000 (09:26 -0800)]
Allow python usdt attachment with pid -1

For usdt with semaphore, user needs to provide pid in order
to create a usdt since enabling semaphore requires write to
virtual memory of the user process.

For attachment to corresponding usdt uprobe, we can pass
valid pid to perf_event_open() syscall so usdt is only
triggered for this process, or pass pid -1 permits usdt is
to triggered for all processes.

There are use cases for usdt to be triggered for other
processes than just one process. For example, for python
usdt function__entry/function__return, users may want to
trace usdt of a particular python process and all its
children processes.

C++ already has API to permit ignoring pid during attachment.
   attach_usdt(const USDT& usdt, pid_t pid = -1)
This patch added similar functionality to python with an
additional parameter to BPF constructor to indicate whether
attach_usdt can ignore pid or not.

Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agoFix bytes - strings confusion in trace tool
Jonathan Giddy [Sun, 21 Feb 2021 09:44:26 +0000 (09:44 +0000)]
Fix bytes - strings confusion in trace tool

4 years agoadd bpf_map_lookup_and_delete_batch in bcc (#3234)
Emilien Gobillot [Mon, 22 Feb 2021 15:45:16 +0000 (16:45 +0100)]
add bpf_map_lookup_and_delete_batch in bcc (#3234)

* add bpf_map_lookup_and_delete_batch in bcc
* add test_map_batch_ops.py to test batch lookup and delete on map
* add items_lookup_and_delete_batch() in the reference guide

4 years agotools/virtiostat: add virtiostat tool
zhenwei pi [Mon, 15 Feb 2021 11:19:17 +0000 (19:19 +0800)]
tools/virtiostat: add virtiostat tool

Add a new tool virtiostat to trace VIRTIO devices IO statistics.

Although we have already had iostat(to show block device statistics),
iftop(to show network device statistics), other devices of VIRTIO
family(Ex, console, balloon, GPU and so on) also need tools for each
type. virtiostat works in virtio lower layer, and it could trace all
the devices.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
4 years agoinclude common.h for std::make_unique
Dane Springmeyer [Sun, 21 Feb 2021 21:09:59 +0000 (13:09 -0800)]
include common.h for std::make_unique

4 years agofix incorrect arch register use for kprobe func with more parameters
Yonghong Song [Fri, 19 Feb 2021 17:13:30 +0000 (09:13 -0800)]
fix incorrect arch register use for kprobe func with more parameters

Commit 12107c6936c6 ("use correct arch register for the
4th param of x86_64 syscalls") tries to use proper syscall
specific registers on x86_64 as its 4th param for syscall
is different from non-syscall. Unfortunately, the
implementation also uses syscall arch. register
for non-syscall kernel functions, which is incorrect.

This patch fixed the issue by using syscall arch
registers only for syscalls.

Reported-by: zhenwei pi <pizhenwei@bytedance.com>
Fixes: 12107c6936c6 ("use correct arch register for the 4th param of x86_64 syscalls")
Signed-off-by: Yonghong Song <yhs@fb.com>
4 years agotools: include kasan header in slabtoprate
Jerome Marchand [Thu, 18 Feb 2021 10:33:20 +0000 (11:33 +0100)]
tools: include kasan header in slabtoprate

slabtoprate fails on 5.10 kernels because of a missing kasan_reset_tag
declaration. We need to include the kasan header file.

Fixes the following error:
In file included from /virtual/main.c:12:
include/linux/slub_def.h:181:27: warning: implicit declaration of function 'kasan_reset_tag' is invalid in C99 [-Wimplicit-function-declaration]
        return reciprocal_divide(kasan_reset_tag(obj) - addr,
                                 ^
include/linux/slub_def.h:181:48: error: invalid operands to binary expression ('int' and 'void *')
        return reciprocal_divide(kasan_reset_tag(obj) - addr,
                                 ~~~~~~~~~~~~~~~~~~~~ ^ ~~~~
1 warning and 1 error generated.
Traceback (most recent call last):
  File "/usr/share/bcc/tools/slabratetop", line 115, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 364, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

4 years agofix a typo in error messages in BPF::attach_usdt()
Goro Fuji [Thu, 11 Feb 2021 07:59:05 +0000 (07:59 +0000)]
fix a typo in error messages in BPF::attach_usdt()

it was something like: "Unable to enable USDT %sprovider:probe from binary  PID 1234 for
probe handle_probe"

4 years agoUpdate tutorial_bcc_python_developer.md
Ilya Margolin [Wed, 10 Feb 2021 20:02:03 +0000 (21:02 +0100)]
Update tutorial_bcc_python_developer.md

that kernel bug is fixed in 4.8-rc3 and what broke there is fixed in 4.8.10
according to https://cdn.kernel.org/pub/linux/kernel/v4.x/ChangeLog-4.8.10

4 years agodocs: explain the relationship between BPF_TABLE and its wrapper macros
Goro Fuji [Thu, 11 Feb 2021 01:42:21 +0000 (01:42 +0000)]
docs: explain the relationship between BPF_TABLE and its wrapper macros

4 years agolibbpf-tools: add arm64 and powerpc vmlinux.h headers
Andrii Nakryiko [Tue, 9 Feb 2021 04:35:00 +0000 (20:35 -0800)]
libbpf-tools: add arm64 and powerpc vmlinux.h headers

Add vmlinux.h for arm64 (aarch64) and powerpc (ppc64le) architectures.
Makefile already normalizes aarch64 -> arm64 and ppc64le -> powerpc, so no
adjustments are necessary.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agolibbpf-tools: add support for per-architecture vmlinux.h
Andrii Nakryiko [Tue, 9 Feb 2021 04:33:49 +0000 (20:33 -0800)]
libbpf-tools: add support for per-architecture vmlinux.h

Move vmlinux.h header into a per-architecture subdirectory to allow
architecture-specific builds of libbpf-tools.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
4 years agolibbpf-tools: minor fixes for readahead
Wenbo Zhang [Sun, 7 Feb 2021 02:09:40 +0000 (10:09 +0800)]
libbpf-tools: minor fixes for readahead

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agolibbpf-tools: fix some tools error info and usage
Wenbo Zhang [Sun, 31 Jan 2021 12:28:09 +0000 (20:28 +0800)]
libbpf-tools: fix some tools error info and usage

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agolibbpf-tools: fix readahead, support v5.10+ kernel
Wenbo Zhang [Sat, 6 Feb 2021 10:27:53 +0000 (18:27 +0800)]
libbpf-tools: fix readahead, support v5.10+ kernel

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agocmake: sync submodule libbpf when do cmake.
Jianpeng Ma [Thu, 4 Feb 2021 03:33:30 +0000 (11:33 +0800)]
cmake: sync submodule libbpf when do cmake.

Meet the following compiler error:
/mnt/trace-tools/eBPF/bcc/src/cc/frontends/clang/b_frontend_action.cc:
In member function bool
ebpf::BTypeVisitor::VisitVarDecl(clang::VarDecl*):]
/mnt/trace-tools/eBPF/bcc/src/cc/frontends/clang/b_frontend_action.cc:1449:18:
error: BPF_MAP_TYPE_RINGBUF was not declared in this scope; did you mean
BPF_MAP_TYPE_QUEUE?
1449 | map_type = BPF_MAP_TYPE_RINGBUF; | ^~~~~~~~~~~~~~~~~~~~ |
     BPF_MAP_TYPE_QUEUE
make[2]: ***  [src/cc/frontends/clang/CMakeFiles/clang_frontend.dir/build.make:95:
rc/cc/frontends/clang/CMakeFiles/clang_frontend.dir/b_frontend_action.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1065: src/cc/frontends/clang/CMakeFiles/clang_frontend.dir/all] Error 2
make: *** [Makefile:160: all] Error 2

This because, submodule libbpf can't sync when do cmake.
So enlarger the sync contion: only submodule is clean, we do sync
submodle when do cmake.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
4 years agoAdd install target to libbpf-tools
Jiri Olsa [Fri, 5 Feb 2021 20:55:55 +0000 (21:55 +0100)]
Add install target to libbpf-tools

We plan to put those tools in separate rpm,
so we need a way to install them.

Adding install target with standard DESTDIR
and prefix make variables.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
4 years agotools/wakeuptime: Switch to using tracepoints if available
Ananth N Mavinakayanahalli [Wed, 3 Feb 2021 10:48:11 +0000 (16:18 +0530)]
tools/wakeuptime: Switch to using tracepoints if available

wakeuptime currently uses kprobes to trace schedule(). Switch to using
tracepoints if available.

Also, in some builds, try_to_wake_up() may get optimized away causing
the script to fail altogether.

With this switch, we however see stack trace entries related to BPF too
in the end for each trace. While correct, it takes up screen real estate
for each backtrace.

    target:          InputThread
    ffffffffaf000107 secondary_startup_64_no_verify
    ffffffffb12495f1 start_kernel
    ffffffffaf10e609 cpu_startup_entry
    ffffffffaf10e40b do_idle
    ffffffffaf946849 cpuidle_enter
    ffffffffaf946577 cpuidle_enter_state
    ffffffffafc00d02 asm_sysvec_apic_timer_interrupt
    ffffffffafbbbc86 sysvec_apic_timer_interrupt
    ffffffffaf0dcc32 irq_exit_rcu
    ffffffffaf02bc47 do_softirq_own_stack
    ffffffffafc01112 asm_call_irq_on_stack
    ffffffffafe000ca __softirqentry_text_start
    ffffffffaf163a66 run_timer_softirq
    ffffffffaf1639df __run_timers.part.0
    ffffffffaf162f09 call_timer_fn
    ffffffffaf8c46c3 input_repeat_key
    ffffffffaf8c318e input_pass_values.part.0
    ffffffffaf8c2085 input_to_handler
    ffffffffaf8c9e81 evdev_events
    ffffffffaf124a1c __wake_up_common_lock
    ffffffffaf1248b0 __wake_up_common
    ffffffffaf375e49 ep_poll_callback
    ffffffffaf124a1c __wake_up_common_lock
    ffffffffaf1248b0 __wake_up_common
    ffffffffaf375e0d ep_poll_callback
    ffffffffaf124a1c __wake_up_common_lock
    ffffffffaf1248b0 __wake_up_common
    ffffffffaf124681 autoremove_wake_function
    ffffffffaf108e57 try_to_wake_up
    ffffffffaf107dcc ttwu_do_wakeup
    ffffffffaf1f48a2 bpf_trace_run1
    ffffffffc16879d3 ftrace_trampoline
    ffffffffaf1f51c9 bpf_get_stackid_raw_tp
    waker:           swapper/0
        169325

4 years agoFix the test_libbcc/test_libbcc_no_libbpf testcase failure when the kernel version...
w00560594 [Tue, 2 Feb 2021 08:16:07 +0000 (16:16 +0800)]
Fix the test_libbcc/test_libbcc_no_libbpf testcase failure when the kernel version is lower than 4.20

4 years agocorrect the path of offcputime.lua
liuchao173 [Sat, 30 Jan 2021 07:05:00 +0000 (15:05 +0800)]
correct the path of offcputime.lua

[root@openEuler bcc]# cd src/lua/
[root@openEuler lua]# ./bcc-lua ../../../examples/lua/offcputime.lua -d 1 >/dev/null 2>/dev/null
[root@openEuler lua]# ./bcc-lua ../../../examples/lua/offcputime.lua -d 1
./bcc-lua: cannot open ../../../examples/lua/offcputime.lua: No such file or directory
stack traceback:
        [C]: in function 'dofile'
        bcc.lua:6338: in function <bcc.lua:6288>
        [C]: at 0x557532f676b0
[root@openEuler lua]#

4 years agoFix freezing of 'test_brb' if iperf is not found
Liu Chao [Fri, 29 Jan 2021 08:57:41 +0000 (08:57 +0000)]
Fix freezing of 'test_brb' if iperf is not found

If iperf is not installed or installed at a location that is not
in PATH as recgnized by Python, then 'test_brb' will fail while
test_brb2 success.

test_brb:
======================================================================
ERROR: test_brb (__main__.TestBPFSocket)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_brb.py", line 200, in test_brb
    nsp_server = NSPopenWithCheck(ns2_ipdb.nl.netns, ["iperf", "-s", "-xSC"])
  File "/root/rpmbuild/BUILD/bcc/tests/python/utils.py", line 63, in __init__
    has_executable(name)
  File "/root/rpmbuild/BUILD/bcc/tests/python/utils.py", line 18, in has_executable
    raise Exception(name + ": command not found")
Exception: iperf: command not found

----------------------------------------------------------------------
Ran 1 test in 2.546s

FAILED (errors=1)

test_brb2:
CRITICAL:root:WARNING! Test test_brb (__main__.TestBPFSocket) failed, but marked as passed because it is decorated with @mayFail.
CRITICAL:root:  The reason why this mayFail was: This fails on github actions environment, and needs to be fixed
CRITICAL:root:  The failure was: "iperf: command not found"
CRITICAL:root:  Stacktrace: "Traceback (most recent call last):
  File "/root/rpmbuild/BUILD/bcc/tests/python/utils.py", line 35, in wrapper
    res = func(*args, **kwargs)
  File "test_brb.py", line 202, in test_brb
    nsp_server = NSPopenWithCheck(ns2_ipdb.nl.netns, ["iperf", "-s", "-xSC"])
  File "/root/rpmbuild/BUILD/bcc/tests/python/utils.py", line 63, in __init__
    has_executable(name)
  File "/root/rpmbuild/BUILD/bcc/tests/python/utils.py", line 18, in has_executable
    raise Exception(name + ": command not found")
Exception: iperf: command not found
"
.
----------------------------------------------------------------------
Ran 1 test in 2.627s

OK

test_brb2 success because there is @mayFail in it which come from
commit a47c44fa0d570b64d8cb06449052db4f363e80a4

so add @mayFail in test_brb

Signed-off-by: Liu Chao <liuchao173@huawei.com>
4 years agocmake: look for either static or dynamic libraries
Matteo Croce [Tue, 26 Jan 2021 23:26:39 +0000 (00:26 +0100)]
cmake: look for either static or dynamic libraries

On some distro, static libraries are shipped in a separate package.
Look for either a static or dynamic libbpf, and only fail if neither is found.

4 years agoINSTALL.md: fix the Debian binary link
Guangyuan Yang [Wed, 27 Jan 2021 20:19:20 +0000 (15:19 -0500)]
INSTALL.md: fix the Debian binary link

4 years agoadd support kfunc/modify_return bpf programs
Yonghong Song [Wed, 27 Jan 2021 07:29:19 +0000 (23:29 -0800)]
add support kfunc/modify_return bpf programs

Add support for tracing program with BPF_MODIFY_RETURN
attachment type. This is used for security oriented bpf
programs which can modify return values for certain
kernel functions:
  - whitelisted for error injection by checking
    within_error_injection_list including all syscalls.
  - lsm security function (prefix "security_").

Also extended load_func() API to allow specify bpf program
is sleepable and this will permits to use some sleepable
helpers like bpf_copy_from_user() and d_path().

4 years agoaarch64: turn off jump table optimization during jit compilation
Chunmei Xu [Tue, 26 Jan 2021 10:04:24 +0000 (18:04 +0800)]
aarch64: turn off jump table optimization during jit compilation

test_clang.py: test_jump_table will get failed with error messgae:
bpf: Failed to load program: Invalid argument
unknown opcode a0
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0

HINT: The 'unknown opcode' can happen if you reference a global or
static variable, or data in read-only section. For example, 'char *p =
"hello"' will result in p referencing a read-only section, and 'char p[]
= "hello"' will have "hello" stored on the stack.

Signed-off-by: Chunmei Xu <xuchunmei@linux.alibaba.com>
4 years agolibbpf-tools: fix runqlen's error handling logic
Wenbo Zhang [Wed, 13 Jan 2021 03:13:20 +0000 (22:13 -0500)]
libbpf-tools: fix runqlen's error handling logic

Signed-off-by: Wenbo Zhang <ethercflow@gmail.com>
4 years agofix some test cases failed (#3235)
xuchunmei000 [Thu, 21 Jan 2021 15:22:23 +0000 (23:22 +0800)]
fix some test cases failed (#3235)

* tests/test_uprobes.py: set larger sleep time to pass test on aarch64
* test/test_clang.py: attach to vfs_read after failed to attach __vfs_read
* tests/test_clang_complex.c: set BPF_TABLE array key type to int
  array_map_check_btf in kernel/bpf/arraymap.c check key type must be
  BTF_KIND_INT

Signed-off-by: Chunmei Xu <xuchunmei@linux.alibaba.com>
4 years agotools/offcputime Warn user when an event skipped by negative duration
Yuto Kawamura [Mon, 18 Jan 2021 11:30:34 +0000 (20:30 +0900)]
tools/offcputime Warn user when an event skipped by negative duration