From: Song Liu <liu.song.a23@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH 2/3] libbpf: Add helper to extract perf fd from bpf_link
Date: Wed, 7 Aug 2019 11:19:51 -0700 [thread overview]
Message-ID: <CAPhsuW4wHQ0XhtzeRXamBjTPpuA-ejUwmqSkhSk6sM58MTXPMw@mail.gmail.com> (raw)
In-Reply-To: <20190806234201.6296-1-dxu@dxuuu.xyz>
On Tue, Aug 6, 2019 at 4:42 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> It is sometimes necessary to perform ioctl's on the underlying perf fd.
> There is not currently a way to extract the fd given a bpf_link, so add a
> helper for it.
Missing "Signed-off-by" tag. Please run scripts/checkpatch.pl on the patches.
Otherwise, looks good to me.
Acked-by: Song Liu <songliubraving@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 13 +++++++++++++
> tools/lib/bpf/libbpf.h | 1 +
> tools/lib/bpf/libbpf.map | 5 +++++
> 3 files changed, 19 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index ead915aec349..8469d69448ae 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4004,6 +4004,19 @@ static int bpf_link__destroy_perf_event(struct bpf_link *link)
> return err;
> }
>
> +int bpf_link__get_perf_fd(struct bpf_link *link)
> +{
> + struct bpf_link_fd *l = (void *)link;
> +
> + if (!link)
> + return -1;
> +
> + if (link->destroy != &bpf_link__destroy_perf_event)
> + return -1;
> +
> + return l->fd;
> +}
> +
> struct bpf_link *bpf_program__attach_perf_event(struct bpf_program *prog,
> int pfd)
> {
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 8a9d462a6f6d..5391ac95e4fa 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -168,6 +168,7 @@ LIBBPF_API void bpf_program__unload(struct bpf_program *prog);
> struct bpf_link;
>
> LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
> +LIBBPF_API int bpf_link__get_perf_fd(struct bpf_link *link);
>
> LIBBPF_API struct bpf_link *
> bpf_program__attach_perf_event(struct bpf_program *prog, int pfd);
> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> index f9d316e873d8..0f844ce29b04 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -184,3 +184,8 @@ LIBBPF_0.0.4 {
> perf_buffer__new_raw;
> perf_buffer__poll;
> } LIBBPF_0.0.3;
> +
> +LIBBPF_0.0.5 {
> + global:
> + bpf_link__get_perf_fd;
> +} LIBBPF_0.0.4;
> --
> 2.20.1
>
next prev parent reply other threads:[~2019-08-07 18:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-06 23:42 [PATCH 2/3] libbpf: Add helper to extract perf fd from bpf_link Daniel Xu
2019-08-06 23:42 ` [PATCH 3/3] tracing/kprobe: Add self test for PERF_EVENT_IOC_QUERY_KPROBE Daniel Xu
2019-08-07 6:01 ` Yonghong Song
2019-08-07 21:49 ` Andrii Nakryiko
2019-08-07 18:19 ` Song Liu [this message]
2019-08-07 18:57 ` [PATCH 2/3] libbpf: Add helper to extract perf fd from bpf_link Andrii Nakryiko
2019-08-09 1:31 ` Daniel Xu
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=CAPhsuW4wHQ0XhtzeRXamBjTPpuA-ejUwmqSkhSk6sM58MTXPMw@mail.gmail.com \
--to=liu.song.a23@gmail.com \
--cc=andriin@fb.com \
--cc=bpf@vger.kernel.org \
--cc=dxu@dxuuu.xyz \
--cc=kernel-team@fb.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).