[llvm] 5a4e221 - Revert "[llvm-exegesis] Use LLVM Support to get thread ID"
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 00:50:01 PDT 2024
Author: Aiden Grossman
Date: 2024-03-13T00:48:46-07:00
New Revision: 5a4e2210bd60fec854822d3fb2a2aaa1e20ad2e1
URL: https://github.com/llvm/llvm-project/commit/5a4e2210bd60fec854822d3fb2a2aaa1e20ad2e1
DIFF: https://github.com/llvm/llvm-project/commit/5a4e2210bd60fec854822d3fb2a2aaa1e20ad2e1.diff
LOG: Revert "[llvm-exegesis] Use LLVM Support to get thread ID"
This reverts commit 1c3b15e9f5bc671e40bcf5d3475f5425466754ce.
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.
Added:
Modified:
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
llvm/tools/llvm-exegesis/lib/SubprocessMemory.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 17ce0355ef4fd0..4e97d188d17259 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -301,7 +301,7 @@ class SubProcessFunctionExecutorImpl
if (AddMemDefError)
return AddMemDefError;
- long ParentTID = get_threadid();
+ long ParentTID = SubprocessMemory::getCurrentTID();
pid_t ParentOrChildPID = fork();
if (ParentOrChildPID == -1) {
diff --git a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
index 28b341c461804f..1fd81bd407becb 100644
--- a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.cpp
@@ -10,7 +10,6 @@
#include "Error.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/Threading.h"
#include <cerrno>
#ifdef __linux__
@@ -25,6 +24,13 @@ namespace exegesis {
#if defined(__linux__) && !defined(__ANDROID__)
+long SubprocessMemory::getCurrentTID() {
+ // We're using the raw syscall here rather than the gettid() function provided
+ // by most libcs for compatibility as gettid() was only added to glibc in
+ // version 2.30.
+ return syscall(SYS_gettid);
+}
+
Error SubprocessMemory::initializeSubprocessMemory(pid_t ProcessID) {
// Add the PID to the shared memory name so that if we're running multiple
// processes at the same time, they won't interfere with each other.
@@ -32,7 +38,7 @@ Error SubprocessMemory::initializeSubprocessMemory(pid_t ProcessID) {
// llvm-lit. Additionally add the TID so that downstream consumers
// using multiple threads don't run into conflicts.
std::string AuxiliaryMemoryName =
- formatv("/{0}auxmem{1}", get_threadid(), ProcessID);
+ formatv("/{0}auxmem{1}", getCurrentTID(), ProcessID);
int AuxiliaryMemoryFD = shm_open(AuxiliaryMemoryName.c_str(),
O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (AuxiliaryMemoryFD == -1)
@@ -53,7 +59,7 @@ Error SubprocessMemory::addMemoryDefinition(
SharedMemoryNames.reserve(MemoryDefinitions.size());
for (auto &[Name, MemVal] : MemoryDefinitions) {
std::string SharedMemoryName =
- formatv("/{0}t{1}memdef{2}", ProcessPID, get_threadid(), MemVal.Index);
+ formatv("/{0}t{1}memdef{2}", ProcessPID, getCurrentTID(), MemVal.Index);
SharedMemoryNames.push_back(SharedMemoryName);
int SharedMemoryFD =
shm_open(SharedMemoryName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -87,7 +93,7 @@ Error SubprocessMemory::addMemoryDefinition(
Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
std::string AuxiliaryMemoryName =
formatv("/{0}auxmem{1}", ParentTID, ParentPID);
int AuxiliaryMemoryFileDescriptor =
@@ -139,7 +145,7 @@ Error SubprocessMemory::addMemoryDefinition(
Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
return make_error<Failure>(
"setupAuxiliaryMemoryInSubprocess is only supported on Linux");
}
diff --git a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.h b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.h
index 807046e38ce6d2..572d1085d9cffa 100644
--- a/llvm/tools/llvm-exegesis/lib/SubprocessMemory.h
+++ b/llvm/tools/llvm-exegesis/lib/SubprocessMemory.h
@@ -35,6 +35,9 @@ class SubprocessMemory {
static constexpr const size_t AuxiliaryMemoryOffset = 1;
static constexpr const size_t AuxiliaryMemorySize = 4096;
+ // Gets the thread ID for the calling thread.
+ static long getCurrentTID();
+
Error initializeSubprocessMemory(pid_t ProcessID);
// The following function sets up memory definitions. It creates shared
@@ -54,7 +57,7 @@ class SubprocessMemory {
// section.
static Expected<int> setupAuxiliaryMemoryInSubprocess(
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor);
+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor);
~SubprocessMemory();
More information about the llvm-commits
mailing list