Skip to content

Commit

Permalink
vt_iothread: New class added
Browse files Browse the repository at this point in the history
Add new support to the parameter: iothread_scheme.

Signed-off-by: Houqi (Nick) Zuo <[email protected]>
  • Loading branch information
nickzhq committed Mar 13, 2024
1 parent 2817f63 commit aecfa14
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions virttest/vt_iothread.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,82 @@ def request_iothread(self, iothread):
return iothread
else:
raise ValueError("Not support request specific iothread")


class MultiPeerRoundRobinManager(IOThreadManagerBase):
"""
Dispatch iothread object in new round-robin way.
Each iothreads will be allocated in round-robin way to the images.
"""

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) if iothreads else 0
self.__current_index = 0
self.__pci_dev_iothread_vq_mapping = {}

@property
def pci_dev_iothread_vq_mapping(self):
return self.__pci_dev_iothread_vq_mapping

@pci_dev_iothread_vq_mapping.setter
def pci_dev_iothread_vq_mapping(self, mapping):
"""
Set the self.__pci_dev_iothread_vq_mapping
:param mapping:
:type mapping: dict, {string: iothread instance}
"""
for key, val in mapping.items():
if key in self.__pci_dev_iothread_vq_mapping:
self.__pci_dev_iothread_vq_mapping[key].append(val)
else:
self.__pci_dev_iothread_vq_mapping[key] = [val]

def request_iothread(self, iothread):
"""Return iothread.
:param iothread: iothread.
:type iothread: QIOThread
:return: iothread.
:rtype: QIOThread
"""
if iothread == "AUTO" or iothread == "auto":
iothread_aid = self.ID_PATTERN % (self.__current_index % self.__length)
iothread = self.find_iothread(iothread_aid)
self.__current_index += 1
return iothread
raise ValueError("Not support request specific 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):
"""Return iothreads.
:param iothread: iothread.
:type iothread: QIOThread
:return: the list of the iothreads.
:rtype: List
"""
if iothread == "AUTO" or iothread == "auto":
return self.__iothreads_list
raise ValueError("Not support request specific iothread!")

0 comments on commit aecfa14

Please sign in to comment.