From bf1f3682aae50791c631aedf233a2f84a42a6d45 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 29 Jul 2019 22:53:53 +0100 Subject: [PATCH] ansible: pin per-CPU muxes to their corresponding CPU This slightly breaks the old scheme, in that CPU 1 may now end up with a mux and the top-level process pinned to it. --- ansible_mitogen/affinity.py | 8 ++++---- ansible_mitogen/process.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ansible_mitogen/affinity.py b/ansible_mitogen/affinity.py index 94539e21..eeeb4d38 100644 --- a/ansible_mitogen/affinity.py +++ b/ansible_mitogen/affinity.py @@ -142,7 +142,7 @@ class Policy(object): Assign the Ansible top-level policy to this process. """ - def assign_muxprocess(self): + def assign_muxprocess(self, index): """ Assign the MuxProcess policy to this process. """ @@ -224,7 +224,7 @@ class FixedPolicy(Policy): )) def _set_cpu(self, cpu): - self._set_affinity(1 << cpu) + self._set_affinity(1 << (cpu % self.cpu_count)) def _clear(self): all_cpus = (1 << self.cpu_count) - 1 @@ -236,8 +236,8 @@ class FixedPolicy(Policy): else: self._balance() - def assign_muxprocess(self): - self._set_cpu(0) + def assign_muxprocess(self, index): + self._set_cpu(index) def assign_worker(self): self._balance() diff --git a/ansible_mitogen/process.py b/ansible_mitogen/process.py index 7cdd68ae..a8052061 100644 --- a/ansible_mitogen/process.py +++ b/ansible_mitogen/process.py @@ -586,7 +586,7 @@ class MuxProcess(object): """ save_pid('mux') ansible_mitogen.logging.set_process_name('mux') - ansible_mitogen.affinity.policy.assign_muxprocess() + ansible_mitogen.affinity.policy.assign_muxprocess(self.index) self._setup_master() self._setup_services()