ansible: log affinity assignments

pull/612/head
David Wilson 5 years ago
parent 16ba1aacce
commit 0f23a90d50

@ -73,7 +73,9 @@ necessarily involves preventing the scheduler from making load balancing
decisions.
"""
from __future__ import absolute_import
import ctypes
import logging
import mmap
import multiprocessing
import os
@ -83,6 +85,9 @@ import mitogen.core
import mitogen.parent
LOG = logging.getLogger(__name__)
try:
_libc = ctypes.CDLL(None, use_errno=True)
_strerror = _libc.strerror
@ -207,11 +212,13 @@ class FixedPolicy(Policy):
self._reserve_mask = 3
self._reserve_shift = 2
def _set_affinity(self, mask):
def _set_affinity(self, descr, mask):
if descr:
LOG.debug('CPU mask for %s: %#08x', descr, mask)
mitogen.parent._preexec_hook = self._clear
self._set_cpu_mask(mask)
def _balance(self):
def _balance(self, descr):
self.state.lock.acquire()
try:
n = self.state.counter
@ -219,28 +226,28 @@ class FixedPolicy(Policy):
finally:
self.state.lock.release()
self._set_cpu(self._reserve_shift + (
self._set_cpu(descr, self._reserve_shift + (
(n % (self.cpu_count - self._reserve_shift))
))
def _set_cpu(self, cpu):
self._set_affinity(1 << (cpu % self.cpu_count))
def _set_cpu(self, descr, cpu):
self._set_affinity(descr, 1 << (cpu % self.cpu_count))
def _clear(self):
all_cpus = (1 << self.cpu_count) - 1
self._set_affinity(all_cpus & ~self._reserve_mask)
self._set_affinity(None, all_cpus & ~self._reserve_mask)
def assign_controller(self):
if self._reserve_controller:
self._set_cpu(1)
self._set_cpu('Ansible top-level process', 1)
else:
self._balance()
self._balance('Ansible top-level process')
def assign_muxprocess(self, index):
self._set_cpu(index)
self._set_cpu('MuxProcess %d' % (index,), index)
def assign_worker(self):
self._balance()
self._balance('WorkerProcess')
def assign_subprocess(self):
self._clear()

@ -275,13 +275,13 @@ def common_setup(enable_affinity=True, _init_logging=True):
save_pid('controller')
ansible_mitogen.logging.set_process_name('top')
if _init_logging:
ansible_mitogen.logging.setup()
if enable_affinity:
ansible_mitogen.affinity.policy.assign_controller()
mitogen.utils.setup_gil()
if _init_logging:
ansible_mitogen.logging.setup()
if faulthandler is not None:
faulthandler.enable()

Loading…
Cancel
Save