summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py
diff options
context:
space:
mode:
authorYury Kylulin <yury.kylulin@intel.com>2021-02-11 16:58:39 +0300
committerYury Kylulin <yury.kylulin@intel.com>2021-02-11 17:04:36 +0300
commit849357bb9ca1d27993c9e96b93156ec69b3ac3a9 (patch)
tree16fc193c87fe5b1ec0554bd151be01e02815cd0d /VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py
parent4ada3cbcdb56c79abd0bb34eef5dede6c36fbe82 (diff)
Add support for native Kubernetes CPU Manager0.0.1
For Kubernetes environment core ids in the config and test files are relative and automatically remapped to the allowed cores allocated for container. There is no change to the baremetal or VM environment. Signed-off-by: Yury Kylulin <yury.kylulin@intel.com> Change-Id: I63e499723e8213de1b05d4175eb3eddc4492ccf5
Diffstat (limited to 'VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py')
-rw-r--r--VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py
index d9e18b09..fb96760e 100644
--- a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py
+++ b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py
@@ -49,6 +49,7 @@ class RapidMachine(object):
break
self.machine_params = machine_params
self.vim = vim
+ self.cpu_mapping = None
def __del__(self):
if ((not self.configonly) and self.machine_params['prox_socket']):
@@ -58,6 +59,62 @@ class RapidMachine(object):
def get_cores(self):
return (self.machine_params['cores'])
+ def expand_cpuset(self, cpuset):
+ """Expand cpuset provided as comma-separated list of CPU numbers and
+ CPU ranges of numbers. For more information please see
+ https://man7.org/linux/man-pages/man7/cpuset.7.html
+ """
+ cpuset_expanded = []
+ for cpu in cpuset.split(','):
+ if '-' in cpu:
+ cpu_range = cpu.split('-')
+ cpuset_expanded += range(int(cpu_range[0]), int(cpu_range[1]) + 1)
+ else:
+ cpuset_expanded.append(int(cpu))
+ return cpuset_expanded
+
+ def read_cpuset(self):
+ """Read list of cpus on which we allowed to execute
+ """
+ cmd = 'cat /sys/fs/cgroup/cpuset/cpuset.cpus'
+ cpuset_cpus = self._client.run_cmd(cmd).decode().rstrip()
+ RapidLog.debug('{} ({}): Allocated cpuset: {}'.format(self.name, self.ip, cpuset_cpus))
+ self.cpu_mapping = self.expand_cpuset(cpuset_cpus)
+ RapidLog.debug('{} ({}): Expanded cpuset: {}'.format(self.name, self.ip, self.cpu_mapping))
+
+ # Log CPU core mapping for user information
+ cpu_mapping_str = ''
+ for i in range(len(self.cpu_mapping)):
+ cpu_mapping_str = cpu_mapping_str + '[' + str(i) + '->' + str(self.cpu_mapping[i]) + '], '
+ cpu_mapping_str = cpu_mapping_str[:-2]
+ RapidLog.debug('{} ({}): CPU mapping: {}'.format(self.name, self.ip, cpu_mapping_str))
+
+ def remap_cpus(self, cpus):
+ """Convert relative cpu ids provided as function parameter to match
+ cpu ids from allocated list
+ """
+ cpus_remapped = []
+ for cpu in cpus:
+ cpus_remapped.append(self.cpu_mapping[cpu])
+ return cpus_remapped
+
+ def remap_all_cpus(self):
+ """Convert relative cpu ids for different parameters (mcore, cores)
+ """
+ if self.cpu_mapping is None:
+ RapidLog.debug('{} ({}): cpu mapping is not defined! Please check the configuration!'.format(self.name, self.ip))
+ return
+
+ if 'mcore' in self.machine_params.keys():
+ cpus_remapped = self.remap_cpus(self.machine_params['mcore'])
+ RapidLog.debug('{} ({}): mcore {} remapped to {}'.format(self.name, self.ip, self.machine_params['mcore'], cpus_remapped))
+ self.machine_params['mcore'] = cpus_remapped
+
+ if 'cores' in self.machine_params.keys():
+ cpus_remapped = self.remap_cpus(self.machine_params['cores'])
+ RapidLog.debug('{} ({}): cores {} remapped to {}'.format(self.name, self.ip, self.machine_params['cores'], cpus_remapped))
+ self.machine_params['cores'] = cpus_remapped
+
def devbind(self):
# Script to bind the right network interface to the poll mode driver
for index, dp_port in enumerate(self.dp_ports, start = 1):
@@ -86,6 +143,8 @@ class RapidMachine(object):
LuaFile.write("eal=\"--socket-mem=512,0 --file-prefix %s --pci-whitelist %s\"\n" % (self.name, self.machine_params['dp_pci_dev']))
else:
LuaFile.write("eal=\"\"\n")
+ if 'mcore' in self.machine_params.keys():
+ LuaFile.write('mcore="%s"\n'% ','.join(map(str, self.machine_params['mcore'])))
if 'cores' in self.machine_params.keys():
LuaFile.write('cores="%s"\n'% ','.join(map(str, self.machine_params['cores'])))
if 'ports' in self.machine_params.keys():
@@ -105,6 +164,9 @@ class RapidMachine(object):
self._client.connect()
if self.vim in ['OpenStack']:
self.devbind()
+ if self.vim in ['kubernetes']:
+ self.read_cpuset()
+ self.remap_all_cpus()
_, prox_config_file_name = os.path.split(self.machine_params['config_file'])
self.generate_lua(self.vim, self.machine_params['config_file'])
self._client.scp_put(self.machine_params['config_file'], '{}/{}'.format(self.rundir, prox_config_file_name))