issue #557: support correct cpu_set_t size
This commit is contained in:
parent
408a96f284
commit
3ff6123483
|
@ -79,6 +79,7 @@ import multiprocessing
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
import mitogen.core
|
||||||
import mitogen.parent
|
import mitogen.parent
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,8 +247,19 @@ class FixedPolicy(Policy):
|
||||||
|
|
||||||
|
|
||||||
class LinuxPolicy(FixedPolicy):
|
class LinuxPolicy(FixedPolicy):
|
||||||
|
def _mask_to_bytes(self, mask):
|
||||||
|
"""
|
||||||
|
Convert the (type long) mask to a cpu_set_t.
|
||||||
|
"""
|
||||||
|
chunks = []
|
||||||
|
shiftmask = (2 ** 64) - 1
|
||||||
|
for x in range(16):
|
||||||
|
chunks.append(struct.pack('<Q', mask & shiftmask))
|
||||||
|
mask >>= 64
|
||||||
|
return mitogen.core.b('').join(chunks)
|
||||||
|
|
||||||
def _set_cpu_mask(self, mask):
|
def _set_cpu_mask(self, mask):
|
||||||
s = struct.pack('L', mask)
|
s = self._mask_to_bytes(mask)
|
||||||
_sched_setaffinity(os.getpid(), len(s), s)
|
_sched_setaffinity(os.getpid(), len(s), s)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -211,5 +211,16 @@ class LinuxPolicyTest(testlib.TestCase):
|
||||||
tf.close()
|
tf.close()
|
||||||
|
|
||||||
|
|
||||||
|
class MockLinuxPolicyTest(testlib.TestCase):
|
||||||
|
klass = ansible_mitogen.affinity.LinuxPolicy
|
||||||
|
|
||||||
|
# Test struct.pack() in _set_cpu_mask().
|
||||||
|
|
||||||
|
def test_high_cpus(self):
|
||||||
|
policy = self.klass(cpu_count=4096)
|
||||||
|
for x in range(1, 4096, 32):
|
||||||
|
policy.assign_subprocess()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest2.main()
|
unittest2.main()
|
||||||
|
|
Loading…
Reference in New Issue