From fcc326fafbd84812af6231cd1ae23a3bfaa44246 Mon Sep 17 00:00:00 2001 From: mcasquer Date: Mon, 24 Jul 2023 09:43:40 +0200 Subject: [PATCH] thread-context: support new object thread-context Includes support in avocado-vt for a new object: thread-context. The intention of this new object is to be used to make NUMA aware of the memory preallocation threads. Signed-off-by: mcasquer --- virttest/qemu_devices/qcontainer.py | 15 +++++++++++++++ virttest/qemu_devices/qdevices.py | 17 +++++++++++++++++ virttest/qemu_vm.py | 12 ++++++++++++ 3 files changed, 44 insertions(+) diff --git a/virttest/qemu_devices/qcontainer.py b/virttest/qemu_devices/qcontainer.py index c9e21b6660a..4fb56b376e4 100644 --- a/virttest/qemu_devices/qcontainer.py +++ b/virttest/qemu_devices/qcontainer.py @@ -2896,6 +2896,21 @@ def throttle_group_define_by_params(self, group_params, name): props = json.loads(group_params.get("throttle_group_parameters", "{}")) return QThrottleGroup(name, props) + def thread_context_define_by_params(self, params, name): + """ + Create thread-context object from params. + """ + tc_params = Params() + prefix = 'thread_context_' + for key in list(params.keys()): + if key.startswith(prefix): + new_key = key.rsplit(prefix)[1] + tc_params[new_key] = params[key] + backend = "thread-context" + dev = qdevices.ThreadContext(backend, params=tc_params) + dev.set_param("id", "%s-%s" % ("thread_context", name)) + return dev + def memory_object_define_by_params(self, params, name): """ Create memory object from params, default backend type is diff --git a/virttest/qemu_devices/qdevices.py b/virttest/qemu_devices/qdevices.py index 4c0aa4193aa..c149a813c1d 100644 --- a/virttest/qemu_devices/qdevices.py +++ b/virttest/qemu_devices/qdevices.py @@ -1528,6 +1528,23 @@ def verify_unplug(self, out, monitor): return not self._query(monitor) +class ThreadContext(QObject): + """ + thread-context object. + """ + + def __init__(self, backend, params=None): + super(ThreadContext, self).__init__(backend, params) + + def verify_hotplug(self, monitor): + """Verify if it is plugged into VM.""" + return self._query(monitor) + + def verify_unplug(self, monitor): + """Verify if it is unplugged from VM.""" + return not self._query(monitor) + + class Memory(QObject): """ diff --git a/virttest/qemu_vm.py b/virttest/qemu_vm.py index 7396174c8c2..92495032cf0 100644 --- a/virttest/qemu_vm.py +++ b/virttest/qemu_vm.py @@ -1252,6 +1252,15 @@ def set_value(opt_string, key, fallback=None): return secret_cmdline + " -spice %s" % (",".join(spice_opts)) + def add_thread_context(devices, params): + for thread_context in params.objects("vm_thread_contexts"): + thread_context_params = params.object_params(thread_context) + dev = devices.thread_context_define_by_params(thread_context_params, thread_context) + set_cmdline_format_by_cfg(dev, self._get_cmdline_format_cfg(), + "vm_thread_contexts") + devices.insert(dev) + return devices + def add_qxl(qxl_nr, base_addr=29): """ adds extra qxl devices @@ -1766,6 +1775,9 @@ def add_secure_guest_descriptor(params): add_memorys(devices, params) mem = int(params.get("mem", 0)) + # Add thread context object + add_thread_context(devices, params) + # Get cpu model, before add smp, to determine cpu topology cpu_model = params.get("cpu_model", "") use_default_cpu_model = True