€•÷2Œ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Œ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”…””}”(hhõhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:vdonnefort@google.com”uh1hóhhë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”…””}”(hj$hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hj!hž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.”…””}”(hj2hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1héhŸh³h K hj!hž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”…””}”(hjKhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hjHhž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.”…””}”(hjYhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1héhŸh³h KhjHhž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).”…””}”(hjghžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1héhŸh³h KhjHhž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:”…””}”(hjuhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1héhŸh³h KhjHhž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 KhjHhž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 hjHhž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; }”…””}”hjôsbah}”(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”j6Œ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”}”(jj jEjBj«j¨jàjÝjjuŒ nametypes”}”(j‰jE‰j«‰jà‰j‰uh}”(j h¶jBj!j¨jHjÝ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.