All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Pavel Fedin <p.fedin@samsung.com>
Cc: "'Paolo Bonzini'" <pbonzini@redhat.com>,
	"'QEMU Developers'" <qemu-devel@nongnu.org>,
	"'Markus Armbruster'" <armbru@redhat.com>,
	"'Andreas Färber'" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH] Do not use slow [*] expansion for GPIO creation
Date: Wed, 29 Jul 2015 14:34:59 +0100	[thread overview]
Message-ID: <20150729133459.GE16847@redhat.com> (raw)
In-Reply-To: <019001d0c9fd$d3268410$79738c30$@samsung.com>

On Wed, Jul 29, 2015 at 03:55:14PM +0300, Pavel Fedin wrote:
> Expansion of [*] suffix is very slow because index expansion is done using
> trial and error strategy, starting every time from zero and retrying with
> the next index until insertion succeeds. With large number of already added
> properties this process takes huge amount of time (O(n^2) complexity).
> 
> Some architectures (like ARM) use very large amount of IRQ pins in interrupt
> controller models. This flaw makes machine startup extremely slow
> (~20 seconds for ARM64 with 32 CPUs. This patch decreases this time down to
> ~10 seconds.
> 
> Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
> ---
>  hw/core/qdev.c | 29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index b2f404a..d285784 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -25,6 +25,8 @@
>     inherit from a particular bus (e.g. PCI or I2C) rather than
>     this API directly.  */
>  
> +#include <glib/gprintf.h>
> +
>  #include "hw/qdev.h"
>  #include "hw/fw-path-provider.h"
>  #include "sysemu/sysemu.h"
> @@ -415,15 +417,24 @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
>  void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler,
>                               const char *name, int n)
>  {
> -    int i;
> +    int i, l;
>      NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);
> -    char *propname = g_strdup_printf("%s[*]", name ? name : "unnamed-gpio-in");
> +    char *propname;
>  
>      assert(gpio_list->num_out == 0 || !name);
> +
> +    if (!name) {
> +        name = "unnamed-gpio-in";
> +    }
> +    l = strlen(name);
> +    propname = g_malloc(l + 13); /* 10 characters for UINT_MAX plus "[]" */
> +    memcpy(propname, name, l);

Please don't do manual string length calculations in combination with
unbounded sprintf calls. It is a recipe for future security bugs.

> +
>      gpio_list->in = qemu_extend_irqs(gpio_list->in, gpio_list->num_in, handler,
>                                       dev, n);
>  
>      for (i = gpio_list->num_in; i < gpio_list->num_in + n; i++) {
> +        g_sprintf(&propname[l], "[%u]", i);

Replace this with

    gchar *propname = g_strdup_printf("%s[%u]", name, i)

>          object_property_add_child(OBJECT(dev), propname,
>                                    OBJECT(gpio_list->in[i]), &error_abort);

    g_free(propname);

>      }
> @@ -440,14 +451,21 @@ void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
>  void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
>                                const char *name, int n)
>  {
> -    int i;
> +    int i, l;
>      NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);
> -    char *propname = g_strdup_printf("%s[*]", name ? name : "unnamed-gpio-out");
> +    char *propname;
>  
>      assert(gpio_list->num_in == 0 || !name);
> -    gpio_list->num_out += n;
> +
> +    if (!name) {
> +        name = "unnamed-gpio-out";
> +    }
> +    l = strlen(name);
> +    propname = g_malloc(l + 13); /* 10 characters for UINT_MAX plus "[]" */
> +    memcpy(propname, name, l);

Same again here.

>  
>      for (i = 0; i < n; ++i) {
> +        g_sprintf(&propname[l], "[%u]", gpio_list->num_out + i);
>          memset(&pins[i], 0, sizeof(*pins));
>          object_property_add_link(OBJECT(dev), propname, TYPE_IRQ,
>                                   (Object **)&pins[i],
> @@ -456,6 +474,7 @@ void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
>                                   &error_abort);
>      }
>      g_free(propname);
> +    gpio_list->num_out += n;
>  }

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2015-07-29 13:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29 12:55 [Qemu-devel] [PATCH] Do not use slow [*] expansion for GPIO creation Pavel Fedin
2015-07-29 13:34 ` Daniel P. Berrange [this message]
2015-07-29 14:08   ` Pavel Fedin
2015-07-29 14:13     ` Daniel P. Berrange

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=20150729133459.GE16847@redhat.com \
    --to=berrange@redhat.com \
    --cc=afaerber@suse.de \
    --cc=armbru@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.