Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Jul 5, 2024

previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook from one thread would be interleaved with the backtrace from another. now, we hold the lock for the full duration of the hook, and the output is ordered.


i noticed some odd things while working on this you may or may not already be aware of.

  • libbacktrace is included as a submodule instead of a normal rustc crate, and as a result uses cfg(backtrace_in_std) instead of a more normal cfg(feature = "rustc-dep-of-std"). probably this is left over from before rust used a cargo-based build system?
  • the default panic handler uses trace_unsynchronized, etc, in sys::backtrace::print. as a result, the lock only applies to concurrent panic handlers, not concurrent threads. in other words, if another, non-panicking, thread tried to print a backtrace at the same time as the panic handler, we may have UB, especially on windows.
    • we have the option of changing backtrace to enable locking when backtrace_in_std is set so we can reuse their lock instead of trying to add our own.

@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 5, 2024
@workingjubilee
Copy link
Member

libbacktrace is included as a submodule instead of a normal rustc crate, and as a result uses cfg(backtrace_in_std) instead of a more normal cfg(feature = "rustc-dep-of-std"). probably this is left over from before rust used a cargo-based build system?

I suspect this is more due to us having needed to internalize, as much as possible, the horrible details of backtraces.

@workingjubilee
Copy link
Member

I also suspect that in practice, backtraces on Windows are actually much more tame now due to us using RtlVirtualUnwind. Am I correct in that, @ChrisDenton?

@ChrisDenton
Copy link
Member

Yes and no. Symbolization is still a problem area. The APIs we're using are designed to be run from an external "debugger" process and not in-process.

@jyn514
Copy link
Member Author

jyn514 commented Jul 5, 2024

i did find a mutex in windows that looks like it takes care of the multi-threading issues for us: https://github.com/rust-lang/backtrace-rs/blob/72265bea210891ae47bbe6d4f17b493ef0606619/src/dbghelp.rs#L283-L376

@ChrisDenton
Copy link
Member

Yeah, we need a special process-wide mutex so that it works if multiple Rust DLLs are in the same process (doesn't help if another language or library uses these functions though).

@workingjubilee
Copy link
Member

Yeah, we need a special process-wide mutex so that it works if multiple Rust DLLs are in the same process (doesn't help if another language or library uses these functions though).

that sounds fine, tbh. "randomly-included C code" can't coordinate perfectly on this, so we can't either, and our responsibility is discharged by doing the best we can.

@workingjubilee
Copy link
Member

 @bors r+

@bors
Copy link
Collaborator

bors commented Jul 8, 2024

📌 Commit 875b730 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2024
@matthiaskrgr
Copy link
Member

@bors r-
#127519 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 9, 2024
@jyn514
Copy link
Member Author

jyn514 commented Jul 9, 2024

lol apparently some test runners set RUST_BACKTRACE=1 on globally? no idea why
anyway i should be able to just unset it for this test

@jyn514 jyn514 force-pushed the multi-thread-panic-hook branch from 875b730 to ae92d6a Compare July 9, 2024 17:55
@workingjubilee
Copy link
Member

Ah, I really should have remembered and asked for //@ needs-threads

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 12, 2024
@jyn514
Copy link
Member Author

jyn514 commented Jul 12, 2024

could you mark this as rollup=iffy?

previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook would be interleaved with the backtrace. now, we hold the lock for the full duration of the hook, and the output is ordered.
@jyn514 jyn514 force-pushed the multi-thread-panic-hook branch from 3a1dd85 to 1c8f9bb Compare July 12, 2024 15:53
@workingjubilee
Copy link
Member

yeah.

@bors rollup=iffy r+

@bors
Copy link
Collaborator

bors commented Jul 12, 2024

📌 Commit 1c8f9bb has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 12, 2024
@bors
Copy link
Collaborator

bors commented Jul 13, 2024

⌛ Testing commit 1c8f9bb with merge 0065384...

@bors
Copy link
Collaborator

bors commented Jul 13, 2024

☀️ Test successful - checks-actions
Approved by: workingjubilee
Pushing 0065384 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 13, 2024
@bors bors merged commit 0065384 into rust-lang:master Jul 13, 2024
@rustbot rustbot added this to the 1.81.0 milestone Jul 13, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0065384): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary -0.0%, secondary -0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 14
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 1

Bootstrap: 706.568s -> 706.526s (-0.01%)
Artifact size: 328.69 MiB -> 328.84 MiB (0.05%)

@jyn514 jyn514 deleted the multi-thread-panic-hook branch July 20, 2024 02:24
@jyn514
Copy link
Member Author

jyn514 commented Jul 20, 2024

congrats to @rust-lang/wg-compiler-performance, this is a really impressively low amount of noise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants