~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/trace/ring-buffer-map.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/trace/ring-buffer-map.rst (Version linux-6.12-rc7) and /Documentation/trace/ring-buffer-map.rst (Version linux-4.15.18)


  1 .. SPDX-License-Identifier: GPL-2.0               
  2                                                   
  3 ==================================                
  4 Tracefs ring-buffer memory mapping                
  5 ==================================                
  6                                                   
  7 :Author: Vincent Donnefort <vdonnefort@google.c    
  8                                                   
  9 Overview                                          
 10 ========                                          
 11 Tracefs ring-buffer memory map provides an eff    
 12 as no memory copy is necessary. The applicatio    
 13 then a consumer for that ring-buffer, in a sim    
 14                                                   
 15 Memory mapping setup                              
 16 ====================                              
 17 The mapping works with a mmap() of the trace_p    
 18                                                   
 19 The first system page of the mapping contains     
 20 description. It is referred to as the meta-pag    
 21 fields of the meta-page is the reader. It cont    
 22 be safely read by the mapper (see ring-buffer-    
 23                                                   
 24 The meta-page is followed by all the sub-buffe    
 25 therefore effortless to know where the reader     
 26                                                   
 27 .. code-block:: c                                 
 28                                                   
 29         reader_id = meta->reader->id;             
 30         reader_offset = meta->meta_page_size +    
 31                                                   
 32 When the application is done with the current     
 33 the trace_pipe_raw ioctl() TRACE_MMAP_IOCTL_GE    
 34 the meta-page fields.                             
 35                                                   
 36 Limitations                                       
 37 ===========                                       
 38 When a mapping is in place on a Tracefs ring-b    
 39 either resize it (either by increasing the ent    
 40 each subbuf). It is also not possible to use s    
 41 the ring buffer data instead of using the copy    
 42                                                   
 43 Concurrent readers (either another application    
 44 kernel with trace_pipe) are allowed but not re    
 45 the ring-buffer and the output is unpredictabl    
 46 trace_pipe would be.                              
 47                                                   
 48 Example                                           
 49 =======                                           
 50                                                   
 51 .. code-block:: c                                 
 52                                                   
 53         #include <fcntl.h>                        
 54         #include <stdio.h>                        
 55         #include <stdlib.h>                       
 56         #include <unistd.h>                       
 57                                                   
 58         #include <linux/trace_mmap.h>             
 59                                                   
 60         #include <sys/mman.h>                     
 61         #include <sys/ioctl.h>                    
 62                                                   
 63         #define TRACE_PIPE_RAW "/sys/kernel/tr    
 64                                                   
 65         int main(void)                            
 66         {                                         
 67                 int page_size = getpagesize(),    
 68                 unsigned long meta_len, data_l    
 69                 struct trace_buffer_meta *meta    
 70                 void *map, *reader, *data;        
 71                                                   
 72                 fd = open(TRACE_PIPE_RAW, O_RD    
 73                 if (fd < 0)                       
 74                         exit(EXIT_FAILURE);       
 75                                                   
 76                 map = mmap(NULL, page_size, PR    
 77                 if (map == MAP_FAILED)            
 78                         exit(EXIT_FAILURE);       
 79                                                   
 80                 meta = (struct trace_buffer_me    
 81                 meta_len = meta->meta_page_siz    
 82                                                   
 83                 printf("entries:        %llu\n    
 84                 printf("overrun:        %llu\n    
 85                 printf("read:           %llu\n    
 86                 printf("nr_subbufs:     %u\n",    
 87                                                   
 88                 data_len = meta->subbuf_size *    
 89                 data = mmap(NULL, data_len, PR    
 90                 if (data == MAP_FAILED)           
 91                         exit(EXIT_FAILURE);       
 92                                                   
 93                 if (ioctl(fd, TRACE_MMAP_IOCTL    
 94                         exit(EXIT_FAILURE);       
 95                                                   
 96                 reader_id = meta->reader.id;      
 97                 reader = data + meta->subbuf_s    
 98                                                   
 99                 printf("Current reader address    
100                                                   
101                 munmap(data, data_len);           
102                 munmap(meta, meta_len);           
103                 close (fd);                       
104                                                   
105                 return 0;                         
106         }                                         
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php