Skip to content

Commit aefad27

Browse files
committed
Revert "[llvm-exegesis] Add thread IDs to subprocess memory names (#84451)"
This reverts commit 6bbe8a2. This breaks building LLVM on macOS, failing with llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp:146:33: error: out-of-line definition of 'setupAuxiliaryMemoryInSubprocess' does not match any declaration in 'llvm::exegesis::SubprocessMemory' Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
1 parent 6bbe8a2 commit aefad27

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ class SubProcessFunctionExecutorImpl
301301
if (AddMemDefError)
302302
return AddMemDefError;
303303

304-
long ParentTID = SubprocessMemory::getCurrentTID();
305304
pid_t ParentOrChildPID = fork();
306305

307306
if (ParentOrChildPID == -1) {
@@ -315,7 +314,7 @@ class SubProcessFunctionExecutorImpl
315314
// Unregister handlers, signal handling is now handled through ptrace in
316315
// the host process.
317316
sys::unregisterHandlers();
318-
prepareAndRunBenchmark(PipeFiles[0], Key, ParentTID);
317+
prepareAndRunBenchmark(PipeFiles[0], Key);
319318
// The child process terminates in the above function, so we should never
320319
// get to this point.
321320
llvm_unreachable("Child process didn't exit when expected.");
@@ -416,8 +415,8 @@ class SubProcessFunctionExecutorImpl
416415
setrlimit(RLIMIT_CORE, &rlim);
417416
}
418417

419-
[[noreturn]] void prepareAndRunBenchmark(int Pipe, const BenchmarkKey &Key,
420-
long ParentTID) const {
418+
[[noreturn]] void prepareAndRunBenchmark(int Pipe,
419+
const BenchmarkKey &Key) const {
421420
// Disable core dumps in the child process as otherwise everytime we
422421
// encounter an execution failure like a segmentation fault, we will create
423422
// a core dump. We report the information directly rather than require the
@@ -474,7 +473,7 @@ class SubProcessFunctionExecutorImpl
474473

475474
Expected<int> AuxMemFDOrError =
476475
SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
477-
Key.MemoryValues, ParentPID, ParentTID, CounterFileDescriptor);
476+
Key.MemoryValues, ParentPID, CounterFileDescriptor);
478477
if (!AuxMemFDOrError)
479478
exit(ChildProcessExitCodeE::AuxiliaryMemorySetupFailed);
480479

llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
#include "SubprocessMemory.h"
1010
#include "Error.h"
1111
#include "llvm/Support/Error.h"
12-
#include "llvm/Support/FormatVariadic.h"
1312
#include <cerrno>
1413

1514
#ifdef __linux__
1615
#include <fcntl.h>
1716
#include <sys/mman.h>
18-
#include <sys/syscall.h>
1917
#include <unistd.h>
2018
#endif
2119

@@ -24,21 +22,12 @@ namespace exegesis {
2422

2523
#if defined(__linux__) && !defined(__ANDROID__)
2624

27-
long SubprocessMemory::getCurrentTID() {
28-
// We're using the raw syscall here rather than the gettid() function provided
29-
// by most libcs for compatibility as gettid() was only added to glibc in
30-
// version 2.30.
31-
return syscall(SYS_gettid);
32-
}
33-
3425
Error SubprocessMemory::initializeSubprocessMemory(pid_t ProcessID) {
3526
// Add the PID to the shared memory name so that if we're running multiple
3627
// processes at the same time, they won't interfere with each other.
3728
// This comes up particularly often when running the exegesis tests with
38-
// llvm-lit. Additionally add the TID so that downstream consumers
39-
// using multiple threads don't run into conflicts.
40-
std::string AuxiliaryMemoryName =
41-
formatv("/{0}auxmem{1}", getCurrentTID(), ProcessID);
29+
// llvm-lit
30+
std::string AuxiliaryMemoryName = "/auxmem" + std::to_string(ProcessID);
4231
int AuxiliaryMemoryFD = shm_open(AuxiliaryMemoryName.c_str(),
4332
O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
4433
if (AuxiliaryMemoryFD == -1)
@@ -58,8 +47,8 @@ Error SubprocessMemory::addMemoryDefinition(
5847
pid_t ProcessPID) {
5948
SharedMemoryNames.reserve(MemoryDefinitions.size());
6049
for (auto &[Name, MemVal] : MemoryDefinitions) {
61-
std::string SharedMemoryName =
62-
formatv("/{0}t{1}memdef{2}", ProcessPID, getCurrentTID(), MemVal.Index);
50+
std::string SharedMemoryName = "/" + std::to_string(ProcessPID) + "memdef" +
51+
std::to_string(MemVal.Index);
6352
SharedMemoryNames.push_back(SharedMemoryName);
6453
int SharedMemoryFD =
6554
shm_open(SharedMemoryName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -93,9 +82,8 @@ Error SubprocessMemory::addMemoryDefinition(
9382

9483
Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
9584
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
96-
pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
97-
std::string AuxiliaryMemoryName =
98-
formatv("/{0}auxmem{1}", ParentTID, ParentPID);
85+
pid_t ParentPID, int CounterFileDescriptor) {
86+
std::string AuxiliaryMemoryName = "/auxmem" + std::to_string(ParentPID);
9987
int AuxiliaryMemoryFileDescriptor =
10088
shm_open(AuxiliaryMemoryName.c_str(), O_RDWR, S_IRUSR | S_IWUSR);
10189
if (AuxiliaryMemoryFileDescriptor == -1)
@@ -109,8 +97,8 @@ Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
10997
return make_error<Failure>("Mapping auxiliary memory failed");
11098
AuxiliaryMemoryMapping[0] = CounterFileDescriptor;
11199
for (auto &[Name, MemVal] : MemoryDefinitions) {
112-
std::string MemoryValueName =
113-
formatv("/{0}t{1}memdef{2}", ParentPID, ParentTID, MemVal.Index);
100+
std::string MemoryValueName = "/" + std::to_string(ParentPID) + "memdef" +
101+
std::to_string(MemVal.Index);
114102
AuxiliaryMemoryMapping[AuxiliaryMemoryOffset + MemVal.Index] =
115103
shm_open(MemoryValueName.c_str(), O_RDWR, S_IRUSR | S_IWUSR);
116104
if (AuxiliaryMemoryMapping[AuxiliaryMemoryOffset + MemVal.Index] == -1)

llvm/tools/llvm-exegesis/lib/SubprocessMemory.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class SubprocessMemory {
3535
static constexpr const size_t AuxiliaryMemoryOffset = 1;
3636
static constexpr const size_t AuxiliaryMemorySize = 4096;
3737

38-
// Gets the thread ID for the calling thread.
39-
static long getCurrentTID();
40-
4138
Error initializeSubprocessMemory(pid_t ProcessID);
4239

4340
// The following function sets up memory definitions. It creates shared
@@ -57,7 +54,7 @@ class SubprocessMemory {
5754
// section.
5855
static Expected<int> setupAuxiliaryMemoryInSubprocess(
5956
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
60-
pid_t ParentPID, long ParentTID, int CounterFileDescriptor);
57+
pid_t ParentPID, int CounterFileDescriptor);
6158

6259
~SubprocessMemory();
6360

llvm/unittests/tools/llvm-exegesis/X86/SubprocessMemoryTest.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <endian.h>
1818
#include <fcntl.h>
1919
#include <sys/mman.h>
20-
#include <sys/syscall.h>
2120
#include <unistd.h>
2221
#endif // __linux__
2322

@@ -50,9 +49,7 @@ class SubprocessMemoryTest : public X86TestBase {
5049

5150
std::string getSharedMemoryName(const unsigned TestNumber,
5251
const unsigned DefinitionNumber) {
53-
long CurrentTID = syscall(SYS_gettid);
54-
return "/" + std::to_string(getSharedMemoryNumber(TestNumber)) + "t" +
55-
std::to_string(CurrentTID) + "memdef" +
52+
return "/" + std::to_string(getSharedMemoryNumber(TestNumber)) + "memdef" +
5653
std::to_string(DefinitionNumber);
5754
}
5855

0 commit comments

Comments
 (0)