€•Ò3Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ)/translations/zh_CN/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/zh_TW/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/it_IT/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/ja_JP/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/ko_KR/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/pt_BR/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ)/translations/sp_SP/trace/ring-buffer-map”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ SPDX-License-Identifier: GPL-2.0”h]”hŒ SPDX-License-Identifier: GPL-2.0”…””}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³ŒC/var/lib/git/docbuild/linux/Documentation/trace/ring-buffer-map.rst”h´KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒ"Tracefs ring-buffer memory mapping”h]”hŒ"Tracefs ring-buffer memory mapping”…””}”(hhÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhhÊh²hh³hÇh´KubhŒ field_list”“”)”}”(hhh]”hŒfield”“”)”}”(hhh]”(hŒ field_name”“”)”}”(hŒAuthor”h]”hŒAuthor”…””}”(hhéh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hçhhäh³hÇh´KubhŒ field_body”“”)”}”(hŒ*Vincent Donnefort ”h]”hŒ paragraph”“”)”}”(hŒ)Vincent Donnefort ”h]”(hŒVincent Donnefort <”…””}”(hhÿh²hh³Nh´NubhŒ reference”“”)”}”(hŒvdonnefort@google.com”h]”hŒvdonnefort@google.com”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:vdonnefort@google.com”uh1jhhÿubhŒ>”…””}”(hhÿh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´Khhùubah}”(h]”h ]”h"]”h$]”h&]”uh1h÷hhäubeh}”(h]”h ]”h"]”h$]”h&]”uh1hâh³hÇh´Khhßh²hubah}”(h]”h ]”h"]”h$]”h&]”uh1hÝhhÊh²hh³hÇh´KubhÉ)”}”(hhh]”(hÎ)”}”(hŒOverview”h]”hŒOverview”…””}”(hj8h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj5h²hh³hÇh´K ubhþ)”}”(hŒäTracefs ring-buffer memory map provides an efficient method to stream data as no memory copy is necessary. The application mapping the ring-buffer becomes then a consumer for that ring-buffer, in a similar fashion to trace_pipe.”h]”hŒäTracefs ring-buffer memory map provides an efficient method to stream data as no memory copy is necessary. The application mapping the ring-buffer becomes then a consumer for that ring-buffer, in a similar fashion to trace_pipe.”…””}”(hjFh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´K hj5h²hubeh}”(h]”Œoverview”ah ]”h"]”Œoverview”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´K ubhÉ)”}”(hhh]”(hÎ)”}”(hŒMemory mapping setup”h]”hŒMemory mapping setup”…””}”(hj_h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj\h²hh³hÇh´Kubhþ)”}”(hŒ@The mapping works with a mmap() of the trace_pipe_raw interface.”h]”hŒ@The mapping works with a mmap() of the trace_pipe_raw interface.”…””}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´Khj\h²hubhþ)”}”(hXThe first system page of the mapping contains ring-buffer statistics and description. It is referred to as the meta-page. One of the most important fields of the meta-page is the reader. It contains the sub-buffer ID which can be safely read by the mapper (see ring-buffer-design.rst).”h]”hXThe first system page of the mapping contains ring-buffer statistics and description. It is referred to as the meta-page. One of the most important fields of the meta-page is the reader. It contains the sub-buffer ID which can be safely read by the mapper (see ring-buffer-design.rst).”…””}”(hj{h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´Khj\h²hubhþ)”}”(hŒ•The meta-page is followed by all the sub-buffers, ordered by ascending ID. It is therefore effortless to know where the reader starts in the mapping:”h]”hŒ•The meta-page is followed by all the sub-buffers, ordered by ascending ID. It is therefore effortless to know where the reader starts in the mapping:”…””}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´Khj\h²hubhŒ literal_block”“”)”}”(hŒcreader_id = meta->reader->id; reader_offset = meta->meta_page_size + reader_id * meta->subbuf_size;”h]”hŒcreader_id = meta->reader->id; reader_offset = meta->meta_page_size + reader_id * meta->subbuf_size;”…””}”hj™sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆŒforce”‰Œlanguage”Œc”Œhighlight_args”}”uh1j—h³hÇh´Khj\h²hubhþ)”}”(hŒ¶When the application is done with the current reader, it can get a new one using the trace_pipe_raw ioctl() TRACE_MMAP_IOCTL_GET_READER. This ioctl also updates the meta-page fields.”h]”hŒ¶When the application is done with the current reader, it can get a new one using the trace_pipe_raw ioctl() TRACE_MMAP_IOCTL_GET_READER. This ioctl also updates the meta-page fields.”…””}”(hj¬h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´K hj\h²hubeh}”(h]”Œmemory-mapping-setup”ah ]”h"]”Œmemory mapping setup”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´KubhÉ)”}”(hhh]”(hÎ)”}”(hŒ Limitations”h]”hŒ Limitations”…””}”(hjÅh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhjÂh²hh³hÇh´K%ubhþ)”}”(hX5When a mapping is in place on a Tracefs ring-buffer, it is not possible to either resize it (either by increasing the entire size of the ring-buffer or each subbuf). It is also not possible to use snapshot and causes splice to copy the ring buffer data instead of using the copyless swap from the ring buffer.”h]”hX5When a mapping is in place on a Tracefs ring-buffer, it is not possible to either resize it (either by increasing the entire size of the ring-buffer or each subbuf). It is also not possible to use snapshot and causes splice to copy the ring buffer data instead of using the copyless swap from the ring buffer.”…””}”(hjÓh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´K&hjÂh²hubhþ)”}”(hXConcurrent readers (either another application mapping that ring-buffer or the kernel with trace_pipe) are allowed but not recommended. They will compete for the ring-buffer and the output is unpredictable, just like concurrent readers on trace_pipe would be.”h]”hXConcurrent readers (either another application mapping that ring-buffer or the kernel with trace_pipe) are allowed but not recommended. They will compete for the ring-buffer and the output is unpredictable, just like concurrent readers on trace_pipe would be.”…””}”(hjáh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hýh³hÇh´K+hjÂh²hubeh}”(h]”Œ limitations”ah ]”h"]”Œ limitations”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´K%ubhÉ)”}”(hhh]”(hÎ)”}”(hŒExample”h]”hŒExample”…””}”(hjúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÍhj÷h²hh³hÇh´K1ubj˜)”}”(hXý#include #include #include #include #include #include #include #define TRACE_PIPE_RAW "/sys/kernel/tracing/per_cpu/cpu0/trace_pipe_raw" int main(void) { int page_size = getpagesize(), fd, reader_id; unsigned long meta_len, data_len; struct trace_buffer_meta *meta; void *map, *reader, *data; fd = open(TRACE_PIPE_RAW, O_RDONLY | O_NONBLOCK); if (fd < 0) exit(EXIT_FAILURE); map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0); if (map == MAP_FAILED) exit(EXIT_FAILURE); meta = (struct trace_buffer_meta *)map; meta_len = meta->meta_page_size; printf("entries: %llu\n", meta->entries); printf("overrun: %llu\n", meta->overrun); printf("read: %llu\n", meta->read); printf("nr_subbufs: %u\n", meta->nr_subbufs); data_len = meta->subbuf_size * meta->nr_subbufs; data = mmap(NULL, data_len, PROT_READ, MAP_SHARED, fd, meta_len); if (data == MAP_FAILED) exit(EXIT_FAILURE); if (ioctl(fd, TRACE_MMAP_IOCTL_GET_READER) < 0) exit(EXIT_FAILURE); reader_id = meta->reader.id; reader = data + meta->subbuf_size * reader_id; printf("Current reader address: %p\n", reader); munmap(data, data_len); munmap(meta, meta_len); close (fd); return 0; }”h]”hXý#include #include #include #include #include #include #include #define TRACE_PIPE_RAW "/sys/kernel/tracing/per_cpu/cpu0/trace_pipe_raw" int main(void) { int page_size = getpagesize(), fd, reader_id; unsigned long meta_len, data_len; struct trace_buffer_meta *meta; void *map, *reader, *data; fd = open(TRACE_PIPE_RAW, O_RDONLY | O_NONBLOCK); if (fd < 0) exit(EXIT_FAILURE); map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0); if (map == MAP_FAILED) exit(EXIT_FAILURE); meta = (struct trace_buffer_meta *)map; meta_len = meta->meta_page_size; printf("entries: %llu\n", meta->entries); printf("overrun: %llu\n", meta->overrun); printf("read: %llu\n", meta->read); printf("nr_subbufs: %u\n", meta->nr_subbufs); data_len = meta->subbuf_size * meta->nr_subbufs; data = mmap(NULL, data_len, PROT_READ, MAP_SHARED, fd, meta_len); if (data == MAP_FAILED) exit(EXIT_FAILURE); if (ioctl(fd, TRACE_MMAP_IOCTL_GET_READER) < 0) exit(EXIT_FAILURE); reader_id = meta->reader.id; reader = data + meta->subbuf_size * reader_id; printf("Current reader address: %p\n", reader); munmap(data, data_len); munmap(meta, meta_len); close (fd); return 0; }”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆj§‰j¨j©jª}”uh1j—h³hÇh´K3hj÷h²hubeh}”(h]”Œexample”ah ]”h"]”Œexample”ah$]”h&]”uh1hÈhhÊh²hh³hÇh´K1ubeh}”(h]”Œ"tracefs-ring-buffer-memory-mapping”ah ]”h"]”Œ"tracefs ring-buffer memory mapping”ah$]”h&]”uh1hÈhhh²hh³hÇh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hÍNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jJŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(j$j!jYjVj¿j¼jôjñjjuŒ nametypes”}”(j$‰jY‰j¿‰jô‰j‰uh}”(j!hÊjVj5j¼j\jñjÂjj÷uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.