diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-06-02 17:42:47 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-07-20 11:33:02 -0300 |
commit | 6af5e4cf3a6521d23ca53df5001319babefdffbf (patch) | |
tree | c3bb8a6b4be5c2683efafc3cf265692b9dd69116 /tools/perf/bench | |
parent | 54d811023b5f99e658511b577b16a6d7014d162c (diff) |
perf bench uprobe empty: Add entry attaching an empty BPF program
Using libbpf and a BPF skel:
# perf bench uprobe all
# Running uprobe/baseline benchmark...
# Executed 1,000 usleep(1000) calls
Total time: 1,055,618 usecs
1,055.618 usecs/op
# Running uprobe/empty benchmark...
# Executed 1,000 usleep(1000) calls
Total time: 1,057,146 usecs +1,528 to baseline
1,057.146 usecs/op
#
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andre Fredette <anfredet@redhat.com>
Cc: Clark Williams <williams@redhat.com>
Cc: Dave Tucker <datucker@redhat.com>
Cc: Derek Barbosa <debarbos@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/20230719204910.539044-5-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/bench')
-rw-r--r-- | tools/perf/bench/bench.h | 1 | ||||
-rw-r--r-- | tools/perf/bench/uprobe.c | 75 |
2 files changed, 73 insertions, 3 deletions
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index 201311f75c96..daf4850b441c 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h @@ -43,6 +43,7 @@ int bench_evlist_open_close(int argc, const char **argv); int bench_breakpoint_thread(int argc, const char **argv); int bench_breakpoint_enable(int argc, const char **argv); int bench_uprobe_baseline(int argc, const char **argv); +int bench_uprobe_empty(int argc, const char **argv); int bench_pmu_scan(int argc, const char **argv); #define BENCH_FORMAT_DEFAULT_STR "default" diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c index a90e09f791c5..dfb90038a4f7 100644 --- a/tools/perf/bench/uprobe.c +++ b/tools/perf/bench/uprobe.c @@ -24,6 +24,11 @@ #define LOOPS_DEFAULT 1000 static int loops = LOOPS_DEFAULT; +enum bench_uprobe { + BENCH_UPROBE__BASELINE, + BENCH_UPROBE__EMPTY, +}; + static const struct option options[] = { OPT_INTEGER('l', "loop", &loops, "Specify number of loops"), OPT_END() @@ -34,6 +39,59 @@ static const char * const bench_uprobe_usage[] = { NULL }; +#ifdef HAVE_BPF_SKEL +#include "bpf_skel/bench_uprobe.skel.h" + +struct bench_uprobe_bpf *skel; + +static int bench_uprobe__setup_bpf_skel(void) +{ + DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); + int err; + + /* Load and verify BPF application */ + skel = bench_uprobe_bpf__open(); + if (!skel) { + fprintf(stderr, "Failed to open and load uprobes bench BPF skeleton\n"); + return -1; + } + + err = bench_uprobe_bpf__load(skel); + if (err) { + fprintf(stderr, "Failed to load and verify BPF skeleton\n"); + goto cleanup; + } + + uprobe_opts.func_name = "usleep"; + skel->links.empty = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.empty, + /*pid=*/-1, + /*binary_path=*/"/lib64/libc.so.6", + /*func_offset=*/0, + /*opts=*/&uprobe_opts); + if (!skel->links.empty) { + err = -errno; + fprintf(stderr, "Failed to attach bench uprobe: %s\n", strerror(errno)); + goto cleanup; + } + + return err; +cleanup: + bench_uprobe_bpf__destroy(skel); + return err; +} + +static void bench_uprobe__teardown_bpf_skel(void) +{ + if (skel) { + bench_uprobe_bpf__destroy(skel); + skel = NULL; + } +} +#else +static int bench_uprobe__setup_bpf_skel(void) { return 0; } +static void bench_uprobe__teardown_bpf_skel(void) {}; +#endif + static int bench_uprobe_format__default_fprintf(const char *name, const char *unit, u64 diff, FILE *fp) { static u64 baseline, previous; @@ -68,7 +126,7 @@ static int bench_uprobe_format__default_fprintf(const char *name, const char *un return printed + 1; } -static int bench_uprobe(int argc, const char **argv) +static int bench_uprobe(int argc, const char **argv, enum bench_uprobe bench) { const char *name = "usleep(1000)", *unit = "usec"; struct timespec start, end; @@ -77,7 +135,10 @@ static int bench_uprobe(int argc, const char **argv) argc = parse_options(argc, argv, options, bench_uprobe_usage, 0); - clock_gettime(CLOCK_REALTIME, &start); + if (bench != BENCH_UPROBE__BASELINE && bench_uprobe__setup_bpf_skel() < 0) + return 0; + + clock_gettime(CLOCK_REALTIME, &start); for (i = 0; i < loops; i++) { usleep(USEC_PER_MSEC); @@ -103,10 +164,18 @@ static int bench_uprobe(int argc, const char **argv) exit(1); } + if (bench != BENCH_UPROBE__BASELINE) + bench_uprobe__teardown_bpf_skel(); + return 0; } int bench_uprobe_baseline(int argc, const char **argv) { - return bench_uprobe(argc, argv); + return bench_uprobe(argc, argv, BENCH_UPROBE__BASELINE); +} + +int bench_uprobe_empty(int argc, const char **argv) +{ + return bench_uprobe(argc, argv, BENCH_UPROBE__EMPTY); } |