Skip to content

PT trace only the executable segment of the main object.#1714

Merged
ltratt merged 1 commit intoykjit:masterfrom
vext01:pt-filtering
May 31, 2025
Merged

PT trace only the executable segment of the main object.#1714
ltratt merged 1 commit intoykjit:masterfrom
vext01:pt-filtering

Conversation

@vext01
Copy link
Copy Markdown
Contributor

@vext01 vext01 commented Apr 25, 2025

deltablue (benchmark that spends a lot of time mapping):

  • time spent mapping reduced in the order of ~10x
  • overall performance improved about 15%

This change means that we can no longer spot longjmp in code outside of
the traced range. Whereas before, we'd spot calls to longjmp when the PT
decoder was disassembling foreign code, now what we do is do some basic
"control flow integrity" checking in the trace builder, checking that
each mappable block is either: the entry block of a function, a return
block from a function, or a static successor of the last mappable block
we processed.

(Annoyingly this means we have to keep track of the previous block ID
(which may be unmappable) and the previous mappable block ID
separately -- although Lukas and I think we could probably do away with
unmappable blocks and thus also the former, but that's another story)

Although to detect longjmp this way we would only need to check this
property when we return from a function, it turns out to be simpler to
implement for every mappable block (return or not) and arguably it's a
really good sanity check that we should probably have had in place from
the start.

An added bonus is that this approach is tracer-agnostic, so the longjmp
tests work for software tracing too.

I had hoped to detect signal handlers this way too, but unfortunately I
can't see an universally unambiguous way to distinguish them from
regular calls. Since signal handlers weren't really the aim of this PR,
I won't let this hold us up. For now I've added an ignored test showing
the issue: currently signal handlers that have IR get inlined.

@ltratt ltratt added this pull request to the merge queue Apr 25, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Apr 25, 2025
@vext01 vext01 mentioned this pull request Apr 28, 2025
@vext01
Copy link
Copy Markdown
Contributor Author

vext01 commented May 30, 2025

Because this has been a long-lived branch, I've been doing many merge commits. Do you mind if I force push a freshly rebased changes to make it easier to review?

@ltratt
Copy link
Copy Markdown
Contributor

ltratt commented May 30, 2025

Please force push.

deltablue (benchmark that spends a lot of time mapping):
  - time spent mapping reduced in the order of ~10x
  - overall performance improved about 15%

This change means that we can no longer spot longjmp in code outside of
the traced range. Whereas before, we'd spot calls to longjmp when the PT
decoder was disassembling foreign code, now what we do is do some basic
"control flow integrity" checking in the trace builder, checking that
each mappable block is either: the entry block of a function, a return
block from a function, or a static successor of the last mappable block
we processed.

(Annoyingly this means we have to keep track of the previous block ID
(which may be unmappable) *and* the previous mappable block ID
separately -- although Lukas and I think we could probably do away with
unmappable blocks and thus also the former, but that's another story)

Although to detect longjmp this way we would only need to check this
property when we return from a function, it turns out to be simpler to
implement for every mappable block (return or not) and arguably it's a
really good sanity check that we should probably have had in place from
the start.

An added bonus is that this approach is tracer-agnostic, so the longjmp
tests work for software tracing too.

I had hoped to detect signal handlers this way too, but unfortunately I
can't see an universally unambiguous way to distinguish them from
regular calls. Since signal handlers weren't really the aim of this PR,
I won't let this hold us up. For now I've added an ignored test showing
the issue: currently signal handlers that have IR get inlined.
@vext01
Copy link
Copy Markdown
Contributor Author

vext01 commented May 30, 2025

Force pushed and updated the PR description.

Requires: ykjit/ykllvm#263

@vext01
Copy link
Copy Markdown
Contributor Author

vext01 commented May 30, 2025

Assigning @ptersilie too, as he may have opinions on the trace builder parts.

@ptersilie
Copy link
Copy Markdown
Contributor

trace_builder part looks ok.

@ltratt ltratt added this pull request to the merge queue May 31, 2025
Merged via the queue into ykjit:master with commit de5b862 May 31, 2025
2 checks passed
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.

3 participants