Lines Matching full:buffer
4 Perf ring buffer
11 2. Ring buffer implementation
13 2.2 Ring buffer for different tracing modes
18 2.3 Accessing buffer
21 2.3.3 Writing samples into buffer
22 2.3.4 Reading samples from buffer
25 3. The mechanism of AUX ring buffer
34 The ring buffer is a fundamental mechanism for data transfer. perf uses
36 kind of ring buffer which is so called auxiliary (AUX) ring buffer also
40 The ring buffer implementation is critical but it's also a very
42 space use the ring buffer to exchange data and stores data into data
43 file, thus the ring buffer needs to transfer data with high throughput;
44 on the other hand, the ring buffer management should avoid significant
47 This documentation dives into the details for perf ring buffer with two
48 parts: firstly it explains the perf ring buffer implementation, then the
49 second part discusses the AUX ring buffer mechanism.
51 2. Ring buffer implementation
57 That said, a typical ring buffer is managed by a head pointer and a tail
70 Figure 1. Ring buffer
72 Perf uses the same way to manage its ring buffer. In the implementation
74 pages, the control structure and then the ring buffer itself. The page
76 in continuous virtual addresses simplifies locating the ring buffer
81 kernel starts to fill records into the ring buffer, it updates the head
83 the buffer. On the other side, when the user page is a writable mapping,
85 data from the ring buffer. Yet another case is for the user page's
91 user page ring buffer
100 Figure 2. Perf ring buffer
102 When using the ``perf record`` tool, we can specify the ring buffer size
106 to VMA area until the perf tool accesses the buffer from the user space.
107 In other words, at the first time accesses the buffer's page from user
113 2.2 Ring buffer for different tracing modes
118 modes and how the ring buffer meets requirements for them. At last we
140 buffers. As shown below, the perf tool allocates individual ring buffer
145 the *T1* thread and stored in the ring buffer associated with the CPU on
157 | Ring buffer 0 |
167 | Ring buffer 1 |
177 | Ring buffer 2 |
187 | Ring buffer 3 |
193 Figure 3. Ring buffer for default mode
211 In this mode, a single ring buffer is allocated for the profiled thread;
242 | Ring buffer |
248 Figure 4. Ring buffer for per-thread mode
250 When perf runs in per-thread mode, a ring buffer is allocated for the
251 profiled thread *T1*. The ring buffer is dedicated for thread *T1*, if the
253 buffer; when the thread is sleeping, all associated events will be
254 disabled, thus no trace data will be recorded into the ring buffer.
273 running on CPU1 and CPU3, since the ring buffer is absent for them, any
288 | Ring buffer 0 |
303 | Ring buffer 1 |
314 Figure 5. Ring buffer for per-CPU mode
331 In the system wide mode, every CPU has its own ring buffer, all threads
333 the ring buffer belonging to the CPU which the events occurred on.
344 | Ring buffer 0 |
354 | Ring buffer 1 |
364 | Ring buffer 2 |
374 | Ring buffer 3 |
380 Figure 6. Ring buffer for system wide mode
382 2.3 Accessing buffer
385 Based on the understanding of how the ring buffer is allocated in
386 various modes, this section explains access the ring buffer.
392 into the ring buffer; the perf command in user space consumes the
393 samples by reading out data from the ring buffer and finally saves the
395 model for using the ring buffer.
401 the ring buffer, and if the used buffer exceeds the watermark, the
402 kernel wakes up the perf process to read samples from the ring buffer.
408 Polling / `--------------| Ring buffer
421 Figure 7. Writing and reading the ring buffer
424 multiple events might share the same ring buffer for recording samples,
425 the core layer iterates every event associated with the ring buffer and
430 one by one, if it finds any ring buffer containing samples it will read
432 perf process is able to run on any CPU, this leads to the ring buffer
440 Linux kernel supports two write directions for the ring buffer: forward and
442 buffer, the backward writing stores data from the end of the ring buffer with
448 The ring buffer in the read-write mode is mapped with the property
461 combinations to support buffer types: the non-overwrite buffer and the
462 overwritable buffer.
472 - Non-overwrite ring buffer
476 - Overwritable ring buffer
478 The non-overwrite ring buffer uses the read-write mapping with forward
479 writing. It starts to save data from the beginning of the ring buffer
481 the normal ring buffer. When the consumer doesn't keep up with the
484 when it finds a space in the ring buffer.
486 The overwritable ring buffer uses the backward writing with the
487 read-only mode. It saves the data from the end of the ring buffer and
489 knows where it starts to read and until the end of the ring buffer, thus
495 2.3.3 Writing samples into buffer argument
498 When a sample is taken and saved into the ring buffer, the kernel
500 info for writing ring buffer which is stored in the structure
502 the ring buffer and updates the head pointer in the user page so the
506 tracking the information related to the buffer. The advantages of it is
507 that it enables concurrent writing to the buffer by different events.
514 2.3.4 Reading samples from buffer argument
518 structure to handle the head and tail of the buffer. It also uses
519 ``perf_mmap`` structure to keep track of a context for the ring buffer, this
520 context includes information about the buffer's starting and ending
522 circular buffer pointer even for an overflow.
525 the recorded data from the ring buffer, and then updates the buffer's
534 ordering, this means it’s possible to access the ring buffer and the
536 sequence for memory accessing perf ring buffer, memory barriers are
555 buffer;
557 (D) pairs with (A). (D) separates the ring buffer data reading from
587 3. The mechanism of AUX ring buffer
591 buffer. In the first part it will discuss the connection between the
592 AUX ring buffer and the regular ring buffer, then the second part will
593 examine how the AUX ring buffer co-works with the regular ring buffer,
594 as well as the additional features introduced by the AUX ring buffer for
600 Generally, the AUX ring buffer is an auxiliary for the regular ring
601 buffer. The regular ring buffer is primarily used to store the event
603 union ``perf_event``; the AUX ring buffer is for recording the hardware
606 The general use and advantage of the AUX ring buffer is that it is
608 regular profile samples that write to the regular ring buffer cause an
610 using interrupts would be overwhelming for the regular ring buffer
611 mechanism. Having an AUX buffer allows for a region of memory more
614 The AUX ring buffer reuses the same algorithm with the regular ring
615 buffer for the buffer management. The control structure
617 for the head and tail pointers of the AUX ring buffer.
620 buffer, the perf tool invokes a second syscall in the
621 ``auxtrace_mmap__mmap()`` function for the mmap of the AUX buffer with
625 regular ring buffer.
634 into the regular ring buffer while the CoreSight's AUX trace data is
635 stored in the AUX ring buffer.
637 As a result, we can see the regular ring buffer and the AUX ring buffer
639 ring buffer and the AUX ring buffer per CPU-wise, which is the same as
643 regular ring buffer and one AUX ring buffer for the whole session. For
661 | Ring buffer 0 |
666 | AUX Ring buffer 0 |
676 | Ring buffer 1 |
681 | AUX Ring buffer 1 |
691 | Ring buffer 2 |
696 | AUX Ring buffer 2 |
706 | Ring buffer 3 |
711 | AUX Ring buffer 3 |
717 Figure 8. AUX ring buffer for system wide mode
723 regular ring buffer, ``perf_aux_output_begin()`` and ``perf_aux_output_end()``
724 serve for the AUX ring buffer for processing the hardware trace data.
726 Once the hardware trace data is stored into the AUX ring buffer, the PMU
728 Similar to the regular ring buffer, the AUX ring buffer needs to apply
730 :ref:`memory_synchronization`. Since the AUX ring buffer is managed by the
738 - It fills an event ``PERF_RECORD_AUX`` into the regular ring buffer, this
740 chunk of hardware trace data has been stored into the AUX ring buffer;
743 ring buffer, the argument *size* indicates how many bytes have been
745 header pointer ``perf_buffer::aux_head`` to reflect the latest buffer usage.
754 buffer to the perf data file, it synthesizes a ``PERF_RECORD_AUXTRACE``
756 which portion of data in the AUX ring buffer is saved. Afterwards, the perf
764 Perf supports snapshot mode for AUX ring buffer, in this mode, users
778 - Before a snapshot is taken, the AUX ring buffer acts in free run mode.
784 tracing. The kernel driver then populates the AUX ring buffer with the
786 regular ring buffer;
789 reads out the hardware trace data from the AUX ring buffer and saves it
797 because the AUX ring buffer can overflow in free run mode, the tail
800 of whether the AUX ring buffer has been wrapped around or not, at the
801 end it fixes up the AUX buffer's head which are used to calculate the
815 | AUX Ring buffer 0 | <- aux_head
819 | AUX Ring buffer 1 | <- aux_head
823 | AUX Ring buffer 2 | <- aux_head
827 | AUX Ring buffer 3 | <- aux_head