All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: "Daniel P. Berrange" <berrange@redhat.com>,
	qemu-devel@nongnu.org, Pavel Fedin <p.fedin@samsung.com>,
	Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 6/7] qom: replace object property list with GHashTable
Date: Thu, 5 Nov 2015 19:05:48 +0100	[thread overview]
Message-ID: <563B9A7C.4010000@suse.de> (raw)
In-Reply-To: <1444739866-14798-7-git-send-email-berrange@redhat.com>

Am 13.10.2015 um 14:37 schrieb Daniel P. Berrange:
> From: Pavel Fedin <p.fedin@samsung.com>
> 
> ARM GICv3 systems with large number of CPUs create lots of IRQ pins. Since
> every pin is represented as a property, number of these properties becomes
> very large. Every property add first makes sure there's no duplicates.
> Traversing the list becomes very slow, therefore qemu initialization takes
> significant time (several seconds for e. g. 16 CPUs).
> 
> This patch replaces list with GHashTable, making lookup very fast. The only
> drawback is that object_child_foreach() and object_child_foreach_recursive()
> 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.

> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
> ---
>  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
>  };
>  
>  struct ObjectPropertyIterator {
> -    ObjectProperty *next;
> +    GHashTableIter iter;
>  };
>  
>  static Type type_interface;
> @@ -330,6 +330,16 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti)
>      }
>  }
>  
> +static void property_free(gpointer data)

Bikeshed: We might call this object_property_free() unless there's a
precedence for property_...?

> +{
> +    ObjectProperty *prop = 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 *type)
>  {
>      Object *obj = data;
[...]
> @@ -363,29 +374,35 @@ static inline bool object_property_is_child(ObjectProperty *prop)
>  
>  static void object_property_del_all(Object *obj)
>  {
> -    while (!QTAILQ_EMPTY(&obj->properties)) {
> -        ObjectProperty *prop = QTAILQ_FIRST(&obj->properties);
> -
> -        QTAILQ_REMOVE(&obj->properties, prop, node);
> +    ObjectProperty *prop;
> +    GHashTableIter iter;
> +    gpointer key, value;
>  
> +    g_hash_table_iter_init(&iter, obj->properties);
> +    while (g_hash_table_iter_next(&iter, &key, &value)) {
> +        prop = 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);
>  }
>  
>  static void object_property_del_child(Object *obj, Object *child, Error **errp)
>  {
>      ObjectProperty *prop;
> +    GHashTableIter iter;
> +    gpointer key, value;
>  
> -    QTAILQ_FOREACH(prop, &obj->properties, node) {
> +    g_hash_table_iter_init(&iter, obj->properties);
> +    while (g_hash_table_iter_next(&iter, &key, &value)) {
> +        prop = value;
>          if (object_property_is_child(prop) && prop->opaque == child) {
> -            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, const char *name,
>  ObjectPropertyIterator *object_property_iter_init(Object *obj)
>  {
>      ObjectPropertyIterator *ret = g_new0(ObjectPropertyIterator, 1);
> -    ret->next = QTAILQ_FIRST(&obj->properties);
> +    g_hash_table_iter_init(&ret->iter, obj->properties);
>      return ret;
>  }
>  

Is it intentional that our iterator pattern differs?

> @@ -940,31 +956,27 @@ void object_property_iter_free(ObjectPropertyIterator *iter)
>  
>  ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter)
>  {
> -    ObjectProperty *ret = iter->next;
> -    if (ret) {
> -        iter->next = QTAILQ_NEXT(iter->next, node);
> +    gpointer key, val;
> +    if (!g_hash_table_iter_next(&iter->iter, &key, &val)) {
> +        return NULL;
>      }
> -    return ret;
> +    return val;
>  }
>  
>  
>  void object_property_del(Object *obj, const char *name, Error **errp)
>  {
> -    ObjectProperty *prop = object_property_find(obj, name, errp);
> -    if (prop == NULL) {
> +    ObjectProperty *prop = g_hash_table_lookup(obj->properties, name);
> +
> +    if (!prop) {
> +        error_setg(errp, "Property '.%s' not found", name);

Is this a behavioral change?

>          return;
>      }
>  
>      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);
>  }
>  
>  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 = NULL;
> +    GHashTableIter iter;
>  
>      g_assert(obj);
>      g_assert(obj->parent != NULL);
>  
> -    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(Object *parent,
>                                                bool *ambiguous)
>  {
>      Object *obj;
> +    GHashTableIter iter;
>      ObjectProperty *prop;
>  
>      obj = object_resolve_abs_path(parent, parts, typename, 0);
>  
> -    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;
>  
>          if (!object_property_is_child(prop)) {

Otherwise looks very good, but third pair of eyes appreciated (Markus?).

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)

  reply	other threads:[~2015-11-05 18:05 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-13 12:37 [Qemu-devel] [PATCH v4 0/7] qom: more efficient object property handling Daniel P. Berrange
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 1/7] qom: introduce ObjectPropertyIterator struct for iteration Daniel P. Berrange
2015-11-05 16:59   ` Andreas Färber
2015-11-17 15:25   ` Markus Armbruster
2015-11-17 15:27     ` Daniel P. Berrange
2015-11-17 15:35       ` Markus Armbruster
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 2/7] qmp: convert QMP code to use object property iterators Daniel P. Berrange
2015-11-05 17:08   ` Andreas Färber
2015-11-17 15:26     ` Markus Armbruster
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 3/7] vl: convert machine help " Daniel P. Berrange
2015-11-05 17:10   ` Andreas Färber
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 4/7] ppc: convert spapr " Daniel P. Berrange
2015-11-05 17:16   ` Andreas Färber
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 5/7] net: convert net filter " Daniel P. Berrange
2015-11-05 17:18   ` Andreas Färber
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 6/7] qom: replace object property list with GHashTable Daniel P. Berrange
2015-11-05 18:05   ` Andreas Färber [this message]
2015-11-06  9:02     ` Pavel Fedin
2015-11-06  9:31     ` Daniel P. Berrange
2015-11-06  9:37       ` Pavel Fedin
2015-11-13 18:14   ` Andreas Färber
2015-11-13 21:00     ` Christian Borntraeger
2015-11-13 21:25       ` Andreas Färber
2015-11-16  7:13         ` Pavel Fedin
2015-11-16  8:16           ` Christian Borntraeger
2015-11-16  9:38             ` Andreas Färber
2015-11-16 10:31               ` Pavel Fedin
2015-11-16 16:44               ` Andreas Färber
2015-11-16 16:53                 ` Daniel P. Berrange
2015-11-16  8:53         ` Paolo Bonzini
2015-11-16  9:48           ` Andreas Färber
2015-11-16  9:50             ` Paolo Bonzini
2015-11-16 11:35       ` Daniel P. Berrange
2015-10-13 12:37 ` [Qemu-devel] [PATCH v4 7/7] qom: allow properties to be registered against classes Daniel P. Berrange
2015-10-13 13:18   ` Pavel Fedin
2015-11-05 18:12     ` Andreas Färber
2015-11-06  9:32       ` Daniel P. Berrange
2015-11-18 23:35         ` Andreas Färber
2015-10-13 12:54 ` [Qemu-devel] [PATCH v4 0/7] qom: more efficient object property handling Andreas Färber
2015-10-13 12:59   ` Daniel P. Berrange
2015-10-14  6:57 ` Pavel Fedin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=563B9A7C.4010000@suse.de \
    --to=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=p.fedin@samsung.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.