Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 21/21] selftests/bpf: Benchmark tracing_multi bpf progs attachment
Date: Mon, 12 Oct 2026 16:52:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-168438@kernel.org> (raw)
In-Reply-To: <20261012154024.29423-22-leon.hwang@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpf: bench fails with EMFILE due to unraised RLIMIT_NOFILE
- [Low] bpf: benchmark time overflow on 32-bit due to long truncation
--

commit d6a7c4ba0d33ae305098f82b092a318e73ea06fb
Author: Leon Hwang <leon.hwang@linux.dev>

selftests/bpf: Benchmark tracing_multi bpf progs attachment

This commit adds an x86-64 one-shot generic benchmark to compare the
performance of attaching 1000 individual fentry links versus a single
fentry.multi link for the same 1000 BPF program targets.

> diff --git a/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c
> new file mode 100644
> index 0000000000000..6cc6851eb488e
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/benchs/bench_tracing_multi_attach_progs.c
[ ... ]
> +static long create_and_attach_fentry(void)
> +{
> +	int link_fds[TARGET_CNT];
> +	long start_ns, end_ns;

[Severity: Low]
Will this truncate the 64-bit nanosecond timestamps returned by get_time_ns()
on 32-bit architectures?

get_time_ns() returns a __u64, and storing it in a 32-bit long drops the upper
32 bits. Also, if the elapsed time (end_ns - start_ns) exceeds roughly 2.14
seconds, the signed 32-bit long will overflow into a negative value, resulting
in negative benchmark times and malformed speedup calculations.

Loading 1000 targets and links could easily exceed 2.14s on slow or emulated
32-bit hosts.

> +	int err, i, j;
> +
> +	start_ns = get_time_ns();
> +
> +	/* An ordinary fentry program is bound to one target when it is loaded. */
[ ... ]
> +	for (i = 0; i < TARGET_CNT; i++) {
> +		link_fds[i] = bpf_link_create(ctx.fentry_prog_fds[i], 0, BPF_TRACE_FENTRY, NULL);
> +		if (link_fds[i] < 0) {

[Severity: Medium]
Will this benchmark predictably fail with EMFILE due to exceeding the default
1024 file descriptor limit?

The benchmark attempts to load 1000 target programs, 1000 fentry programs, and
1000 links (over 3000 FDs total) sequentially without raising RLIMIT_NOFILE in
setup_libbpf() or bench.c. Running this locally without manually increasing
the open file limit via ulimit -n will cause bpf_link_create() or program
loading to fail.

> +			err = errno;
> +			for (j = 0; j < i; j++)
> +				close(link_fds[j]);
> +			fprintf(stderr, "failed to create fentry link %d: %s\n",
> +				i, strerror(err));
> +			exit(1);
> +		}
> +	}
> +	end_ns = get_time_ns();
> +
> +	for (i = 0; i < TARGET_CNT; i++)
> +		close(link_fds[i]);
> +
> +	return end_ns - start_ns;
> +}
[ ... ]
> +static void setup(void)
> +{
> +	double fentry_multi_ms, fentry_ms;
> +	long fentry_multi_ns, fentry_ns;

[Severity: Low]
Similar to the issue in create_and_attach_fentry() above, will these signed
long values overflow and yield negative durations if the elapsed benchmark
time exceeds 2.14 seconds on 32-bit architectures?

> +
> +	prepare();
> +	fentry_ns = create_and_attach_fentry();
> +	fentry_multi_ns = create_and_attach_fentry_multi();

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012154024.29423-1-leon.hwang@linux.dev?part=21

      parent reply	other threads:[~2026-10-12 16:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 15:40 [PATCH bpf-next v2 00/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 01/21] bpf: Initialize ftrace_managed in bpf_trampoline_get() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 02/21] bpf: Drop unnecessary ftrace_location() in register/unregister/modify_fentry_multi() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 03/21] bpf, x86: Factor out bpf_arch_text_poke_prepare_insns() helper on x86_64 Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 04/21] bpf, x86: Factor out bpf_arch_text_poke_check_ip() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 05/21] bpf, x86: Introduce bpf_arch_text_poke_batch() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 06/21] bpf: Add bpf_text_poke_batch() helper in trampoline Leon Hwang
2026-10-12 16:11   ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 07/21] bpf: Check tgt_prog before is_tracing_multi_id() in verifier Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 08/21] bpf: Move helpers out of CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard in trampoline Leon Hwang
2026-10-12 16:11   ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 09/21] bpf: Add bpf_trampoline_multi_prog_attach/detach() Leon Hwang
2026-10-12 16:16   ` sashiko-bot
2026-10-12 16:33   ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 10/21] bpf: Shrink CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard scope for bpf_tracing_multi_attach() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 11/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 16:33   ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 12/21] libbpf: " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 13/21] bpf: Add tracing_multi link fdinfo " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 14/21] bpf: Add tracing_multi link info " Leon Hwang
2026-10-12 16:33   ` bot+bpf-ci
2026-10-12 16:36   ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 15/21] selftests/bpf: Add tracing_multi bpf prog attach test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 16/21] selftests/bpf: Add tracing_multi bpf prog attach failure tests Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 17/21] selftests/bpf: Add tracing_multi bpf prog cookie test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 18/21] selftests/bpf: Add tracing_multi bpf prog rollback test Leon Hwang
2026-10-12 16:46   ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 19/21] selftests/bpf: Add tracing_multi bpf prog link info test Leon Hwang
2026-10-12 16:11   ` bot+bpf-ci
2026-10-12 16:43   ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 20/21] selftests/bpf: Test tailcall with fentry.multi Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 21/21] selftests/bpf: Benchmark tracing_multi bpf progs attachment Leon Hwang
2026-10-12 16:33   ` bot+bpf-ci
2026-10-12 16:52   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-168438@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox