Re: Building perf with BUILD_BPF_SKEL=1 by default

Song Liu
2021-12-06T17:08:27Z

> On Dec 6, 2021, at 4:32 AM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> Em Fri, Dec 03, 2021 at 08:05:59PM +0000, Song Liu escreveu:
>>> On Dec 3, 2021, at 5:28 AM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>>> The failure for fedora:32, which seems to be on the threshold for clang
>>> to be considered recent enough for building skels fails differently:
>
>>> clang version 10.0.1 (Fedora 10.0.1-3.fc32)
>>> Target: x86_64-unknown-linux-gnu
>>> Thread model: posix
>>> InstalledDir: /usr/bin
>>> Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/10
>>> Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/10
>>> Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/10
>>> Candidate multilib: .;@m64
>>> Candidate multilib: 32;@m32
>>> Selected multilib: .;@m64
>>> + '[' '!' ']'
>>> + rm -rf /tmp/build/perf
>>> + mkdir /tmp/build/perf
>>> + make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= BUILD_BPF_SKEL=1 -C tools/perf O=/tmp/build/perf
>>> make: Entering directory '/git/perf-5.16.0-rc3/tools/perf'
>>> BUILD: Doing 'make -j32' parallel build
>>> HOSTCC /tmp/build/perf/fixdep.o
>>> HOSTLD /tmp/build/perf/fixdep-in.o
>>> LINK /tmp/build/perf/fixdep
>>> /bin/sh: -c: line 0: syntax error near unexpected token `('
>>> /bin/sh: -c: line 0: `expr bison (GNU Bison) 3.5 \>\= 371'
>>> Makefile.config:997: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev
>>>
>>> Auto-detecting system features:
>>> ... dwarf: [ on ]
>>> ... dwarf_getlocations: [ on ]
>>> ... glibc: [ on ]
>>> ... libbfd: [ on ]
>>> ... libbfd-buildid: [ on ]
>>> ... libcap: [ on ]
>>> ... libelf: [ on ]
>>> ... libnuma: [ on ]
>>> ... numa_num_possible_cpus: [ on ]
>>> ... libperl: [ on ]
>>> ... libpython: [ on ]
>>> ... libcrypto: [ on ]
>>> ... libunwind: [ on ]
>>> ... libdw-dwarf-unwind: [ on ]
>>> ... zlib: [ on ]
>>> ... lzma: [ on ]
>>> ... get_cpuid: [ on ]
>>> ... bpf: [ on ]
>>> ... libaio: [ on ]
>>> ... libzstd: [ on ]
>>> ... disassembler-four-args: [ on ]
>>>
>
> <SNIP>
>
>>> GEN /tmp/build/perf/util/bpf_skel/vmlinux.h
>>> CLANG /tmp/build/perf/util/bpf_skel/.tmp/bpf_prog_profiler.bpf.o
>>> CLANG /tmp/build/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
>>> CLANG /tmp/build/perf/util/bpf_skel/.tmp/bperf_follower.bpf.o
>>> CLANG /tmp/build/perf/util/bpf_skel/.tmp/bperf_cgroup.bpf.o
>>> GENSKEL /tmp/build/perf/util/bpf_skel/bpf_prog_profiler.skel.h
>>> GENSKEL /tmp/build/perf/util/bpf_skel/bperf_leader.skel.h
>>> libbpf: elf: skipping unrecognized data section(9) .eh_frame
>>> libbpf: elf: skipping relo section(15) .rel.eh_frame for section(9) .eh_frame
>>> libbpf: elf: skipping unrecognized data section(7) .eh_frame
>>> libbpf: elf: skipping relo section(12) .rel.eh_frame for section(7) .eh_frame
>>> libbpf: map 'prev_readings': unexpected def kind var.
>>> Error: failed to open BPF object file: Invalid argument
>>> make[2]: *** [Makefile.perf:1076: /tmp/build/perf/util/bpf_skel/bperf_leader.skel.h] Error 255
>>> make[2]: *** Waiting for unfinished jobs....
>>> make[1]: *** [Makefile.perf:240: sub-make] Error 2
>>> make: *** [Makefile:70: all] Error 2
>>> make: Leaving directory '/git/perf-5.16.0-rc3/tools/perf'
>>> + exit 1
>>> [perfbuilder@five 32]$
>>
>> Cc Andrii.
>>
>> Could you please try the fix below?
>>
>> If it doesn't work, could you please dump btf for debugging?
>>
>> bpftool btf dump file /tmp/build/perf/util/bpf_skel/.tmp/bperf_leader.bpf.o
>
> It fixes the issue on Alpine Linux 3.12 and 3.13, Alt Linux p9 and fedora:32, probably others, still testing.
>
> Can you please provide a cset commit log for me to stamp on it?

Please see the following commit log.

Thanks,
Song

====================================== 8< ========================================

perf/bpf_skel: use vmlinux.h in skeletons

When building bpf_skel in perf on a system with older linux/bpf.h header,
we got errors like:

util/bpf_skel/bperf_leader.bpf.c:13:20: error: use of undeclared
identifier 'BPF_F_PRESERVE_ELEMS'
__uint(map_flags, BPF_F_PRESERVE_ELEMS);

Fix this by using vmlinux.h instead. Also remove include of perf_event.h,
as it redefines structs in vmlinux.h.

Fixes: fa853c4b839e ("perf stat: Enable counting events for BPF programs")
Fixes: 7fac83aaf2ee ("perf stat: Introduce 'bperf' to share hardware PMCs with BPF")
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Song Liu <songliubraving@fb.com>