Skip to content

Commit ed166c9

Browse files
committed
selftests/bpf: Add 5-byte NOP uprobe trigger benchmark
JIRA: https://issues.redhat.com/browse/RHEL-78203 commit fe8e5a3 Author: Jiri Olsa <jolsa@kernel.org> Date: Mon Apr 14 10:36:47 2025 +0200 selftests/bpf: Add 5-byte NOP uprobe trigger benchmark Add a 5-byte NOP uprobe trigger benchmark (x86_64 specific) to measure uprobes/uretprobes on top of NOP5 instructions. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Song Liu <songliubraving@fb.com> Cc: Yonghong Song <yhs@fb.com> Cc: John Fastabend <john.fastabend@gmail.com> Cc: Hao Luo <haoluo@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Alan Maguire <alan.maguire@oracle.com> Link: https://lore.kernel.org/r/20250414083647.1234007-2-jolsa@kernel.org Signed-off-by: Viktor Malik <vmalik@redhat.com>
1 parent 0ac8dae commit ed166c9

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

tools/testing/selftests/bpf/bench.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ extern const struct bench bench_trig_uprobe_multi_push;
526526
extern const struct bench bench_trig_uretprobe_multi_push;
527527
extern const struct bench bench_trig_uprobe_multi_ret;
528528
extern const struct bench bench_trig_uretprobe_multi_ret;
529+
#ifdef __x86_64__
530+
extern const struct bench bench_trig_uprobe_nop5;
531+
extern const struct bench bench_trig_uretprobe_nop5;
532+
extern const struct bench bench_trig_uprobe_multi_nop5;
533+
extern const struct bench bench_trig_uretprobe_multi_nop5;
534+
#endif
529535

530536
extern const struct bench bench_rb_libbpf;
531537
extern const struct bench bench_rb_custom;
@@ -586,6 +592,12 @@ static const struct bench *benchs[] = {
586592
&bench_trig_uretprobe_multi_push,
587593
&bench_trig_uprobe_multi_ret,
588594
&bench_trig_uretprobe_multi_ret,
595+
#ifdef __x86_64__
596+
&bench_trig_uprobe_nop5,
597+
&bench_trig_uretprobe_nop5,
598+
&bench_trig_uprobe_multi_nop5,
599+
&bench_trig_uretprobe_multi_nop5,
600+
#endif
589601
/* ringbuf/perfbuf benchmarks */
590602
&bench_rb_libbpf,
591603
&bench_rb_custom,

tools/testing/selftests/bpf/benchs/bench_trigger.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ static void *uprobe_producer_ret(void *input)
333333
return NULL;
334334
}
335335

336+
#ifdef __x86_64__
337+
__nocf_check __weak void uprobe_target_nop5(void)
338+
{
339+
asm volatile (".byte 0x0f, 0x1f, 0x44, 0x00, 0x00");
340+
}
341+
342+
static void *uprobe_producer_nop5(void *input)
343+
{
344+
while (true)
345+
uprobe_target_nop5();
346+
return NULL;
347+
}
348+
#endif
349+
336350
static void usetup(bool use_retprobe, bool use_multi, void *target_addr)
337351
{
338352
size_t uprobe_offset;
@@ -448,6 +462,28 @@ static void uretprobe_multi_ret_setup(void)
448462
usetup(true, true /* use_multi */, &uprobe_target_ret);
449463
}
450464

465+
#ifdef __x86_64__
466+
static void uprobe_nop5_setup(void)
467+
{
468+
usetup(false, false /* !use_multi */, &uprobe_target_nop5);
469+
}
470+
471+
static void uretprobe_nop5_setup(void)
472+
{
473+
usetup(true, false /* !use_multi */, &uprobe_target_nop5);
474+
}
475+
476+
static void uprobe_multi_nop5_setup(void)
477+
{
478+
usetup(false, true /* use_multi */, &uprobe_target_nop5);
479+
}
480+
481+
static void uretprobe_multi_nop5_setup(void)
482+
{
483+
usetup(true, true /* use_multi */, &uprobe_target_nop5);
484+
}
485+
#endif
486+
451487
const struct bench bench_trig_syscall_count = {
452488
.name = "trig-syscall-count",
453489
.validate = trigger_validate,
@@ -506,3 +542,9 @@ BENCH_TRIG_USERMODE(uprobe_multi_ret, ret, "uprobe-multi-ret");
506542
BENCH_TRIG_USERMODE(uretprobe_multi_nop, nop, "uretprobe-multi-nop");
507543
BENCH_TRIG_USERMODE(uretprobe_multi_push, push, "uretprobe-multi-push");
508544
BENCH_TRIG_USERMODE(uretprobe_multi_ret, ret, "uretprobe-multi-ret");
545+
#ifdef __x86_64__
546+
BENCH_TRIG_USERMODE(uprobe_nop5, nop5, "uprobe-nop5");
547+
BENCH_TRIG_USERMODE(uretprobe_nop5, nop5, "uretprobe-nop5");
548+
BENCH_TRIG_USERMODE(uprobe_multi_nop5, nop5, "uprobe-multi-nop5");
549+
BENCH_TRIG_USERMODE(uretprobe_multi_nop5, nop5, "uretprobe-multi-nop5");
550+
#endif

tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -eufo pipefail
44

5-
for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret}
5+
for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret,nop5}
66
do
77
summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-)
88
printf "%-15s: %s\n" $i "$summary"

0 commit comments

Comments
 (0)