Skip to content

Commit

Permalink
qcontainer.py: add new support to the parameter
Browse files Browse the repository at this point in the history
qemu_vm.py: add new support to the parameter
vt_iothread.py: add new support to the parameter

Add new support to the parameter: iothread_scheme.

Signed-off-by: Houqi (Nick) Zuo <[email protected]>
  • Loading branch information
nickzhq committed Oct 25, 2023
1 parent 50e0894 commit 2eec422
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
36 changes: 32 additions & 4 deletions virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ def get_qmp_cmds(qemu_binary, workaround_qemu_qmp_crash=False):
self.__iothread_manager = None
self.__iothread_supported_devices = set()
self.temporary_image_snapshots = set()
self.iothread_scheme = None
self.iothreads_length = None

@property
def qemu_version(self):
Expand All @@ -196,11 +198,34 @@ def initialize_iothread_manager(self, params, guestcpuinfo,
"""
iothreads_lst = params.objects("iothreads")
iothread_scheme = params.get("iothread_scheme")
iothread_vqs_mapping = params.get("iothread_vqs_mapping", "")

if iothread_scheme == "oto":
iothreads_lst = []
elif iothread_scheme == "rhv":
iothreads_lst = iothreads_lst[:1] or ["iothread0"]
if ":" not in iothread_scheme:
"""
The legacy 'iothread_scheme' does NOT support the
parameter 'iothread_vqs_mapping'. If you're going to use the legacy
'iothread_scheme', the 'iothread_vqs_mapping' must be set to None.
"""
if not iothread_vqs_mapping:
if iothread_scheme == "oto":
iothreads_lst = []
elif iothread_scheme == "rhv":
iothreads_lst = iothreads_lst[:1] or ["iothread0"]
elif ":" in iothread_scheme and not iothread_vqs_mapping:
iothread_scheme, num_iothreads = iothread_scheme.split(":")
num_iothreads = int(num_iothreads)
self.iothreads_length = num_iothreads
# todo: check nr_iothreads?
if len(iothreads_lst) > num_iothreads:
raise ValueError("The quantities of 'iothreads' are less than"
"the quantities parsed from 'iothread_scheme'")
if iothread_scheme in ("roundrobin", "full"):
iothread_scheme = iothread_scheme.replace("roundrobin",
"new_roundrobin")
else:
raise ValueError("There's a conflict in the configuration! Please "
"check the 'iothread_scheme' and "
"'iothread_vqs_mapping'.")

iothread_props = {"iothread_poll_max_ns": "poll-max-ns"}
iothreads = []
Expand All @@ -220,10 +245,13 @@ def initialize_iothread_manager(self, params, guestcpuinfo,
"roundrobin": vt_iothread.RoundRobinManager,
"oto": vt_iothread.OTOManager,
"rhv": vt_iothread.RoundRobinManager,
"new_roundrobin": vt_iothread.NewRoundRobinManager,
"full": vt_iothread.FullManager
}
manager = scheme_to_manager.get(iothread_scheme,
vt_iothread.PredefinedManager)

self.iothread_scheme = iothread_scheme
self.insert(iothreads)

self.__iothread_manager = manager(iothreads)
Expand Down
26 changes: 26 additions & 0 deletions virttest/qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,7 @@ def add_secure_guest_descriptor(params):
"images")
devices.insert(dev)

image_dev = [] # record the all related image devices
# Add images (harddrives)
for image_name in params.objects("images"):
# FIXME: Use qemu_devices for handling indexes
Expand Down Expand Up @@ -2310,6 +2311,31 @@ def add_secure_guest_descriptor(params):
set_cmdline_format_by_cfg(_, self._get_cmdline_format_cfg(),
"images")
devices.insert(_)
image_dev.append(_)
# Fixme: Here's a workaround solution about allocating the iothreads.
# Due to adapting the new roundrobin( or full ) iothread scheme,
# allocating the iothread has to execute after all the related
# image devices are created completely.
if devices.iothread_scheme in ("new_roundrobin", ):
i = 0
while i < devices.iothreads_length:
for dev in image_dev:
if "pci" in dev.get_param("driver", ""):
iothread = dev.get_param("iothread_vqs_mapping", "")
iothread_obj = devices.allocate_iothread(None, dev)
if iothread_obj:
iothread += iothread_obj.get_aid() + " "
dev.set_param("iothread_vqs_mapping", iothread)
i += 1
elif devices.iothread_scheme in ("full", ):
for dev in image_dev:
if "pci" in dev.get_param("driver", ""):
iothread = ""
iothread_list = devices.allocate_iothread(None, dev)
if iothread_list:
iothread_list = [_.get_aid() for _ in iothread_list]
iothread = " ".join(iothread_list)
dev.set_param("iothread_vqs_mapping", iothread)

# Add filesystems
for fs_name in params.objects("filesystems"):
Expand Down
54 changes: 54 additions & 0 deletions virttest/vt_iothread.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,57 @@ def request_iothread(self, iothread):
return iothread
else:
raise ValueError("Not support request specific iothread")


class NewRoundRobinManager(IOThreadManagerBase):
"""Dispatch iothread object in new round-robin way."""
def __init__(self, iothreads=None):
"""
Initialize iothread manager.
:param iothreads: list of iothread objects, its id must conform with
ID_PATTERN.
:type iothreads: List
"""
super().__init__(iothreads)
self.__length = len(iothreads)
self.__current_index = 0

def request_iothread(self, iothread=None):
"""Return iothread.
:param iothread: iothread specified. In this function, the variable is
NOT used.
:type iothread: QIOThread
:return: iothread.
:rtype: QIOThread
"""
iothread_aid = self.ID_PATTERN % (self.__current_index % self.__length)
iothread = self.find_iothread(iothread_aid)
self.__current_index += 1
return iothread


class FullManager(IOThreadManagerBase):
"""Dispatch all iothread objects to an image device."""
def __init__(self, iothreads=None):
"""
Initialize iothread manager.
:param iothreads: list of iothread objects, its id must conform with
ID_PATTERN.
:type iothreads: List
"""
super().__init__(iothreads)
self.__iothreads_list = iothreads

def request_iothread(self, iothread=None):
"""Return iothreads.
:param iothread: iothread specified. In this function, the variable is
NOT used.
:type iothread: QIOThread
:return: the list of the iothreads.
:rtype: List
"""
return self.__iothreads_list

0 comments on commit 2eec422

Please sign in to comment.