Introducing trace buffer mapping by user-space
Subsystems (2)
Vincent Donnefort
maintainercover Introducing trace buffer mapping by user-space
Hi all,
We (Android folks) have been recently working on bringing tracing to the pKVM hypervisor (more about pKVM? [1] [2]) reusing as much as possible the tracefs support already available in the host. More specifically, sharing the ring_buffer_per_cpu between the kernel and the hypervisor, the later being the writer while the former is only reading. After presenting this endeavour at the tracingsummit, end of last year [3], Steven observed this is a similar problem to another idea he had a while ago: mapping the tracing ring buffers directly into userspace.
The tracing ring-buffer can be stored or sent to network without any copy via splice. However the later doesn't allow real time processing of the traces by userspace without a copy, which can only be achieved by letting userspace map directly the ring-buffer.
And indeed, in both ideas, we have a ring-buffer, an entity being the writer, the other being a reader and both share the ring buffer pages while having different VA spaces. So here's an RFC bringing userspace mapping of a ring-buffer and if it doesn't cover the pKVM hypervisor it nonetheless brings building blocks that will be reused later.
Any feedback very much appreciated.
Vincent
[1] https://lwn.net/Articles/836693/
[2] https://www.youtube.com/watch?v=9npebeVFbFw
[3] https://tracingsummit.org/ts/2022/hypervisortracing/
Signature · 218 lines
As an example, Steve wrote this quick demo that only needs libtracefs:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <tracefs.h>
#include <kbuffer.h>
#include <event-parse.h>
#include <asm/types.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#define TRACE_MMAP_IOCTL_GET_READER_PAGE _IO('T', 0x1)
#define TRACE_MMAP_IOCTL_UPDATE_META_PAGE _IO('T', 0x2)
struct ring_buffer_meta_page {
__u64 entries;
__u64 overrun;
__u32 pages_touched;
__u32 reader_page;
__u32 nr_data_pages;
__u32 data_page_head;
__u32 data_pages[];
};
static char *argv0;
static int page_size;
static char *get_this_name(void)
{
static char *this_name;
char *arg;
char *p;
if (this_name)
return this_name;
arg = argv0;
p = arg+strlen(arg);
while (p >= arg && *p != '/')
p--;
p++;
this_name = p;
return p;
}
static void usage(void)
{
char *p = get_this_name();
printf("usage: %s exec\n"
"\n",p);
exit(-1);
}
static void __vdie(const char *fmt, va_list ap, int err)
{
int ret = errno;
char *p = get_this_name();
if (err && errno)
perror(p);
else
ret = -1;
fprintf(stderr, " ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
exit(ret);
}
void die(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
__vdie(fmt, ap, 0);
va_end(ap);
}
void pdie(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
__vdie(fmt, ap, 1);
va_end(ap);
}
static void read_page(struct tep_handle *tep, struct kbuffer *kbuf,
void *data, int page)
{
static struct trace_seq seq;
struct tep_record record;
if (seq.buffer)
trace_seq_reset(&seq);
else
trace_seq_init(&seq);
kbuffer_load_subbuffer(kbuf, data + page_size * page);
while ((record.data = kbuffer_read_event(kbuf, &record.ts))) {
kbuffer_next_event(kbuf, NULL);
tep_print_event(tep, &seq, &record,
"%s-%d %9d\t%s: %s\n",
TEP_PRINT_COMM,
TEP_PRINT_PID,
TEP_PRINT_TIME,
TEP_PRINT_NAME,
TEP_PRINT_INFO);
trace_seq_do_printf(&seq);
trace_seq_reset(&seq);
}
}
static int get_reader_page(int fd, struct ring_buffer_meta_page *meta)
{
return meta->reader_page;
}
static int next_reader_page(int fd, struct ring_buffer_meta_page *meta)
{
if (ioctl(fd, TRACE_MMAP_IOCTL_GET_READER_PAGE) < 0)
pdie("ioctl");
return meta->reader_page;
}
int main (int argc, char **argv)
{
struct ring_buffer_meta_page *map;
struct tep_handle *tep;
struct kbuffer *kbuf;
unsigned long *p;
void *meta;
void *data;
char *buf;
int data_len;
int start;
int page;
int fd;
argv0 = argv[0];
tep = tracefs_local_events(NULL);
kbuf = tep_kbuffer(tep);
page_size = getpagesize();
fd = tracefs_instance_file_open(NULL, "per_cpu/cpu0/trace_pipe_raw",
O_RDONLY);
if (fd < 0)
pdie("raw");
meta = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
if (meta == MAP_FAILED)
pdie("mmap");
if (ioctl(fd, TRACE_MMAP_IOCTL_UPDATE_META_PAGE) < 0)
pdie("ioctl");
map = meta;
printf("entries: %llu\n", map->entries);
printf("overrun: %llu\n", map->overrun);
printf("pages_touched: %u\n", map->pages_touched);
printf("reader_page: %u\n", map->reader_page);
printf("nr_data_pages: %u\n\n", map->nr_data_pages);
data_len = page_size * map->nr_data_pages;
data = mmap(NULL, data_len, PROT_READ, MAP_SHARED, fd, page_size);
if (data == MAP_FAILED)
pdie("mmap data");
page = get_reader_page(fd, meta);
start = page;
do {
read_page(tep, kbuf, data, page);
printf("reader_page: %u\n", map->reader_page);
printf("PAGE: %d\n", page);
} while ((page = next_reader_page(fd, meta)) != start);
p = data;
printf("%lx\n%lx\n%lx\n\n", p[0], p[1], p[2]);
munmap(data, data_len);
munmap(meta, page_size);
close(fd);
buf = tracefs_instance_file_read(NULL, "per_cpu/cpu0/stats", NULL);
if (!buf)
pdie("stats");
printf("%s\n", buf);
free(buf);
return 0;
}
Vincent Donnefort (2):
ring-buffer: Introducing ring-buffer mapping functions
tracing: Allow user-space mapping of the ring-buffer
include/linux/ring_buffer.h | 8 +
include/uapi/linux/trace_mmap.h | 17 ++
kernel/trace/ring_buffer.c | 355 +++++++++++++++++++++++++++++++-
kernel/trace/trace.c | 74 ++++++-
4 files changed, 441 insertions(+), 13 deletions(-)
create mode 100644 include/uapi/linux/trace_mmap.h
--
2.39.1.581.gbfd45094c4-googVincent Donnefort
maintainerRFC PATCH 1/2 ring-buffer: Introducing ring-buffer mapping functions
In preparation for allowing the user-space to map a ring-buffer, add a set of mapping functions:
ring_buffer_{map,unmap}()
ring_buffer_map_fault()
And controls on the ring-buffer:
ring_buffer_get_reader_page() /* swap reader and head */ ring_buffer_update_meta_page()
Mapping the ring-buffer also involves:
A unique ID for each page of the ring-buffer, as currently the pages are only identified through their in-kernel VA.
A meta-page, where are stored statistics about the ring-buffer and the list of pages ID, ordered. A field gives what page is the reader one and one to gives where the ring-buffer starts in the list of data pages.
The linear mapping exposes the meta-page, and each page of the ring-buffer, ordered following their unique ID, assigned during the first mapping.
Once mapped, no page can get in or out of the ring-buffer: the buffer size will remain unmodified and the splice enabling functions will in reality simply memcpy the data instead of swapping pages.
Also, the meta-page being... a single page, this limits at the moment the number of pages in the ring-buffer that can be mapped.
include/linux/ring_buffer.h +8 -0
@@ -6,6 +6,8 @@#include <linux/seq_file.h> #include <linux/poll.h> +#include <uapi/linux/trace_mmap.h> +struct trace_buffer ;struct ring_buffer_iter ;
@@ -211,4 +213,10 @@ int trace_rb_cpu_prepare(unsigned int cpu, struct hlist_node *node);#define trace_rb_cpu_prepare NULL#endif +int ring_buffer_map (struct trace_buffer *buffer,int cpu); +int ring_buffer_unmap (struct trace_buffer *buffer,int cpu); +struct page *ring_buffer_map_fault (struct trace_buffer *buffer,int cpu, +unsigned long pgoff); +int ring_buffer_get_reader_page (struct trace_buffer *buffer,int cpu); +int ring_buffer_update_meta_page (struct trace_buffer *buffer,int cpu);#endif /* _LINUX_RING_BUFFER_H */
include/uapi/linux/trace_mmap.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _UAPI_TRACE_MMAP_H_ +#define _UAPI_TRACE_MMAP_H_ + +struct ring_buffer_meta_page { +__u64 entries; +__u64 overrun; +__u32 pages_touched; +__u32 reader_page; +__u32 nr_data_pages; +__u32 data_page_head; +__u32 data_pages[]; +}; + +#endif /* _UAPI_TRACE_MMAP_H_ */
kernel/trace/ring_buffer.c +345 -10
436 lines not on this page · raw message
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
kernel test robot
build botRe: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vincent,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc7 next-20230210]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 patch link: https://lore.kernel.org/r/20230212153250.1099136-2-vdonnefort%40google.com patch subject: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions config: loongarch-allyesconfig (https://download.01.org/0day-ci/archive/20230213/[email protected]/config) compiler: loongarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/96cfb7d92682fb5df39febc590fec75748b47e15
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 git checkout 96cfb7d92682fb5df39febc590fec75748b47e15
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch SHELL=/bin/bash kernel/trace/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> kernel/trace/ring_buffer.c:6017:6: warning: no previous prototype for 'rb_put_mapped_buffer' [-Wmissing-prototypes]
6017 | void rb_put_mapped_buffer(struct ring_buffer_per_cpu *cpu_buffer)
| ^~~~~~~~~~~~~~~~~~~~
vim +/rb_put_mapped_buffer +6017 kernel/trace/ring_buffer.c
6016
> 6017 void rb_put_mapped_buffer(struct ring_buffer_per_cpu *cpu_buffer)
6018 {
6019 up_read(&cpu_buffer->mapping_lock);
6020 }
6021
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions
In reply to Vincent Donnefort[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vincent,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on rostedt-trace/for-next]
[cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 patch link: https://lore.kernel.org/r/20230212153250.1099136-2-vdonnefort%40google.com patch subject: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions config: hexagon-randconfig-r045-20230212 (https://download.01.org/0day-ci/archive/20230213/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project db0e6591612b53910a1b366863348bdb9d7d2fb1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/96cfb7d92682fb5df39febc590fec75748b47e15
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 git checkout 96cfb7d92682fb5df39febc590fec75748b47e15
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash kernel/trace/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from kernel/trace/ring_buffer.c:7:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from kernel/trace/ring_buffer.c:7:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from kernel/trace/ring_buffer.c:7:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
>> kernel/trace/ring_buffer.c:6017:6: warning: no previous prototype for function 'rb_put_mapped_buffer' [-Wmissing-prototypes]
void rb_put_mapped_buffer(struct ring_buffer_per_cpu *cpu_buffer)
^ kernel/trace/ring_buffer.c:6017:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void rb_put_mapped_buffer(struct ring_buffer_per_cpu *cpu_buffer)
^
static
7 warnings generated.
vim +/rb_put_mapped_buffer +6017 kernel/trace/ring_buffer.c
6016
> 6017 void rb_put_mapped_buffer(struct ring_buffer_per_cpu *cpu_buffer)
6018 {
6019 up_read(&cpu_buffer->mapping_lock);
6020 }
6021
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions
In reply to Vincent Donnefort[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vincent,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on rostedt-trace/for-next v6.2-rc7 next-20230210] [cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 patch link: https://lore.kernel.org/r/20230212153250.1099136-2-vdonnefort%40google.com patch subject: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions config: x86_64-randconfig-a016 (https://download.01.org/0day-ci/archive/20230213/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/96cfb7d92682fb5df39febc590fec75748b47e15
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 git checkout 96cfb7d92682fb5df39febc590fec75748b47e15
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <built-in>:1:
>> ./usr/include/linux/trace_mmap.h:5:2: error: unknown type name '__u64'
__u64 entries;
^
./usr/include/linux/trace_mmap.h:6:2: error: unknown type name '__u64'
__u64 overrun;
^
>> ./usr/include/linux/trace_mmap.h:7:2: error: unknown type name '__u32'
__u32 pages_touched;
^
./usr/include/linux/trace_mmap.h:8:2: error: unknown type name '__u32'
__u32 reader_page;
^
./usr/include/linux/trace_mmap.h:9:2: error: unknown type name '__u32'
__u32 nr_data_pages;
^
./usr/include/linux/trace_mmap.h:10:2: error: unknown type name '__u32'
__u32 data_page_head;
^
./usr/include/linux/trace_mmap.h:11:2: error: unknown type name '__u32'
__u32 data_pages[];
^7 errors generated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions
In reply to Vincent Donnefort[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vincent,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on rostedt-trace/for-next v6.2-rc7 next-20230210] [cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 patch link: https://lore.kernel.org/r/20230212153250.1099136-2-vdonnefort%40google.com patch subject: [RFC PATCH 1/2] ring-buffer: Introducing ring-buffer mapping functions config: i386-randconfig-s003 (https://download.01.org/0day-ci/archive/20230213/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.4-39-gce1a6720-dirty # https://github.com/intel-lab-lkp/linux/commit/96cfb7d92682fb5df39febc590fec75748b47e15 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Vincent-Donnefort/ring-buffer-Introducing-ring-buffer-mapping-functions/20230212-233420 git checkout 96cfb7d92682fb5df39febc590fec75748b47e15 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 olddefconfig make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash kernel/trace/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
kernel/trace/ring_buffer.c:1140:32: sparse: sparse: incorrect type in return expression (different base types) @@ expected restricted __poll_t @@ got int @@
kernel/trace/ring_buffer.c:1140:32: sparse: expected restricted __poll_t
kernel/trace/ring_buffer.c:1140:32: sparse: got int
>> kernel/trace/ring_buffer.c:6017:6: sparse: sparse: symbol 'rb_put_mapped_buffer' was not declared. Should it be static?
kernel/trace/ring_buffer.c:5043:9: sparse: sparse: context imbalance in 'ring_buffer_peek' - different lock contexts for basic block kernel/trace/ring_buffer.c:5129:9: sparse: sparse: context imbalance in 'ring_buffer_consume' - different lock contexts for basic block kernel/trace/ring_buffer.c:5492:17: sparse: sparse: context imbalance in 'ring_buffer_empty' - different lock contexts for basic block kernel/trace/ring_buffer.c:5522:9: sparse: sparse: context imbalance in 'ring_buffer_empty_cpu' - different lock contexts for basic block
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Vincent Donnefort
maintainerRFC PATCH 2/2 tracing: Allow user-space mapping of the ring-buffer
In reply to Vincent DonnefortCurrently, 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 not possible 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 exposed via the per-CPU file trace_pipe_raw. The first page is the meta-page and is followed by each page of the ring-buffer, ordered by their unique page ID. It is therefore easy to translate a page-ID to an offset into the mapping.
* Meta-page -- include/uapi/linux/trace_mmap.h for a description
* Page ID 0
* Page ID 1
...
The mapper must then do what use to be the kernel jobs: swap the reader with the head. This is done with a newly introduced ioctl:TRACE_MMAP_IOCTL_GET_READER_PAGE.
To avoid putting to much work on the writer, the meta-page is not automatically updated. User-space must query an update before reading with another ioctl: TRACE_MMAP_IOCTL_UPDATE_META_PAGE.
include/uapi/linux/trace_mmap.h +3 -0
@@ -11,4 +11,7 @@ struct ring_buffer_meta_page { __u32 data_pages[]; }; +#define TRACE_MMAP_IOCTL_GET_READER_PAGE _IO('T', 0x1) +#define TRACE_MMAP_IOCTL_UPDATE_META_PAGE _IO('T', 0x2) +#endif /* _UAPI_TRACE_MMAP_H_ */
kernel/trace/trace.c +71 -3
105 lines not on this page · raw message
Signature · 1 line
2.39.1.581.gbfd45094c4-goog