aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaryam Tahhan <maryam.tahhan@intel.com>2016-03-02 13:01:41 +0000
committerMaryam Tahhan <maryam.tahhan@intel.com>2016-03-08 13:58:14 +0000
commitf7366919b9d985b2b3d267750ea16667b636cdac (patch)
treea66e93d86a33556edfd266929448fb47fa924641 /src
parent86bc27fe76137a777979f17556fa999a74027428 (diff)
dpdk: enable vfio_pci support
Enable vfio_pci support for DPDK in the case where the end user doesn't want to use igb_uio. Changes: * Use generic functions to strip the path and .ko extension from the module to be inserted/removed. * Removed debug line in Modules_Manager. * Removed commented code. * Fixed all pylint issues. JIRA: VSPERF-249 Change-Id: I69c9077735879bcbf7ce5c970c1ec53c219e9f90 Signed-off-by: Maryam Tahhan <maryam.tahhan@intel.com> Reviewed-by: Martin Klozik <martinx.klozik@intel.com> Reviewed-by: Al Morton <acmorton@att.com> Reviewed-by: Christian Trautman <ctrautma@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/dpdk/dpdk.py169
1 files changed, 56 insertions, 113 deletions
diff --git a/src/dpdk/dpdk.py b/src/dpdk/dpdk.py
index f2f6ec9f..127ecaf2 100644
--- a/src/dpdk/dpdk.py
+++ b/src/dpdk/dpdk.py
@@ -34,7 +34,6 @@ RTE_PCI_TOOL = os.path.join(
settings.getValue('RTE_SDK'), 'tools', 'dpdk_nic_bind.py')
_DPDK_MODULE_MANAGER = ModuleManager()
-
#
# system management
#
@@ -46,7 +45,6 @@ def init():
if not _is_linux():
_LOGGER.error('Not running on a compatible Linux version. Exiting...')
return
-
_insert_modules()
_remove_vhost_net()
_bind_nics()
@@ -63,31 +61,10 @@ def cleanup():
_remove_modules()
_vhost_user_cleanup()
-
-#
-# vhost specific modules management
-#
-
-
-def insert_vhost_modules():
- """Inserts VHOST related kernel modules
- """
- mod_path_prefix = os.path.join(settings.getValue('RTE_SDK'),
- 'lib',
- 'librte_vhost')
- _insert_module_group('VHOST_MODULE', mod_path_prefix)
-
-
-def remove_vhost_modules():
- """Removes all VHOST related kernel modules
- """
- _remove_module_group('VHOST_MODULE')
-
#
# basic compatibility test
#
-
def _is_linux():
"""Check if running on Linux.
@@ -102,20 +79,6 @@ def _is_linux():
# module management
#
-
-def _is_module_inserted(module):
- """Check if a module is inserted on system.
- """
- with open('/proc/modules') as mod_file:
- loaded_mods = mod_file.readlines()
-
- # first check if module is loaded
- for line in loaded_mods:
- if line.startswith(module):
- return True
- return False
-
-
def _insert_modules():
"""Ensure required modules are inserted on system.
"""
@@ -123,74 +86,48 @@ def _insert_modules():
_DPDK_MODULE_MANAGER.insert_modules(settings.getValue('SYS_MODULES'))
mod_path_prefix = settings.getValue('OVS_DIR')
- _insert_module_group('OVS_MODULES', mod_path_prefix)
- mod_path_prefix = os.path.join(settings.getValue('RTE_SDK'),
- settings.getValue('RTE_TARGET'))
- _insert_module_group('DPDK_MODULES', mod_path_prefix)
-
-
-def _insert_module_group(module_group, group_path_prefix):
- """Ensure all modules in a group are inserted into the system.
-
- :param module_group: A name of configuration item containing a list
- of module names
- """
- for module in settings.getValue(module_group):
- # first check if module is loaded
- if _is_module_inserted(module[1]):
- continue
-
- try:
- mod_path = os.path.join(group_path_prefix, module[0],
- '%s.ko' % module[1])
- tasks.run_task(['sudo', 'insmod', mod_path], _LOGGER,
- 'Inserting module \'%s\'...' % module[1], True)
- except subprocess.CalledProcessError:
- _LOGGER.error('Unable to insert module \'%s\'.', module[1])
- raise # fail catastrophically
-
+ _DPDK_MODULE_MANAGER.insert_module_group(settings.getValue('OVS_MODULES'),
+ mod_path_prefix)
+ if 'vfio-pci' not in settings.getValue('DPDK_MODULES'):
+ mod_path_prefix = os.path.join(settings.getValue('RTE_SDK'),
+ settings.getValue('RTE_TARGET'))
+ _DPDK_MODULE_MANAGER.insert_module_group(settings.getValue('DPDK_MODULES'),
+ mod_path_prefix)
+ else:
+ _DPDK_MODULE_MANAGER.insert_modules(settings.getValue('DPDK_MODULES'))
def _remove_modules():
"""Ensure required modules are removed from system.
"""
- _remove_module_group('OVS_MODULES')
- _remove_module_group('DPDK_MODULES')
-
_DPDK_MODULE_MANAGER.remove_modules()
-def _remove_module_group(module_group):
- """Ensure all modules in a group are removed from the system.
+#
+# vhost specific modules management
+#
- :param module_group: A name of configuration item containing a list
- of module names
+def insert_vhost_modules():
+ """Inserts VHOST related kernel modules
"""
- for module in settings.getValue(module_group):
- # first check if module is loaded
- if not _is_module_inserted(module[1]):
- continue
+ mod_path_prefix = os.path.join(settings.getValue('RTE_SDK'),
+ 'lib',
+ 'librte_vhost')
+ _DPDK_MODULE_MANAGER.insert_module_group('VHOST_MODULE', mod_path_prefix)
- try:
- tasks.run_task(['sudo', 'rmmod', module[1]], _LOGGER,
- 'Removing module \'%s\'...' % module[1], True)
- except subprocess.CalledProcessError:
- _LOGGER.error('Unable to remove module \'%s\'.', module[1])
- continue
+
+def remove_vhost_modules():
+ """Removes all VHOST related kernel modules
+ """
+ _DPDK_MODULE_MANAGER.remove_module_group(settings.getValue('VHOST_MODULE'))
#
-# 'vhost-net' module management
+# 'vhost-net' module cleanup
#
def _remove_vhost_net():
"""Remove vhost-net driver and file.
"""
- if _is_module_inserted('vhost_net'):
- try:
- tasks.run_task(['sudo', 'rmmod', 'vhost_net'], _LOGGER,
- 'Removing \'/dev/vhost-net\' directory...', True)
- except subprocess.CalledProcessError:
- _LOGGER.error('Unable to remove module \'vhost_net\'.')
-
+ _DPDK_MODULE_MANAGER.remove_module('vhost-net')
try:
tasks.run_task(['sudo', 'rm', '-f', '/dev/vhost-net'], _LOGGER,
'Removing \'/dev/vhost-net\' directory...', True)
@@ -198,6 +135,26 @@ def _remove_vhost_net():
_LOGGER.error('Unable to remove directory \'/dev/vhost-net\'.')
#
+# Vhost-user cleanup
+#
+
+def _vhost_user_cleanup():
+ """Remove files created by vhost-user tests.
+ """
+ for sock in settings.getValue('VHOST_USER_SOCKS'):
+ if os.path.exists(sock):
+ try:
+ tasks.run_task(['sudo', 'rm', sock],
+ _LOGGER,
+ 'Deleting vhost-user socket \'%s\'...' %
+ sock,
+ True)
+
+ except subprocess.CalledProcessError:
+ _LOGGER.error('Unable to delete vhost-user socket \'%s\'.',
+ sock)
+ continue
+#
# NIC management
#
@@ -206,7 +163,17 @@ def _bind_nics():
"""Bind NICs using the Intel DPDK ``dpdk_nic_bind.py`` tool.
"""
try:
- tasks.run_task(['sudo', RTE_PCI_TOOL, '--bind', 'igb_uio'] +
+ _driver = 'igb_uio'
+ if 'vfio-pci' in settings.getValue('DPDK_MODULES'):
+ _driver = 'vfio-pci'
+ tasks.run_task(['sudo', 'chmod', 'a+x', '/dev/vfio'],
+ _LOGGER, 'Setting VFIO permissions .. a+x',
+ True)
+ tasks.run_task(['sudo', 'chmod', '-R', '666', '/dev/vfio/'],
+ _LOGGER, 'Setting VFIO permissions .. 0666',
+ True)
+
+ tasks.run_task(['sudo', RTE_PCI_TOOL, '--bind=' + _driver] +
settings.getValue('WHITELIST_NICS'), _LOGGER,
'Binding NICs %s...' %
settings.getValue('WHITELIST_NICS'),
@@ -256,30 +223,6 @@ def _unbind_nics():
str(settings.getValue('WHITELIST_NICS')),
nic_drivers)
-
-
-#
-# Vhost-user cleanup
-#
-
-def _vhost_user_cleanup():
- """Remove files created by vhost-user tests.
- """
- for sock in settings.getValue('VHOST_USER_SOCKS'):
- if os.path.exists(sock):
- try:
- tasks.run_task(['sudo', 'rm', sock],
- _LOGGER,
- 'Deleting vhost-user socket \'%s\'...' %
- sock,
- True)
-
- except subprocess.CalledProcessError:
- _LOGGER.error('Unable to delete vhost-user socket \'%s\'.',
- sock)
- continue
-
-
class Dpdk(object):
"""A context manager for the system init/cleanup.
"""