BPF List
 help / color / mirror / Atom feed
* [PATCH v1 0/1] libbpf: perfbuf custom event reader
@ 2022-07-07  7:13 Jon Doron
  2022-07-07  7:13 ` [PATCH v1 1/1] libbpf: perfbuf: allow raw access to buffers Jon Doron
  0 siblings, 1 reply; 4+ messages in thread
From: Jon Doron @ 2022-07-07  7:13 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel; +Cc: Jon Doron

From: Jon Doron <jond@wiz.io>

Add support for writing a custom event reader, by exposing the ring
buffer state, and allowing to set it's tail.

Few simple examples where this type of needed:
1. perf_event_read_simple is allocating using malloc, perhaps you want
   to handle the wrap-around in some other way.
2. Since perf buf is per-cpu then the order of the events is not
   guarnteed, for example:
   Given 3 events where each event has a timestamp t0 < t1 < t2,
   and the events are spread on more than 1 CPU, then we can end
   up with the following state in the ring buf:
   CPU[0] => [t0, t2]
   CPU[1] => [t1]
   When you consume the events from CPU[0], you could know there is
   a t1 missing, (assuming there are no drops, and your event data
   contains a sequential index).
   So now one can simply do the following, for CPU[0], you can store
   the address of t0 and t2 in an array (without moving the tail, so
   there data is not perished) then move on the CPU[1] and set the
   address of t1 in the same array.
   So you end up with something like:
   void **arr[] = [&t0, &t1, &t2], now you can consume it orderely
   and move the tails as you process in order.

Jon Doron (1):
  libbpf: perfbuf: allow raw access to buffers

 tools/lib/bpf/libbpf.c | 40 ++++++++++++++++++++++++++++++++++++++++
 tools/lib/bpf/libbpf.h |  6 ++++++
 2 files changed, 46 insertions(+)

-- 
2.36.1


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

end of thread, other threads:[~2022-07-08  6:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-07  7:13 [PATCH v1 0/1] libbpf: perfbuf custom event reader Jon Doron
2022-07-07  7:13 ` [PATCH v1 1/1] libbpf: perfbuf: allow raw access to buffers Jon Doron
2022-07-08  5:26   ` Song Liu
2022-07-08  6:08     ` Jon Doron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox