@@ -98,8 +98,7 @@ class InProcessFunctionExecutorImpl : public BenchmarkRunner::FunctionExecutor {
98
98
public:
99
99
static Expected<std::unique_ptr<InProcessFunctionExecutorImpl>>
100
100
create (const LLVMState &State, object::OwningBinary<object::ObjectFile> Obj,
101
- BenchmarkRunner::ScratchSpace *Scratch,
102
- std::optional<int > BenchmarkProcessCPU) {
101
+ BenchmarkRunner::ScratchSpace *Scratch) {
103
102
Expected<ExecutableFunction> EF =
104
103
ExecutableFunction::create (State.createTargetMachine (), std::move (Obj));
105
104
@@ -191,31 +190,27 @@ class SubProcessFunctionExecutorImpl
191
190
public:
192
191
static Expected<std::unique_ptr<SubProcessFunctionExecutorImpl>>
193
192
create (const LLVMState &State, object::OwningBinary<object::ObjectFile> Obj,
194
- const BenchmarkKey &Key, std::optional< int > BenchmarkProcessCPU ) {
193
+ const BenchmarkKey &Key) {
195
194
Expected<ExecutableFunction> EF =
196
195
ExecutableFunction::create (State.createTargetMachine (), std::move (Obj));
197
196
if (!EF)
198
197
return EF.takeError ();
199
198
200
199
return std::unique_ptr<SubProcessFunctionExecutorImpl>(
201
- new SubProcessFunctionExecutorImpl (State, std::move (*EF), Key,
202
- BenchmarkProcessCPU));
200
+ new SubProcessFunctionExecutorImpl (State, std::move (*EF), Key));
203
201
}
204
202
205
203
private:
206
204
SubProcessFunctionExecutorImpl (const LLVMState &State,
207
205
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) {}
212
208
213
209
enum ChildProcessExitCodeE {
214
210
CounterFDReadFailed = 1 ,
215
211
RSeqDisableFailed,
216
212
FunctionDataMappingFailed,
217
- AuxiliaryMemorySetupFailed,
218
- SetCPUAffinityFailed
213
+ AuxiliaryMemorySetupFailed
219
214
};
220
215
221
216
StringRef childProcessExitCodeToString (int ExitCode) const {
@@ -228,8 +223,6 @@ class SubProcessFunctionExecutorImpl
228
223
return " Failed to map memory for assembled snippet" ;
229
224
case ChildProcessExitCodeE::AuxiliaryMemorySetupFailed:
230
225
return " Failed to setup auxiliary memory" ;
231
- case ChildProcessExitCodeE::SetCPUAffinityFailed:
232
- return " Failed to set CPU affinity of the benchmarking process" ;
233
226
default :
234
227
return " Child process returned with unknown exit code" ;
235
228
}
@@ -391,36 +384,6 @@ class SubProcessFunctionExecutorImpl
391
384
return make_error<SnippetSignal>(ChildSignalInfo.si_signo );
392
385
}
393
386
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
-
424
387
Error createSubProcessAndRunBenchmark (
425
388
StringRef CounterName, SmallVectorImpl<int64_t > &CounterValues,
426
389
ArrayRef<const char *> ValidationCounters,
@@ -453,10 +416,6 @@ class SubProcessFunctionExecutorImpl
453
416
}
454
417
455
418
if (ParentOrChildPID == 0 ) {
456
- if (BenchmarkProcessCPU.has_value ()) {
457
- setCPUAffinityIfRequested (*BenchmarkProcessCPU);
458
- }
459
-
460
419
// We are in the child process, close the write end of the pipe.
461
420
close (PipeFiles[1 ]);
462
421
// Unregister handlers, signal handling is now handled through ptrace in
@@ -579,7 +538,6 @@ class SubProcessFunctionExecutorImpl
579
538
const LLVMState &State;
580
539
const ExecutableFunction Function;
581
540
const BenchmarkKey &Key;
582
- const std::optional<int > BenchmarkProcessCPU;
583
541
};
584
542
#endif // __linux__
585
543
} // namespace
@@ -657,15 +615,11 @@ BenchmarkRunner::getRunnableConfiguration(
657
615
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
658
616
BenchmarkRunner::createFunctionExecutor (
659
617
object::OwningBinary<object::ObjectFile> ObjectFile,
660
- const BenchmarkKey &Key, std::optional< int > BenchmarkProcessCPU ) const {
618
+ const BenchmarkKey &Key) const {
661
619
switch (ExecutionMode) {
662
620
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
-
667
621
auto InProcessExecutorOrErr = InProcessFunctionExecutorImpl::create (
668
- State, std::move (ObjectFile), Scratch.get (), BenchmarkProcessCPU );
622
+ State, std::move (ObjectFile), Scratch.get ());
669
623
if (!InProcessExecutorOrErr)
670
624
return InProcessExecutorOrErr.takeError ();
671
625
@@ -674,7 +628,7 @@ BenchmarkRunner::createFunctionExecutor(
674
628
case ExecutionModeE::SubProcess: {
675
629
#ifdef __linux__
676
630
auto SubProcessExecutorOrErr = SubProcessFunctionExecutorImpl::create (
677
- State, std::move (ObjectFile), Key, BenchmarkProcessCPU );
631
+ State, std::move (ObjectFile), Key);
678
632
if (!SubProcessExecutorOrErr)
679
633
return SubProcessExecutorOrErr.takeError ();
680
634
@@ -689,8 +643,8 @@ BenchmarkRunner::createFunctionExecutor(
689
643
}
690
644
691
645
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 {
694
648
Benchmark &BenchmarkResult = RC.BenchmarkResult ;
695
649
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile ;
696
650
@@ -711,8 +665,7 @@ std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
711
665
}
712
666
713
667
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 );
716
669
if (!Executor)
717
670
return {Executor.takeError (), std::move (BenchmarkResult)};
718
671
auto NewMeasurements = runMeasurements (**Executor);
0 commit comments