From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuOv4-0005CN-IQ for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:05:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuOv1-0001wY-1D for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:05:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:60016) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuOv0-0001wR-NE for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:05:50 -0500 References: <1444739866-14798-1-git-send-email-berrange@redhat.com> <1444739866-14798-7-git-send-email-berrange@redhat.com> From: =?UTF-8?Q?Andreas_F=c3=a4rber?= Message-ID: <563B9A7C.4010000@suse.de> Date: Thu, 5 Nov 2015 19:05:48 +0100 MIME-Version: 1.0 In-Reply-To: <1444739866-14798-7-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 6/7] qom: replace object property list with GHashTable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org, Pavel Fedin , Markus Armbruster Cc: Paolo Bonzini Am 13.10.2015 um 14:37 schrieb Daniel P. Berrange: > From: Pavel Fedin >=20 > ARM GICv3 systems with large number of CPUs create lots of IRQ pins. Si= nce > every pin is represented as a property, number of these properties beco= mes > very large. Every property add first makes sure there's no duplicates. > Traversing the list becomes very slow, therefore qemu initialization ta= kes > significant time (several seconds for e. g. 16 CPUs). >=20 > This patch replaces list with GHashTable, making lookup very fast. The = only > drawback is that object_child_foreach() and object_child_foreach_recurs= ive() > cannot modify their objects during traversal, since GHashTableIter does= not > have modify-safe version. However, the code seems not to modify objects= via > these functions. "modify objects" seems a little misleading here; from what I see only adding or removing properties (including child<>s) is forbidden, right? Modifying one ObjectProperty or its value should still be okay. I believe that limitation is fine. >=20 > Signed-off-by: Daniel P. Berrange > Signed-off-by: Pavel Fedin > --- > include/qom/object.h | 10 ++++-- > qom/object.c | 98 ++++++++++++++++++++++++++++++--------------= -------- > 2 files changed, 64 insertions(+), 44 deletions(-) [...] > diff --git a/qom/object.c b/qom/object.c > index 7dace59..dd01652 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -68,7 +68,7 @@ struct TypeImpl > }; > =20 > struct ObjectPropertyIterator { > - ObjectProperty *next; > + GHashTableIter iter; > }; > =20 > static Type type_interface; > @@ -330,6 +330,16 @@ static void object_post_init_with_type(Object *obj= , TypeImpl *ti) > } > } > =20 > +static void property_free(gpointer data) Bikeshed: We might call this object_property_free() unless there's a precedence for property_...? > +{ > + ObjectProperty *prop =3D data; > + > + g_free(prop->name); > + g_free(prop->type); > + g_free(prop->description); > + g_free(prop); > +} > + > void object_initialize_with_type(void *data, size_t size, TypeImpl *ty= pe) > { > Object *obj =3D data; [...] > @@ -363,29 +374,35 @@ static inline bool object_property_is_child(Objec= tProperty *prop) > =20 > static void object_property_del_all(Object *obj) > { > - while (!QTAILQ_EMPTY(&obj->properties)) { > - ObjectProperty *prop =3D QTAILQ_FIRST(&obj->properties); > - > - QTAILQ_REMOVE(&obj->properties, prop, node); > + ObjectProperty *prop; > + GHashTableIter iter; > + gpointer key, value; > =20 > + g_hash_table_iter_init(&iter, obj->properties); > + while (g_hash_table_iter_next(&iter, &key, &value)) { > + prop =3D value; > if (prop->release) { > prop->release(obj, prop->name, prop->opaque); > } Why is this not in property_free(), too? Is there a timing difference? > - > - g_free(prop->name); > - g_free(prop->type); > - g_free(prop->description); > - g_free(prop); > } > + > + g_hash_table_unref(obj->properties); > } > =20 > static void object_property_del_child(Object *obj, Object *child, Erro= r **errp) > { > ObjectProperty *prop; > + GHashTableIter iter; > + gpointer key, value; > =20 > - QTAILQ_FOREACH(prop, &obj->properties, node) { > + g_hash_table_iter_init(&iter, obj->properties); > + while (g_hash_table_iter_next(&iter, &key, &value)) { > + prop =3D value; > if (object_property_is_child(prop) && prop->opaque =3D=3D chil= d) { > - object_property_del(obj, prop->name, errp); > + if (prop->release) { > + prop->release(obj, prop->name, prop->opaque); > + } Ditto? > + g_hash_table_iter_remove(&iter); > break; > } > } [...] > @@ -924,7 +940,7 @@ ObjectProperty *object_property_find(Object *obj, c= onst char *name, > ObjectPropertyIterator *object_property_iter_init(Object *obj) > { > ObjectPropertyIterator *ret =3D g_new0(ObjectPropertyIterator, 1); > - ret->next =3D QTAILQ_FIRST(&obj->properties); > + g_hash_table_iter_init(&ret->iter, obj->properties); > return ret; > } > =20 Is it intentional that our iterator pattern differs? > @@ -940,31 +956,27 @@ void object_property_iter_free(ObjectPropertyIter= ator *iter) > =20 > ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter= ) > { > - ObjectProperty *ret =3D iter->next; > - if (ret) { > - iter->next =3D QTAILQ_NEXT(iter->next, node); > + gpointer key, val; > + if (!g_hash_table_iter_next(&iter->iter, &key, &val)) { > + return NULL; > } > - return ret; > + return val; > } > =20 > =20 > void object_property_del(Object *obj, const char *name, Error **errp) > { > - ObjectProperty *prop =3D object_property_find(obj, name, errp); > - if (prop =3D=3D NULL) { > + ObjectProperty *prop =3D g_hash_table_lookup(obj->properties, name= ); > + > + if (!prop) { > + error_setg(errp, "Property '.%s' not found", name); Is this a behavioral change? > return; > } > =20 > if (prop->release) { > prop->release(obj, name, prop->opaque); > } property_free()? > - > - QTAILQ_REMOVE(&obj->properties, prop, node); > - > - g_free(prop->name); > - g_free(prop->type); > - g_free(prop->description); > - g_free(prop); > + g_hash_table_remove(obj->properties, name); > } > =20 > void object_property_get(Object *obj, Visitor *v, const char *name, > @@ -1484,11 +1496,13 @@ void object_property_add_const_link(Object *obj= , const char *name, > gchar *object_get_canonical_path_component(Object *obj) > { > ObjectProperty *prop =3D NULL; > + GHashTableIter iter; > =20 > g_assert(obj); > g_assert(obj->parent !=3D NULL); > =20 > - QTAILQ_FOREACH(prop, &obj->parent->properties, node) { > + g_hash_table_iter_init(&iter, obj->parent->properties); > + while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&prop)) { Is this cast needed? > if (!object_property_is_child(prop)) { > continue; > } > @@ -1572,11 +1586,13 @@ static Object *object_resolve_partial_path(Obje= ct *parent, > bool *ambiguous) > { > Object *obj; > + GHashTableIter iter; > ObjectProperty *prop; > =20 > obj =3D object_resolve_abs_path(parent, parts, typename, 0); > =20 > - QTAILQ_FOREACH(prop, &parent->properties, node) { > + g_hash_table_iter_init(&iter, parent->properties); > + while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&prop)) { Ditto? > Object *found; > =20 > if (!object_property_is_child(prop)) { Otherwise looks very good, but third pair of eyes appreciated (Markus?). Regards, Andreas --=20 SUSE Linux GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Felix Imend=F6rffer, Jane Smithard, Graham Norton; HRB 21284 (AG N=FC= rnberg)