[llvm] [llvm-exegesis] Add support for pinning benchmarking process to a CPU (PR #85168)
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 00:49:08 PDT 2024
================
@@ -310,6 +321,29 @@ class SubProcessFunctionExecutorImpl
}
if (ParentOrChildPID == 0) {
+ if (BenchmarkProcessCPU) {
+ // Set the CPU affinity for the child process, so that we ensure that if
+ // the user specified a CPU the process should run on, the benchmarking
+ // process is running on that CPU.
+ cpu_set_t CPUMask;
+ CPU_ZERO(&CPUMask);
+ CPU_SET(*BenchmarkProcessCPU, &CPUMask);
+ // TODO(boomanaiden154): Rewrite this to use LLVM primitives once they
+ // are available.
+ int SetAffinityReturn = sched_setaffinity(0, sizeof(CPUMask), &CPUMask);
+ if (SetAffinityReturn == -1) {
+ exit(ChildProcessExitCodeE::SetCPUAffinityFailed);
+ }
+
+ // Check (if assertions are enabled) that we are actually running on the
+ // CPU that was specified by the user.
+ unsigned int CurrentCPU;
+ assert(getcpu(&CurrentCPU, nullptr) == 0 &&
+ "Expected getcpu call to succeed.");
+ assert(static_cast<int>(CurrentCPU) == *BenchmarkProcessCPU &&
+ "Expected current CPU to equal the CPU requested by the user");
+ }
----------------
legrosbuffle wrote:
Please move this to a separate function.
https://github.com/llvm/llvm-project/pull/85168
More information about the llvm-commits
mailing list