Re: [PATCH bpf-next v2 2/2] perf: stop using deprecated bpf__object_next() API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 1/6/22 12:00 PM, Christy Lee wrote:
Previously libbpf maintained a list of bpf_objects, and bpf_objects
can be added to the list via bpf__object__next() API. Libbpf has
deprecated the ability to keep track of object list inside libbpf,
so we need to hoist the tracking logic to perf.

Committer note:

This is tested by following the committer's note in the original commit
"aa3abf30bb28addcf593578d37447d42e3f65fc3".

I ran 'perf test -v LLVM' and used it's output to generate a script for
compiling the perf test object:

--------------------------------------------------
$ cat ~/bin/hello-ebpf
INPUT_FILE=/tmp/test.c
OUTPUT_FILE=/tmp/test.o

export KBUILD_DIR=/lib/modules/5.12.0-0_fbk2_3390_g7ecb4ac46d7f/build
export NR_CPUS=56
export LINUX_VERSION_CODE=0x50c00
export CLANG_EXEC=/data/users/christylee/devtools/llvm/latest/bin/clang
export CLANG_OPTIONS=-xc
export KERNEL_INC_OPTIONS="KERNEL_INC_OPTIONS= -nostdinc \
-isystem /usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include \
-I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi \
-I./arch/x86/include/generated/uapi -I./include/uapi \
-I./include/generated/uapi -include ./include/linux/compiler-version.h \
-include ./include/linux/kconfig.h"
export PERF_BPF_INC_OPTIONS=-I/usr/lib/perf/include/bpf
export WORKING_DIR=/lib/modules/5.12.0-0_fbk2_3390_g7ecb4ac46d7f/build
export CLANG_SOURCE=-

rm -f $OUTPUT_FILE
cat $INPUT_FILE | /data/users/christylee/devtools/llvm/latest/bin/clang \
-D__KERNEL__ -D__NR_CPUS__=56 -DLINUX_VERSION_CODE=0x50c00 -xc  \
-I/usr/lib/perf/include/bpf -nostdinc \
-isystem /usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include \
-I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi \
-I./arch/x86/include/generated/uapi -I./include/uapi \
-I./include/generated/uapi -include ./include/linux/compiler-version.h \
-include ./include/linux/kconfig.h -Wno-unused-value -Wno-pointer-sign \
-working-directory /lib/modules/5.12.0-0_fbk2_3390_g7ecb4ac46d7f/build \
-c - -target bpf -O2 -o $OUTPUT_FILE
--------------------------------------------------

I then wrote and compiled a script that ask to get asks to put a probe
at a function that
does not exists in the kernel, it errors out as expected:

$ cat /tmp/test.c
__attribute__((section("probe_point=not_exist"), used))
int probe_point(void *ctx) {
     return 0;
}
char _license[] __attribute__((section("license"), used)) = "GPL";
int _version __attribute__((section("version"), used)) = 0x40100;

$ cd ~/bin && ./hello-ebpf
$ ./perf record --event /tmp/test.o sleep 1

Using perf wrapper that supports hot-text. Try perf.real if you
encounter any issues.

The above doesn't exist in upstream perf. It would be good to just demonstrate with upstream built perf. Otherwise, people will confuse
what 'perf' we are talking about here.

The same for another 'perf record' below.

Probe point 'not_exist' not found.
event syntax error: '/tmp/test.o'
                      \___ You need to check probing points in BPF file

(add -v to see detail)
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

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

Next I changed the attribute to something that exists in the kernel.
As expected, it errors out
with permission problem:
$ cat /tmp/test.c
__attribute__((section("probe_point=kernel_execve"), used))
int probe_point(void *ctx) {
     return 0;
}
char _license[] __attribute__((section("license"), used)) = "GPL";
int _version __attribute__((section("version"), used)) = 0x40100;

$ grep kernel_execve /proc/kallsyms
ffffffff812dc210 T kernel_execve

$ cd ~/bin && ./hello-ebpf
$ ./perf record --event /tmp/test.o sleep 1

Using perf wrapper that supports hot-text. Try perf.real if you
encounter any issues.

here.

Failed to open kprobe_events: Permission denied
event syntax error: '/tmp/test.o'
                      \___ You need to be root

(add -v to see detail)
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

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux