From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
lkml <linux-kernel@vger.kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>
Subject: Re: [PATCHv2 bpf-next 4/4] selftests/bpf: Add attach bench test
Date: Thu, 21 Apr 2022 08:56:26 +0200 [thread overview]
Message-ID: <YmEAGhGVhyiHBQ3S@krava> (raw)
In-Reply-To: <CAEf4BzYuvLgVtxbtz7pjCmtSp0hEKJd0peCnbX0E_-Tqy5g4dw@mail.gmail.com>
On Wed, Apr 20, 2022 at 02:56:53PM -0700, Andrii Nakryiko wrote:
SNIP
> > +#define DEBUGFS "/sys/kernel/debug/tracing/"
> > +
> > +static int get_syms(char ***symsp, size_t *cntp)
> > +{
> > + size_t cap = 0, cnt = 0, i;
> > + char *name, **syms = NULL;
> > + struct hashmap *map;
> > + char buf[256];
> > + FILE *f;
> > + int err;
> > +
> > + /*
> > + * The available_filter_functions contains many duplicates,
> > + * but other than that all symbols are usable in kprobe multi
> > + * interface.
> > + * Filtering out duplicates by using hashmap__add, which won't
> > + * add existing entry.
> > + */
> > + f = fopen(DEBUGFS "available_filter_functions", "r");
>
> nit: DEBUGFS "constant" just makes it harder to follow the code and
> doesn't add anything, please just use the full path here directly
there's another one DEBUGFS in trace_helpers.c,
we could put it in trace_helpers.h
>
> > + if (!f)
> > + return -EINVAL;
> > +
> > + map = hashmap__new(symbol_hash, symbol_equal, NULL);
> > + err = libbpf_get_error(map);
>
> hashmap__new() is an internal API, so please use IS_ERR() directly
> here. libbpf_get_error() should be used for public libbpf APIs, and
> preferably not in libbpf 1.0 mode
ok
>
> > + if (err)
> > + goto error;
> > +
> > + while (fgets(buf, sizeof(buf), f)) {
> > + /* skip modules */
> > + if (strchr(buf, '['))
> > + continue;
>
> [...]
>
> > + attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0;
> > + detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
> > +
> > + fprintf(stderr, "%s: found %lu functions\n", __func__, cnt);
> > + fprintf(stderr, "%s: attached in %7.3lfs\n", __func__, attach_delta);
> > + fprintf(stderr, "%s: detached in %7.3lfs\n", __func__, detach_delta);
>
>
> why stderr? just do printf() and let test_progs handle output
ok
>
>
> > +
> > +cleanup:
> > + kprobe_multi_empty__destroy(skel);
> > + if (syms) {
> > + for (i = 0; i < cnt; i++)
> > + free(syms[i]);
> > + free(syms);
> > + }
> > +}
> > +
> > void test_kprobe_multi_test(void)
> > {
> > if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
> > @@ -320,4 +454,6 @@ void test_kprobe_multi_test(void)
> > test_attach_api_syms();
> > if (test__start_subtest("attach_api_fails"))
> > test_attach_api_fails();
> > + if (test__start_subtest("bench_attach"))
> > + test_bench_attach();
> > }
> > diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_empty.c b/tools/testing/selftests/bpf/progs/kprobe_multi_empty.c
> > new file mode 100644
> > index 000000000000..be9e3d891d46
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/progs/kprobe_multi_empty.c
> > @@ -0,0 +1,12 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +#include <linux/bpf.h>
> > +#include <bpf/bpf_helpers.h>
> > +#include <bpf/bpf_tracing.h>
> > +
> > +char _license[] SEC("license") = "GPL";
> > +
> > +SEC("kprobe.multi/*")
>
> use SEC("kprobe.multi") to make it clear that we are attaching it "manually"?
yep, will do
thanks,
jirka
prev parent reply other threads:[~2022-04-21 6:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-18 12:48 [PATCHv2 bpf-next 0/4] bpf: Speed up symbol resolving in kprobe multi link Jiri Olsa
2022-04-18 12:48 ` [PATCHv2 bpf-next 1/4] kallsyms: Add kallsyms_lookup_names function Jiri Olsa
2022-04-18 14:35 ` Masami Hiramatsu
2022-04-19 8:26 ` Jiri Olsa
2022-04-22 6:47 ` Jiri Olsa
2022-04-26 10:01 ` Masami Hiramatsu
2022-04-26 12:27 ` Jiri Olsa
2022-04-26 16:03 ` Masami Hiramatsu
2022-04-18 12:48 ` [PATCHv2 bpf-next 2/4] fprobe: Resolve symbols with kallsyms_lookup_names Jiri Olsa
2022-04-18 14:39 ` Masami Hiramatsu
2022-04-18 12:48 ` [PATCHv2 bpf-next 3/4] bpf: Resolve symbols with kallsyms_lookup_names for kprobe multi link Jiri Olsa
2022-04-20 21:49 ` Andrii Nakryiko
2022-04-21 6:49 ` Jiri Olsa
2022-04-18 12:48 ` [PATCHv2 bpf-next 4/4] selftests/bpf: Add attach bench test Jiri Olsa
2022-04-20 21:56 ` Andrii Nakryiko
2022-04-21 6:56 ` Jiri Olsa [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=YmEAGhGVhyiHBQ3S@krava \
--to=olsajiri@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.