Re: perf eBPF patch ordering. was: Re: perf test LLVM was: Re: [GIT PULL 00/39] perf tools: filtering events using eBPF programs

From: Wangnan (F)
Date: Tue Aug 04 2015 - 01:28:52 EST


Hi Arnaldo,

The following changes since commit 922cc21746202956acb41c89a6190bb50805fa31:

perf tools: Introduce llvm config options (2015-07-31 12:17:50 -0300)

are available in the git repository at:

https://github.com/WangNan0/linux.git ebpf

for you to fetch changes up to d85bf4b6470b8d860bbae25418e5ae3ccd9711e8:

perf tools: Support attach BPF program on uprobe events (2015-08-04 04:59:20 +0000)

----------------------------------------------------------------

The new cset has following improvements:

1. Improve error message: now don't dump LLVM environment setting messages
if clang is found. Also, describe how to pre-compile .c file into .o.

See: perf tools: Call clang to compile C source to object code
https://github.com/WangNan0/linux/commit/264676a5b922aaf1e9be3800fe06d5b67b06cd12

2. Reorder patches, so when 'perf record' is able to accept '--event file.c', the BPF filter
should work. Also, an example BPF script file is provided, and the compilation
method is described in commit message.

See:
perf tools: Infrastructure for compiling scriptlets when passing '.c' to --event
https://github.com/WangNan0/linux/commit/eca622f4a88e1a791fc2405c398256ad572eba54

3. Introduce 'perf test BPF', which uses previous introduced scriptlet, fork a
'perf record' to utilise it and uses 'perf report' to check the result.

See: perf tests: Enforce LLVM test for BPF test
https://github.com/WangNan0/linux/commit/a7cdab453863c580446dc2c3a3f3a86f21b770ce

perf test: Enable 'perf test' run as test targets
https://github.com/WangNan0/linux/commit/b14f2627e95d348be5ec19bd24a5117e8c2ffe46
and
perf test: Add 'perf test BPF'
https://github.com/WangNan0/linux/commit/8414217dbfa57df4dbb55642dc26205e1c7cbdf1

4. Fix a bug that if the filename doesn't contain '/' it is recongnised as event name then
failed to be applied by order adjusting in parse-events.l: bring {bpf_object} and
{bpf_source} ahead.

You need to pop 9 patches from your perf/ebpf tree and rebase my tree. However, until
patch "perf tools: Enable passing bpf object file to --event" the changes is tiny. Please
check.

Thank you.

On 2015/8/4 3:49, Arnaldo Carvalho de Melo wrote:
Em Mon, Aug 03, 2015 at 01:11:16PM -0300, Arnaldo Carvalho de Melo escreveu:
ERROR: unable to compile ./foo.c
Hint: Check error message shown above.
LLVM 3.7 or newer is required. Which can be found from http://llvm.org
You may want to try git trunk:
git clone http://llvm.org/git/llvm.git
and
<SNIP>
or: perf record [<options>] -- <command> [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
[root@felicio ~]#
Now to find a hello.c BPF scriptlet...
So, we do not need to provide all this LLVM environment installation
hints when we get to any error, i.e. the one above was just becasuse
"./foo.c" doesn't exist, clang ran successfully, so no need for telling
the user how to install it.

The following error also shouldn't emit those hints:

[root@felicio ~]# perf record -e ./lock_page.bpf.c sleep 1
/root/./lock_page.bpf.c:1:5: error: expected parameter declarator
SEC("lock_page=__lock_page page->flags")
^
/root/./lock_page.bpf.c:1:5: error: expected ')'
/root/./lock_page.bpf.c:1:4: note: to match this '('
SEC("lock_page=__lock_page page->flags")
^
/root/./lock_page.bpf.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
SEC("lock_page=__lock_page page->flags")
^
/root/./lock_page.bpf.c:1:41: error: expected ';' after top level declarator
SEC("lock_page=__lock_page page->flags")
^
;
/root/./lock_page.bpf.c:2:22: warning: declaration of 'struct pt_regs' will not be visible outside of this function [-Wvisibility]
int lock_page(struct pt_regs *ctx, int err, unsigned long flags)
^
2 warnings and 3 errors generated.
ERROR: unable to compile ./lock_page.bpf.c
Hint: Check error message shown above.
LLVM 3.7 or newer is required. Which can be found from http://llvm.org
You may want to try git trunk:
git clone http://llvm.org/git/llvm.git
and
git clone http://llvm.org/git/clang.git

Or fetch the latest clang/llvm 3.7 from pre-built llvm packages for
debian/ubuntu:
http://llvm.org/apt

If you are using old version of clang, change 'clang-bpf-cmd-template'
option in [llvm] section of ~/.perfconfig to:

"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \
-working-directory $WORKING_DIR -c $CLANG_SOURCE \
-emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -"
(Replace /path/to/llc with path to your llc)

Hint: You can also pre-compile it into .o
invalid or unsupported event: './lock_page.bpf.c'
Run 'perf list' for a list of valid events

usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]

-e, --event <event> event selector. use 'perf list' to list available events
[root@felicio ~]#

And I am interested in that "Hint: You can also pre-compile it into .o", seems
like a useful one, if it was on the screen, i.e. how can I pre-compile this
into a .o, its some random piece of eBPF "scriptlet" I found in one of your
csets, after this cset in your patchkit:

[root@felicio ~]# cat lock_page.bpf.c
SEC("lock_page=__lock_page page->flags")
int lock_page(struct pt_regs *ctx, int err, unsigned long flags)
{
return 1;
}
[root@felicio ~]#

Also it would be nice to tell the user, when compilation fails, where to look
for a eBPF scriptlet primer, i.e. where can I find some documentation on how
to write such scriptlets?

At this point I expect it to build the .c into a .o, then, as the wiring up is
not there, tell the user that all went well, but more infrastructure is needed,
apply the following patches from Wang Nan! 8-)

- Arnaldo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/