commit b2dd5fb464590e6253070cb604d62313c90d1791 Author: Jim Gauld Date: Fri Oct 16 15:26:35 2020 -0400 Fix DRBD task affinity to platform cores This changes the input format of DRBD resource config option cpu-mask so it is correctly parsed in the kernel. The underlying bitmap_parse routine expects large hex values delimited every 8 characters with a comma. e.g., On large-cpu systems, we would see the following kern.log : 2020-10-13T20:55:34.079 controller-0 kernel: warning [ 269.423462] drbd drbd-dockerdistribution: Overflow in bitmap_parse(300000003), truncating to 64 bits This resulted in drbd_w_* tasks affined to individual cores instead of platform cores. Partial-Bug: 1900174 Change-Id: Ib31d3c8b6d59b94f06d172143497678b0c9a7bc1 Signed-off-by: Jim Gauld diff --git a/sysinv/sysinv/sysinv/sysinv/common/utils.py b/sysinv/sysinv/sysinv/sysinv/common/utils.py index 99f3cf3..b6f3565 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/utils.py +++ b/sysinv/sysinv/sysinv/sysinv/common/utils.py @@ -2410,3 +2410,21 @@ def run_playbook(playbook_command): out, _ = proc.communicate() LOG.info("ansible-playbook: %s." % out) return proc.returncode + + +def format_hex_grouped(value, sep=',', chunk=8): + """ + Format integer as hex string with a separater every 'chunk' + characters from the right. + + E.g., 0x300000003 is formatted as '3,00000003'. + + :param value: integer + :param sep: string + :param chunk: integer + :return: string + """ + x = '{:x}'.format(value) + r = x[::-1] + chunks = [r[i:i + chunk][::-1] for i in range(0, len(r), chunk)] + return sep.join(reversed(chunks)) diff --git a/sysinv/sysinv/sysinv/sysinv/puppet/platform.py b/sysinv/sysinv/sysinv/sysinv/puppet/platform.py index 8356eb7..3ade044 100644 --- a/sysinv/sysinv/sysinv/sysinv/puppet/platform.py +++ b/sysinv/sysinv/sysinv/sysinv/puppet/platform.py @@ -504,7 +504,8 @@ class PlatformPuppet(base.BasePuppet): for cpu in platform_cpus: platform_cpumask |= 1 << cpu.cpu - drbd_cpumask = '%x' % platform_cpumask + drbd_cpumask = "\"%s\"" % (utils.format_hex_grouped( + platform_cpumask, sep=',', chunk=8)) config.update({ 'platform::drbd::params::cpumask': drbd_cpumask diff --git a/sysinv/sysinv/sysinv/sysinv/tests/common/test_utils.py b/sysinv/sysinv/sysinv/sysinv/tests/common/test_utils.py new file mode 100644 index 0000000..3450eb0 --- /dev/null +++ b/sysinv/sysinv/sysinv/sysinv/tests/common/test_utils.py @@ -0,0 +1,44 @@ +# +# Copyright (c) 2020 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +""" +Tests for the common utilities. +""" + +from sysinv.common import utils +from sysinv.tests import base + + +class TestCommonUtilities(base.TestCase): + def test_format_hex_grouped(self): + TEST_MASKS = [ + {'value': 0xabcdef1234, 'sep': ',', 'chunk': 8, + 'expect': 'ab,cdef1234'}, + {'value': 0xabcdef1234, 'sep': ',', 'chunk': 4, + 'expect': 'ab,cdef,1234'}, + {'value': 0xabcdef1234, 'sep': ',', 'chunk': 2, + 'expect': 'ab,cd,ef,12,34'}, + {'value': 0xabcdef1234567890, 'sep': ',', 'chunk': 8, + 'expect': 'abcdef12,34567890'}, + {'value': 0xabcdef1234567890cab, 'sep': ',', 'chunk': 8, + 'expect': 'abc,def12345,67890cab'}, + {'value': 0xabcdef1234, 'sep': ':', 'chunk': 4, + 'expect': 'ab:cdef:1234'}, + {'value': 0x300000003, 'sep': ',', 'chunk': 8, 'expect': + '3,00000003'}, + {'value': 0x8008, 'sep': ',', 'chunk': 8, + 'expect': '8008'}, + {'value': 0x8008, 'sep': ',', 'chunk': 2, + 'expect': '80,08'}, + {'value': 0x3, 'sep': ',', 'chunk': 8, + 'expect': '3'}, + {'value': 0x0, 'sep': ',', 'chunk': 8, + 'expect': '0'}, + ] + for t in TEST_MASKS: + result = utils.format_hex_grouped( + t['value'], sep=t['sep'], chunk=t['chunk']) + self.assertEqual(result, t['expect'])