platform/upstream/bcc.git
6 years agodbus-message-size : python shell script syntax error fix 34/161334/1 accepted/tizen_5.0_unified accepted/tizen/5.0/unified/20181102.023145 accepted/tizen/unified/20171130.063440 submit/tizen/20171129.110101 submit/tizen_5.0/20181101.000005
INSUN PYO [Thu, 23 Nov 2017 01:35:31 +0000 (10:35 +0900)]
dbus-message-size : python shell script syntax error fix

Signed-off-by: INSUN PYO <insun.pyo@samsung.com>
Change-Id: Ib33135f5395a3a7410a2afb9336d5f61636c3ec7

6 years agodbus-messages-sent: some messages were counted twice 56/159556/1
Adrian Szyndela [Thu, 9 Nov 2017 15:33:41 +0000 (16:33 +0100)]
dbus-messages-sent: some messages were counted twice

dbus-messages-sent set uprobes on functions:
dbus_connection_send
dbus_connection_send_preallocated
dbus_connection_send_with_reply
dbus_connection_send_with_reply_and_block

However, dbus_connection_send_with_reply_and block calls
dbus_connection_send_with_reply, so the messages were counted twice.
This commit removes uprobe from
dbus_connection_send_with_reply_and_block.

Change-Id: Id6774ed36016607db58c48ca613ba3cdd1e93db6

6 years agodbus tools: generalized dbus includes 38/159538/3
Adrian Szyndela [Thu, 9 Nov 2017 11:57:44 +0000 (12:57 +0100)]
dbus tools: generalized dbus includes

Definitions of structures used in dbus tools were included inline
in the tools. This commit creates separate include files with
the structures extracted.

Change-Id: Ib7ac526f854477d3242650ce2942f5250e7687bd

6 years agoarm: handling size type differences between arm host and bpf 22/158022/3
Adrian Szyndela [Thu, 26 Oct 2017 10:21:21 +0000 (10:21 +0000)]
arm: handling size type differences between arm host and bpf

Change-Id: I977bb03332040df8f49c06645abca7233a90aaac

6 years agofixed typo: tok -> top 62/156462/1
Adrian Szyndela [Wed, 18 Oct 2017 11:12:48 +0000 (13:12 +0200)]
fixed typo: tok -> top

Change-Id: I4a4bf197476dc50f60418b4143780b3088ee2251

6 years agotemporary workaround for derefs on arm32 56/156456/1 submit/tizen_4.0/20171018.110122
Adrian Szyndela [Wed, 18 Oct 2017 10:50:47 +0000 (12:50 +0200)]
temporary workaround for derefs on arm32

Change-Id: Ic3fa9045a008dfc0f6aba639bf2747ab0266d2c1

6 years agoBPF: make 'pseudo' function return pointer 80/148680/4
Adrian Szyndela [Wed, 6 Sep 2017 13:14:57 +0000 (15:14 +0200)]
BPF: make 'pseudo' function return pointer

'pseudo' function returns u64. However, in fact it returns pointers.
It makes difference for 32-bit systems. The generated IR
has additional trunc instruction, which may make further problems,
remote: when passed to eBPF verifier.

This patch is made to handle similar change in llvm.

Change-Id: I4a691bdfa4b10b207197941c589026997b62f8fe

6 years agoAdd 6 tools tracking dbus. 26/150426/5
Dawid Kuczma [Fri, 15 Sep 2017 10:39:40 +0000 (12:39 +0200)]
Add 6 tools tracking dbus.

- messages size (dbus and gdbus)
- number of messages sent
- dbus procesor time usage
- glib procesor time usage
- message type
- message latency (dbus and gdbus)

Change-Id: Ie283b427581f12ea76dc342c4e3c4eb71ef72486

6 years agoworkaround for redefined memset in ARM kernel headers 20/153720/3
Adrian Szyndela [Fri, 29 Sep 2017 07:44:37 +0000 (07:44 +0000)]
workaround for redefined memset in ARM kernel headers

Change-Id: Iffd4c4e558fc0e9a1916a9f6ec570c368b6cbbd5

6 years agocorrected snprintf format to match needed 64-bits 92/149592/2
Adrian Szyndela [Tue, 12 Sep 2017 13:49:48 +0000 (15:49 +0200)]
corrected snprintf format to match needed 64-bits

Change-Id: Ied3890d6a25a814a48847f83b8e987b97436f042

6 years agoARM support added 62/148062/2
Rafal Pietruch [Thu, 29 Jun 2017 09:09:35 +0000 (11:09 +0200)]
ARM support added

* fix compilation errors on 32bit systems regarding int128
* add function calling convention for ARM (R0-R3) as defined
  in "Procedure Call Standard for the ARM Architecture"
* disable including kernel header files with ARM assembly code
  as for arm64 (https://patchwork.kernel.org/patch/7605601/)
* provide BPF syscall number for ARM (386)
  as defined in kernel src: linux/arch/arm/tools/syscall.tbl
* create clang driver for armv7l-tizen-linux-gnueabi triple
* fix libbcc python/C wrapper with proper arguments types
* define generic PT_REGS macros for ARM

Change-Id: Ifbd2ea3f18a8851e8b93b6936548b097bbe66ef7

6 years agopackaging: Add tizen spec 61/148061/2
Rafal Pietruch [Thu, 13 Jul 2017 08:43:45 +0000 (10:43 +0200)]
packaging: Add tizen spec

Signed-off-by: Rafał Pietruch <r.pietruch@samsung.com>
[ Added llvm-static-devel build dependency, .gbs.conf, adjusted to current upstream ]
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
Change-Id: Ia63984e954be3e49bfdc407f123afaec82033b65

6 years agoMerge pull request #1337 from pbhole/fix_vlan_learning
Brendan Gregg [Mon, 4 Sep 2017 18:31:39 +0000 (11:31 -0700)]
Merge pull request #1337 from pbhole/fix_vlan_learning

examples: fix vlan_learning example

6 years agonfsslower: trace slow NFS operations
samuelnair [Mon, 4 Sep 2017 16:57:49 +0000 (00:57 +0800)]
nfsslower: trace slow NFS operations

* Initial commit of nfsslower, tracking NFS4_READ, NFS4_WRITE and NFS4_OPEN

* Added in documentation, examples, support for csv and tracing for GETATTR

* Added in man pages, READM mods and example file, to comply with
https://github.com/samuelnair/bcc/blob/master/CONTRIBUTING-SCRIPTS.md

* Changes to address comments from @brendangregg and a small bug regarding
the output header not being printed when tracing all NFS operations

* Added nfsslower to the correct alphabetical postion

* Addressing Sasha's comments. I appreciate the thoroughness of the review

* Added test case for nfsslower and an extra function to check if the NFS kernel
module is loaded

6 years agoexamples: fix vlan_learning example
Prashant Bhole [Mon, 4 Sep 2017 00:26:08 +0000 (09:26 +0900)]
examples: fix vlan_learning example

BPF_HASH declaration fixed.

6 years agostackcount: add -K, -U, -d, -D, and -f (#1335)
Brendan Gregg [Sun, 3 Sep 2017 19:08:52 +0000 (12:08 -0700)]
stackcount: add -K, -U, -d, -D, and -f (#1335)

* stackcount: add -K and -U

* stackcount: add -D for duration

* stackcount: add -f for folded output

6 years agoIncreased allowed path name for USDT probes
Romain Cledat [Tue, 18 Jul 2017 00:09:13 +0000 (17:09 -0700)]
Increased allowed path name for USDT probes

Also added a warning if the length is exceeded

6 years agoMerge pull request #1324 from mskarbek/zfs_tools_fix
Brendan Gregg [Mon, 28 Aug 2017 20:14:43 +0000 (13:14 -0700)]
Merge pull request #1324 from mskarbek/zfs_tools_fix

zfs tools fix for zpl_read/zpl_write removal

6 years agozfs tools fix for zpl_read/zpl_write removal
Marcin Skarbek [Mon, 28 Aug 2017 15:39:50 +0000 (17:39 +0200)]
zfs tools fix for zpl_read/zpl_write removal

6 years agoFix _GNU_SOURCE redefined warning
Nan Xiao [Mon, 28 Aug 2017 03:44:19 +0000 (11:44 +0800)]
Fix _GNU_SOURCE redefined warning

6 years agoFix uninitialized ProcMountNS in USDT Context
Teng Qin [Fri, 25 Aug 2017 23:29:16 +0000 (16:29 -0700)]
Fix uninitialized ProcMountNS in USDT Context

6 years agoUse correct data type for class Data
Nan Xiao [Thu, 17 Aug 2017 02:56:36 +0000 (10:56 +0800)]
Use correct data type for class Data

6 years agoUpdate after lookup in map.increment for HASH types
Brenden Blanco [Wed, 23 Aug 2017 22:15:32 +0000 (15:15 -0700)]
Update after lookup in map.increment for HASH types

Performing the update before lookup incurs an extra spinlock in the
kernel, which hurts performance. Reorder the code and increment to 1.
The memset is there I believe due to some type mismatch warnings, so I'm
leaving as is rather than doing a direct assign to 1. The resulting code
is optimized away anyway.

Fixes: #1314
Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agofix a bug introduced by previous lua-bcc build fix commit
Yonghong Song [Thu, 24 Aug 2017 06:56:56 +0000 (23:56 -0700)]
fix a bug introduced by previous lua-bcc build fix commit

The bug does not show up in my previous test probably because
I did not clean up the build directory and did not have a clean cmake.

In gcc 4.8.5 environment where -no-pie is not supported,
a clean cmake will trigger the issue as subsequent other
cxx compile test will fail due to additional -no-pie flag.

The fix is to reset the CMAKE_REQUIRED_FLAGS to its previous value
after the specific test.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoBetter check for compiler standard support
Teng Qin [Fri, 25 Aug 2017 22:56:23 +0000 (15:56 -0700)]
Better check for compiler standard support

6 years agoFix compile errors with ENABLE_USDT=Off
Brenden Blanco [Thu, 24 Aug 2017 17:59:46 +0000 (10:59 -0700)]
Fix compile errors with ENABLE_USDT=Off

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoFix for ubuntu elf linker error
Brenden Blanco [Wed, 23 Aug 2017 01:31:03 +0000 (18:31 -0700)]
Fix for ubuntu elf linker error

6 years agoAdd c-library only option
Brenden Blanco [Tue, 22 Aug 2017 22:47:12 +0000 (15:47 -0700)]
Add c-library only option

Allow building of JUST the libbpf library and related headers. No clang,
llvm, python, lua, etc. Not even tests :(

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agomove api and create dependent option
Brenden Blanco [Thu, 29 Jun 2017 00:37:06 +0000 (17:37 -0700)]
move api and create dependent option

Move the C++ api files under a new subdirectory.
Use CMAKE_DEPENDENT_OPTION to enforce sdt->cpp_api relationship.

Since linking .a into a .so can cause global symbols to be dropped, add
a helper file to force exported symbols to be retained (link_all.cc).
This problem doesn't exist for building the static cpp examples.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoMove source file names into cmake variables
Brenden Blanco [Tue, 27 Jun 2017 21:34:54 +0000 (14:34 -0700)]
Move source file names into cmake variables

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agosrc/cc: cmake file cleanup and split usdt into subdir
Brenden Blanco [Mon, 26 Jun 2017 20:37:34 +0000 (13:37 -0700)]
src/cc: cmake file cleanup and split usdt into subdir

Move two usdt related files to a new subdirectory and link them into the
final product. Introduce a cmake option to disable that feature (turning
it off currently fails to compile).

Move some of the cmake flag computation into a helper cmake file and
include that rather than inlining it.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoRemove unused shared_table.h
Brenden Blanco [Fri, 23 Jun 2017 20:39:57 +0000 (13:39 -0700)]
Remove unused shared_table.h

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agofunccount: add -d for duration
Brendan Gregg [Wed, 23 Aug 2017 22:00:30 +0000 (15:00 -0700)]
funccount: add -d for duration

6 years agofix lua-bcc build issue with cmake try_compile
Yonghong Song [Wed, 23 Aug 2017 20:40:47 +0000 (13:40 -0700)]
fix lua-bcc build issue with cmake try_compile

Certain versions of recent gcc (e.g., gcc 6.3.0 on ubuntu17.04)
has pie enabled by default at linker (collect2) stage.
The compilation flag "-no-pie" is available to negate
this linker option.

Add -no-pie to compilation flag only if it is available.
Earlier gcc compiler may not have this option but it does
not have linker pie on-by-default either.

Tested with ubuntu 17.04 and my local gcc 4.8.5 (not accepting -no-pie).

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoFix segfault on incomplete types
Paul Chaignon [Wed, 23 Aug 2017 05:25:30 +0000 (07:25 +0200)]
Fix segfault on incomplete types

The bcc rewriter segfaults when it encounters an incomplete type
(missing declaration or declaration after use) in a map declaration.
This commit fixes it by first checking the type and returning an
error if it is incomplete.

6 years agoTest case for incomplete types
Paul Chaignon [Tue, 22 Aug 2017 21:00:08 +0000 (23:00 +0200)]
Test case for incomplete types

The bcc rewriter segfaults when it encounters an incomplete type
(missing declaration or declaration after use) in a map declaration.

6 years agoAdd /tests/ to CODEOWNERS
Brenden Blanco [Wed, 23 Aug 2017 06:20:46 +0000 (23:20 -0700)]
Add /tests/ to CODEOWNERS

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoAdd CODEOWNERS file with list of maintainers/reviewers
Brenden Blanco [Tue, 22 Aug 2017 06:52:30 +0000 (23:52 -0700)]
Add CODEOWNERS file with list of maintainers/reviewers

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoTrace external pointers from helpers
Paul Chaignon [Sun, 6 Aug 2017 12:33:20 +0000 (14:33 +0200)]
Trace external pointers from helpers

At this time, a single helper can return a kernel pointer,
bpf_get_current_task.

6 years agoMerge pull request #1301 from albusshin/patch-1
Brendan Gregg [Wed, 23 Aug 2017 00:36:41 +0000 (17:36 -0700)]
Merge pull request #1301 from albusshin/patch-1

Update obsolete file name bitesize -> bitehist

6 years agoMerge pull request #1305 from NanXiao/format-vfscount
Brendan Gregg [Tue, 22 Aug 2017 23:53:15 +0000 (16:53 -0700)]
Merge pull request #1305 from NanXiao/format-vfscount

Format code of vfscount.py

6 years agoMerge pull request #1303 from pchaigno/remove-bpf_probe_reads
Brendan Gregg [Tue, 22 Aug 2017 23:37:38 +0000 (16:37 -0700)]
Merge pull request #1303 from pchaigno/remove-bpf_probe_reads

Remove unnecessary bpf_probe_reads

6 years agolibbpf: fix typo in bpf_attach_xdp()
Gary Lin [Fri, 18 Aug 2017 10:10:43 +0000 (18:10 +0800)]
libbpf: fix typo in bpf_attach_xdp()

6 years agoAllow the flags to be specified in remove_xdp()
Gary Lin [Fri, 18 Aug 2017 09:42:08 +0000 (17:42 +0800)]
Allow the flags to be specified in remove_xdp()

When detaching a generic XDP program to an interface without native XDP
support, remove_xdp() showed the following message:

   bpf: nlmsg error Operation not supported

Add the flags parameter to notify the kernel that it's a generic XDP
program.

6 years agoFormat code of vfscount.py
Nan Xiao [Tue, 22 Aug 2017 01:59:26 +0000 (09:59 +0800)]
Format code of vfscount.py

6 years agobcc-lua: --no-pie, not -no-pie
Mark Drayton [Fri, 18 Aug 2017 17:28:48 +0000 (18:28 +0100)]
bcc-lua: --no-pie, not -no-pie

Some versions of GCC don't accept `-no-pie`. For instance, on a GCC 5 build I
have here:

```
$ gcc -no-pie
gcc: error: unrecognized command line option ‘-no-pie’
gcc: fatal error: no input files
```

5.4 from Xenial will take `-no-pie`, as will versions of 4, 6 and 7 that I
tried. The issue may be related to
https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg170818.html but I'm not
certain.

A workaround for this is to use `--no-pie`, which is accepted by all versions
of GCC 4, 5, 6 and 7 that I tried.

6 years agoUpdate obsolete file name bitesize -> bitehist
Tian Xin [Sat, 19 Aug 2017 00:07:23 +0000 (17:07 -0700)]
Update obsolete file name bitesize -> bitehist

Update tutorial to change the file name.

6 years agoFixes for debian and ubuntu docker build
Pavel Safronov [Thu, 17 Aug 2017 17:41:47 +0000 (20:41 +0300)]
Fixes for debian and ubuntu docker build

* Fixed build for debian and ubuntu
* Bumped debian and ubuntu versions (fix some build-dependency issues)
* Make debian and ubuntu Dockerfiles use the same build script
* Build-dependencies now installing automatically via pbuilder

6 years agoMerge pull request #1294 from iovisor/yhs_dev
4ast [Thu, 17 Aug 2017 07:36:31 +0000 (00:36 -0700)]
Merge pull request #1294 from iovisor/yhs_dev

avoid large map memory allocation in userspace

6 years agoavoid large map memory allocation in userspace
Yonghong Song [Wed, 16 Aug 2017 23:18:22 +0000 (16:18 -0700)]
avoid large map memory allocation in userspace

In bcc, internal BPF_F_TABLE defines a structure to
contain all the table information for later easy
extraction. A global structure will be defined
with this type. Note that this structure will be
allocated by LLVM during compilation.

In the table structure, one of field is:
   _leaf_type data[_max_entries]

If the _leaf_type and _max_entries are big,
significant memory will be consumed. A big
_leaf_type size example is for BPF_STACK_TRACE map
with 127*8=1016 bytes. If max_entries is bigger
as well, significant amount of memory will be
consumed by LLVM.

This patch replaces
  _leaf_type data[_max_entries]
to
  unsigned ing max_entries

The detail of a test example can be found in issue #1291.
For the example in #1291, without this patch, for a
BPF_STACK_TRACE map with 1M entries, the RSS is roughly
3GB (roughly 3KB per entry). With this patch, it is 5.8MB.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMerge pull request #1293 from iovisor/tools_fixes
Brendan Gregg [Wed, 16 Aug 2017 19:20:29 +0000 (12:20 -0700)]
Merge pull request #1293 from iovisor/tools_fixes

Couple minor tools fixes

6 years agopython - set attach_xdp's default flag value to 0
Gabriel Ganne [Wed, 16 Aug 2017 07:23:09 +0000 (09:23 +0200)]
python - set attach_xdp's default flag value to 0

Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>
6 years agohave uniform uprobe event names for python and C++
Yonghong Song [Fri, 28 Jul 2017 23:30:35 +0000 (16:30 -0700)]
have uniform uprobe event names for python and C++

This is a followup change for previous commit 0ba15075fc5f
(permit multiple pids attaching to the same probe).
That commit changes the event name for python uprobe API
in order to permit multiple processes attaching to the
same uprobe point. The C++ uprobe event name remains
unchanged and thus a descrepancy.

This patch add changes to C++ side and also make python uretprobe
having the same naming convention.

Originally I experimented to put the common code to generate
event names in libbpf.c. But doing this seems more klunky
than simplicity of C++ and Python. So I stick to the current
design.

No need to add pid to kprobe event names as kprobe bpf invocation
will ignore pid anyway.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoRemove extra S_MAXSTAT array allocation in some tools
Brenden Blanco [Wed, 16 Aug 2017 18:29:23 +0000 (11:29 -0700)]
Remove extra S_MAXSTAT array allocation in some tools

Fixes: #1280
Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoOmit include of ptrace.h for empty usdt contexts
Brenden Blanco [Wed, 16 Aug 2017 18:26:14 +0000 (11:26 -0700)]
Omit include of ptrace.h for empty usdt contexts

Fixes: #1280
Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoAdd clang check for -nopie option
Brenden Blanco [Fri, 11 Aug 2017 15:00:14 +0000 (08:00 -0700)]
Add clang check for -nopie option

The -no-pie option is not available in clang until 6.0. Per the
documentation, -nopie serves the same purpose as -no-pie (but not
-fno-pie). Hence, use the -nopie option when clang is in use as the CC.

Fixes: #1237
Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agoCorrect commit id for BPF_FUNC_get_socket_cookie
Paul Chaignon [Sun, 6 Aug 2017 12:20:23 +0000 (14:20 +0200)]
Correct commit id for BPF_FUNC_get_socket_cookie

6 years agotools/tcptracer: print ns timestamps with -v
Iago López Galeiras [Fri, 4 Aug 2017 16:13:05 +0000 (18:13 +0200)]
tools/tcptracer: print ns timestamps with -v

6 years agotools/tcptracer: add timestamp option
Iago López Galeiras [Fri, 4 Aug 2017 14:57:20 +0000 (16:57 +0200)]
tools/tcptracer: add timestamp option

Similar to other tools from the tcp* family.

6 years agoSince LUA_GLOBALSINDEX is obsolete from Lua 5.2, use lua_getglobal function
Nan Xiao [Wed, 2 Aug 2017 02:04:44 +0000 (10:04 +0800)]
Since LUA_GLOBALSINDEX is obsolete from Lua 5.2, use lua_getglobal function
instead.

6 years agobetter state default value handling
Brendan Gregg [Thu, 3 Aug 2017 18:49:27 +0000 (11:49 -0700)]
better state default value handling

6 years agoadd --state to offcputime
Brendan Gregg [Tue, 1 Aug 2017 01:39:30 +0000 (18:39 -0700)]
add --state to offcputime

6 years agoexplain that 'args' can be used as 'ctx' in tracepoints
Jean-Tiare Le Bigot [Sun, 30 Jul 2017 17:19:11 +0000 (19:19 +0200)]
explain that 'args' can be used as 'ctx' in tracepoints

6 years agomake it easier to discover the reference documentation
Jean-Tiare Le Bigot [Sun, 30 Jul 2017 17:17:57 +0000 (19:17 +0200)]
make it easier to discover the reference documentation

6 years agotcptop: Filter out negative values in receive probe
Benjamin Poirier [Fri, 28 Jul 2017 20:25:14 +0000 (13:25 -0700)]
tcptop: Filter out negative values in receive probe

When tcp_cleanup_rbuf() is called from tcp_recvmsg(), "copied" may be an
error code, especially -EAGAIN for non-blocking receives.

6 years agotcptop: Cleanup argument parsing
Benjamin Poirier [Thu, 27 Jul 2017 23:07:06 +0000 (16:07 -0700)]
tcptop: Cleanup argument parsing

6 years agotcpretrans: Remove unnecessary bpf_probe_reads
Paul Chaignon [Sun, 6 Aug 2017 09:15:11 +0000 (11:15 +0200)]
tcpretrans: Remove unnecessary bpf_probe_reads

6 years agotcpconnlat: Remove unnecessary bpf_probe_reads
Paul Chaignon [Sun, 6 Aug 2017 09:14:12 +0000 (11:14 +0200)]
tcpconnlat: Remove unnecessary bpf_probe_reads

6 years agosolisten: Remove unnecessary bpf_probe_reads
Paul Chaignon [Sun, 6 Aug 2017 09:12:26 +0000 (11:12 +0200)]
solisten: Remove unnecessary bpf_probe_reads

The use of a kernel function to cast sk is masking the assignment of
the external pointer to the bcc rewriter and prevents subsequent use
of dereferences.

6 years agoUse unsigned conversion specifier for nlmsg_pid
Toshiaki Makita [Mon, 31 Jul 2017 11:20:55 +0000 (20:20 +0900)]
Use unsigned conversion specifier for nlmsg_pid

nlmsg_pid is __u32, so let's use %u instead of %d.

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
6 years agoFix wrong netlink port id check
Toshiaki Makita [Mon, 31 Jul 2017 11:20:55 +0000 (20:20 +0900)]
Fix wrong netlink port id check

As per man netlink, nlmsg_pid is not process id and in fact a value
different from process id can be used.

  bpf: Wrong pid -1615084642, expected 24407

This problem can be triggered by using pyroute2 with bcc.

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
6 years agoRemove redundant semicolon
Nan Xiao [Mon, 31 Jul 2017 05:02:20 +0000 (13:02 +0800)]
Remove redundant semicolon

6 years ago1. Use more safe snprintf instead of sprintf;
Nan Xiao [Sat, 29 Jul 2017 02:47:24 +0000 (10:47 +0800)]
1. Use more safe snprintf instead of sprintf;
2. Modify procfilename buffer length in bcc_procutils_language function.

6 years agoPut libfl-dev into Build-Depends on Debian
Ivan Babrou [Fri, 28 Jul 2017 21:57:26 +0000 (14:57 -0700)]
Put libfl-dev into Build-Depends on Debian

On Debian Stretch `libfl-dev` is not installed automatically
if you install `flex`, this takjes care of the issue.

6 years agoMerge pull request #1263 from iovisor/yhs_dev
Brenden Blanco [Thu, 27 Jul 2017 15:47:08 +0000 (08:47 -0700)]
Merge pull request #1263 from iovisor/yhs_dev

permit multiple pids attaching to the same probe

6 years agopermit multiple pids attaching to the same probe
Yonghong Song [Sat, 22 Jul 2017 05:13:20 +0000 (22:13 -0700)]
permit multiple pids attaching to the same probe

Currently, if more than one pid-associated USDT attaching to
the same probe, usdt readarg code will be generated twice and
the compiler will complain.

This patch solves issue by preventing code duplication if
a previous context with the same mnt point and exec binary
has generated the code for the same probe. The event name is
also changed to have pid embedded so different pid-associated
uprobe event will have different names.

This patch introduces an internal uprobe event name
discrepency. It is a good idea to have event name
generation in libbpf so that both C++ API and Python API
will have consistent name conventions. This will be
addressed in a subsequent commit as it is largely
a different issue.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMerge pull request #1261 from iovisor/yhs_dev
4ast [Wed, 19 Jul 2017 05:08:48 +0000 (22:08 -0700)]
Merge pull request #1261 from iovisor/yhs_dev

generate proper usdt code to prevent llvm meddling with ctx->#fields

6 years agogenerate proper usdt code to prevent llvm meddling with ctx->#fields
Yonghong Song [Tue, 18 Jul 2017 21:12:10 +0000 (14:12 -0700)]
generate proper usdt code to prevent llvm meddling with ctx->#fields

Qin reported a test case where llvm still messes up with ctx->#fields.
For code like below:
  switch(ctx->ip) {
    case 0x7fdf2ede9820ULL: *((int64_t *)dest) = *(volatile int64_t *)&ctx->r12; return 0;
    case 0x7fdf2edecd9cULL: *((int64_t *)dest) = *(volatile int64_t *)&ctx->bx; return 0;
  }
The compiler still generates:
    # r1 is the pointer to the ctx
    r1 += 24
    goto LBB0_4
  LBB0_3:
    r1 += 40
  LBB0_4:
    r3 = *(u64 *)(r1 + 0)
The verifier will reject the above code since the last load is not "ctx + field_offset"
format.

The responsible llvm optimization pass is CFGSimplifyPass. Its main implementation
in llvm/lib/Transforms/Utils/SimplifyCFG.cpp. The main routine to do the optimization
is SinkThenElseCodeToEnd. The routine canSinkInstructions is used to determine whether
an insn is a candidate for sinking.

Unfortunately, volatile load/store is not a condition to prevent the optimization.
But inline assembly is a condition which can prevent further optimization.

In this patch, instead of using volatile to annotate ctx->#field access, we do
normal ctx->#field access but put a compiler inline assembly memory barrier
   __asm__ __volatile__(\"\": : :\"memory\");
after the field access.

Tested with usdt unit test case, usdt_samples example, a couple of usdt unit tests
developed in the past.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMySQL tracing without USDT (#1239)
Igor Mazur [Tue, 18 Jul 2017 07:06:34 +0000 (10:06 +0300)]
MySQL tracing without USDT (#1239)

Support tracing MySQL queries even when MySQL is built
without USDT support, by using uprobes on internal functions
responsible for command (query) dispatching.

6 years agoMerge pull request #1259 from iovisor/yhs_dev
4ast [Tue, 18 Jul 2017 07:04:45 +0000 (00:04 -0700)]
Merge pull request #1259 from iovisor/yhs_dev

Fix a clang memory leak

6 years agoFix a clang memory leak
Yonghong Song [Tue, 18 Jul 2017 06:20:17 +0000 (23:20 -0700)]
Fix a clang memory leak

In clang frontend actions, several compiler invocations are called
for rewriter and transforming source code to IR. During the invocation
to transform source code to IR, CodeGenOpts.DisableFree is used
to control whether the top target machine structure should be
freed or not for a particular clang invocation,
and its default value is TRUE.

See clang:lib/CodeGen/BackendUtil.cpp:
  ~EmitAssemblyHelper() {
    if (CodeGenOpts.DisableFree)
      BuryPointer(std::move(TM));
  }

So by default, the memory held by TM will not freed, even if
BPF module itself is freed. This is even more problematic
when continuous building/loading/unloading happens for long
live service.

This patch explicitly sets CodeGenOpts.DisableFree to FALSE
so memory can be properly freed. I did a simple experiment
to compile/load/unload an empty BPF program and the saving
is roughly 0.5MB.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMerge pull request #1258 from shodoco/tcpbpf
Brenden Blanco [Mon, 17 Jul 2017 22:55:57 +0000 (15:55 -0700)]
Merge pull request #1258 from shodoco/tcpbpf

Update bpf.h and virtual_bpf.h to 4.13-rc1

6 years agoUpdate bpf.h and virtual_bpf.h to 4.13-rc1
Huapeng Zhou [Mon, 17 Jul 2017 22:06:14 +0000 (15:06 -0700)]
Update bpf.h and virtual_bpf.h to 4.13-rc1

6 years agotools: Add some documentation to lib/ucalls.py output (#1257)
Geneviève Bastien [Fri, 14 Jul 2017 20:04:12 +0000 (16:04 -0400)]
tools: Add some documentation to lib/ucalls.py output (#1257)

Signed-off-by: Geneviève Bastien <gbastien@versatic.net>
6 years agoFix trace.py for library filenames containing colons (#1252)
vkhromov [Fri, 14 Jul 2017 19:42:29 +0000 (20:42 +0100)]
Fix trace.py for library filenames containing colons (#1252)

`trace.py` parses a probe using the colon as a separator.  As a result, it
fails to create a uprobe for binary/library with a filename containing colons.

This diff fixes that issue with `trace.py`.  It requires a kernel with
https://lkml.org/lkml/2017/1/13/585 merged to work properly, otherwise
`trace.py` still fails for create uprobes.

6 years agocc: Add open_perf_event to the C/C++ API (#1232)
Romain [Tue, 11 Jul 2017 18:15:09 +0000 (11:15 -0700)]
cc: Add open_perf_event to the C/C++ API (#1232)

6 years agomemleak: expand allocator coverage (#1214)
Rinat Ibragimov [Tue, 11 Jul 2017 18:14:08 +0000 (21:14 +0300)]
memleak: expand allocator coverage (#1214)

* memleak: handle libc allocation functions other than malloc

* memleak: use tracepoints to track kernel allocations

* memleak: add combined-only mode

With large number of outstanding allocations, amount of data passed from
kernel becomes large, which slows everything down.

This patch calculates allocation statistics inside kernel, allowing user-
space part to pull combined statistics data only, thus significantly
reducing amount of passed data.

* memleak: increase hashtable capacities

There are a lot of allocations happen in kernel. Default values are not
enough to keep up.

* test: add a test for the memleak tool

6 years agoAdd USDT sample (#1229)
bveldhoen [Tue, 11 Jul 2017 18:09:35 +0000 (20:09 +0200)]
Add USDT sample (#1229)

This sample contains:
    - A library with an operation that uses usdt probes.
    - A console application that calls the operation.
    - Scripts to trace the latency of the operation.
    - Corresponding cmake files.

6 years agodocs: update features list
Quentin Monnet [Fri, 7 Jul 2017 11:39:40 +0000 (13:39 +0200)]
docs: update features list

And fix a typo: direct_action -> direct-action

6 years agolibbpf: fix build warning on setns (#1246)
Colin Ian King [Thu, 6 Jul 2017 12:58:17 +0000 (13:58 +0100)]
libbpf: fix build warning on setns (#1246)

The macro _GNU_SOURCE should be defined to pick up the function
declaration for setns.  Fixes build warning:

"src/cc/libbpf.c:482:7: warning: implicit declaration of
 function 'setns' [-Wimplicit-function-declaration]
   if (setns(target_fd, CLONE_NEWNS)) {"

Signed-off-by: Colin Ian King <colin.king@canonical.com>
6 years agoMerge pull request #1237 from iovisor/yhs_dev
4ast [Sat, 1 Jul 2017 19:59:49 +0000 (12:59 -0700)]
Merge pull request #1237 from iovisor/yhs_dev

Fix bcc.lua build issue in Ubuntu 17.04

6 years agousdt: Use ProcMountNS
Vicent Marti [Tue, 27 Jun 2017 17:06:46 +0000 (19:06 +0200)]
usdt: Use ProcMountNS

6 years agoproc: Enhance bcc_mapping_is_file_backed
Vicent Marti [Tue, 27 Jun 2017 13:22:38 +0000 (15:22 +0200)]
proc: Enhance bcc_mapping_is_file_backed

Cleanup the `strncmp` code and add a few more ignored map names

6 years agoFix bcc.lua build issue in Ubuntu 17.04
Yonghong Song [Fri, 30 Jun 2017 05:46:29 +0000 (22:46 -0700)]
Fix bcc.lua build issue in Ubuntu 17.04

In fc25 box, gcc6.3.1 is configured with pie default off.
Here, pie stands for position independent execution.

In ubuntu 17.04, gcc6.3.0, however, is configured with
pie default on. The gcc driver automatically adds -pie
to the linker options.

Since bcc.lua build needs pie off, previously, -fno-pie
is passed to the compiler. -fno-pie is a gcc option
impacting the code generation and it didn't
negate the -pie option in the linker. The correct way
seems to use gcc linker option -no-pie which can
successfully cancel the default -pie in the linker.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoUpdate LINKS.md
Nan Xiao [Fri, 30 Jun 2017 01:52:47 +0000 (09:52 +0800)]
Update LINKS.md

6 years agoAdded helpers for BPF_PERCPU_ARRAY (#1230)
Romain [Thu, 29 Jun 2017 19:00:31 +0000 (12:00 -0700)]
Added helpers for BPF_PERCPU_ARRAY (#1230)

6 years agoAdd an option to strip leading zeros from histograms (#1226)
Taekho Nam [Thu, 29 Jun 2017 14:20:47 +0000 (23:20 +0900)]
Add an option to strip leading zeros from histograms (#1226)

6 years agotest: python3 fix for test_uprobes (#1228)
Brenden Blanco [Fri, 23 Jun 2017 08:08:07 +0000 (01:08 -0700)]
test: python3 fix for test_uprobes (#1228)

Treat strings as bytes. This is independent of the larger refactor
(#1139) from which it is cherry-picked)

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agogethostlatency was rounding to full ms
Brendan Gregg [Thu, 22 Jun 2017 18:58:21 +0000 (11:58 -0700)]
gethostlatency was rounding to full ms

6 years agoChange clang frontend optimization level from 0 to 2
Yonghong Song [Mon, 12 Jun 2017 01:37:25 +0000 (18:37 -0700)]
Change clang frontend optimization level from 0 to 2

The issue is caused by the following clang change on 5.0:
https://reviews.llvm.org/D28404

Basically, at -O0, unless always inlining is specified, a
function will be marked as optnone and noinline.

This causes two kinds of issues: (1). optnone will generate
suboptimal code with heavy stack use and this high likely can
cause verifier failure; and (2). even if user mark all his/her
defined functions in bpf program as always inlining, some
functions in linux header files are not marked as always inline
and hence will be marked as noinline instead, ultimately
causing llvm complaining about global function reference.

This patch bumps the clang optimization level to -O2.
This should work with older versions of llvm as well.

Signed-off-by: Yonghong Song <yhs@fb.com>