platform/upstream/bcc.git
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>
6 years agoMerge pull request #1224 from NavinF/patch-1
Brendan Gregg [Wed, 14 Jun 2017 16:28:13 +0000 (09:28 -0700)]
Merge pull request #1224 from NavinF/patch-1

Update the installation instructions for Fedora

6 years agoUpdate the installation instructions for Fedora
Navin Francis [Wed, 14 Jun 2017 13:15:07 +0000 (06:15 -0700)]
Update the installation instructions for Fedora

6 years agoAdd probe result verification for usdt unit test
Yonghong Song [Fri, 2 Jun 2017 07:41:44 +0000 (00:41 -0700)]
Add probe result verification for usdt unit test

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoAdd installation instructions for openSUSE (#1222)
Gary Ching-Pang Lin [Mon, 12 Jun 2017 10:22:10 +0000 (18:22 +0800)]
Add installation instructions for openSUSE (#1222)

7 years agofix cc: error: unrecognized command line option -no-pie
Carlos Neira [Fri, 9 Jun 2017 19:07:37 +0000 (15:07 -0400)]
fix cc: error: unrecognized command line option -no-pie

cnb@ubuntu-14:~/iovisor/bcc/build$ make
[  6%] Built target clang_frontend
[  9%] Built target bpf-static
[ 16%] Built target bcc-loader-static
[ 30%] Built target b_frontend
[ 47%] Built target bcc-static
[ 48%] Built target CPUDistribution
[ 50%] Built target FollyRequestContextSwitch
[ 51%] Built target HelloWorld
[ 52%] Built target LLCStat
[ 54%] Built target RandomRead
[ 55%] Built target RecordMySQLQuery
[ 56%] Built target TCPSendStack
[ 80%] Built target bcc-shared
[ 83%] Built target bpf-shared
[ 84%] Built target bcc_py
Linking C executable bcc-lua
cc: error: unrecognized command line option â-no-pieâ
make[2]: *** [src/lua/bcc-lua] Error 1
make[1]: *** [src/lua/CMakeFiles/bcc-lua.dir/all] Error

option is called -fno-pie

7 years agoFix ld error due to debian/ubuntu -pie default
Ryan Tomayko [Mon, 5 Jun 2017 17:43:46 +0000 (17:43 +0000)]
Fix ld error due to debian/ubuntu -pie default

Fixes #782. Solution taken verbatim from @jepio here:

https://github.com/iovisor/bcc/issues/782#issuecomment-259075010

I ran into the same issue attempting to compile from source on
a fresh Ubuntu 16.10/Yakkety host:

Linking C executable bcc-lua
/usr/bin/ld: libluajit-5.1.a(ljamalg.o): relocation R_X86_64_32S
    against `.rodata' can not be used when making a shared object;
    recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output

Build succeeded after patch was applied.

7 years agofix incorrect code generation in usdt
Yonghong Song [Tue, 6 Jun 2017 00:55:24 +0000 (17:55 -0700)]
fix incorrect code generation in usdt

o This is caused by my ignorant error in previous usdt change.
  Obviously, I need to store into pointer address in order to
  propagate value back to caller.
o Thanks Tetsuo Handa pointing this out.

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoAdd missing funcslower from the snap.
Evan Dandrea [Thu, 27 Apr 2017 15:20:39 +0000 (11:20 -0400)]
Add missing funcslower from the snap.

7 years agoAdd aliases for all commands in the snap (e.g. bcc.biotop -> biotop)
Evan Dandrea [Thu, 27 Apr 2017 15:16:01 +0000 (11:16 -0400)]
Add aliases for all commands in the snap (e.g. bcc.biotop -> biotop)

7 years agoRequire a more recent, auto-updating version of snapd for alises.
Evan Dandrea [Mon, 8 May 2017 13:04:00 +0000 (08:04 -0500)]
Require a more recent, auto-updating version of snapd for alises.

7 years agoAdd libbcc-example package for Ubuntu Xenial
Taekho Nam [Mon, 5 Jun 2017 09:52:39 +0000 (09:52 +0000)]
Add libbcc-example package for Ubuntu Xenial

7 years agoAdd a python test for usdt
Yonghong Song [Tue, 30 May 2017 13:37:02 +0000 (06:37 -0700)]
Add a python test for usdt

  o The sample application covers different aspects
    of usdt rewriter code generation:
    - const
    - *(ctx + offset)
    - use bpf_probe_read to get trace data
    - the switch in ctx->ip if the same probe
      is triggered in multiple .text locations.
  o folly (https://github.com/facebook/folly/) tracing
    header files are pulled into python test directory and
    used to produce USDT probes.

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoImprove PerfEventArray clean up
Teng Qin [Thu, 25 May 2017 20:30:13 +0000 (13:30 -0700)]
Improve PerfEventArray clean up

7 years agoMerge pull request #1212 from iovisor/yhs_dev
4ast [Wed, 31 May 2017 21:08:57 +0000 (14:08 -0700)]
Merge pull request #1212 from iovisor/yhs_dev

Force udst ctx->#reg load to be volatile

7 years agoMerge pull request #1211 from iovisor/libbpf_c_includes
4ast [Wed, 31 May 2017 16:08:43 +0000 (09:08 -0700)]
Merge pull request #1211 from iovisor/libbpf_c_includes

Add linux/sched.h to list of libbpf.c includes

7 years agoAdd linux/sched.h to list of libbpf.c includes
Brenden Blanco [Wed, 31 May 2017 15:44:22 +0000 (08:44 -0700)]
Add linux/sched.h to list of libbpf.c includes

This should hopefully fix compile errors on some ubuntu systems.

Also, reorders the includes according to clang-format

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agomake libbpf standalone-ready
Brenden Blanco [Wed, 31 May 2017 00:35:53 +0000 (17:35 -0700)]
make libbpf standalone-ready

Break the c++ dependency in libbpf.c, and turn it into a separate lib
from cmake point of view.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agoMove ProcMountNSGuard to separate file
Brenden Blanco [Thu, 25 May 2017 20:24:15 +0000 (13:24 -0700)]
Move ProcMountNSGuard to separate file

This moves ProcMountNS[Guard] classes to a separate header file and
implementation. The goal will be to use these more directly in libbpf.c
without creating a circular dependency.
Removed the friend class statements and exposed a few public getters instead.
Slightly changed the implementation in ProcMountNS constructor to avoid
a few error cases and the use of snprintf.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agobcc_procutils_which: return if snprintf fails or would overflow
Christian Resell [Fri, 26 May 2017 19:44:07 +0000 (21:44 +0200)]
bcc_procutils_which: return if snprintf fails or would overflow

7 years agobcc_proc.c: fix stack overflow in bcc_procutils_which()
Christian Resell [Fri, 26 May 2017 14:50:52 +0000 (16:50 +0200)]
bcc_proc.c: fix stack overflow in bcc_procutils_which()

7 years agoForce udst ctx->#reg load to be volatile
Yonghong Song [Tue, 30 May 2017 09:03:06 +0000 (02:03 -0700)]
Force udst ctx->#reg load to be volatile

This is related to issue #1133. Compiler sometimes
generates code patterns likes:
     r1 = ctx + 96
     goto next
   here:
     r1 = ctx + 48
   next:
     r3 = load (r1 + 0)
Verifier will fail for such cases as r1 is marked
as "unknown" at the time of load.

The previous workaround is to add volatile attribute
to the store like
   *(volatile u64 *)&dest = ctx->bx
The hope is to force ctx related load in-place since
its value is needed for store.

Unfortunately, this does not always work and compiler
still has freedom to merge different ctx loads at the
same time honoring the volatile &dest. In USDT generated
code, different branches of &dest are the same.

This patch directly make ctx->bx itself as a volatile load:
  *(volatile u64 *)&ctx->bx
This seems working as compiler stops playing around
the address pointing to a volatile data.

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoMention that linux-headers deb must be installed.
Tomaz Solc [Fri, 26 May 2017 11:52:30 +0000 (13:52 +0200)]
Mention that linux-headers deb must be installed.

7 years agoMerge pull request #1201 from htbegin/master
Brenden Blanco [Thu, 25 May 2017 18:54:14 +0000 (11:54 -0700)]
Merge pull request #1201 from htbegin/master

funclatency/sslsniff: fix the TypeError when enabling pid filter on u…

7 years agoMerge pull request #1191 from GBuella/cmake_build_type_fix
4ast [Thu, 25 May 2017 05:14:11 +0000 (22:14 -0700)]
Merge pull request #1191 from GBuella/cmake_build_type_fix

Fix usage of CMAKE_BUILD_TYPE setting

7 years agoMerge pull request #1190 from palmtenor/cur_cpu
4ast [Thu, 25 May 2017 05:13:44 +0000 (22:13 -0700)]
Merge pull request #1190 from palmtenor/cur_cpu

Use BPF_F_CURRENT_CPU in perf_submit when possible

7 years agoUse BPF_F_CURRENT_CPU in perf_submit / perf_read when possible
Teng Qin [Tue, 23 May 2017 18:57:44 +0000 (11:57 -0700)]
Use BPF_F_CURRENT_CPU in perf_submit / perf_read when possible

7 years agoMerge pull request #1200 from palmtenor/perf_event_clean_up
4ast [Wed, 24 May 2017 20:08:26 +0000 (13:08 -0700)]
Merge pull request #1200 from palmtenor/perf_event_clean_up

Improve perf event clean up

7 years agoDisable perf event FD before free
Teng Qin [Wed, 24 May 2017 05:18:56 +0000 (22:18 -0700)]
Disable perf event FD before free

7 years agoAdd bpf_close_perf_event_fd
Teng Qin [Tue, 23 May 2017 23:35:11 +0000 (16:35 -0700)]
Add bpf_close_perf_event_fd

Add bpf_close_perf_event_fd helper that first disables, then closes a
perf event fd. Use it in Python and C++ API for detach perf event

7 years agoMerge pull request #1196 from palmtenor/cpp_sym_option
4ast [Wed, 24 May 2017 16:53:51 +0000 (09:53 -0700)]
Merge pull request #1196 from palmtenor/cpp_sym_option

Support symbol option in C++ API stack table

7 years agofunclatency/sslsniff: fix the TypeError when enabling pid filter on uprobe
htbegin [Wed, 24 May 2017 14:53:17 +0000 (22:53 +0800)]
funclatency/sslsniff: fix the TypeError when enabling pid filter on uprobe

attach_uprobe() and attach_uretprobe() expect the type of pid argument
is "int" instead of "str". Fix it by specifying the type of the "-p"/"--pid"
option as "int", and updating the format string of args.pid accordingly.

Fixes: d73c58f0c8c754bd591264205ac2ddc83c1d2c7f

7 years agoMerge pull request #1185 from gospo/master
Brenden Blanco [Tue, 23 May 2017 18:56:59 +0000 (11:56 -0700)]
Merge pull request #1185 from gospo/master

Add support for generic XDP mode

7 years agoSupport symbol option in C++ API stack table
Teng Qin [Tue, 23 May 2017 18:30:33 +0000 (11:30 -0700)]
Support symbol option in C++ API stack table

7 years agoAdd support for generic XDP mode
Andy Gospodarek [Wed, 17 May 2017 20:18:45 +0000 (16:18 -0400)]
Add support for generic XDP mode

Reused some of the code and command-line format from kernel XDP samples.

$ sudo ./xdp_drop_count.py -S enp1s0
Printing drops per IP protocol-number, hit CTRL+C to stop
17: 36616 pkt/s
17: 19720757 pkt/s
17: 19685768 pkt/s
17: 19643601 pkt/s
17: 19694537 pkt/s
[...]
$ sudo ./xdp_drop_count.py enp1s0
Printing drops per IP protocol-number, hit CTRL+C to stop
17: 7029 pkt/s
17: 29996706 pkt/s
17: 30048705 pkt/s
17: 30261417 pkt/s
17: 30291967 pkt/s
[...]

Throughput difference is expected since generic XDP takes more
instructions per packet than optimized XDP.

v2: switch __u32 to uint32_t in bpf_attach_xdp

Signed-off-by: Andy Gospodarek <gospo@broadcom.com>
7 years agoMerge pull request #1193 from palmtenor/cppleak
4ast [Mon, 22 May 2017 16:31:24 +0000 (09:31 -0700)]
Merge pull request #1193 from palmtenor/cppleak

Fix bcc_resolve_symname memory leak in C++ API

7 years agoMerge pull request #1192 from palmtenor/perf_config
4ast [Mon, 22 May 2017 14:56:10 +0000 (07:56 -0700)]
Merge pull request #1192 from palmtenor/perf_config

Unify Perf Event related Enums and checks