@@ -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,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(
650615Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
651616BenchmarkRunner::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
684645std::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);
0 commit comments