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

[LLVM][DWARF] Create thread safe context for DWP DWARFContext #68262

Merged
merged 6 commits into from
Oct 10, 2023

Conversation

ayermolo
Copy link
Contributor

@ayermolo ayermolo commented Oct 4, 2023

Right now DWARFContext that is created is the same when input is DWO or DWP file.
Changed so that for DWP it creates a thread safe context. This allows for a multi threaded safe access to {cu,tu}-index

@llvmbot
Copy link

llvmbot commented Oct 4, 2023

@llvm/pr-subscribers-debuginfo

Changes

Right now DWARFContext is created is the same when input is DWO or DWP file.
Changed so that for DWP it creates a thread safe context.


Full diff: https://github.com/llvm/llvm-project/pull/68262.diff

1 Files Affected:

  • (modified) llvm/lib/DebugInfo/DWARF/DWARFContext.cpp (+5-2)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 1e1ab814673f423..6a91be97255b8bb 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -575,8 +575,11 @@ class ThreadUnsafeDWARFContextState : public DWARFContext::DWARFContextState {
 
     auto S = std::make_shared<DWOFile>();
     S->File = std::move(Obj.get());
-    S->Context = DWARFContext::create(*S->File.getBinary(),
-                                      DWARFContext::ProcessDebugRelocations::Ignore);
+    StringRef FileName = S->File.getBinary()->getFileName();
+    S->Context = DWARFContext::create(
+        *S->File.getBinary(), DWARFContext::ProcessDebugRelocations::Ignore,
+        nullptr, "", nullptr, nullptr,
+        FileName.find(".dwp") != StringRef::npos);
     *Entry = S;
     auto *Ctxt = S->Context.get();
     return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);

Right now DWARFContext is created is the same when input is DWO or DWP file.
Changed so that for DWP it creates a thread safe context.
@ayermolo
Copy link
Contributor Author

ayermolo commented Oct 9, 2023

@dwblaikie @clayborg ping :D

@dwblaikie
Copy link
Collaborator

Not sure I follow - wouldn't it be suitable for a ThreadUnsafeDWARFContext to create a ThreadUnsafeDWARFContext for the DWP? And only a ThreadSafeDWARFContext would create a ThreadSafeDWARFContext for the DWP?

@clayborg
Copy link
Collaborator

clayborg commented Oct 9, 2023

Not sure I follow - wouldn't it be suitable for a ThreadUnsafeDWARFContext to create a ThreadUnsafeDWARFContext for the DWP? And only a ThreadSafeDWARFContext would create a ThreadSafeDWARFContext for the DWP?

No one is creating a thread safe context right now except llvm-gsymutil. So we could enable thread safe everywhere, but people seemed to think there would be some performance hit if that was done.

@clayborg
Copy link
Collaborator

clayborg commented Oct 9, 2023

Not sure I follow - wouldn't it be suitable for a ThreadUnsafeDWARFContext to create a ThreadUnsafeDWARFContext for the DWP? And only a ThreadSafeDWARFContext would create a ThreadSafeDWARFContext for the DWP?

No one is creating a thread safe context right now except llvm-gsymutil. So we could enable thread safe everywhere, but people seemed to think there would be some performance hit if that was done.

If this issue here was we had a thread safe DWARContext for the main DWARF, and this wasn't being correctly propagated into the .dwp DWARFContext, then this should be fixed by detecting the thread safe setting from the DWARContext and using that setting for any child DWARFContext (.dwp and any .dwo files that are not in a .dwp file) objects.

@dwblaikie
Copy link
Collaborator

Not sure I follow - wouldn't it be suitable for a ThreadUnsafeDWARFContext to create a ThreadUnsafeDWARFContext for the DWP? And only a ThreadSafeDWARFContext would create a ThreadSafeDWARFContext for the DWP?

No one is creating a thread safe context right now except llvm-gsymutil. So we could enable thread safe everywhere, but people seemed to think there would be some performance hit if that was done.

If this issue here was we had a thread safe DWARContext for the main DWARF, and this wasn't being correctly propagated into the .dwp DWARFContext, then this should be fixed by detecting the thread safe setting from the DWARContext and using that setting for any child DWARFContext (.dwp and any .dwo files that are not in a .dwp file) objects.

But this code change is being made in the ThreadUnsafeDWARFContextState - the thread unsafe class is making a thread safe DWP context. That doesn't seem right? Shouldn't only a ThreadSafeDWARFContextState create a thread safe context for the DWP?

@clayborg
Copy link
Collaborator

clayborg commented Oct 9, 2023

So sounds like we need to change this patch to propagate the "ThreadSafe" from one context to any child DWARFContext things (like for owned .dwp and .dwo contexts. I would recommend adding a new virtual function to DWARFContext:

virtual bool IsThreadSafe() = 0;

Then have ThreadUnsafeDWARFContextState override this and return false, and ThreadSafeState override it return true. Then it will be easy to propagate the setting using the current "DWARFContext::State" iivar from a DWARFContext to create another.

@ayermolo
Copy link
Contributor Author

ayermolo commented Oct 9, 2023

OK, will make the change so that DWO/DWP DWARFContext is controlled by main binary DWARFContext thread safetiness.

Copy link
Collaborator

@dwblaikie dwblaikie left a comment

Choose a reason for hiding this comment

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

Sounds OK

@ayermolo ayermolo merged commit 2a9f02b into llvm:main Oct 10, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants