Skip to content

Commit

Permalink
perf - reader.go: document possible garbage read from perf ring, add …
Browse files Browse the repository at this point in the history
…reproducer

A patch for this was submitted upstream:
https://lore.kernel.org/patchwork/patch/1244339.

Promises about the buffer's alignment were also removed because they were
inacurrate. The `perf_event_open` man page is incorrect, and there's
another bug in the kernel that causes these buffers to be unaligned.
  • Loading branch information
ti-mo committed May 29, 2020
1 parent 2fcd512 commit 3e03ece
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions perf/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ type Record struct {
CPU int

// The data submitted via bpf_perf_event_output.
// They are padded with 0 to have a 64-bit alignment.
// If you are using variable length samples you need to take
// this into account.
// Due to a kernel bug, this can contain between 0 and 7 bytes of trailing
// garbage from the ring depending on the input sample's length.
RawSample []byte

// The number of samples which could not be output, since
Expand Down Expand Up @@ -317,9 +316,11 @@ func (pr *Reader) Close() error {
// Read the next record from the perf ring buffer.
//
// The function blocks until there are at least Watermark bytes in one
// of the per CPU buffers.
// of the per CPU buffers. Records from buffers below the Watermark
// are not returned.
//
// Records from buffers below the Watermark are not returned.
// Records can contain between 0 and 7 bytes of trailing garbage from the ring
// depending on the input sample's length.
//
// Calling Close interrupts the function.
func (pr *Reader) Read() (Record, error) {
Expand Down

0 comments on commit 3e03ece

Please sign in to comment.