Skip to content

Commit 2cd20c2

Browse files
Revert "[llvm-exegesis] Add support for pinning benchmarking process to a CPU (#85168)"
This reverts commit 6fc2451. This broke some more buildbots.
1 parent cce1fa3 commit 2cd20c2

File tree

5 files changed

+15
-83
lines changed

5 files changed

+15
-83
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 & 59 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,36 +384,6 @@ class SubProcessFunctionExecutorImpl
391384
return make_error<SnippetSignal>(ChildSignalInfo.si_signo);
392385
}
393386

394-
static void setCPUAffinityIfRequested(int CPUToUse) {
395-
// Special case this function for x86_64 for now as certain more esoteric
396-
// platforms have different definitions for some of the libc functions that
397-
// cause buildtime failures. Additionally, the subprocess executor mode (the
398-
// sole mode where this is supported) currently only supports x86_64.
399-
#if defined(__x86_64__)
400-
// Set the CPU affinity for the child process, so that we ensure that if
401-
// the user specified a CPU the process should run on, the benchmarking
402-
// process is running on that CPU.
403-
cpu_set_t CPUMask;
404-
CPU_ZERO(&CPUMask);
405-
CPU_SET(CPUToUse, &CPUMask);
406-
// TODO(boomanaiden154): Rewrite this to use LLVM primitives once they
407-
// are available.
408-
int SetAffinityReturn = sched_setaffinity(0, sizeof(CPUMask), &CPUMask);
409-
if (SetAffinityReturn == -1) {
410-
exit(ChildProcessExitCodeE::SetCPUAffinityFailed);
411-
}
412-
413-
// Check (if assertions are enabled) that we are actually running on the
414-
// CPU that was specified by the user.
415-
[[maybe_unused]] unsigned int CurrentCPU;
416-
assert(getcpu(&CurrentCPU, nullptr) == 0 &&
417-
"Expected getcpu call to succeed.");
418-
assert(static_cast<int>(CurrentCPU) == CPUToUse &&
419-
"Expected current CPU to equal the CPU requested by the user");
420-
#endif // defined(__x86_64__)
421-
exit(ChildProcessExitCodeE::SetCPUAffinityFailed);
422-
}
423-
424387
Error createSubProcessAndRunBenchmark(
425388
StringRef CounterName, SmallVectorImpl<int64_t> &CounterValues,
426389
ArrayRef<const char *> ValidationCounters,
@@ -453,10 +416,6 @@ class SubProcessFunctionExecutorImpl
453416
}
454417

455418
if (ParentOrChildPID == 0) {
456-
if (BenchmarkProcessCPU.has_value()) {
457-
setCPUAffinityIfRequested(*BenchmarkProcessCPU);
458-
}
459-
460419
// We are in the child process, close the write end of the pipe.
461420
close(PipeFiles[1]);
462421
// Unregister handlers, signal handling is now handled through ptrace in
@@ -579,7 +538,6 @@ class SubProcessFunctionExecutorImpl
579538
const LLVMState &State;
580539
const ExecutableFunction Function;
581540
const BenchmarkKey &Key;
582-
const std::optional<int> BenchmarkProcessCPU;
583541
};
584542
#endif // __linux__
585543
} // namespace
@@ -657,15 +615,11 @@ BenchmarkRunner::getRunnableConfiguration(
657615
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
658616
BenchmarkRunner::createFunctionExecutor(
659617
object::OwningBinary<object::ObjectFile> ObjectFile,
660-
const BenchmarkKey &Key, std::optional<int> BenchmarkProcessCPU) const {
618+
const BenchmarkKey &Key) const {
661619
switch (ExecutionMode) {
662620
case ExecutionModeE::InProcess: {
663-
if (BenchmarkProcessCPU.has_value())
664-
return make_error<Failure>("The inprocess execution mode does not "
665-
"support benchmark core pinning.");
666-
667621
auto InProcessExecutorOrErr = InProcessFunctionExecutorImpl::create(
668-
State, std::move(ObjectFile), Scratch.get(), BenchmarkProcessCPU);
622+
State, std::move(ObjectFile), Scratch.get());
669623
if (!InProcessExecutorOrErr)
670624
return InProcessExecutorOrErr.takeError();
671625

@@ -674,7 +628,7 @@ BenchmarkRunner::createFunctionExecutor(
674628
case ExecutionModeE::SubProcess: {
675629
#ifdef __linux__
676630
auto SubProcessExecutorOrErr = SubProcessFunctionExecutorImpl::create(
677-
State, std::move(ObjectFile), Key, BenchmarkProcessCPU);
631+
State, std::move(ObjectFile), Key);
678632
if (!SubProcessExecutorOrErr)
679633
return SubProcessExecutorOrErr.takeError();
680634

@@ -689,8 +643,8 @@ BenchmarkRunner::createFunctionExecutor(
689643
}
690644

691645
std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
692-
RunnableConfiguration &&RC, const std::optional<StringRef> &DumpFile,
693-
std::optional<int> BenchmarkProcessCPU) const {
646+
RunnableConfiguration &&RC,
647+
const std::optional<StringRef> &DumpFile) const {
694648
Benchmark &BenchmarkResult = RC.BenchmarkResult;
695649
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile;
696650

@@ -711,8 +665,7 @@ std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
711665
}
712666

713667
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>> Executor =
714-
createFunctionExecutor(std::move(ObjectFile), RC.BenchmarkResult.Key,
715-
BenchmarkProcessCPU);
668+
createFunctionExecutor(std::move(ObjectFile), RC.BenchmarkResult.Key);
716669
if (!Executor)
717670
return {Executor.takeError(), std::move(BenchmarkResult)};
718671
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)