Re: [RFC bpf-next 09/11] selftests/bpf: Add usdt trigger bench

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

 



On Tue, Nov 5, 2024 at 5:35 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> Adding usdt trigger bench to meassure optimized usdt probes.
>
> Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> ---
>  tools/testing/selftests/bpf/bench.c           |  2 +
>  .../selftests/bpf/benchs/bench_trigger.c      | 45 +++++++++++++++++++
>  .../selftests/bpf/progs/trigger_bench.c       | 10 ++++-
>  3 files changed, 56 insertions(+), 1 deletion(-)
>

Why not just adding uprobe-nop5 benchmark instead of going all the way
into USDT? Seems simpler and will benchmark all the same stuff?

> diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
> index 1bd403a5ef7b..dc5121e49623 100644
> --- a/tools/testing/selftests/bpf/bench.c
> +++ b/tools/testing/selftests/bpf/bench.c
> @@ -526,6 +526,7 @@ extern const struct bench bench_trig_uprobe_multi_push;
>  extern const struct bench bench_trig_uretprobe_multi_push;
>  extern const struct bench bench_trig_uprobe_multi_ret;
>  extern const struct bench bench_trig_uretprobe_multi_ret;
> +extern const struct bench bench_trig_usdt;
>
>  extern const struct bench bench_rb_libbpf;
>  extern const struct bench bench_rb_custom;
> @@ -586,6 +587,7 @@ static const struct bench *benchs[] = {
>         &bench_trig_uretprobe_multi_push,
>         &bench_trig_uprobe_multi_ret,
>         &bench_trig_uretprobe_multi_ret,
> +       &bench_trig_usdt,
>         /* ringbuf/perfbuf benchmarks */
>         &bench_rb_libbpf,
>         &bench_rb_custom,
> diff --git a/tools/testing/selftests/bpf/benchs/bench_trigger.c b/tools/testing/selftests/bpf/benchs/bench_trigger.c
> index 32e9f194d449..bdee8b8362d0 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_trigger.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_trigger.c
> @@ -8,6 +8,7 @@
>  #include "bench.h"
>  #include "trigger_bench.skel.h"
>  #include "trace_helpers.h"
> +#include "../sdt.h"
>
>  #define MAX_TRIG_BATCH_ITERS 1000
>
> @@ -333,6 +334,13 @@ static void *uprobe_producer_ret(void *input)
>         return NULL;
>  }
>
> +static void *uprobe_producer_usdt(void *input)
> +{
> +       while (true)
> +               STAP_PROBE(trigger, usdt);
> +       return NULL;
> +}
> +
>  static void usetup(bool use_retprobe, bool use_multi, void *target_addr)
>  {
>         size_t uprobe_offset;
> @@ -383,6 +391,37 @@ static void usetup(bool use_retprobe, bool use_multi, void *target_addr)
>         }
>  }
>
> +static void __usdt_setup(const char *provider, const char *name)
> +{
> +       struct bpf_link *link;
> +       int err;
> +
> +       setup_libbpf();
> +
> +       ctx.skel = trigger_bench__open();
> +       if (!ctx.skel) {
> +               fprintf(stderr, "failed to open skeleton\n");
> +               exit(1);
> +       }
> +
> +       bpf_program__set_autoload(ctx.skel->progs.bench_trigger_usdt, true);
> +
> +       err = trigger_bench__load(ctx.skel);
> +       if (err) {
> +               fprintf(stderr, "failed to load skeleton\n");
> +               exit(1);
> +       }
> +
> +       link = bpf_program__attach_usdt(ctx.skel->progs.bench_trigger_usdt,
> +                                       -1 /* all PIDs */, "/proc/self/exe",
> +                                       provider, name, NULL);
> +       if (!link) {
> +               fprintf(stderr, "failed to attach uprobe!\n");
> +               exit(1);
> +       }
> +       ctx.skel->links.bench_trigger_usdt = link;
> +}
> +
>  static void usermode_count_setup(void)
>  {
>         ctx.usermode_counters = true;
> @@ -448,6 +487,11 @@ static void uretprobe_multi_ret_setup(void)
>         usetup(true, true /* use_multi */, &uprobe_target_ret);
>  }
>
> +static void usdt_setup(void)
> +{
> +       __usdt_setup("trigger", "usdt");
> +}
> +
>  const struct bench bench_trig_syscall_count = {
>         .name = "trig-syscall-count",
>         .validate = trigger_validate,
> @@ -506,3 +550,4 @@ BENCH_TRIG_USERMODE(uprobe_multi_ret, ret, "uprobe-multi-ret");
>  BENCH_TRIG_USERMODE(uretprobe_multi_nop, nop, "uretprobe-multi-nop");
>  BENCH_TRIG_USERMODE(uretprobe_multi_push, push, "uretprobe-multi-push");
>  BENCH_TRIG_USERMODE(uretprobe_multi_ret, ret, "uretprobe-multi-ret");
> +BENCH_TRIG_USERMODE(usdt, usdt, "usdt");
> diff --git a/tools/testing/selftests/bpf/progs/trigger_bench.c b/tools/testing/selftests/bpf/progs/trigger_bench.c
> index 044a6d78923e..7b7d4a71e7d4 100644
> --- a/tools/testing/selftests/bpf/progs/trigger_bench.c
> +++ b/tools/testing/selftests/bpf/progs/trigger_bench.c
> @@ -1,8 +1,9 @@
>  // SPDX-License-Identifier: GPL-2.0
>  // Copyright (c) 2020 Facebook
> -#include <linux/bpf.h>
> +#include "vmlinux.h"
>  #include <asm/unistd.h>
>  #include <bpf/bpf_helpers.h>
> +#include <bpf/usdt.bpf.h>
>  #include <bpf/bpf_tracing.h>
>  #include "bpf_misc.h"
>
> @@ -138,3 +139,10 @@ int bench_trigger_rawtp(void *ctx)
>         inc_counter();
>         return 0;
>  }
> +
> +SEC("?usdt")
> +int bench_trigger_usdt(struct pt_regs *ctx)
> +{
> +       inc_counter();
> +       return 0;
> +}
> --
> 2.47.0
>





[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