@@ -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,29 +384,6 @@ class SubProcessFunctionExecutorImpl
391
384
return make_error<SnippetSignal>(ChildSignalInfo.si_signo );
392
385
}
393
386
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
-
417
387
Error createSubProcessAndRunBenchmark (
418
388
StringRef CounterName, SmallVectorImpl<int64_t > &CounterValues,
419
389
ArrayRef<const char *> ValidationCounters,
@@ -446,10 +416,6 @@ class SubProcessFunctionExecutorImpl
446
416
}
447
417
448
418
if (ParentOrChildPID == 0 ) {
449
- if (BenchmarkProcessCPU.has_value ()) {
450
- setCPUAffinityIfRequested (*BenchmarkProcessCPU);
451
- }
452
-
453
419
// We are in the child process, close the write end of the pipe.
454
420
close (PipeFiles[1 ]);
455
421
// Unregister handlers, signal handling is now handled through ptrace in
@@ -572,7 +538,6 @@ class SubProcessFunctionExecutorImpl
572
538
const LLVMState &State;
573
539
const ExecutableFunction Function;
574
540
const BenchmarkKey &Key;
575
- const std::optional<int > BenchmarkProcessCPU;
576
541
};
577
542
#endif // __linux__
578
543
} // namespace
@@ -650,15 +615,11 @@ BenchmarkRunner::getRunnableConfiguration(
650
615
Expected<std::unique_ptr<BenchmarkRunner::FunctionExecutor>>
651
616
BenchmarkRunner::createFunctionExecutor (
652
617
object::OwningBinary<object::ObjectFile> ObjectFile,
653
- const BenchmarkKey &Key, std::optional< int > BenchmarkProcessCPU ) const {
618
+ const BenchmarkKey &Key) const {
654
619
switch (ExecutionMode) {
655
620
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
-
660
621
auto InProcessExecutorOrErr = InProcessFunctionExecutorImpl::create (
661
- State, std::move (ObjectFile), Scratch.get (), BenchmarkProcessCPU );
622
+ State, std::move (ObjectFile), Scratch.get ());
662
623
if (!InProcessExecutorOrErr)
663
624
return InProcessExecutorOrErr.takeError ();
664
625
@@ -667,7 +628,7 @@ BenchmarkRunner::createFunctionExecutor(
667
628
case ExecutionModeE::SubProcess: {
668
629
#ifdef __linux__
669
630
auto SubProcessExecutorOrErr = SubProcessFunctionExecutorImpl::create (
670
- State, std::move (ObjectFile), Key, BenchmarkProcessCPU );
631
+ State, std::move (ObjectFile), Key);
671
632
if (!SubProcessExecutorOrErr)
672
633
return SubProcessExecutorOrErr.takeError ();
673
634
@@ -682,8 +643,8 @@ BenchmarkRunner::createFunctionExecutor(
682
643
}
683
644
684
645
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 {
687
648
Benchmark &BenchmarkResult = RC.BenchmarkResult ;
688
649
object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile ;
689
650
@@ -704,8 +665,7 @@ std::pair<Error, Benchmark> BenchmarkRunner::runConfiguration(
704
665
}
705
666
706
667
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 );
709
669
if (!Executor)
710
670
return {Executor.takeError (), std::move (BenchmarkResult)};
711
671
auto NewMeasurements = runMeasurements (**Executor);
0 commit comments