aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/CpuUtils.py
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2019-01-04 07:38:16 +0000
committerPeter Mikus <pmikus@cisco.com>2019-01-08 12:11:59 +0000
commitd57482c4cd391c5c0b6a440629f81df09169bc82 (patch)
tree8b9d74527ce5667755614bab9cccf12300623576 /resources/libraries/python/CpuUtils.py
parentd1c1b27d17033799cd586a079820d708cc8a541c (diff)
CSIT-1387 Implement mapping function
Implement universal mapping function for placing the NF threads to cpu cores/threads. - Must be SMT aware. - Must work with N-core NF. - Must be DUT (vswtich) aware. - Must be deterministic. - Must use DTCR and MTCR parameters. Change-Id: I98b61861f85c5af7ecd856719b4adf2ba95c262f Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/CpuUtils.py')
-rw-r--r--resources/libraries/python/CpuUtils.py59
1 files changed, 54 insertions, 5 deletions
diff --git a/resources/libraries/python/CpuUtils.py b/resources/libraries/python/CpuUtils.py
index f4d52f8662..aa1bd79419 100644
--- a/resources/libraries/python/CpuUtils.py
+++ b/resources/libraries/python/CpuUtils.py
@@ -49,7 +49,6 @@ class CpuUtils(object):
:returns: True if SMT is enabled, False if SMT is disabled.
:rtype: bool
"""
-
cpu_mems = [item[-4:] for item in cpu_info]
cpu_mems_len = len(cpu_mems) / CpuUtils.NR_OF_THREADS
count = 0
@@ -117,7 +116,6 @@ class CpuUtils(object):
:raises RuntimeError: If node cpuinfo is not available
or if SMT is not enabled.
"""
-
cpu_node = int(cpu_node)
cpu_info = node.get("cpuinfo")
if cpu_info is None:
@@ -160,7 +158,6 @@ class CpuUtils(object):
:rtype: list
:raises RuntimeError: If we require more cpus than available.
"""
-
cpu_list = CpuUtils.cpu_list_per_node(node, cpu_node, smt_used)
cpu_list_len = len(cpu_list)
@@ -202,7 +199,6 @@ class CpuUtils(object):
:returns: Cpu numbers related to numa from argument.
:rtype: str
"""
-
cpu_list = CpuUtils.cpu_slice_of_list_per_node(node, cpu_node,
skip_cnt=skip_cnt,
cpu_cnt=cpu_cnt,
@@ -229,7 +225,6 @@ class CpuUtils(object):
:returns: String of node related range of CPU numbers.
:rtype: str
"""
-
cpu_list = CpuUtils.cpu_slice_of_list_per_node(node, cpu_node,
skip_cnt=skip_cnt,
cpu_cnt=cpu_cnt,
@@ -246,3 +241,57 @@ class CpuUtils(object):
cpu_range = "{}{}{}".format(cpu_list[0], sep, cpu_list[-1])
return cpu_range
+
+ @staticmethod
+ def cpu_slice_of_list_for_nf(**kwargs):
+ """Return list of node related list of CPU numbers.
+
+ :param kwargs: Key-value pairs used to compute placement.
+ :type kwargs: dict
+ :returns: Cpu numbers related to numa from argument.
+ :rtype: list
+ :raises RuntimeError: If we require more cpus than available or if
+ placement is not possible due to wrong parameters.
+ """
+ if kwargs['chain_id'] - 1 >= kwargs['chains']:
+ raise RuntimeError("ChainID is higher than total number of chains!")
+ if kwargs['node_id'] - 1 >= kwargs['nodeness']:
+ raise RuntimeError("NodeID is higher than chain nodeness!")
+
+ smt_used = CpuUtils.is_smt_enabled(kwargs['node']['cpuinfo'])
+ cpu_list = CpuUtils.cpu_list_per_node(kwargs['node'],
+ kwargs['cpu_node'], smt_used)
+ cpu_list_len = len(cpu_list)
+
+ mt_req = ((kwargs['chains'] * kwargs['nodeness']) + kwargs['mtcr'] - 1)\
+ / kwargs['mtcr']
+ dt_req = ((kwargs['chains'] * kwargs['nodeness']) + kwargs['dtcr'] - 1)\
+ / kwargs['dtcr']
+
+ if kwargs['skip_cnt'] + mt_req + dt_req > cpu_list_len:
+ raise RuntimeError("Not enough CPU cores available for placement!")
+
+ offset = (kwargs['node_id'] - 1) + (kwargs['chain_id'] - 1)\
+ * kwargs['nodeness']
+ dtc = kwargs['dtc']
+ try:
+ mt_odd = (offset / mt_req) & 1
+ mt_skip = kwargs['skip_cnt'] + (offset % mt_req)
+ dt_skip = kwargs['skip_cnt'] + mt_req + (offset % dt_req) * dtc
+ except ZeroDivisionError:
+ raise RuntimeError("Invalid placement combination!")
+
+ if smt_used:
+ cpu_list_0 = cpu_list[:cpu_list_len / CpuUtils.NR_OF_THREADS]
+ cpu_list_1 = cpu_list[cpu_list_len / CpuUtils.NR_OF_THREADS:]
+
+ mt_cpu_list = [cpu for cpu in cpu_list_1[mt_skip:mt_skip + 1]] \
+ if mt_odd else [cpu for cpu in cpu_list_0[mt_skip:mt_skip + 1]]
+
+ dt_cpu_list = [cpu for cpu in cpu_list_0[dt_skip:dt_skip + dtc]]
+ dt_cpu_list += [cpu for cpu in cpu_list_1[dt_skip:dt_skip + dtc]]
+ else:
+ mt_cpu_list = [cpu for cpu in cpu_list[mt_skip:mt_skip + 1]]
+ dt_cpu_list = [cpu for cpu in cpu_list[dt_skip:dt_skip + dtc]]
+
+ return mt_cpu_list + dt_cpu_list