Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: Implement perf live event reordering. #62

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

ishitatsuyuki
Copy link
Contributor

The perf ring buffers are divided by CPUs and processes and naively concatenating read events can yield wrong ordering. In particular, this is problematic for fork and exec events since mmaped modules will go into the wrong process and cause unwind to fail.

Introduce a streaming event sorter to tackle this. Note that timestamps should not be considered 100% reliable and cases where timestamps go backwards should be still gracefully handled. In particular for perf, a NMI could interrupt event writes, thus even timestamp inversion within the same ring buffer can happen.

This is based on top of #61 for convenience, but still split into commits. I can rebase on top of main if needed.

Link: #26

Copy link
Owner

@mstange mstange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you so much!!

Since it's not used by the perf file importer at the moment, I would move it to samply/src/linux rather than linux_shared - this will fix the macOS build warnings. Were you planning to use it for the perf file importer in the future?

This transposes the perf event loop to an internal iteration-like
manner. The `consume_events` function calls the callback as long as
there are events to consume, then returns, at which the caller should
call into epoll to wait for new events.

This simplifies logic especially with the forthcoming live event
reordering.
The perf ring buffers are divided by CPUs and processes and naively
concatenating read events can yield wrong ordering. In particular, this
is problematic for fork and exec events since mmaped modules will go
into the wrong process and cause unwind to fail.

Introduce a streaming event sorter to tackle this. Note that timestamps
should not be considered 100% reliable and cases where timestamps go
backwards should be still gracefully handled. In particular for perf, a
NMI could interrupt event writes, thus even timestamp inversion within
the same ring buffer can happen.
@ishitatsuyuki
Copy link
Contributor Author

Were you planning to use it for the perf file importer in the future?

It makes sense, but I have no problem with the current file importer either. I have moved it to the linux module.

@mstange mstange merged commit c847f95 into mstange:main Aug 25, 2023
@ishitatsuyuki ishitatsuyuki deleted the reordering branch August 25, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants