bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
@ 2019-08-06 23:38 Daniel Xu
  2019-08-07  5:24 ` Yonghong Song
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Daniel Xu @ 2019-08-06 23:38 UTC (permalink / raw)
  To: songliubraving, yhs, andriin; +Cc: Daniel Xu, bpf, kernel-team

It's useful to know kprobe's nmissed and nhit stats. For example with
tracing tools, it's important to know when events may have been lost.
There is currently no way to get that information from the perf API.
This patch adds a new ioctl that lets users query this information.

Daniel Xu (3):
  tracing/kprobe: Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
  libbpf: Add helper to extract perf fd from bpf_link
  tracing/kprobe: Add self test for PERF_EVENT_IOC_QUERY_KPROBE

 include/linux/trace_events.h                  |  6 +++
 include/uapi/linux/perf_event.h               | 23 ++++++++++
 kernel/events/core.c                          | 11 +++++
 kernel/trace/trace_kprobe.c                   | 25 +++++++++++
 tools/include/uapi/linux/perf_event.h         | 23 ++++++++++
 tools/lib/bpf/libbpf.c                        | 13 ++++++
 tools/lib/bpf/libbpf.h                        |  1 +
 tools/lib/bpf/libbpf.map                      |  5 +++
 .../selftests/bpf/prog_tests/attach_probe.c   | 43 +++++++++++++++++++
 9 files changed, 150 insertions(+)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
  2019-08-06 23:38 [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl Daniel Xu
@ 2019-08-07  5:24 ` Yonghong Song
  2019-08-07 17:49 ` Song Liu
  2019-08-07 19:03 ` Andrii Nakryiko
  2 siblings, 0 replies; 6+ messages in thread
From: Yonghong Song @ 2019-08-07  5:24 UTC (permalink / raw)
  To: Daniel Xu, Song Liu, Andrii Nakryiko; +Cc: bpf, Kernel Team



On 8/6/19 4:38 PM, Daniel Xu wrote:
> It's useful to know kprobe's nmissed and nhit stats. For example with
> tracing tools, it's important to know when events may have been lost.
> There is currently no way to get that information from the perf API.
> This patch adds a new ioctl that lets users query this information.

Probably worthwhile to further elaborate the use case.
The debugfs does have a way to count kprobe nmissed and nhit
through /sys/kernel/debug/tracing/kprobe_profile.
But there is no uapi to count the nmissed and nhit for
FD-based kprobe interface. bpf program itself might be able
to count nhit, but still no uapi to get the nmissed counters.

> 
> Daniel Xu (3):
>    tracing/kprobe: Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
>    libbpf: Add helper to extract perf fd from bpf_link
>    tracing/kprobe: Add self test for PERF_EVENT_IOC_QUERY_KPROBE
> 
>   include/linux/trace_events.h                  |  6 +++
>   include/uapi/linux/perf_event.h               | 23 ++++++++++
>   kernel/events/core.c                          | 11 +++++
>   kernel/trace/trace_kprobe.c                   | 25 +++++++++++
>   tools/include/uapi/linux/perf_event.h         | 23 ++++++++++
>   tools/lib/bpf/libbpf.c                        | 13 ++++++
>   tools/lib/bpf/libbpf.h                        |  1 +
>   tools/lib/bpf/libbpf.map                      |  5 +++
>   .../selftests/bpf/prog_tests/attach_probe.c   | 43 +++++++++++++++++++
>   9 files changed, 150 insertions(+)
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
  2019-08-06 23:38 [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl Daniel Xu
  2019-08-07  5:24 ` Yonghong Song
@ 2019-08-07 17:49 ` Song Liu
  2019-08-07 19:03 ` Andrii Nakryiko
  2 siblings, 0 replies; 6+ messages in thread
From: Song Liu @ 2019-08-07 17:49 UTC (permalink / raw)
  To: Daniel Xu; +Cc: Song Liu, Yonghong Song, Andrii Nakryiko, bpf, Kernel Team

On Tue, Aug 6, 2019 at 4:39 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> It's useful to know kprobe's nmissed and nhit stats. For example with
> tracing tools, it's important to know when events may have been lost.
> There is currently no way to get that information from the perf API.
> This patch adds a new ioctl that lets users query this information.
>

Part of the change is on perf side, so please include linux-kernel and
perf mantainers and reviewers:

M:      Peter Zijlstra <peterz@infradead.org>
M:      Ingo Molnar <mingo@redhat.com>
M:      Arnaldo Carvalho de Melo <acme@kernel.org>
R:      Alexander Shishkin <alexander.shishkin@linux.intel.com>
R:      Jiri Olsa <jolsa@redhat.com>
R:      Namhyung Kim <namhyung@kernel.org>
L:      linux-kernel@vger.kernel.org

I guess this is based on bpf-next tree. So please use subject perfix
[PATCH bpf-next] ([PATCH v2 bpf-next] when resend).

Thanks,
Song

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
  2019-08-06 23:38 [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl Daniel Xu
  2019-08-07  5:24 ` Yonghong Song
  2019-08-07 17:49 ` Song Liu
@ 2019-08-07 19:03 ` Andrii Nakryiko
  2019-08-08 22:32   ` Daniel Xu
  2 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2019-08-07 19:03 UTC (permalink / raw)
  To: Daniel Xu; +Cc: Song Liu, Yonghong Song, Andrii Nakryiko, bpf, Kernel Team

On Tue, Aug 6, 2019 at 4:39 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> It's useful to know kprobe's nmissed and nhit stats. For example with

Is nmissed/nhit kprobe-specific? What about tracepoints and raw
tracepoints, do they have something similar or they can never be
missed? At least nhit still seems useful, so would be nice to have
ability to get that with the same API, is it possible?

> tracing tools, it's important to know when events may have been lost.
> There is currently no way to get that information from the perf API.
> This patch adds a new ioctl that lets users query this information.
>
> Daniel Xu (3):
>   tracing/kprobe: Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
>   libbpf: Add helper to extract perf fd from bpf_link
>   tracing/kprobe: Add self test for PERF_EVENT_IOC_QUERY_KPROBE
>
>  include/linux/trace_events.h                  |  6 +++
>  include/uapi/linux/perf_event.h               | 23 ++++++++++
>  kernel/events/core.c                          | 11 +++++
>  kernel/trace/trace_kprobe.c                   | 25 +++++++++++
>  tools/include/uapi/linux/perf_event.h         | 23 ++++++++++
>  tools/lib/bpf/libbpf.c                        | 13 ++++++
>  tools/lib/bpf/libbpf.h                        |  1 +
>  tools/lib/bpf/libbpf.map                      |  5 +++
>  .../selftests/bpf/prog_tests/attach_probe.c   | 43 +++++++++++++++++++
>  9 files changed, 150 insertions(+)
>
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
  2019-08-07 19:03 ` Andrii Nakryiko
@ 2019-08-08 22:32   ` Daniel Xu
  2019-08-09 17:18     ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Xu @ 2019-08-08 22:32 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Song Liu, Yonghong Song, Andrii Nakryiko, bpf, Kernel Team

On Wed, Aug 7, 2019, at 12:03 PM, Andrii Nakryiko wrote:
> On Tue, Aug 6, 2019 at 4:39 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
> >
> > It's useful to know kprobe's nmissed and nhit stats. For example with
> 
> Is nmissed/nhit kprobe-specific? What about tracepoints and raw
> tracepoints, do they have something similar or they can never be
> missed? At least nhit still seems useful, so would be nice to have
> ability to get that with the same API, is it possible?
> 

I'm still trying to grok all the tracepoint/ftrace machinery, but it appears
to me like it is kprobe/uprobe specific. My guess is that b/c tracepoints are
inline (and don't require trapping interrupts), it cannot really "miss".

This brings up a good point, though. I think we want the same querying
functionality for uprobes so it might be worthwhile to make this API generic.
Something like PERF_EVENT_IOC_QUERY_PROBE so we can later add in
uprobe stats. And maybe tracepoint if it makes sense.

Thoughts?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl
  2019-08-08 22:32   ` Daniel Xu
@ 2019-08-09 17:18     ` Andrii Nakryiko
  0 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2019-08-09 17:18 UTC (permalink / raw)
  To: Daniel Xu; +Cc: Song Liu, Yonghong Song, Andrii Nakryiko, bpf, Kernel Team

On Thu, Aug 8, 2019 at 3:32 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> On Wed, Aug 7, 2019, at 12:03 PM, Andrii Nakryiko wrote:
> > On Tue, Aug 6, 2019 at 4:39 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
> > >
> > > It's useful to know kprobe's nmissed and nhit stats. For example with
> >
> > Is nmissed/nhit kprobe-specific? What about tracepoints and raw
> > tracepoints, do they have something similar or they can never be
> > missed? At least nhit still seems useful, so would be nice to have
> > ability to get that with the same API, is it possible?
> >
>
> I'm still trying to grok all the tracepoint/ftrace machinery, but it appears
> to me like it is kprobe/uprobe specific. My guess is that b/c tracepoints are
> inline (and don't require trapping interrupts), it cannot really "miss".
>
> This brings up a good point, though. I think we want the same querying
> functionality for uprobes so it might be worthwhile to make this API generic.
> Something like PERF_EVENT_IOC_QUERY_PROBE so we can later add in
> uprobe stats. And maybe tracepoint if it makes sense.
>
> Thoughts?

Yeah, we should definitely unify uprobes, if possible. Having nhit
would be great for tracepoints/raw_tracepoints, but we need to look
whether it's possible and whether it hurts performance. With bpf_stats
we trigger them only from time to time, so counting overhead might be
noticeable for some use cases.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-09 17:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06 23:38 [PATCH 0/3] Add PERF_EVENT_IOC_QUERY_KPROBE ioctl Daniel Xu
2019-08-07  5:24 ` Yonghong Song
2019-08-07 17:49 ` Song Liu
2019-08-07 19:03 ` Andrii Nakryiko
2019-08-08 22:32   ` Daniel Xu
2019-08-09 17:18     ` Andrii Nakryiko

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).