fast qom tree get
v5 cover fast qom tree get
Using qom-list and qom-get to get all the nodes and property values in a QOM tree can take multiple seconds because it requires 1000's of individual QOM requests. Some managers fetch the entire tree or a large subset of it when starting a new VM, and this cost is a substantial fraction of start up time.
To reduce this cost, consider QAPI calls that fetch more information in each call:
* qom-list-get-one: given a path, return a list of properties and values.
* qom-list-get: given a list of paths, return a list of properties and values for each path.
* qom-tree-get: given a path, return all descendant nodes rooted at that path, with properties and values for each.
In all cases, a returned property is represented by ObjectPropertyValue, with fields name, type, and value. If an error occurs when reading a value the value field is omitted. Thus an error for one property will not cause a bulk fetch operation to fail.
To evaluate each method, I modified scripts/qmp/qom-tree to use the method, verified all methods produce the same output, and timed each using:
qemu-system-x86_64 -display none \
-chardev socket,id=monitor0,path=/tmp/vm1.sock,server=on,wait=off \
-mon monitor0,mode=control & time qom-tree -s /tmp/vm1.sock > /dev/null
I only measured once per method, but the variation is low after a warm up run. The 'real - user - sys' column is a proxy for QEMU CPU time.
method real(s) user(s) sys(s) (real - user - sys)(s) qom-list / qom-get 2.048 0.932 0.057 1.059 qom-list-get-one 0.402 0.230 0.029 0.143 qom-list-get 0.200 0.132 0.015 0.053 qom-tree-get 0.143 0.123 0.012 0.008
qom-tree-get is the fastest, reducing elapsed time by a factor of 14X, and reducing QEMU CPU time by 132X.
qom-list-get is slower when fetching the entire tree, but can beat qom-tree-get when only a subset of the tree needs to be fetched (not shown). To keep things simple, provide only qom-list-get.
Changes in V5:
* tweaked the commit messages
* tweaked the doc
* added RBs etc
Changes in V4:
* renamed qom-list-getv -> qom-list-get
* expanded the qtest to verify a value
* cosmetic changes in the docs
* expanded the qom-list-get commit message
Changes in V3:
* dropped qom-tree-get
* modified the qom-tree script to use qom-list-getv
* cosmetic changes in the docs and code.
Changes in V2:
* removed "qom: qom_resolve_path", which was pulled separately
* dropped the error member
* fixed missing _list_tree in qom.py
* updated 10.0 to 10.1
Steve Sistare (3):
qom: qom-list-get
python: use qom-list-get tests/qtest/qom-test: unit test for qom-list-get
python/qemu/utils/qom.py | 43 ++++++++------- python/qemu/utils/qom_common.py | 53 ++++++++++++++++++ qapi/qom.json | 50 +++++++++++++++++ qom/qom-qmp-cmds.c | 53 ++++++++++++++++++ tests/qtest/qom-test.c | 116 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 296 insertions(+), 19 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v5 1/3 qom: qom-list-get
Using qom-list and qom-get to get all the nodes and property values in a QOM tree can take multiple seconds because it requires 1000's of individual QOM requests. Some managers fetch the entire tree or a large subset of it when starting a new VM, and this cost is a substantial fraction of start up time.
Define the qom-list-get command, which fetches all the properties and values for a list of paths. This can be much faster than qom-list plus qom-get. When getting an entire QOM tree, I measured a 10x speedup in elapsed time.
--- qapi/qom.json | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ qom/qom-qmp-cmds.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+)
qapi/qom.json +50 -0
@@ -46,6 +46,34 @@ '*default-value': 'any' } } ## +# @ObjectPropertyValue: +# +# @name: the name of the property. +# +# @type: the type of the property, as described in `ObjectPropertyInfo`. +# +# @value: the value of the property. Absent when the property cannot +# be read. +# +# Since 10.1 +## +{ 'struct': 'ObjectPropertyValue', + 'data': { 'name': 'str', + 'type': 'str', + '*value': 'any' } } + +## +# @ObjectPropertiesValues: +# +# @properties: a list of properties. +# +# Since 10.1 +## +{ 'struct': 'ObjectPropertiesValues', + 'data': { 'properties': [ 'ObjectPropertyValue' ] }} + + +## # @qom-list: # # This command will list any properties of a object given a path in
@@ -126,6 +154,28 @@ 'allow-preconfig': true } ## +# @qom-list-get: +# +# List properties and their values for each object path in the input +# list. +# +# @paths: The absolute or partial path for each object, as described +# in `qom-get`. +# +# Errors: +# - If any path is not valid or is ambiguous +# +# Returns: A list where each element is the result for the +# corresponding element of @paths. +# +# Since 10.1 +## +{ 'command': 'qom-list-get', + 'data': { 'paths': [ 'str' ] }, + 'returns': [ 'ObjectPropertiesValues' ], + 'allow-preconfig': true } + +## # @qom-set: # # This command will set a property from a object model path.
qom/qom-qmp-cmds.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 2/3 python: use qom-list-get
In reply to Steve SistareUse qom-list-get to speed up the qom-tree command.
--- python/qemu/utils/qom.py | 43 +++++++++++++++++++-------------- python/qemu/utils/qom_common.py | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 18 deletions(-)
python/qemu/utils/qom.py +25 -18
@@ -224,28 +224,35 @@ def __init__(self, args: argparse.Namespace): super().__init__(args) self.path = args.path - def _list_node(self, path: str) -> None: - print(path) - items = self.qom_list(path) - for item in items: - if item.child: - continue - try: - rsp = self.qmp.cmd('qom-get', path=path, - property=item.name) - print(f" {item.name}: {rsp} ({item.type})") - except ExecuteError as err: - print(f" {item.name}: <EXCEPTION: {err!s}> ({item.type})") - print('') - for item in items: - if not item.child: - continue + def _list_nodes(self, paths: [str]) -> None: + all_paths_props = self.qom_list_get(paths) + i = 0 + + for props in all_paths_props: + path = paths[i] + i = i + 1 + print(path) if path == '/': path = '' - self._list_node(f"{path}/{item.name}") + newpaths = [] + + for item in props.properties: + if item.child: + newpaths += [ f"{path}/{item.name}" ] + else: + value = item.value + if value == None: + value = f"<EXCEPTION: property could not be read>" + print(f" {item.name}: {value} ({item.type})") + + print('') + + if newpaths: + self._list_nodes(newpaths) + def run(self) -> int: - self._list_node(self.path) + self._list_nodes([self.path]) return 0
python/qemu/utils/qom_common.py +53 -0
65 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 3/3 tests/qtest/qom-test: unit test for qom-list-get
In reply to Steve SistareAdd a unit test for qom-list-get.
--- tests/qtest/qom-test.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-)
tests/qtest/qom-test.c +115 -1
@@ -11,11 +11,119 @@#include "qobject/qdict.h" #include "qobject/qlist.h" +#include "qobject/qstring.h" #include "qemu/cutils.h" #include "libqtest.h" +#define RAM_NAME "node0" +#define RAM_SIZE 65536 +static int verbosity_level; +/* +* Verify that the /object/RAM_NAME 'size' property is RAM_SIZE. +*/ +static void test_list_get_value (QTestState *qts) +{ +QDict *args =qdict_new (); +g_autoptr (QDict) response =NULL ; +g_autoptr (QList) paths =qlist_new (); +QListEntry *entry, *prop_entry; +const char *prop_name; +QList *properties, *return_list; +QDict *obj; + +qlist_append_str (paths,"/objects/" RAM_NAME ); +qdict_put_obj (args,"paths" ,QOBJECT (qlist_copy (paths))); + response =qtest_qmp (qts,"{ 'execute': 'qom-list-get'," +" 'arguments': %p }" , args); +g_assert (response); +g_assert (qdict_haskey (response,"return" )); + return_list =qobject_to (QList,qdict_get (response,"return" )); + + entry =QTAILQ_FIRST (&return_list->head); + obj =qobject_to (QDict,qlist_entry_obj (entry)); +g_assert (qdict_haskey (obj,"properties" )); + properties =qobject_to (QList,qdict_get (obj,"properties" )); + + QLIST_FOREACH_ENTRY(properties, prop_entry) { +QDict *prop =qobject_to (QDict,qlist_entry_obj (prop_entry)); + +g_assert (qdict_haskey (prop,"name" )); +g_assert (qdict_haskey (prop,"value" )); + + prop_name =qdict_get_str (prop,"name" ); +if (!strcmp (prop_name,"type" )) { + g_assert_cmpstr(qdict_get_str(prop, "value"), ==, +"memory-backend-ram" ); + + }else if (!strcmp (prop_name,"size" )) { + g_assert_cmpint(qdict_get_int(prop, "value"), ==, RAM_SIZE); + } + } +} + +static void test_list_get (QTestState *qts,QList *paths) +{ +QListEntry *entry, *prop_entry, *path_entry; +g_autoptr (QDict) response =NULL ; +QDict *args =qdict_new (); +QDict *prop; +QList *return_list; + +if (verbosity_level >=2 ) { +g_test_message ("Obtaining properties for paths:" ); + QLIST_FOREACH_ENTRY(paths, path_entry) { +QString *qstr =qobject_to (QString,qlist_entry_obj (path_entry)); +g_test_message (" %s" ,qstring_get_str (qstr)); + } + } + +qdict_put_obj (args,"paths" ,QOBJECT (qlist_copy (paths))); + response =qtest_qmp (qts,"{ 'execute': 'qom-list-get'," +" 'arguments': %p }" , args); +g_assert (response); +g_assert (qdict_haskey (response,"return" )); + return_list =qobject_to (QList,qdict_get (response,"return" )); +g_assert (!qlist_empty (return_list)); + + path_entry =QTAILQ_FIRST (&paths->head); + QLIST_FOREACH_ENTRY(return_list, entry) { +QDict *obj =qobject_to (QDict,qlist_entry_obj (entry)); +g_assert (qdict_haskey (obj,"properties" )); +QList *properties =qobject_to (QList,qdict_get (obj,"properties" )); +bool has_child = false; + + QLIST_FOREACH_ENTRY(properties, prop_entry) { + prop =qobject_to (QDict,qlist_entry_obj (prop_entry)); +g_assert (qdict_haskey (prop,"name" )); +g_assert (qdict_haskey (prop,"type" )); + has_child |=strstart (qdict_get_str (prop,"type" ),"child<" ,NULL ); + } + +if (has_child) { +/* build a list of child paths */ +QString *qstr =qobject_to (QString,qlist_entry_obj (path_entry)); +const char *path =qstring_get_str (qstr); +g_autoptr (QList) child_paths =qlist_new (); + + QLIST_FOREACH_ENTRY(properties, prop_entry) { + prop =qobject_to (QDict,qlist_entry_obj (prop_entry)); +if (strstart (qdict_get_str (prop,"type" ),"child<" ,NULL )) { + g_autofree char *child_path = g_strdup_printf( +"%s/%s" , path,qdict_get_str (prop,"name" )); +qlist_append_str (child_paths, child_path); + } + } + +/* fetch props for all children with one qom-list-get call */ +test_list_get (qts, child_paths); + } + + path_entry =QTAILQ_NEXT (path_entry, next); + } +} +static void test_properties (QTestState *qts,const char *path,bool recurse) {char *child_path;
@@ -85,8 +193,10 @@ static void test_machine(gconstpointer data)const char *machine = data;QDict *response;QTestState *qts; +g_autoptr (QList) paths =qlist_new (); - qts =qtest_initf ("-machine %s" , machine); + qts =qtest_initf ("-machine %s -object memory-backend-ram,id=%s,size=%d" , + machine,RAM_NAME ,RAM_SIZE );if (g_test_slow ()) {/* Make sure we can get the machine class properties: */
@@ -101,6 +211,10 @@ static void test_machine(gconstpointer data)test_properties (qts,"/machine" , true); +qlist_append_str (paths,"/machine" ); +test_list_get (qts, paths); +test_list_get_value (qts); + response =qtest_qmp (qts,"{ 'execute': 'quit' }" );g_assert (qdict_haskey (response,"return" ));qobject_unref (response);
Signature · 1 line
1.8.3.1
Markus Armbruster
AppliedQuoted 5 lines · Steve Sistare
Using qom-list and qom-get to get all the nodes and property values in a QOM tree can take multiple seconds because it requires 1000's of individual QOM requests. Some managers fetch the entire tree or a large subset of it when starting a new VM, and this cost is a substantial fraction of start up time.
[...]
Queued for 10.1. Thanks!