Skip to content

Commit 5e3d48a

Browse files
Revert "[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)"
This reverts commit 9886788. This was breaking builds on ppc64 and AIX. Pulling so I have time to investigate.
1 parent 02a1d31 commit 5e3d48a

File tree

5 files changed

+15
-76
lines changed

5 files changed

+15
-76
lines changed

llvm/test/tools/llvm-exegesis/X86/latency/cpu-pinning-execution-mode.s

Lines changed: 0 additions & 5 deletions
This file was deleted.

llvm/test/tools/llvm-exegesis/X86/latency/cpu-pinning.s

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
9898
public:
9999
static Expected<std::unique_ptr<InProcessFunctionExecutorImpl>>
100100
create(const LLVMState &State, object::OwningBinary<object::ObjectFile> Obj,
101-
BenchmarkRunner::ScratchSpace *Scratch,
102-
std::optional<int> BenchmarkProcessCPU) {
101+
BenchmarkRunner::ScratchSpace *Scratch) {
103102
Expected<ExecutableFunction> EF =
104103
ExecutableFunction::create(State.createTargetMachine(), std::move(Obj));
105104

@@ -191,31 +190,27 @@ class SubProcessFunctionExecutorImpl
191190
public:
192191
static Expected<std::unique_ptr<SubProcessFunctionExecutorImpl>>
193192
create(const LLVMState &State, object::OwningBinary<object::ObjectFile> Obj,
194-
const BenchmarkKey &Key, std::optional<int> BenchmarkProcessCPU) {
193+
const BenchmarkKey &Key) {
195194
Expected<ExecutableFunction> EF =
196195
ExecutableFunction::create(State.createTargetMachine(), std::move(Obj));
197196
if (!EF)
198197
return EF.takeError();
199198

200199
return std::unique_ptr<SubProcessFunctionExecutorImpl>(
201-
new SubProcessFunctionExecutorImpl(State, std::move(*EF), Key,
202-
BenchmarkProcessCPU));
200+
new SubProcessFunctionExecutorImpl(State, std::move(*EF), Key));
203201
}
204202

205203
private:
206204
SubProcessFunctionExecutorImpl(const LLVMState &State,
207205
ExecutableFunction Function,
208-
const BenchmarkKey &Key,
209-
std::optional<int> BenchmarkCPU)
210-
: State(State), Function(std::move(Function)), Key(Key),
211-
BenchmarkProcessCPU(BenchmarkCPU) {}
206+
const BenchmarkKey &Key)
207+
: State(State), Function(std::move(Function)), Key(Key) {}
212208

213209
enum ChildProcessExitCodeE {
214210
CounterFDReadFailed = 1,
215211
RSeqDisableFailed,
216212
FunctionDataMappingFailed,
217-
AuxiliaryMemorySetupFailed,
218-
SetCPUAffinityFailed
213+
AuxiliaryMemorySetupFailed
219214
};
220215

221216
StringRef childProcessExitCodeToString(int ExitCode) const {
@@ -228,8 +223,6 @@ class SubProcessFunctionExecutorImpl
228223
return "Failed to map memory for assembled snippet";
229224
case ChildProcessExitCodeE::AuxiliaryMemorySetupFailed:
230225
return "Failed to setup auxiliary memory";
231-
case ChildProcessExitCodeE::SetCPUAffinityFailed:
232-
return "Failed to set CPU affinity of the benchmarking process";
233226
default:
234227
return "Child process returned with unknown exit code";
235228
}
@@ -391,29 +384,6 @@ class SubProcessFunctionExecutorImpl
391384
return make_error<SnippetSignal>(ChildSignalInfo.si_signo);
392385
}
393386

394-
static void setCPUAffinityIfRequested(int CPUToUse) {
395-
// Set the CPU affinity for the child process, so that we ensure that if
396-
// the user specified a CPU the process should run on, the benchmarking
397-
// process is running on that CPU.
398-
cpu_set_t CPUMask;
399-
CPU_ZERO(&CPUMask);
400-
CPU_SET(CPUToUse, &CPUMask);
401-
// TODO(boomanaiden154): Rewrite this to use LLVM primitives once they
402-
// are available.
403-
int SetAffinityReturn = sched_setaffinity(0, sizeof(CPUMask), &CPUMask);
404-
if (SetAffinityReturn == -1) {
405-
exit(ChildProcessExitCodeE::SetCPUAffinityFailed);
406-
}
407-
408-
// Check (if assertions are enabled) that we are actually running on the
409-
// CPU that was specified by the user.
410-
unsigned int CurrentCPU;
411-
assert(getcpu(&CurrentCPU, nullptr) == 0 &&
412-
"Expected getcpu call to succeed.");
413-
assert(static_cast<int>(CurrentCPU) == CPUToUse &&
414-
"Expected current CPU to equal the CPU requested by the user");
415-
}
416-
417387
Error createSubProcessAndRunBenchmark(
418388
StringRef CounterName, SmallVectorImpl<int64_t> &CounterValues,
419389
ArrayRef<const char *> ValidationCounters,
@@ -446,10 +416,6 @@ class SubProcessFunctionExecutorImpl
446416
}
447417

448418
if (ParentOrChildPID == 0) {
449-
if (BenchmarkProcessCPU.has_value()) {
450-
setCPUAffinityIfRequested(*BenchmarkProcessCPU);
451-
}
452-
453419
// We are in the child process, close the write end of the pipe.
454420
close(PipeFiles[1]);
455421
// Unregister handlers, signal handling is now handled through ptrace in
@@ -572,7 +538,6 @@ class SubProcessFunctionExecutorImpl
572538
const LLVMState &State;
573539
const ExecutableFunction Function;
574540
const BenchmarkKey &Key;
575-
const std::optional<int> BenchmarkProcessCPU;
576541
};
577542
#endif // __linux__
578543
} // namespace
@@ -650,15 +615,11 @@ BenchmarkRunner::getRunnableConfiguration(
650615
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
651616
BenchmarkRunner::createFunctionExecutor(
652617
object::OwningBinary<object::ObjectFile> ObjectFile,
653-
const BenchmarkKey &Key, std::optional<int> BenchmarkProcessCPU) const {
618+
const BenchmarkKey &Key) const {
654619
switch (ExecutionMode) {
655620
case ExecutionModeE::InProcess: {
656-
if (BenchmarkProcessCPU.has_value())
657-
return make_error<Failure>("The inprocess execution mode does not "
658-
"support benchmark core pinning.");
659-
660621
auto InProcessExecutorOrErr = InProcessFunctionExecutorImpl::create(
661-
State, std::move(ObjectFile), Scratch.get(), BenchmarkProcessCPU);
622+
State, std::move(ObjectFile), Scratch.get());
662623
if (!InProcessExecutorOrErr)
663624
return InProcessExecutorOrErr.takeError();
664625

@@ -667,7 +628,7 @@ BenchmarkRunner::createFunctionExecutor(
667628
case ExecutionModeE::SubProcess: {
668629
#ifdef __linux__
669630
auto SubProcessExecutorOrErr = SubProcessFunctionExecutorImpl::create(
670-
State, std::move(ObjectFile), Key, BenchmarkProcessCPU);
631+
State, std::move(ObjectFile), Key);
671632
if (!SubProcessExecutorOrErr)
672633
return SubProcessExecutorOrErr.takeError();
673634

@@ -682,8 +643,8 @@ BenchmarkRunner::createFunctionExecutor(
682643
}
683644

684645
std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
685-
RunnableConfiguration &&RC, const std::optional<StringRef> &DumpFile,
686-
std::optional<int> BenchmarkProcessCPU) const {
646+
RunnableConfiguration &&RC,
647+
const std::optional<StringRef> &DumpFile) const {
687648
Benchmark &BenchmarkResult = RC.BenchmarkResult;
688649
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile;
689650

@@ -704,8 +665,7 @@ std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
704665
}
705666

706667
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>> Executor =
707-
createFunctionExecutor(std::move(ObjectFile), RC.BenchmarkResult.Key,
708-
BenchmarkProcessCPU);
668+
createFunctionExecutor(std::move(ObjectFile), RC.BenchmarkResult.Key);
709669
if (!Executor)
710670
return {Executor.takeError(), std::move(BenchmarkResult)};
711671
auto NewMeasurements = runMeasurements(**Executor);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class BenchmarkRunner {
6868

6969
std::pair<Error, Benchmark>
7070
runConfiguration(RunnableConfiguration &&RC,
71-
const std::optional<StringRef> &DumpFile,
72-
std::optional<int> BenchmarkProcessCPU) const;
71+
const std::optional<StringRef> &DumpFile) const;
7372

7473
// Scratch space to run instructions that touch memory.
7574
struct ScratchSpace {
@@ -136,8 +135,7 @@ class BenchmarkRunner {
136135

137136
Expected<std::unique_ptr<FunctionExecutor>>
138137
createFunctionExecutor(object::OwningBinary<object::ObjectFile> Obj,
139-
const BenchmarkKey &Key,
140-
std::optional<int> BenchmarkProcessCPU) const;
138+
const BenchmarkKey &Key) const;
141139
};
142140

143141
} // namespace exegesis

llvm/tools/llvm-exegesis/llvm-exegesis.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ static cl::list<ValidationEvent> ValidationCounters(
269269
"counter to validate benchmarking assumptions"),
270270
cl::CommaSeparated, cl::cat(BenchmarkOptions), ValidationEventOptions());
271271

272-
static cl::opt<int> BenchmarkProcessCPU(
273-
"benchmark-process-cpu",
274-
cl::desc("The CPU number that the benchmarking process should executon on"),
275-
cl::cat(BenchmarkOptions), cl::init(-1));
276-
277272
static ExitOnError ExitOnErr("llvm-exegesis error: ");
278273

279274
// Helper function that logs the error(s) and exits.
@@ -423,12 +418,8 @@ static void runBenchmarkConfigurations(
423418
std::optional<StringRef> DumpFile;
424419
if (DumpObjectToDisk.getNumOccurrences())
425420
DumpFile = DumpObjectToDisk;
426-
const std::optional<int> BenchmarkCPU =
427-
BenchmarkProcessCPU == -1
428-
? std::nullopt
429-
: std::optional(BenchmarkProcessCPU.getValue());
430421
auto [Err, BenchmarkResult] =
431-
Runner.runConfiguration(std::move(RC), DumpFile, BenchmarkCPU);
422+
Runner.runConfiguration(std::move(RC), DumpFile);
432423
if (Err) {
433424
// Errors from executing the snippets are fine.
434425
// All other errors are a framework issue and should fail.

0 commit comments

Comments
 (0)