@@ -98,8 +98,7 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
9898public:
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
191190public:
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
205203private:
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(
657615Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
658616BenchmarkRunner::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
691645std::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);
0 commit comments