Skip to content

perf: why does the reader return more data than was submitted from BPF? #970

Answered by ti-mo
llhhbc asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @llhhbc, this is indeed a great question. :) Depending on the size of the input passed to perf_event_output in your BPF program, there can be between 0 and 7 extra bytes at the end of perf event records. The kernel aligns the event header (4 bytes) plus the input to 64 bits, but the []byte returned from Reader.Read() won't include the header. This means you can expect slices of length 4, 12, 20, 28 etc. bytes depending on the length of your input.

Note that the padding bytes are not cleared, so once the ring wraps the page boundary, you'll start seeing garbage show up where there were zeroes before. This behaviour is documented on Record.RawSample. I've sent a patch upstream to zero t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@llhhbc
Comment options

Answer selected by ti-mo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants