Skip to content

[lts8.6] selftests/bpf: Fix pyperf180 compilation failure with clang18 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/testing/selftests/bpf/progs/pyperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ int __on_event(struct bpf_raw_tracepoint_args *ctx)
#ifdef NO_UNROLL
#pragma clang loop unroll(disable)
#else
#ifdef UNROLL_COUNT
#pragma clang loop unroll_count(UNROLL_COUNT)
#else
#pragma clang loop unroll(full)
#endif
#endif /* NO_UNROLL */
/* Unwind python stack */
for (int i = 0; i < STACK_MAX_LEN; ++i) {
if (frame_ptr && get_frame_data(frame_ptr, pidData, &frame, &sym)) {
Expand Down
22 changes: 22 additions & 0 deletions tools/testing/selftests/bpf/progs/pyperf180.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019 Facebook
#define STACK_MAX_LEN 180

/* llvm upstream commit at clang18
* https://github.com/llvm/llvm-project/commit/1a2e77cf9e11dbf56b5720c607313a566eebb16e
* changed inlining behavior and caused compilation failure as some branch
* target distance exceeded 16bit representation which is the maximum for
* cpu v1/v2/v3. Macro __BPF_CPU_VERSION__ is later implemented in clang18
* to specify which cpu version is used for compilation. So a smaller
* unroll_count can be set if __BPF_CPU_VERSION__ is less than 4, which
* reduced some branch target distances and resolved the compilation failure.
*
* To capture the case where a developer/ci uses clang18 but the corresponding
* repo checkpoint does not have __BPF_CPU_VERSION__, a smaller unroll_count
* will be set as well to prevent potential compilation failures.
*/
#ifdef __BPF_CPU_VERSION__
#if __BPF_CPU_VERSION__ < 4
#define UNROLL_COUNT 90
#endif
#elif __clang_major__ == 18
#define UNROLL_COUNT 90
#endif

#include "pyperf.h"
11 changes: 7 additions & 4 deletions tools/testing/selftests/bpf/progs/pyperf600.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019 Facebook
#define STACK_MAX_LEN 600
/* clang will not unroll the loop 600 times.
* Instead it will unroll it to the amount it deemed
* appropriate, but the loop will still execute 600 times.
* Total program size is around 90k insns
/* Full unroll of 600 iterations will have total
* program size close to 298k insns and this may
* cause BPF_JMP insn out of 16-bit integer range.
* So limit the unroll size to 150 so the
* total program size is around 80k insns but
* the loop will still execute 600 times.
*/
#define UNROLL_COUNT 150
#include "pyperf.h"