[PATCH] D115416: [lld-macho] Prevent writing map files on the critical path
Vincent Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 13 18:20:14 PST 2021
thevinster updated this revision to Diff 394103.
thevinster added a comment.
Show two different ways of using threadPool
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115416/new/
https://reviews.llvm.org/D115416
Files:
lld/MachO/Writer.cpp
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -29,6 +29,7 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/xxhash.h"
@@ -64,6 +65,7 @@
template <class LP> void run();
+ ThreadPool writerThreadPool;
std::unique_ptr<FileOutputBuffer> &buffer;
uint64_t addr = 0;
uint64_t fileOff = 0;
@@ -1035,10 +1037,17 @@
dataInCodeSection,
functionStartsSection,
};
- parallelForEach(linkEditSections, [](LinkEditSection *osec) {
- if (osec)
- osec->finalizeContents();
- });
+ SmallVector<std::shared_future<void>> threadFutures;
+ for (LinkEditSection *osec : linkEditSections) {
+ threadFutures.emplace_back(writerThreadPool.async(
+ [](LinkEditSection *osec) {
+ if (osec)
+ osec->finalizeContents();
+ },
+ osec));
+ }
+ for (std::shared_future<void> &future : threadFutures)
+ future.wait();
// Now that __LINKEDIT is filled out, do a proper calculation of its
// addresses and offsets.
@@ -1091,14 +1100,19 @@
// values.
void Writer::writeUuid() {
TimeTraceScope timeScope("Computing UUID");
+ ThreadPool writeUuidThreadPool;
+
ArrayRef<uint8_t> data{buffer->getBufferStart(), buffer->getBufferEnd()};
unsigned chunkCount = parallel::strategy.compute_thread_count() * 10;
// Round-up integer division
size_t chunkSize = (data.size() + chunkCount - 1) / chunkCount;
std::vector<ArrayRef<uint8_t>> chunks = split(data, chunkSize);
std::vector<uint64_t> hashes(chunks.size());
- parallelForEachN(0, chunks.size(),
- [&](size_t i) { hashes[i] = xxHash64(chunks[i]); });
+ for (size_t i = 0; i < chunks.size(); ++i)
+ writeUuidThreadPool.async(
+ [&](size_t i) { hashes[i] = xxHash64(chunks[i]); }, i);
+ writeUuidThreadPool.wait();
+
uint64_t digest = xxHash64({reinterpret_cast<uint8_t *>(hashes.data()),
hashes.size() * sizeof(uint64_t)});
uuidCommand->writeUuid(digest);
@@ -1147,8 +1161,8 @@
sortSegmentsAndSections();
createLoadCommands<LP>();
finalizeAddresses();
+ writerThreadPool.async(writeMapFile);
finalizeLinkEditSegment();
- writeMapFile();
writeOutputFile();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115416.394103.patch
Type: text/x-patch
Size: 2446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211214/47214347/attachment.bin>
More information about the llvm-commits
mailing list