tracing: Allow user-space mapping of the ring-buffer
authorVincent Donnefort <vdonnefort@google.com>
Fri, 10 May 2024 14:04:32 +0000 (15:04 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Mon, 13 May 2024 22:09:56 +0000 (18:09 -0400)
commitcf9f0f7c4c5bb45e7bb270e48bab6f7837825a64
tree74d4eeab2c64aea8a583cbec5cb12145cf9bccbd
parent117c39200d9d760cbd5944bb89efb7b9c51965aa
tracing: Allow user-space mapping of the ring-buffer

Currently, user-space extracts data from the ring-buffer via splice,
which is handy for storage or network sharing. However, due to splice
limitations, it is imposible to do real-time analysis without a copy.

A solution for that problem is to let the user-space map the ring-buffer
directly.

The mapping is exposed via the per-CPU file trace_pipe_raw. The first
element of the mapping is the meta-page. It is followed by each
subbuffer constituting the ring-buffer, ordered by their unique page ID:

  * Meta-page -- include/uapi/linux/trace_mmap.h for a description
  * Subbuf ID 0
  * Subbuf ID 1
     ...

It is therefore easy to translate a subbuf ID into an offset in the
mapping:

  reader_id = meta->reader->id;
  reader_offset = meta->meta_page_size + reader_id * meta->subbuf_size;

When new data is available, the mapper must call a newly introduced ioctl:
TRACE_MMAP_IOCTL_GET_READER. This will update the Meta-page reader ID to
point to the next reader containing unread data.

Mapping will prevent snapshot and buffer size modifications.

Link: https://lore.kernel.org/linux-trace-kernel/20240510140435.3550353-4-vdonnefort@google.com
CC: <linux-mm@kvack.org>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
include/uapi/linux/trace_mmap.h
kernel/trace/trace.c
kernel/trace/trace.h