[Kimchi-devel] [PATCH] [Kimchi 1/2] Improve PCI passthrough performance
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Wed Jul 27 21:49:20 UTC 2016
- This commit improves PCI passthrough performance by re-using the
device(s) model instead of creating new instances, which was
the source cause of a huge overhead.
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
model/vmhostdevs.py | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/model/vmhostdevs.py b/model/vmhostdevs.py
index 70f0b17..15b5bec 100644
--- a/model/vmhostdevs.py
+++ b/model/vmhostdevs.py
@@ -51,6 +51,8 @@ class VMHostDevsModel(object):
self.objstore = kargs['objstore']
self.events = kargs['eventsloop']
self.caps = CapabilitiesModel(**kargs)
+ self.devs_model = DevicesModel(**kargs)
+ self.dev_model = DeviceModel(**kargs)
self.task = TaskModel(**kargs)
self._cb = None
self.events.registerAttachDevicesEvent(
@@ -70,8 +72,7 @@ class VMHostDevsModel(object):
return [DeviceModel.deduce_dev_name(e, self.conn) for e in hostdev]
def _passthrough_device_validate(self, dev_name):
- eligible_dev_names = \
- DevicesModel(conn=self.conn).get_list(_passthrough='true')
+ eligible_dev_names = self.devs_model.get_list(_passthrough='true')
if dev_name not in eligible_dev_names:
raise InvalidParameter('KCHVMHDEV0002E', {'dev_name': dev_name})
@@ -89,7 +90,7 @@ class VMHostDevsModel(object):
def create(self, vmid, params):
dev_name = params['name']
self._passthrough_device_validate(dev_name)
- dev_info = DeviceModel(conn=self.conn).lookup(dev_name)
+ dev_info = self.dev_model.lookup(dev_name)
if dev_info['device_type'] == 'pci':
taskid = add_task(u'/plugins/kimchi/vms/%s/hostdevs/' %
@@ -192,7 +193,7 @@ class VMHostDevsModel(object):
slots = []
try:
devices = root.devices
- slots = [DeviceModel._toint(dev.attrib['slot'])
+ slots = [self.dev_model._toint(dev.attrib['slot'])
for dev in devices.findall('.//address')
if 'slot' in dev.attrib]
@@ -235,14 +236,12 @@ class VMHostDevsModel(object):
driver = 'vfio'
# Attach all PCI devices in the same IOMMU group
- dev_model = DeviceModel(conn=self.conn)
- devs_model = DevicesModel(conn=self.conn)
- affected_names = devs_model.get_list(
+ affected_names = self.devs_model.get_list(
_passthrough_affected_by=dev_info['name'])
- passthrough_names = devs_model.get_list(
+ passthrough_names = self.devs_model.get_list(
_cap='pci', _passthrough='true')
group_names = list(set(affected_names) & set(passthrough_names))
- pci_infos = [dev_model.lookup(dev_name) for dev_name in
+ pci_infos = [self.dev_model.lookup(dev_name) for dev_name in
group_names]
pci_infos.append(dev_info)
@@ -250,7 +249,7 @@ class VMHostDevsModel(object):
pci_infos = sorted(pci_infos, key=itemgetter('name'))
# does not allow hot-plug of 3D graphic cards
- is_3D_device = dev_model.is_device_3D_controller(dev_info)
+ is_3D_device = self.dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
msg = WokMessage('KCHVMHDEV0006E', {'name': dev_info['name']})
cb(msg.get_text(), False)
@@ -359,7 +358,7 @@ class VMHostDevsModel(object):
continue
name = DeviceModel.deduce_dev_name(device, self.conn)
- info = DeviceModel(conn=self.conn).lookup(name)
+ info = self.dev_model.lookup(name)
if 'vga3d' in info and info['vga3d']:
counter += 1
@@ -534,6 +533,8 @@ class VMHostDevModel(object):
self.objstore = kargs['objstore']
self.events = kargs['eventsloop']
self.task = TaskModel(**kargs)
+ self.devs_model = DevicesModel(**kargs)
+ self.dev_model = DeviceModel(**kargs)
self._cb = None
self.events.registerDetachDevicesEvent(
self.conn,
@@ -550,11 +551,10 @@ class VMHostDevModel(object):
raise NotFoundError('KCHVMHDEV0001E',
{'vmid': vmid, 'dev_name': dev_name})
- dev_model = DeviceModel(conn=self.conn)
for e in hostdev:
deduced_name = DeviceModel.deduce_dev_name(e, self.conn)
if deduced_name == dev_name:
- dev_info = dev_model.lookup(dev_name)
+ dev_info = self.dev_model.lookup(dev_name)
return {'name': dev_name,
'type': e.attrib['type'],
'product': dev_info.get('product', None),
@@ -612,9 +612,8 @@ class VMHostDevModel(object):
pci_devs = [(DeviceModel.deduce_dev_name(e, self.conn), e)
for e in hostdev if e.attrib['type'] == 'pci']
- dev_model = DeviceModel(conn=self.conn)
- dev_info = dev_model.lookup(dev_name)
- is_3D_device = dev_model.is_device_3D_controller(dev_info)
+ dev_info = self.dev_model.lookup(dev_name)
+ is_3D_device = self.dev_model.is_device_3D_controller(dev_info)
if is_3D_device and DOM_STATE_MAP[dom.info()[0]] != "shutoff":
raise InvalidOperation('KCHVMHDEV0006E',
{'name': dev_info['name']})
@@ -685,9 +684,8 @@ class VMHostDevModel(object):
return True
def _delete_affected_pci_devices(self, dom, dev_name, pci_devs):
- dev_model = DeviceModel(conn=self.conn)
try:
- dev_model.lookup(dev_name)
+ self.dev_model.lookup(dev_name)
except NotFoundError:
return
--
2.7.4
More information about the Kimchi-devel
mailing list