Skip to content

Commit 5a4e221

Browse files
Revert "[llvm-exegesis] Use LLVM Support to get thread ID"
This reverts commit 1c3b15e. This (and/or) a related patch was causing build failures on one of the buildbots. More information is available at https://lab.llvm.org/buildbot/#/builders/178/builds/7015.
1 parent 0a443f1 commit 5a4e221

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class SubProcessFunctionExecutorImpl
301301
if (AddMemDefError)
302302
return AddMemDefError;
303303

304-
long ParentTID = get_threadid();
304+
long ParentTID = SubprocessMemory::getCurrentTID();
305305
pid_t ParentOrChildPID = fork();
306306

307307
if (ParentOrChildPID == -1) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "Error.h"
1111
#include "llvm/Support/Error.h"
1212
#include "llvm/Support/FormatVariadic.h"
13-
#include "llvm/Support/Threading.h"
1413
#include <cerrno>
1514

1615
#ifdef __linux__
@@ -25,14 +24,21 @@ namespace exegesis {
2524

2625
#if defined(__linux__) && !defined(__ANDROID__)
2726

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+
2834
Error SubprocessMemory::initializeSubprocessMemory(pid_t ProcessID) {
2935
// Add the PID to the shared memory name so that if we're running multiple
3036
// processes at the same time, they won't interfere with each other.
3137
// This comes up particularly often when running the exegesis tests with
3238
// llvm-lit. Additionally add the TID so that downstream consumers
3339
// using multiple threads don't run into conflicts.
3440
std::string AuxiliaryMemoryName =
35-
formatv("/{0}auxmem{1}", get_threadid(), ProcessID);
41+
formatv("/{0}auxmem{1}", getCurrentTID(), ProcessID);
3642
int AuxiliaryMemoryFD = shm_open(AuxiliaryMemoryName.c_str(),
3743
O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
3844
if (AuxiliaryMemoryFD == -1)
@@ -53,7 +59,7 @@ Error SubprocessMemory::addMemoryDefinition(
5359
SharedMemoryNames.reserve(MemoryDefinitions.size());
5460
for (auto &[Name, MemVal] : MemoryDefinitions) {
5561
std::string SharedMemoryName =
56-
formatv("/{0}t{1}memdef{2}", ProcessPID, get_threadid(), MemVal.Index);
62+
formatv("/{0}t{1}memdef{2}", ProcessPID, getCurrentTID(), MemVal.Index);
5763
SharedMemoryNames.push_back(SharedMemoryName);
5864
int SharedMemoryFD =
5965
shm_open(SharedMemoryName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -87,7 +93,7 @@ Error SubprocessMemory::addMemoryDefinition(
8793

8894
Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
8995
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
90-
pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
96+
pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
9197
std::string AuxiliaryMemoryName =
9298
formatv("/{0}auxmem{1}", ParentTID, ParentPID);
9399
int AuxiliaryMemoryFileDescriptor =
@@ -139,7 +145,7 @@ Error SubprocessMemory::addMemoryDefinition(
139145

140146
Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
141147
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
142-
pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
148+
pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
143149
return make_error<Failure>(
144150
"setupAuxiliaryMemoryInSubprocess is only supported on Linux");
145151
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ 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+
3841
Error initializeSubprocessMemory(pid_t ProcessID);
3942

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

5962
~SubprocessMemory();
6063

0 commit comments

Comments
 (0)