Received: from eggs.gnu.org ([2001:4830:134:3::10]:53747)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from
) id 1ZKQtM-0003zE-8f
for qemu-devel@nongnu.org; Wed, 29 Jul 2015 08:55:29 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1ZKQtI-0003Rs-39
for qemu-devel@nongnu.org; Wed, 29 Jul 2015 08:55:28 -0400
Received: from mailout1.w1.samsung.com ([210.118.77.11]:30477)
by eggs.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1ZKQtH-0003RM-TI
for qemu-devel@nongnu.org; Wed, 29 Jul 2015 08:55:24 -0400
Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245])
by mailout1.w1.samsung.com
(Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5
2014)) with ESMTP id <0NS9002AO2K8I760@mailout1.w1.samsung.com> for
qemu-devel@nongnu.org; Wed, 29 Jul 2015 13:55:20 +0100 (BST)
From: Pavel Fedin
Date: Wed, 29 Jul 2015 15:55:14 +0300
Message-id: <019001d0c9fd$d3268410$79738c30$@samsung.com>
MIME-version: 1.0
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: 7bit
Content-language: ru
Subject: [Qemu-devel] [PATCH] Do not use slow [*] expansion for GPIO creation
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: 'QEMU Developers'
Cc: 'Paolo Bonzini' , =?ISO-8859-1?Q?'Andreas_F=E4rber'?= , 'Markus Armbruster'
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
---
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
+
#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);
+
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);
object_property_add_child(OBJECT(dev), propname,
OBJECT(gpio_list->in[i]), &error_abort);
}
@@ -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);
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;
}
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
--
1.9.5.msysgit.0