All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code
@ 2014-08-29 20:31 Eduardo Habkost
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix Eduardo Habkost
                   ` (17 more replies)
  0 siblings, 18 replies; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

This is an attempt to convert the accel initialization and registration code
to be QOM-based. Some use cases for this are:

 * Isolating KVM-specific CPU initialization and compatibility code;
 * Use compat_props to implement accelrator-specific compatibility code
   on machine-types;
 * Returning accelerator-specific information on the "query-cpu-definitions"
   QMP command (e.g. "runnable" information; CPU features).

Changes v1 -> v2:
 * Remove the TYPE_X86_ACCEL interface and KVM-specific changes, by now
   (they will be submitted later).
 * Introduce ACCEL_CLASS_NAME(s) macro.

Cc: Michael Mueller <mimu@linux.vnet.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Andreas Färber <afaerber@suse.de>
Cc: Marcel Apfelbaum <marcel.a@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>

Eduardo Habkost (17):
  vl.c: Small coding style fix
  accel: Move accel code to accel.c
  accel: Create AccelType typedef
  accel: Simplify configure_accelerator() using AccelType *acc variable
  accel: Move accel name lookup to separate function
  accel: Use QOM classes for accel types
  accel: Make AccelClass.available() optional
  accel: Move KVM accel registration to kvm-all.c
  accel: Move Xen registration code to xen-common.c
  accel: Move qtest accel registration to qtest.c
  accel: Remove tcg_available() function
  accel: Move accel init/allowed code to separate function
  accel: Rename 'init' method to 'init_machine'
  accel: Pass MachineState object to accel init functions
  accel: Create accel object when initializing machine
  accel: Save AccelState on MachineState when initializing
  kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

 arch_init.c                |   5 --
 hw/core/Makefile.objs      |   1 +
 hw/core/accel.c            | 157 +++++++++++++++++++++++++++++++++++++++++++++
 include/hw/accel.h         |  62 ++++++++++++++++++
 include/hw/boards.h        |   1 +
 include/hw/xen/xen.h       |   1 -
 include/qemu/typedefs.h    |   3 +
 include/sysemu/arch_init.h |   1 -
 include/sysemu/kvm.h       |   2 -
 include/sysemu/qtest.h     |   1 -
 kvm-all.c                  |  40 ++++++++++--
 kvm-stub.c                 |   5 --
 qtest.c                    |  27 +++++++-
 vl.c                       |  83 +-----------------------
 xen-common-stub.c          |   6 --
 xen-common.c               |  25 +++++++-
 16 files changed, 311 insertions(+), 109 deletions(-)
 create mode 100644 hw/core/accel.c
 create mode 100644 include/hw/accel.h

-- 
1.9.3

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:11   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c Eduardo Habkost
                   ` (16 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Just to make checkpatch.pl happy when moving the code.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 vl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index 95be92d..e49c115 100644
--- a/vl.c
+++ b/vl.c
@@ -2711,7 +2711,7 @@ static int configure_accelerator(MachineClass *mc)
         if (*p == ':') {
             p++;
         }
-        p = get_opt_name(buf, sizeof (buf), p, ':');
+        p = get_opt_name(buf, sizeof(buf), p, ':');
         for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
             if (strcmp(accel_list[i].opt_name, buf) == 0) {
                 if (!accel_list[i].available()) {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:00   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef Eduardo Habkost
                   ` (15 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/Makefile.objs |   1 +
 hw/core/accel.c       | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/accel.h    |  32 ++++++++++++++
 vl.c                  |  81 +-----------------------------------
 4 files changed, 147 insertions(+), 80 deletions(-)
 create mode 100644 hw/core/accel.c
 create mode 100644 include/hw/accel.h

diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index 17845df..6e56e47 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -14,3 +14,4 @@ common-obj-$(CONFIG_SOFTMMU) += machine.o
 common-obj-$(CONFIG_SOFTMMU) += null-machine.o
 common-obj-$(CONFIG_SOFTMMU) += loader.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
+common-obj-$(CONFIG_SOFTMMU) += accel.o
diff --git a/hw/core/accel.c b/hw/core/accel.c
new file mode 100644
index 0000000..04da696
--- /dev/null
+++ b/hw/core/accel.c
@@ -0,0 +1,113 @@
+/*
+ * QEMU System Emulator, accelerator interfaces
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/accel.h"
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/kvm.h"
+#include "sysemu/qtest.h"
+#include "hw/xen/xen.h"
+
+int tcg_tb_size;
+static bool tcg_allowed = true;
+
+static int tcg_init(MachineClass *mc)
+{
+    tcg_exec_init(tcg_tb_size * 1024 * 1024);
+    return 0;
+}
+
+static struct {
+    const char *opt_name;
+    const char *name;
+    int (*available)(void);
+    int (*init)(MachineClass *mc);
+    bool *allowed;
+} accel_list[] = {
+    { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
+    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
+    { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
+    { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
+};
+
+int configure_accelerator(MachineClass *mc)
+{
+    const char *p;
+    char buf[10];
+    int i, ret;
+    bool accel_initialised = false;
+    bool init_failed = false;
+
+    p = qemu_opt_get(qemu_get_machine_opts(), "accel");
+    if (p == NULL) {
+        /* Use the default "accelerator", tcg */
+        p = "tcg";
+    }
+
+    while (!accel_initialised && *p != '\0') {
+        if (*p == ':') {
+            p++;
+        }
+        p = get_opt_name(buf, sizeof(buf), p, ':');
+        for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
+            if (strcmp(accel_list[i].opt_name, buf) == 0) {
+                if (!accel_list[i].available()) {
+                    printf("%s not supported for this target\n",
+                           accel_list[i].name);
+                    break;
+                }
+                *(accel_list[i].allowed) = true;
+                ret = accel_list[i].init(mc);
+                if (ret < 0) {
+                    init_failed = true;
+                    fprintf(stderr, "failed to initialize %s: %s\n",
+                            accel_list[i].name,
+                            strerror(-ret));
+                    *(accel_list[i].allowed) = false;
+                } else {
+                    accel_initialised = true;
+                }
+                break;
+            }
+        }
+        if (i == ARRAY_SIZE(accel_list)) {
+            fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+        }
+    }
+
+    if (!accel_initialised) {
+        if (!init_failed) {
+            fprintf(stderr, "No accelerator found!\n");
+        }
+        exit(1);
+    }
+
+    if (init_failed) {
+        fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
+    }
+
+    return !accel_initialised;
+}
diff --git a/include/hw/accel.h b/include/hw/accel.h
new file mode 100644
index 0000000..5537d74
--- /dev/null
+++ b/include/hw/accel.h
@@ -0,0 +1,32 @@
+/* QEMU accelerator interfaces
+ *
+ * Copyright (c) 2014 Red Hat Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef HW_ACCEL_H
+#define HW_ACCEL_H
+
+#include "qemu/typedefs.h"
+
+extern int tcg_tb_size;
+
+int configure_accelerator(MachineClass *mc);
+
+#endif
diff --git a/vl.c b/vl.c
index e49c115..911de91 100644
--- a/vl.c
+++ b/vl.c
@@ -61,6 +61,7 @@ int main(int argc, char **argv)
 #include "qemu/sockets.h"
 #include "hw/hw.h"
 #include "hw/boards.h"
+#include "hw/accel.h"
 #include "hw/usb.h"
 #include "hw/pcmcia.h"
 #include "hw/i386/pc.h"
@@ -212,11 +213,9 @@ static NotifierList exit_notifiers =
 static NotifierList machine_init_done_notifiers =
     NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
 
-static bool tcg_allowed = true;
 bool xen_allowed;
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_EMULATE;
-static int tcg_tb_size;
 
 static int has_defaults = 1;
 static int default_serial = 1;
@@ -2674,84 +2673,6 @@ static MachineClass *machine_parse(const char *name)
     exit(!name || !is_help_option(name));
 }
 
-static int tcg_init(MachineClass *mc)
-{
-    tcg_exec_init(tcg_tb_size * 1024 * 1024);
-    return 0;
-}
-
-static struct {
-    const char *opt_name;
-    const char *name;
-    int (*available)(void);
-    int (*init)(MachineClass *mc);
-    bool *allowed;
-} accel_list[] = {
-    { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
-    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
-    { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
-    { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
-};
-
-static int configure_accelerator(MachineClass *mc)
-{
-    const char *p;
-    char buf[10];
-    int i, ret;
-    bool accel_initialised = false;
-    bool init_failed = false;
-
-    p = qemu_opt_get(qemu_get_machine_opts(), "accel");
-    if (p == NULL) {
-        /* Use the default "accelerator", tcg */
-        p = "tcg";
-    }
-
-    while (!accel_initialised && *p != '\0') {
-        if (*p == ':') {
-            p++;
-        }
-        p = get_opt_name(buf, sizeof(buf), p, ':');
-        for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-            if (strcmp(accel_list[i].opt_name, buf) == 0) {
-                if (!accel_list[i].available()) {
-                    printf("%s not supported for this target\n",
-                           accel_list[i].name);
-                    break;
-                }
-                *(accel_list[i].allowed) = true;
-                ret = accel_list[i].init(mc);
-                if (ret < 0) {
-                    init_failed = true;
-                    fprintf(stderr, "failed to initialize %s: %s\n",
-                            accel_list[i].name,
-                            strerror(-ret));
-                    *(accel_list[i].allowed) = false;
-                } else {
-                    accel_initialised = true;
-                }
-                break;
-            }
-        }
-        if (i == ARRAY_SIZE(accel_list)) {
-            fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
-        }
-    }
-
-    if (!accel_initialised) {
-        if (!init_failed) {
-            fprintf(stderr, "No accelerator found!\n");
-        }
-        exit(1);
-    }
-
-    if (init_failed) {
-        fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
-    }
-
-    return !accel_initialised;
-}
-
 void qemu_add_exit_notifier(Notifier *notify)
 {
     notifier_list_add(&exit_notifiers, notify);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix Eduardo Habkost
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:00   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
                   ` (14 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 04da696..c23c04b 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -40,13 +40,15 @@ static int tcg_init(MachineClass *mc)
     return 0;
 }
 
-static struct {
+typedef struct AccelType {
     const char *opt_name;
     const char *name;
     int (*available)(void);
     int (*init)(MachineClass *mc);
     bool *allowed;
-} accel_list[] = {
+} AccelType;
+
+static AccelType accel_list[] = {
     { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
     { "xen", "Xen", xen_available, xen_init, &xen_allowed },
     { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (2 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:00   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
                   ` (13 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index c23c04b..00a71c0 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -62,6 +62,7 @@ int configure_accelerator(MachineClass *mc)
     int i, ret;
     bool accel_initialised = false;
     bool init_failed = false;
+    AccelType *acc = NULL;
 
     p = qemu_opt_get(qemu_get_machine_opts(), "accel");
     if (p == NULL) {
@@ -75,20 +76,21 @@ int configure_accelerator(MachineClass *mc)
         }
         p = get_opt_name(buf, sizeof(buf), p, ':');
         for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-            if (strcmp(accel_list[i].opt_name, buf) == 0) {
-                if (!accel_list[i].available()) {
+            acc = &accel_list[i];
+            if (strcmp(acc->opt_name, buf) == 0) {
+                if (!acc->available()) {
                     printf("%s not supported for this target\n",
-                           accel_list[i].name);
+                           acc->name);
                     break;
                 }
-                *(accel_list[i].allowed) = true;
-                ret = accel_list[i].init(mc);
+                *(acc->allowed) = true;
+                ret = acc->init(mc);
                 if (ret < 0) {
                     init_failed = true;
                     fprintf(stderr, "failed to initialize %s: %s\n",
-                            accel_list[i].name,
+                            acc->name,
                             strerror(-ret));
-                    *(accel_list[i].allowed) = false;
+                    *(acc->allowed) = false;
                 } else {
                     accel_initialised = true;
                 }
@@ -108,7 +110,7 @@ int configure_accelerator(MachineClass *mc)
     }
 
     if (init_failed) {
-        fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
+        fprintf(stderr, "Back to %s accelerator.\n", acc->name);
     }
 
     return !accel_initialised;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (3 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:01   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types Eduardo Habkost
                   ` (12 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c | 57 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 00a71c0..7f9b715 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -55,11 +55,24 @@ static AccelType accel_list[] = {
     { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
 };
 
+/* Lookup AccelType from opt_name. Returns NULL if not found */
+static AccelType *accel_find(const char *opt_name)
+{
+    int i;
+    for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
+        AccelType *acc = &accel_list[i];
+        if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) {
+            return acc;
+        }
+    }
+    return NULL;
+}
+
 int configure_accelerator(MachineClass *mc)
 {
     const char *p;
     char buf[10];
-    int i, ret;
+    int ret;
     bool accel_initialised = false;
     bool init_failed = false;
     AccelType *acc = NULL;
@@ -75,30 +88,26 @@ int configure_accelerator(MachineClass *mc)
             p++;
         }
         p = get_opt_name(buf, sizeof(buf), p, ':');
-        for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-            acc = &accel_list[i];
-            if (strcmp(acc->opt_name, buf) == 0) {
-                if (!acc->available()) {
-                    printf("%s not supported for this target\n",
-                           acc->name);
-                    break;
-                }
-                *(acc->allowed) = true;
-                ret = acc->init(mc);
-                if (ret < 0) {
-                    init_failed = true;
-                    fprintf(stderr, "failed to initialize %s: %s\n",
-                            acc->name,
-                            strerror(-ret));
-                    *(acc->allowed) = false;
-                } else {
-                    accel_initialised = true;
-                }
-                break;
-            }
-        }
-        if (i == ARRAY_SIZE(accel_list)) {
+        acc = accel_find(buf);
+        if (!acc) {
             fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+            continue;
+        }
+        if (!acc->available()) {
+            printf("%s not supported for this target\n",
+                   acc->name);
+            continue;
+        }
+        *(acc->allowed) = true;
+        ret = acc->init(mc);
+        if (ret < 0) {
+            init_failed = true;
+            fprintf(stderr, "failed to initialize %s: %s\n",
+                    acc->name,
+                    strerror(-ret));
+            *(acc->allowed) = false;
+        } else {
+            accel_initialised = true;
         }
     }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (4 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:02   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
                   ` (11 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Instead of having a static AccelType array, register a class for each
accelerator type, and use class name lookup to find accelerator
information.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c    | 117 ++++++++++++++++++++++++++++++++++++++++++-----------
 include/hw/accel.h |  30 ++++++++++++++
 2 files changed, 123 insertions(+), 24 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 7f9b715..01cdbc3 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -30,6 +30,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/qtest.h"
 #include "hw/xen/xen.h"
+#include "qom/object.h"
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
@@ -40,32 +41,20 @@ static int tcg_init(MachineClass *mc)
     return 0;
 }
 
-typedef struct AccelType {
-    const char *opt_name;
-    const char *name;
-    int (*available)(void);
-    int (*init)(MachineClass *mc);
-    bool *allowed;
-} AccelType;
-
-static AccelType accel_list[] = {
-    { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
-    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
-    { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
-    { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
+static const TypeInfo accel_type = {
+    .name = TYPE_ACCEL,
+    .parent = TYPE_OBJECT,
+    .class_size = sizeof(AccelClass),
+    .instance_size = sizeof(AccelState),
 };
 
-/* Lookup AccelType from opt_name. Returns NULL if not found */
-static AccelType *accel_find(const char *opt_name)
+/* Lookup AccelClass from opt_name. Returns NULL if not found */
+static AccelClass *accel_find(const char *opt_name)
 {
-    int i;
-    for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
-        AccelType *acc = &accel_list[i];
-        if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) {
-            return acc;
-        }
-    }
-    return NULL;
+    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
+    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
+    g_free(class_name);
+    return ac;
 }
 
 int configure_accelerator(MachineClass *mc)
@@ -75,7 +64,7 @@ int configure_accelerator(MachineClass *mc)
     int ret;
     bool accel_initialised = false;
     bool init_failed = false;
-    AccelType *acc = NULL;
+    AccelClass *acc = NULL;
 
     p = qemu_opt_get(qemu_get_machine_opts(), "accel");
     if (p == NULL) {
@@ -124,3 +113,83 @@ int configure_accelerator(MachineClass *mc)
 
     return !accel_initialised;
 }
+
+
+static void tcg_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "tcg";
+    ac->available = tcg_available;
+    ac->init = tcg_init;
+    ac->allowed = &tcg_allowed;
+}
+
+#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
+
+static const TypeInfo tcg_accel_type = {
+    .name = TYPE_TCG_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = tcg_accel_class_init,
+};
+
+static void xen_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "Xen";
+    ac->available = xen_available;
+    ac->init = xen_init;
+    ac->allowed = &xen_allowed;
+}
+
+#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
+
+static const TypeInfo xen_accel_type = {
+    .name = TYPE_XEN_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = xen_accel_class_init,
+};
+
+static void kvm_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "KVM";
+    ac->available = kvm_available;
+    ac->init = kvm_init;
+    ac->allowed = &kvm_allowed;
+}
+
+#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
+
+static const TypeInfo kvm_accel_type = {
+    .name = TYPE_KVM_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = kvm_accel_class_init,
+};
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "QTest";
+    ac->available = qtest_available;
+    ac->init = qtest_init_accel;
+    ac->allowed = &qtest_allowed;
+}
+
+#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
+
+static const TypeInfo qtest_accel_type = {
+    .name = TYPE_QTEST_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = qtest_accel_class_init,
+};
+
+static void register_accel_types(void)
+{
+    type_register_static(&accel_type);
+    type_register_static(&tcg_accel_type);
+    type_register_static(&xen_accel_type);
+    type_register_static(&kvm_accel_type);
+    type_register_static(&qtest_accel_type);
+}
+
+type_init(register_accel_types);
diff --git a/include/hw/accel.h b/include/hw/accel.h
index 5537d74..120ca0e 100644
--- a/include/hw/accel.h
+++ b/include/hw/accel.h
@@ -24,6 +24,36 @@
 #define HW_ACCEL_H
 
 #include "qemu/typedefs.h"
+#include "qom/object.h"
+
+typedef struct AccelState {
+    /*< private >*/
+    Object parent_obj;
+} AccelState;
+
+typedef struct AccelClass {
+    /*< private >*/
+    ObjectClass parent_class;
+    /*< public >*/
+
+    const char *opt_name;
+    const char *name;
+    int (*available)(void);
+    int (*init)(MachineClass *mc);
+    bool *allowed;
+} AccelClass;
+
+#define TYPE_ACCEL "accel"
+
+#define ACCEL_CLASS_SUFFIX  "-" TYPE_ACCEL
+#define ACCEL_CLASS_NAME(a) (a ACCEL_CLASS_SUFFIX)
+
+#define ACCEL_CLASS(klass) \
+    OBJECT_CLASS_CHECK(AccelClass, (klass), TYPE_ACCEL)
+#define ACCEL(obj) \
+    OBJECT_CHECK(AccelState, (obj), TYPE_ACCEL)
+#define ACCEL_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
 
 extern int tcg_tb_size;
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (5 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:02   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
                   ` (10 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

When we move accel classes outside accel.c, the available() function
won't be necessary anymore, because the classes will be registered only
if the accelerator code is really enabled at build time.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 01cdbc3..483bbe8 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -82,7 +82,7 @@ int configure_accelerator(MachineClass *mc)
             fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
             continue;
         }
-        if (!acc->available()) {
+        if (acc->available && !acc->available()) {
             printf("%s not supported for this target\n",
                    acc->name);
             continue;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (6 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:03   ` Paolo Bonzini
  2014-09-26 15:03   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
                   ` (9 subsequent siblings)
  17 siblings, 2 replies; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Note that this has an user-visible side-effect: instead of reporting
"KVM is not supported for this target", QEMU binaries not supporting KVM
will report "kvm accelerator does not exist".

As kvm_availble() always return 1 when CONFIG_KVM is enabled, we don't
need to set AccelClass.available anymore. kvm_enabled() is not being
completely removed yet only because qmp_query_kvm() still uses it.

This also allows us to make kvm_init() static.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c      | 18 ------------------
 include/sysemu/kvm.h |  2 --
 kvm-all.c            | 26 +++++++++++++++++++++++++-
 kvm-stub.c           |  5 -----
 4 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 483bbe8..61dafcb 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -149,23 +149,6 @@ static const TypeInfo xen_accel_type = {
     .class_init = xen_accel_class_init,
 };
 
-static void kvm_accel_class_init(ObjectClass *oc, void *data)
-{
-    AccelClass *ac = ACCEL_CLASS(oc);
-    ac->name = "KVM";
-    ac->available = kvm_available;
-    ac->init = kvm_init;
-    ac->allowed = &kvm_allowed;
-}
-
-#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
-
-static const TypeInfo kvm_accel_type = {
-    .name = TYPE_KVM_ACCEL,
-    .parent = TYPE_ACCEL,
-    .class_init = kvm_accel_class_init,
-};
-
 static void qtest_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
@@ -188,7 +171,6 @@ static void register_accel_types(void)
     type_register_static(&accel_type);
     type_register_static(&tcg_accel_type);
     type_register_static(&xen_accel_type);
-    type_register_static(&kvm_accel_type);
     type_register_static(&qtest_accel_type);
 }
 
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 174ea36..7b95bfd 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -163,8 +163,6 @@ extern KVMState *kvm_state;
 
 /* external API */
 
-int kvm_init(MachineClass *mc);
-
 int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
 int kvm_has_robust_singlestep(void);
diff --git a/kvm-all.c b/kvm-all.c
index b240bf8..7db966e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -26,6 +26,7 @@
 #include "qemu/config-file.h"
 #include "sysemu/sysemu.h"
 #include "hw/hw.h"
+#include "hw/accel.h"
 #include "hw/pci/msi.h"
 #include "hw/s390x/adapter.h"
 #include "exec/gdbstub.h"
@@ -110,6 +111,8 @@ struct KVMState
 #endif
 };
 
+#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
+
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
@@ -1368,7 +1371,7 @@ static int kvm_max_vcpus(KVMState *s)
     return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-int kvm_init(MachineClass *mc)
+static int kvm_init(MachineClass *mc)
 {
     static const char upgrade_note[] =
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
@@ -2213,3 +2216,24 @@ int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target)
     }
     return r;
 }
+
+static void kvm_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "KVM";
+    ac->init = kvm_init;
+    ac->allowed = &kvm_allowed;
+}
+
+static const TypeInfo kvm_accel_type = {
+    .name = TYPE_KVM_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = kvm_accel_class_init,
+};
+
+static void kvm_type_init(void)
+{
+    type_register_static(&kvm_accel_type);
+}
+
+type_init(kvm_type_init);
diff --git a/kvm-stub.c b/kvm-stub.c
index 8e7737c..43fc0dd 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -35,11 +35,6 @@ int kvm_init_vcpu(CPUState *cpu)
     return -ENOSYS;
 }
 
-int kvm_init(MachineClass *mc)
-{
-    return -ENOSYS;
-}
-
 void kvm_flush_coalesced_mmio_buffer(void)
 {
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (7 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:04   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
                   ` (8 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Note that this has an user-visible side-effect: instead of reporting
"Xen is not supported for this target", QEMU binaries not supporting Xen
will report "xen accelerator does not exist".

As xen_available() always return 1 when CONFIG_XEN is enabled, we don't
need to set AccelClass.available anymore. xen_enabled() is not being
removed yet, but only because vl.c is still using it.

This also allows us to make xen_init() static.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c      | 18 ------------------
 include/hw/xen/xen.h |  1 -
 xen-common-stub.c    |  6 ------
 xen-common.c         | 25 ++++++++++++++++++++++++-
 4 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 61dafcb..ecd1efa 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -132,23 +132,6 @@ static const TypeInfo tcg_accel_type = {
     .class_init = tcg_accel_class_init,
 };
 
-static void xen_accel_class_init(ObjectClass *oc, void *data)
-{
-    AccelClass *ac = ACCEL_CLASS(oc);
-    ac->name = "Xen";
-    ac->available = xen_available;
-    ac->init = xen_init;
-    ac->allowed = &xen_allowed;
-}
-
-#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
-
-static const TypeInfo xen_accel_type = {
-    .name = TYPE_XEN_ACCEL,
-    .parent = TYPE_ACCEL,
-    .class_init = xen_accel_class_init,
-};
-
 static void qtest_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
@@ -170,7 +153,6 @@ static void register_accel_types(void)
 {
     type_register_static(&accel_type);
     type_register_static(&tcg_accel_type);
-    type_register_static(&xen_accel_type);
     type_register_static(&qtest_accel_type);
 }
 
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index f71f2d8..b0ed04c 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -36,7 +36,6 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
-int xen_init(MachineClass *mc);
 void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
 #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
diff --git a/xen-common-stub.c b/xen-common-stub.c
index bd56ca2..906f991 100644
--- a/xen-common-stub.c
+++ b/xen-common-stub.c
@@ -11,9 +11,3 @@
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
 }
-
-int xen_init(MachineClass *mc)
-{
-    return -ENOSYS;
-}
-
diff --git a/xen-common.c b/xen-common.c
index f07b35e..f0b34be 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -9,6 +9,7 @@
  */
 
 #include "hw/xen/xen_backend.h"
+#include "hw/accel.h"
 #include "qmp-commands.h"
 #include "sysemu/char.h"
 
@@ -109,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running,
     }
 }
 
-int xen_init(MachineClass *mc)
+static int xen_init(MachineClass *mc)
 {
     xen_xc = xen_xc_interface_open(0, 0, 0);
     if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
@@ -121,3 +122,25 @@ int xen_init(MachineClass *mc)
     return 0;
 }
 
+static void xen_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "Xen";
+    ac->init = xen_init;
+    ac->allowed = &xen_allowed;
+}
+
+#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
+
+static const TypeInfo xen_accel_type = {
+    .name = TYPE_XEN_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = xen_accel_class_init,
+};
+
+static void xen_type_init(void)
+{
+    type_register_static(&xen_accel_type);
+}
+
+type_init(xen_type_init);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (8 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:04   ` Paolo Bonzini
  2014-09-26 15:06   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function Eduardo Habkost
                   ` (7 subsequent siblings)
  17 siblings, 2 replies; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

As qtest_availble() returns 1 only when CONFIG_POSIX is set, keep
setting AccelClass.available to keep current behavior (this is different
from what we did for KVM and Xen).

This also allows us to make qtest_init_accel() static.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c        | 18 ------------------
 include/sysemu/qtest.h |  1 -
 qtest.c                | 27 ++++++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index ecd1efa..5853551 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -132,28 +132,10 @@ static const TypeInfo tcg_accel_type = {
     .class_init = tcg_accel_class_init,
 };
 
-static void qtest_accel_class_init(ObjectClass *oc, void *data)
-{
-    AccelClass *ac = ACCEL_CLASS(oc);
-    ac->name = "QTest";
-    ac->available = qtest_available;
-    ac->init = qtest_init_accel;
-    ac->allowed = &qtest_allowed;
-}
-
-#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
-
-static const TypeInfo qtest_accel_type = {
-    .name = TYPE_QTEST_ACCEL,
-    .parent = TYPE_ACCEL,
-    .class_init = qtest_accel_class_init,
-};
-
 static void register_accel_types(void)
 {
     type_register_static(&accel_type);
     type_register_static(&tcg_accel_type);
-    type_register_static(&qtest_accel_type);
 }
 
 type_init(register_accel_types);
diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
index 95c9ade..05473b7 100644
--- a/include/sysemu/qtest.h
+++ b/include/sysemu/qtest.h
@@ -26,7 +26,6 @@ static inline bool qtest_enabled(void)
 
 bool qtest_driver(void);
 
-int qtest_init_accel(MachineClass *mc);
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
 
 static inline int qtest_available(void)
diff --git a/qtest.c b/qtest.c
index ef0d991..829128e 100644
--- a/qtest.c
+++ b/qtest.c
@@ -17,6 +17,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
+#include "hw/accel.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/cpus.h"
 #include "qemu/config-file.h"
@@ -519,7 +520,7 @@ static void configure_qtest_icount(const char *options)
     qemu_opts_del(opts);
 }
 
-int qtest_init_accel(MachineClass *mc)
+static int qtest_init_accel(MachineClass *mc)
 {
     configure_qtest_icount("0");
     return 0;
@@ -557,3 +558,27 @@ bool qtest_driver(void)
 {
     return qtest_chr;
 }
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "QTest";
+    ac->available = qtest_available;
+    ac->init = qtest_init_accel;
+    ac->allowed = &qtest_allowed;
+}
+
+#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
+
+static const TypeInfo qtest_accel_type = {
+    .name = TYPE_QTEST_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = qtest_accel_class_init,
+};
+
+static void qtest_type_init(void)
+{
+    type_register_static(&qtest_accel_type);
+}
+
+type_init(qtest_type_init);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (9 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:05   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
                   ` (6 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

As the function always return 1, it is not needed anymore.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 arch_init.c                | 5 -----
 hw/core/accel.c            | 1 -
 include/sysemu/arch_init.h | 1 -
 3 files changed, 7 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 28ece76..4cd21c9 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1335,11 +1335,6 @@ void cpudef_init(void)
 #endif
 }
 
-int tcg_available(void)
-{
-    return 1;
-}
-
 int kvm_available(void)
 {
 #ifdef CONFIG_KVM
diff --git a/hw/core/accel.c b/hw/core/accel.c
index 5853551..aeb779a 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -119,7 +119,6 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "tcg";
-    ac->available = tcg_available;
     ac->init = tcg_init;
     ac->allowed = &tcg_allowed;
 }
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 182d48d..5968837 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -32,7 +32,6 @@ void do_smbios_option(QemuOpts *opts);
 void ram_mig_init(void);
 void cpudef_init(void);
 void audio_init(void);
-int tcg_available(void);
 int kvm_available(void);
 int xen_available(void);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (10 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:05   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
                   ` (5 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index aeb779a..5817c3c 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -57,6 +57,17 @@ static AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
+static int accel_init(AccelClass *acc, MachineClass *mc)
+{
+    int ret;
+    *(acc->allowed) = true;
+    ret = acc->init(mc);
+    if (ret < 0) {
+        *(acc->allowed) = false;
+    }
+    return ret;
+}
+
 int configure_accelerator(MachineClass *mc)
 {
     const char *p;
@@ -87,14 +98,12 @@ int configure_accelerator(MachineClass *mc)
                    acc->name);
             continue;
         }
-        *(acc->allowed) = true;
-        ret = acc->init(mc);
+        ret = accel_init(acc, mc);
         if (ret < 0) {
             init_failed = true;
             fprintf(stderr, "failed to initialize %s: %s\n",
                     acc->name,
                     strerror(-ret));
-            *(acc->allowed) = false;
         } else {
             accel_initialised = true;
         }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine'
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (11 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:09   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
                   ` (4 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

This makes explicit the fact that the method is for machine
initialization, not just for accelerator object initialization.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c    | 8 ++++----
 include/hw/accel.h | 2 +-
 kvm-all.c          | 2 +-
 qtest.c            | 2 +-
 xen-common.c       | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 5817c3c..55378f3 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -57,11 +57,11 @@ static AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
-static int accel_init(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineClass *mc)
 {
     int ret;
     *(acc->allowed) = true;
-    ret = acc->init(mc);
+    ret = acc->init_machine(mc);
     if (ret < 0) {
         *(acc->allowed) = false;
     }
@@ -98,7 +98,7 @@ int configure_accelerator(MachineClass *mc)
                    acc->name);
             continue;
         }
-        ret = accel_init(acc, mc);
+        ret = accel_init_machine(acc, mc);
         if (ret < 0) {
             init_failed = true;
             fprintf(stderr, "failed to initialize %s: %s\n",
@@ -128,7 +128,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "tcg";
-    ac->init = tcg_init;
+    ac->init_machine = tcg_init;
     ac->allowed = &tcg_allowed;
 }
 
diff --git a/include/hw/accel.h b/include/hw/accel.h
index 120ca0e..8812cda 100644
--- a/include/hw/accel.h
+++ b/include/hw/accel.h
@@ -39,7 +39,7 @@ typedef struct AccelClass {
     const char *opt_name;
     const char *name;
     int (*available)(void);
-    int (*init)(MachineClass *mc);
+    int (*init_machine)(MachineClass *mc);
     bool *allowed;
 } AccelClass;
 
diff --git a/kvm-all.c b/kvm-all.c
index 7db966e..dd03dc4 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2221,7 +2221,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "KVM";
-    ac->init = kvm_init;
+    ac->init_machine = kvm_init;
     ac->allowed = &kvm_allowed;
 }
 
diff --git a/qtest.c b/qtest.c
index 829128e..4051868 100644
--- a/qtest.c
+++ b/qtest.c
@@ -564,7 +564,7 @@ static void qtest_accel_class_init(ObjectClass *oc, void *data)
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "QTest";
     ac->available = qtest_available;
-    ac->init = qtest_init_accel;
+    ac->init_machine = qtest_init_accel;
     ac->allowed = &qtest_allowed;
 }
 
diff --git a/xen-common.c b/xen-common.c
index f0b34be..246d76b 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -126,7 +126,7 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "Xen";
-    ac->init = xen_init;
+    ac->init_machine = xen_init;
     ac->allowed = &xen_allowed;
 }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (12 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:10   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine Eduardo Habkost
                   ` (3 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Most of the machine options and machine state information is in the
MachineState object, not on the MachineClass. This will allow init
functions to use the MachineState object directly instead of
qemu_get_machine_opts() or the current_machine global.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c         | 11 ++++++-----
 include/hw/accel.h      |  4 ++--
 include/qemu/typedefs.h |  1 +
 kvm-all.c               |  3 ++-
 qtest.c                 |  2 +-
 vl.c                    |  2 +-
 xen-common.c            |  2 +-
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 55378f3..98fcf0d 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -24,6 +24,7 @@
  */
 
 #include "hw/accel.h"
+#include "hw/boards.h"
 #include "qemu-common.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
@@ -35,7 +36,7 @@
 int tcg_tb_size;
 static bool tcg_allowed = true;
 
-static int tcg_init(MachineClass *mc)
+static int tcg_init(MachineState *ms)
 {
     tcg_exec_init(tcg_tb_size * 1024 * 1024);
     return 0;
@@ -57,18 +58,18 @@ static AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
-static int accel_init_machine(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
     int ret;
     *(acc->allowed) = true;
-    ret = acc->init_machine(mc);
+    ret = acc->init_machine(ms);
     if (ret < 0) {
         *(acc->allowed) = false;
     }
     return ret;
 }
 
-int configure_accelerator(MachineClass *mc)
+int configure_accelerator(MachineState *ms)
 {
     const char *p;
     char buf[10];
@@ -98,7 +99,7 @@ int configure_accelerator(MachineClass *mc)
                    acc->name);
             continue;
         }
-        ret = accel_init_machine(acc, mc);
+        ret = accel_init_machine(acc, ms);
         if (ret < 0) {
             init_failed = true;
             fprintf(stderr, "failed to initialize %s: %s\n",
diff --git a/include/hw/accel.h b/include/hw/accel.h
index 8812cda..997720f 100644
--- a/include/hw/accel.h
+++ b/include/hw/accel.h
@@ -39,7 +39,7 @@ typedef struct AccelClass {
     const char *opt_name;
     const char *name;
     int (*available)(void);
-    int (*init_machine)(MachineClass *mc);
+    int (*init_machine)(MachineState *ms);
     bool *allowed;
 } AccelClass;
 
@@ -57,6 +57,6 @@ typedef struct AccelClass {
 
 extern int tcg_tb_size;
 
-int configure_accelerator(MachineClass *mc);
+int configure_accelerator(MachineState *ms);
 
 #endif
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 5f20b0e..04df51b 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -32,6 +32,7 @@ typedef struct MemoryMappingList MemoryMappingList;
 
 typedef struct QEMUMachine QEMUMachine;
 typedef struct MachineClass MachineClass;
+typedef struct MachineState MachineState;
 typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
diff --git a/kvm-all.c b/kvm-all.c
index dd03dc4..9815eaf 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1371,8 +1371,9 @@ static int kvm_max_vcpus(KVMState *s)
     return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-static int kvm_init(MachineClass *mc)
+static int kvm_init(MachineState *ms)
 {
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
     static const char upgrade_note[] =
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
         "(see http://sourceforge.net/projects/kvm).\n";
diff --git a/qtest.c b/qtest.c
index 4051868..0dbcb58 100644
--- a/qtest.c
+++ b/qtest.c
@@ -520,7 +520,7 @@ static void configure_qtest_icount(const char *options)
     qemu_opts_del(opts);
 }
 
-static int qtest_init_accel(MachineClass *mc)
+static int qtest_init_accel(MachineState *ms)
 {
     configure_qtest_icount("0");
     return 0;
diff --git a/vl.c b/vl.c
index 911de91..8c52092 100644
--- a/vl.c
+++ b/vl.c
@@ -4177,7 +4177,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    configure_accelerator(machine_class);
+    configure_accelerator(current_machine);
 
     if (qtest_chrdev) {
         Error *local_err = NULL;
diff --git a/xen-common.c b/xen-common.c
index 246d76b..5616f0c 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -110,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running,
     }
 }
 
-static int xen_init(MachineClass *mc)
+static int xen_init(MachineState *ms)
 {
     xen_xc = xen_xc_interface_open(0, 0, 0);
     if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (13 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:10   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing Eduardo Habkost
                   ` (2 subsequent siblings)
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Create an actual TYPE_ACCEL object when initializing a machine. This
will allow accelerator classes to implement some initialization on
instance_init, and to save state on the TYPE_ACCEL object.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 98fcf0d..66ee1fa 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -60,11 +60,15 @@ static AccelClass *accel_find(const char *opt_name)
 
 static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
+    ObjectClass *oc = OBJECT_CLASS(acc);
+    const char *cname = object_class_get_name(oc);
+    AccelState *accel = ACCEL(object_new(cname));
     int ret;
     *(acc->allowed) = true;
     ret = acc->init_machine(ms);
     if (ret < 0) {
         *(acc->allowed) = false;
+        object_unref(OBJECT(accel));
     }
     return ret;
 }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (14 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:11   ` Paolo Bonzini
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
  2014-09-26 15:12 ` [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Paolo Bonzini
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

This will allow machine initialization code to get the accelerator
object if necessary.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/accel.c         | 3 +++
 include/hw/boards.h     | 1 +
 include/qemu/typedefs.h | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/hw/core/accel.c b/hw/core/accel.c
index 66ee1fa..2e1ea76 100644
--- a/hw/core/accel.c
+++ b/hw/core/accel.c
@@ -32,6 +32,7 @@
 #include "sysemu/qtest.h"
 #include "hw/xen/xen.h"
 #include "qom/object.h"
+#include "hw/boards.h"
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
@@ -64,9 +65,11 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)
     const char *cname = object_class_get_name(oc);
     AccelState *accel = ACCEL(object_new(cname));
     int ret;
+    ms->accelerator = accel;
     *(acc->allowed) = true;
     ret = acc->init_machine(ms);
     if (ret < 0) {
+        ms->accelerator = NULL;
         *(acc->allowed) = false;
         object_unref(OBJECT(accel));
     }
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 605a970..1cff2b4 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -132,6 +132,7 @@ struct MachineState {
     char *kernel_cmdline;
     char *initrd_filename;
     const char *cpu_model;
+    AccelState *accelerator;
 };
 
 #endif
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 04df51b..446af93 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -30,6 +30,8 @@ typedef struct MemoryListener MemoryListener;
 
 typedef struct MemoryMappingList MemoryMappingList;
 
+typedef struct AccelState AccelState;
+
 typedef struct QEMUMachine QEMUMachine;
 typedef struct MachineClass MachineClass;
 typedef struct MachineState MachineState;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (15 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing Eduardo Habkost
@ 2014-08-29 20:31 ` Eduardo Habkost
  2014-09-26 15:11   ` Paolo Bonzini
  2014-09-26 15:12 ` [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Paolo Bonzini
  17 siblings, 1 reply; 40+ messages in thread
From: Eduardo Habkost @ 2014-08-29 20:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Paolo Bonzini, Andreas Färber

Now that we create an accel object before calling machine_init, we can
simply use the accel object to save all KVMState data, instead of
allocationg KVMState manually.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 kvm-all.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 9815eaf..8a25f79 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -75,8 +75,10 @@ typedef struct KVMSlot
 
 typedef struct kvm_dirty_log KVMDirtyLog;
 
-struct KVMState
+typedef struct KVMState
 {
+    AccelState parent_obj;
+
     KVMSlot *slots;
     int nr_slots;
     int fd;
@@ -109,10 +111,13 @@ struct KVMState
     QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
     bool direct_msi;
 #endif
-};
+} KVMState;
 
 #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
 
+#define KVM_STATE(obj) \
+    OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL)
+
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
@@ -1392,7 +1397,7 @@ static int kvm_init(MachineState *ms)
     int i, type = 0;
     const char *kvm_type;
 
-    s = g_malloc0(sizeof(KVMState));
+    s = KVM_STATE(ms->accelerator);
 
     /*
      * On systems where the kernel can support different base page
@@ -1581,7 +1586,6 @@ err:
         close(s->fd);
     }
     g_free(s->slots);
-    g_free(s);
 
     return ret;
 }
@@ -2230,6 +2234,7 @@ static const TypeInfo kvm_accel_type = {
     .name = TYPE_KVM_ACCEL,
     .parent = TYPE_ACCEL,
     .class_init = kvm_accel_class_init,
+    .instance_size = sizeof(KVMState),
 };
 
 static void kvm_type_init(void)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c Eduardo Habkost
@ 2014-09-26 15:00   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:00 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/Makefile.objs |   1 +
>  hw/core/accel.c       | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++

This is not hw/core/, so please leave it in the root directory.

>  include/hw/accel.h    |  32 ++++++++++++++

... and please put this in include/sysemu/.

Apart from this,

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

>  vl.c                  |  81 +-----------------------------------
>  4 files changed, 147 insertions(+), 80 deletions(-)
>  create mode 100644 hw/core/accel.c
>  create mode 100644 include/hw/accel.h
> 
> diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
> index 17845df..6e56e47 100644
> --- a/hw/core/Makefile.objs
> +++ b/hw/core/Makefile.objs
> @@ -14,3 +14,4 @@ common-obj-$(CONFIG_SOFTMMU) += machine.o
>  common-obj-$(CONFIG_SOFTMMU) += null-machine.o
>  common-obj-$(CONFIG_SOFTMMU) += loader.o
>  common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
> +common-obj-$(CONFIG_SOFTMMU) += accel.o
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> new file mode 100644
> index 0000000..04da696
> --- /dev/null
> +++ b/hw/core/accel.c
> @@ -0,0 +1,113 @@
> +/*
> + * QEMU System Emulator, accelerator interfaces
> + *
> + * Copyright (c) 2003-2008 Fabrice Bellard
> + * Copyright (c) 2014 Red Hat Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "hw/accel.h"
> +#include "qemu-common.h"
> +#include "sysemu/arch_init.h"
> +#include "sysemu/sysemu.h"
> +#include "sysemu/kvm.h"
> +#include "sysemu/qtest.h"
> +#include "hw/xen/xen.h"
> +
> +int tcg_tb_size;
> +static bool tcg_allowed = true;
> +
> +static int tcg_init(MachineClass *mc)
> +{
> +    tcg_exec_init(tcg_tb_size * 1024 * 1024);
> +    return 0;
> +}
> +
> +static struct {
> +    const char *opt_name;
> +    const char *name;
> +    int (*available)(void);
> +    int (*init)(MachineClass *mc);
> +    bool *allowed;
> +} accel_list[] = {
> +    { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
> +    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
> +    { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
> +    { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
> +};
> +
> +int configure_accelerator(MachineClass *mc)
> +{
> +    const char *p;
> +    char buf[10];
> +    int i, ret;
> +    bool accel_initialised = false;
> +    bool init_failed = false;
> +
> +    p = qemu_opt_get(qemu_get_machine_opts(), "accel");
> +    if (p == NULL) {
> +        /* Use the default "accelerator", tcg */
> +        p = "tcg";
> +    }
> +
> +    while (!accel_initialised && *p != '\0') {
> +        if (*p == ':') {
> +            p++;
> +        }
> +        p = get_opt_name(buf, sizeof(buf), p, ':');
> +        for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
> +            if (strcmp(accel_list[i].opt_name, buf) == 0) {
> +                if (!accel_list[i].available()) {
> +                    printf("%s not supported for this target\n",
> +                           accel_list[i].name);
> +                    break;
> +                }
> +                *(accel_list[i].allowed) = true;
> +                ret = accel_list[i].init(mc);
> +                if (ret < 0) {
> +                    init_failed = true;
> +                    fprintf(stderr, "failed to initialize %s: %s\n",
> +                            accel_list[i].name,
> +                            strerror(-ret));
> +                    *(accel_list[i].allowed) = false;
> +                } else {
> +                    accel_initialised = true;
> +                }
> +                break;
> +            }
> +        }
> +        if (i == ARRAY_SIZE(accel_list)) {
> +            fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
> +        }
> +    }
> +
> +    if (!accel_initialised) {
> +        if (!init_failed) {
> +            fprintf(stderr, "No accelerator found!\n");
> +        }
> +        exit(1);
> +    }
> +
> +    if (init_failed) {
> +        fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
> +    }
> +
> +    return !accel_initialised;
> +}
> diff --git a/include/hw/accel.h b/include/hw/accel.h
> new file mode 100644
> index 0000000..5537d74
> --- /dev/null
> +++ b/include/hw/accel.h
> @@ -0,0 +1,32 @@
> +/* QEMU accelerator interfaces
> + *
> + * Copyright (c) 2014 Red Hat Inc
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +#ifndef HW_ACCEL_H
> +#define HW_ACCEL_H
> +
> +#include "qemu/typedefs.h"
> +
> +extern int tcg_tb_size;
> +
> +int configure_accelerator(MachineClass *mc);
> +
> +#endif
> diff --git a/vl.c b/vl.c
> index e49c115..911de91 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -61,6 +61,7 @@ int main(int argc, char **argv)
>  #include "qemu/sockets.h"
>  #include "hw/hw.h"
>  #include "hw/boards.h"
> +#include "hw/accel.h"
>  #include "hw/usb.h"
>  #include "hw/pcmcia.h"
>  #include "hw/i386/pc.h"
> @@ -212,11 +213,9 @@ static NotifierList exit_notifiers =
>  static NotifierList machine_init_done_notifiers =
>      NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
>  
> -static bool tcg_allowed = true;
>  bool xen_allowed;
>  uint32_t xen_domid;
>  enum xen_mode xen_mode = XEN_EMULATE;
> -static int tcg_tb_size;
>  
>  static int has_defaults = 1;
>  static int default_serial = 1;
> @@ -2674,84 +2673,6 @@ static MachineClass *machine_parse(const char *name)
>      exit(!name || !is_help_option(name));
>  }
>  
> -static int tcg_init(MachineClass *mc)
> -{
> -    tcg_exec_init(tcg_tb_size * 1024 * 1024);
> -    return 0;
> -}
> -
> -static struct {
> -    const char *opt_name;
> -    const char *name;
> -    int (*available)(void);
> -    int (*init)(MachineClass *mc);
> -    bool *allowed;
> -} accel_list[] = {
> -    { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
> -    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
> -    { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
> -    { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
> -};
> -
> -static int configure_accelerator(MachineClass *mc)
> -{
> -    const char *p;
> -    char buf[10];
> -    int i, ret;
> -    bool accel_initialised = false;
> -    bool init_failed = false;
> -
> -    p = qemu_opt_get(qemu_get_machine_opts(), "accel");
> -    if (p == NULL) {
> -        /* Use the default "accelerator", tcg */
> -        p = "tcg";
> -    }
> -
> -    while (!accel_initialised && *p != '\0') {
> -        if (*p == ':') {
> -            p++;
> -        }
> -        p = get_opt_name(buf, sizeof(buf), p, ':');
> -        for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
> -            if (strcmp(accel_list[i].opt_name, buf) == 0) {
> -                if (!accel_list[i].available()) {
> -                    printf("%s not supported for this target\n",
> -                           accel_list[i].name);
> -                    break;
> -                }
> -                *(accel_list[i].allowed) = true;
> -                ret = accel_list[i].init(mc);
> -                if (ret < 0) {
> -                    init_failed = true;
> -                    fprintf(stderr, "failed to initialize %s: %s\n",
> -                            accel_list[i].name,
> -                            strerror(-ret));
> -                    *(accel_list[i].allowed) = false;
> -                } else {
> -                    accel_initialised = true;
> -                }
> -                break;
> -            }
> -        }
> -        if (i == ARRAY_SIZE(accel_list)) {
> -            fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
> -        }
> -    }
> -
> -    if (!accel_initialised) {
> -        if (!init_failed) {
> -            fprintf(stderr, "No accelerator found!\n");
> -        }
> -        exit(1);
> -    }
> -
> -    if (init_failed) {
> -        fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
> -    }
> -
> -    return !accel_initialised;
> -}
> -
>  void qemu_add_exit_notifier(Notifier *notify)
>  {
>      notifier_list_add(&exit_notifiers, notify);
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef Eduardo Habkost
@ 2014-09-26 15:00   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:00 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 04da696..c23c04b 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -40,13 +40,15 @@ static int tcg_init(MachineClass *mc)
>      return 0;
>  }
>  
> -static struct {
> +typedef struct AccelType {
>      const char *opt_name;
>      const char *name;
>      int (*available)(void);
>      int (*init)(MachineClass *mc);
>      bool *allowed;
> -} accel_list[] = {
> +} AccelType;
> +
> +static AccelType accel_list[] = {
>      { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
>      { "xen", "Xen", xen_available, xen_init, &xen_allowed },
>      { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
@ 2014-09-26 15:00   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:00 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index c23c04b..00a71c0 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -62,6 +62,7 @@ int configure_accelerator(MachineClass *mc)
>      int i, ret;
>      bool accel_initialised = false;
>      bool init_failed = false;
> +    AccelType *acc = NULL;
>  
>      p = qemu_opt_get(qemu_get_machine_opts(), "accel");
>      if (p == NULL) {
> @@ -75,20 +76,21 @@ int configure_accelerator(MachineClass *mc)
>          }
>          p = get_opt_name(buf, sizeof(buf), p, ':');
>          for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
> -            if (strcmp(accel_list[i].opt_name, buf) == 0) {
> -                if (!accel_list[i].available()) {
> +            acc = &accel_list[i];
> +            if (strcmp(acc->opt_name, buf) == 0) {
> +                if (!acc->available()) {
>                      printf("%s not supported for this target\n",
> -                           accel_list[i].name);
> +                           acc->name);
>                      break;
>                  }
> -                *(accel_list[i].allowed) = true;
> -                ret = accel_list[i].init(mc);
> +                *(acc->allowed) = true;
> +                ret = acc->init(mc);
>                  if (ret < 0) {
>                      init_failed = true;
>                      fprintf(stderr, "failed to initialize %s: %s\n",
> -                            accel_list[i].name,
> +                            acc->name,
>                              strerror(-ret));
> -                    *(accel_list[i].allowed) = false;
> +                    *(acc->allowed) = false;
>                  } else {
>                      accel_initialised = true;
>                  }
> @@ -108,7 +110,7 @@ int configure_accelerator(MachineClass *mc)
>      }
>  
>      if (init_failed) {
> -        fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
> +        fprintf(stderr, "Back to %s accelerator.\n", acc->name);
>      }
>  
>      return !accel_initialised;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
@ 2014-09-26 15:01   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:01 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c | 57 +++++++++++++++++++++++++++++++++------------------------
>  1 file changed, 33 insertions(+), 24 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 00a71c0..7f9b715 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -55,11 +55,24 @@ static AccelType accel_list[] = {
>      { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
>  };
>  
> +/* Lookup AccelType from opt_name. Returns NULL if not found */
> +static AccelType *accel_find(const char *opt_name)
> +{
> +    int i;
> +    for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
> +        AccelType *acc = &accel_list[i];
> +        if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) {
> +            return acc;
> +        }
> +    }
> +    return NULL;
> +}
> +
>  int configure_accelerator(MachineClass *mc)
>  {
>      const char *p;
>      char buf[10];
> -    int i, ret;
> +    int ret;
>      bool accel_initialised = false;
>      bool init_failed = false;
>      AccelType *acc = NULL;
> @@ -75,30 +88,26 @@ int configure_accelerator(MachineClass *mc)
>              p++;
>          }
>          p = get_opt_name(buf, sizeof(buf), p, ':');
> -        for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
> -            acc = &accel_list[i];
> -            if (strcmp(acc->opt_name, buf) == 0) {
> -                if (!acc->available()) {
> -                    printf("%s not supported for this target\n",
> -                           acc->name);
> -                    break;
> -                }
> -                *(acc->allowed) = true;
> -                ret = acc->init(mc);
> -                if (ret < 0) {
> -                    init_failed = true;
> -                    fprintf(stderr, "failed to initialize %s: %s\n",
> -                            acc->name,
> -                            strerror(-ret));
> -                    *(acc->allowed) = false;
> -                } else {
> -                    accel_initialised = true;
> -                }
> -                break;
> -            }
> -        }
> -        if (i == ARRAY_SIZE(accel_list)) {
> +        acc = accel_find(buf);
> +        if (!acc) {
>              fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
> +            continue;
> +        }
> +        if (!acc->available()) {
> +            printf("%s not supported for this target\n",
> +                   acc->name);
> +            continue;
> +        }
> +        *(acc->allowed) = true;
> +        ret = acc->init(mc);
> +        if (ret < 0) {
> +            init_failed = true;
> +            fprintf(stderr, "failed to initialize %s: %s\n",
> +                    acc->name,
> +                    strerror(-ret));
> +            *(acc->allowed) = false;
> +        } else {
> +            accel_initialised = true;
>          }
>      }
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types Eduardo Habkost
@ 2014-09-26 15:02   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:02 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Instead of having a static AccelType array, register a class for each
> accelerator type, and use class name lookup to find accelerator
> information.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c    | 117 ++++++++++++++++++++++++++++++++++++++++++-----------
>  include/hw/accel.h |  30 ++++++++++++++
>  2 files changed, 123 insertions(+), 24 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 7f9b715..01cdbc3 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -30,6 +30,7 @@
>  #include "sysemu/kvm.h"
>  #include "sysemu/qtest.h"
>  #include "hw/xen/xen.h"
> +#include "qom/object.h"
>  
>  int tcg_tb_size;
>  static bool tcg_allowed = true;
> @@ -40,32 +41,20 @@ static int tcg_init(MachineClass *mc)
>      return 0;
>  }
>  
> -typedef struct AccelType {
> -    const char *opt_name;
> -    const char *name;
> -    int (*available)(void);
> -    int (*init)(MachineClass *mc);
> -    bool *allowed;
> -} AccelType;
> -
> -static AccelType accel_list[] = {
> -    { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
> -    { "xen", "Xen", xen_available, xen_init, &xen_allowed },
> -    { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
> -    { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
> +static const TypeInfo accel_type = {
> +    .name = TYPE_ACCEL,
> +    .parent = TYPE_OBJECT,
> +    .class_size = sizeof(AccelClass),
> +    .instance_size = sizeof(AccelState),
>  };
>  
> -/* Lookup AccelType from opt_name. Returns NULL if not found */
> -static AccelType *accel_find(const char *opt_name)
> +/* Lookup AccelClass from opt_name. Returns NULL if not found */
> +static AccelClass *accel_find(const char *opt_name)
>  {
> -    int i;
> -    for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
> -        AccelType *acc = &accel_list[i];
> -        if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) {
> -            return acc;
> -        }
> -    }
> -    return NULL;
> +    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
> +    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
> +    g_free(class_name);
> +    return ac;
>  }
>  
>  int configure_accelerator(MachineClass *mc)
> @@ -75,7 +64,7 @@ int configure_accelerator(MachineClass *mc)
>      int ret;
>      bool accel_initialised = false;
>      bool init_failed = false;
> -    AccelType *acc = NULL;
> +    AccelClass *acc = NULL;
>  
>      p = qemu_opt_get(qemu_get_machine_opts(), "accel");
>      if (p == NULL) {
> @@ -124,3 +113,83 @@ int configure_accelerator(MachineClass *mc)
>  
>      return !accel_initialised;
>  }
> +
> +
> +static void tcg_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "tcg";
> +    ac->available = tcg_available;
> +    ac->init = tcg_init;
> +    ac->allowed = &tcg_allowed;
> +}
> +
> +#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
> +
> +static const TypeInfo tcg_accel_type = {
> +    .name = TYPE_TCG_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = tcg_accel_class_init,
> +};
> +
> +static void xen_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "Xen";
> +    ac->available = xen_available;
> +    ac->init = xen_init;
> +    ac->allowed = &xen_allowed;
> +}
> +
> +#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> +
> +static const TypeInfo xen_accel_type = {
> +    .name = TYPE_XEN_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = xen_accel_class_init,
> +};
> +
> +static void kvm_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "KVM";
> +    ac->available = kvm_available;
> +    ac->init = kvm_init;
> +    ac->allowed = &kvm_allowed;
> +}
> +
> +#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
> +
> +static const TypeInfo kvm_accel_type = {
> +    .name = TYPE_KVM_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = kvm_accel_class_init,
> +};
> +
> +static void qtest_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "QTest";
> +    ac->available = qtest_available;
> +    ac->init = qtest_init_accel;
> +    ac->allowed = &qtest_allowed;
> +}
> +
> +#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
> +
> +static const TypeInfo qtest_accel_type = {
> +    .name = TYPE_QTEST_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = qtest_accel_class_init,
> +};
> +
> +static void register_accel_types(void)
> +{
> +    type_register_static(&accel_type);
> +    type_register_static(&tcg_accel_type);
> +    type_register_static(&xen_accel_type);
> +    type_register_static(&kvm_accel_type);
> +    type_register_static(&qtest_accel_type);
> +}
> +
> +type_init(register_accel_types);
> diff --git a/include/hw/accel.h b/include/hw/accel.h
> index 5537d74..120ca0e 100644
> --- a/include/hw/accel.h
> +++ b/include/hw/accel.h
> @@ -24,6 +24,36 @@
>  #define HW_ACCEL_H
>  
>  #include "qemu/typedefs.h"
> +#include "qom/object.h"
> +
> +typedef struct AccelState {
> +    /*< private >*/
> +    Object parent_obj;
> +} AccelState;
> +
> +typedef struct AccelClass {
> +    /*< private >*/
> +    ObjectClass parent_class;
> +    /*< public >*/
> +
> +    const char *opt_name;
> +    const char *name;
> +    int (*available)(void);
> +    int (*init)(MachineClass *mc);
> +    bool *allowed;
> +} AccelClass;
> +
> +#define TYPE_ACCEL "accel"
> +
> +#define ACCEL_CLASS_SUFFIX  "-" TYPE_ACCEL
> +#define ACCEL_CLASS_NAME(a) (a ACCEL_CLASS_SUFFIX)
> +
> +#define ACCEL_CLASS(klass) \
> +    OBJECT_CLASS_CHECK(AccelClass, (klass), TYPE_ACCEL)
> +#define ACCEL(obj) \
> +    OBJECT_CHECK(AccelState, (obj), TYPE_ACCEL)
> +#define ACCEL_GET_CLASS(obj) \
> +    OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
>  
>  extern int tcg_tb_size;
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
@ 2014-09-26 15:02   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:02 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> When we move accel classes outside accel.c, the available() function
> won't be necessary anymore, because the classes will be registered only
> if the accelerator code is really enabled at build time.

... which alone is worth the whole series. :)

> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 01cdbc3..483bbe8 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -82,7 +82,7 @@ int configure_accelerator(MachineClass *mc)
>              fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
>              continue;
>          }
> -        if (!acc->available()) {
> +        if (acc->available && !acc->available()) {
>              printf("%s not supported for this target\n",
>                     acc->name);
>              continue;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
@ 2014-09-26 15:03   ` Paolo Bonzini
  2014-09-26 15:03   ` Paolo Bonzini
  1 sibling, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:03 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Note that this has an user-visible side-effect: instead of reporting
> "KVM is not supported for this target", QEMU binaries not supporting KVM
> will report "kvm accelerator does not exist".

"does not exist" perhaps is a bit too strong.  Perhaps change the
message to "not found"?

Paolo

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
  2014-09-26 15:03   ` Paolo Bonzini
@ 2014-09-26 15:03   ` Paolo Bonzini
  1 sibling, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:03 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Note that this has an user-visible side-effect: instead of reporting
> "KVM is not supported for this target", QEMU binaries not supporting KVM
> will report "kvm accelerator does not exist".
> 
> As kvm_availble() always return 1 when CONFIG_KVM is enabled, we don't
> need to set AccelClass.available anymore. kvm_enabled() is not being
> completely removed yet only because qmp_query_kvm() still uses it.
> 
> This also allows us to make kvm_init() static.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c      | 18 ------------------
>  include/sysemu/kvm.h |  2 --
>  kvm-all.c            | 26 +++++++++++++++++++++++++-
>  kvm-stub.c           |  5 -----
>  4 files changed, 25 insertions(+), 26 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 483bbe8..61dafcb 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -149,23 +149,6 @@ static const TypeInfo xen_accel_type = {
>      .class_init = xen_accel_class_init,
>  };
>  
> -static void kvm_accel_class_init(ObjectClass *oc, void *data)
> -{
> -    AccelClass *ac = ACCEL_CLASS(oc);
> -    ac->name = "KVM";
> -    ac->available = kvm_available;
> -    ac->init = kvm_init;
> -    ac->allowed = &kvm_allowed;
> -}
> -
> -#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
> -
> -static const TypeInfo kvm_accel_type = {
> -    .name = TYPE_KVM_ACCEL,
> -    .parent = TYPE_ACCEL,
> -    .class_init = kvm_accel_class_init,
> -};
> -
>  static void qtest_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
> @@ -188,7 +171,6 @@ static void register_accel_types(void)
>      type_register_static(&accel_type);
>      type_register_static(&tcg_accel_type);
>      type_register_static(&xen_accel_type);
> -    type_register_static(&kvm_accel_type);
>      type_register_static(&qtest_accel_type);
>  }
>  
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 174ea36..7b95bfd 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -163,8 +163,6 @@ extern KVMState *kvm_state;
>  
>  /* external API */
>  
> -int kvm_init(MachineClass *mc);
> -
>  int kvm_has_sync_mmu(void);
>  int kvm_has_vcpu_events(void);
>  int kvm_has_robust_singlestep(void);
> diff --git a/kvm-all.c b/kvm-all.c
> index b240bf8..7db966e 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -26,6 +26,7 @@
>  #include "qemu/config-file.h"
>  #include "sysemu/sysemu.h"
>  #include "hw/hw.h"
> +#include "hw/accel.h"
>  #include "hw/pci/msi.h"
>  #include "hw/s390x/adapter.h"
>  #include "exec/gdbstub.h"
> @@ -110,6 +111,8 @@ struct KVMState
>  #endif
>  };
>  
> +#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
> +
>  KVMState *kvm_state;
>  bool kvm_kernel_irqchip;
>  bool kvm_async_interrupts_allowed;
> @@ -1368,7 +1371,7 @@ static int kvm_max_vcpus(KVMState *s)
>      return (ret) ? ret : kvm_recommended_vcpus(s);
>  }
>  
> -int kvm_init(MachineClass *mc)
> +static int kvm_init(MachineClass *mc)
>  {
>      static const char upgrade_note[] =
>          "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
> @@ -2213,3 +2216,24 @@ int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target)
>      }
>      return r;
>  }
> +
> +static void kvm_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "KVM";
> +    ac->init = kvm_init;
> +    ac->allowed = &kvm_allowed;
> +}
> +
> +static const TypeInfo kvm_accel_type = {
> +    .name = TYPE_KVM_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = kvm_accel_class_init,
> +};
> +
> +static void kvm_type_init(void)
> +{
> +    type_register_static(&kvm_accel_type);
> +}
> +
> +type_init(kvm_type_init);
> diff --git a/kvm-stub.c b/kvm-stub.c
> index 8e7737c..43fc0dd 100644
> --- a/kvm-stub.c
> +++ b/kvm-stub.c
> @@ -35,11 +35,6 @@ int kvm_init_vcpu(CPUState *cpu)
>      return -ENOSYS;
>  }
>  
> -int kvm_init(MachineClass *mc)
> -{
> -    return -ENOSYS;
> -}
> -
>  void kvm_flush_coalesced_mmio_buffer(void)
>  {
>  }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
@ 2014-09-26 15:04   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:04 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Note that this has an user-visible side-effect: instead of reporting
> "Xen is not supported for this target", QEMU binaries not supporting Xen
> will report "xen accelerator does not exist".
> 
> As xen_available() always return 1 when CONFIG_XEN is enabled, we don't
> need to set AccelClass.available anymore. xen_enabled() is not being
> removed yet, but only because vl.c is still using it.
> 
> This also allows us to make xen_init() static.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c      | 18 ------------------
>  include/hw/xen/xen.h |  1 -
>  xen-common-stub.c    |  6 ------
>  xen-common.c         | 25 ++++++++++++++++++++++++-
>  4 files changed, 24 insertions(+), 26 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 61dafcb..ecd1efa 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -132,23 +132,6 @@ static const TypeInfo tcg_accel_type = {
>      .class_init = tcg_accel_class_init,
>  };
>  
> -static void xen_accel_class_init(ObjectClass *oc, void *data)
> -{
> -    AccelClass *ac = ACCEL_CLASS(oc);
> -    ac->name = "Xen";
> -    ac->available = xen_available;
> -    ac->init = xen_init;
> -    ac->allowed = &xen_allowed;
> -}
> -
> -#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> -
> -static const TypeInfo xen_accel_type = {
> -    .name = TYPE_XEN_ACCEL,
> -    .parent = TYPE_ACCEL,
> -    .class_init = xen_accel_class_init,
> -};
> -
>  static void qtest_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
> @@ -170,7 +153,6 @@ static void register_accel_types(void)
>  {
>      type_register_static(&accel_type);
>      type_register_static(&tcg_accel_type);
> -    type_register_static(&xen_accel_type);
>      type_register_static(&qtest_accel_type);
>  }
>  
> diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
> index f71f2d8..b0ed04c 100644
> --- a/include/hw/xen/xen.h
> +++ b/include/hw/xen/xen.h
> @@ -36,7 +36,6 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
>  
>  qemu_irq *xen_interrupt_controller_init(void);
>  
> -int xen_init(MachineClass *mc);
>  void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
>  
>  #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
> diff --git a/xen-common-stub.c b/xen-common-stub.c
> index bd56ca2..906f991 100644
> --- a/xen-common-stub.c
> +++ b/xen-common-stub.c
> @@ -11,9 +11,3 @@
>  void xenstore_store_pv_console_info(int i, CharDriverState *chr)
>  {
>  }
> -
> -int xen_init(MachineClass *mc)
> -{
> -    return -ENOSYS;
> -}
> -
> diff --git a/xen-common.c b/xen-common.c
> index f07b35e..f0b34be 100644
> --- a/xen-common.c
> +++ b/xen-common.c
> @@ -9,6 +9,7 @@
>   */
>  
>  #include "hw/xen/xen_backend.h"
> +#include "hw/accel.h"
>  #include "qmp-commands.h"
>  #include "sysemu/char.h"
>  
> @@ -109,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running,
>      }
>  }
>  
> -int xen_init(MachineClass *mc)
> +static int xen_init(MachineClass *mc)
>  {
>      xen_xc = xen_xc_interface_open(0, 0, 0);
>      if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
> @@ -121,3 +122,25 @@ int xen_init(MachineClass *mc)
>      return 0;
>  }
>  
> +static void xen_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "Xen";
> +    ac->init = xen_init;
> +    ac->allowed = &xen_allowed;
> +}
> +
> +#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
> +
> +static const TypeInfo xen_accel_type = {
> +    .name = TYPE_XEN_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = xen_accel_class_init,
> +};
> +
> +static void xen_type_init(void)
> +{
> +    type_register_static(&xen_accel_type);
> +}
> +
> +type_init(xen_type_init);
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
@ 2014-09-26 15:04   ` Paolo Bonzini
  2014-09-26 15:06   ` Paolo Bonzini
  1 sibling, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:04 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> As qtest_availble() returns 1 only when CONFIG_POSIX is set, keep
> setting AccelClass.available to keep current behavior (this is different
> from what we did for KVM and Xen).
> 
> This also allows us to make qtest_init_accel() static.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c        | 18 ------------------
>  include/sysemu/qtest.h |  1 -
>  qtest.c                | 27 ++++++++++++++++++++++++++-
>  3 files changed, 26 insertions(+), 20 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index ecd1efa..5853551 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -132,28 +132,10 @@ static const TypeInfo tcg_accel_type = {
>      .class_init = tcg_accel_class_init,
>  };
>  
> -static void qtest_accel_class_init(ObjectClass *oc, void *data)
> -{
> -    AccelClass *ac = ACCEL_CLASS(oc);
> -    ac->name = "QTest";
> -    ac->available = qtest_available;
> -    ac->init = qtest_init_accel;
> -    ac->allowed = &qtest_allowed;
> -}
> -
> -#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
> -
> -static const TypeInfo qtest_accel_type = {
> -    .name = TYPE_QTEST_ACCEL,
> -    .parent = TYPE_ACCEL,
> -    .class_init = qtest_accel_class_init,
> -};
> -
>  static void register_accel_types(void)
>  {
>      type_register_static(&accel_type);
>      type_register_static(&tcg_accel_type);
> -    type_register_static(&qtest_accel_type);
>  }
>  
>  type_init(register_accel_types);
> diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
> index 95c9ade..05473b7 100644
> --- a/include/sysemu/qtest.h
> +++ b/include/sysemu/qtest.h
> @@ -26,7 +26,6 @@ static inline bool qtest_enabled(void)
>  
>  bool qtest_driver(void);
>  
> -int qtest_init_accel(MachineClass *mc);
>  void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
>  
>  static inline int qtest_available(void)
> diff --git a/qtest.c b/qtest.c
> index ef0d991..829128e 100644
> --- a/qtest.c
> +++ b/qtest.c
> @@ -17,6 +17,7 @@
>  #include "exec/ioport.h"
>  #include "exec/memory.h"
>  #include "hw/irq.h"
> +#include "hw/accel.h"
>  #include "sysemu/sysemu.h"
>  #include "sysemu/cpus.h"
>  #include "qemu/config-file.h"
> @@ -519,7 +520,7 @@ static void configure_qtest_icount(const char *options)
>      qemu_opts_del(opts);
>  }
>  
> -int qtest_init_accel(MachineClass *mc)
> +static int qtest_init_accel(MachineClass *mc)
>  {
>      configure_qtest_icount("0");
>      return 0;
> @@ -557,3 +558,27 @@ bool qtest_driver(void)
>  {
>      return qtest_chr;
>  }
> +
> +static void qtest_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "QTest";
> +    ac->available = qtest_available;
> +    ac->init = qtest_init_accel;
> +    ac->allowed = &qtest_allowed;
> +}
> +
> +#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
> +
> +static const TypeInfo qtest_accel_type = {
> +    .name = TYPE_QTEST_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = qtest_accel_class_init,
> +};
> +
> +static void qtest_type_init(void)
> +{
> +    type_register_static(&qtest_accel_type);
> +}
> +
> +type_init(qtest_type_init);
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function Eduardo Habkost
@ 2014-09-26 15:05   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:05 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> As the function always return 1, it is not needed anymore.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  arch_init.c                | 5 -----
>  hw/core/accel.c            | 1 -
>  include/sysemu/arch_init.h | 1 -
>  3 files changed, 7 deletions(-)
> 
> diff --git a/arch_init.c b/arch_init.c
> index 28ece76..4cd21c9 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -1335,11 +1335,6 @@ void cpudef_init(void)
>  #endif
>  }
>  
> -int tcg_available(void)
> -{
> -    return 1;
> -}
> -
>  int kvm_available(void)
>  {
>  #ifdef CONFIG_KVM
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 5853551..aeb779a 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -119,7 +119,6 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "tcg";
> -    ac->available = tcg_available;
>      ac->init = tcg_init;
>      ac->allowed = &tcg_allowed;
>  }
> diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
> index 182d48d..5968837 100644
> --- a/include/sysemu/arch_init.h
> +++ b/include/sysemu/arch_init.h
> @@ -32,7 +32,6 @@ void do_smbios_option(QemuOpts *opts);
>  void ram_mig_init(void);
>  void cpudef_init(void);
>  void audio_init(void);
> -int tcg_available(void);
>  int kvm_available(void);
>  int xen_available(void);
>  
> 

When we will support disabling of TCG, we will move the registration to
translate-all.c so the function will not exist anyway.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
@ 2014-09-26 15:05   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:05 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index aeb779a..5817c3c 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -57,6 +57,17 @@ static AccelClass *accel_find(const char *opt_name)
>      return ac;
>  }
>  
> +static int accel_init(AccelClass *acc, MachineClass *mc)
> +{
> +    int ret;
> +    *(acc->allowed) = true;
> +    ret = acc->init(mc);
> +    if (ret < 0) {
> +        *(acc->allowed) = false;
> +    }
> +    return ret;
> +}
> +
>  int configure_accelerator(MachineClass *mc)
>  {
>      const char *p;
> @@ -87,14 +98,12 @@ int configure_accelerator(MachineClass *mc)
>                     acc->name);
>              continue;
>          }
> -        *(acc->allowed) = true;
> -        ret = acc->init(mc);
> +        ret = accel_init(acc, mc);
>          if (ret < 0) {
>              init_failed = true;
>              fprintf(stderr, "failed to initialize %s: %s\n",
>                      acc->name,
>                      strerror(-ret));
> -            *(acc->allowed) = false;
>          } else {
>              accel_initialised = true;
>          }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
  2014-09-26 15:04   ` Paolo Bonzini
@ 2014-09-26 15:06   ` Paolo Bonzini
  2014-09-26 19:37     ` Eduardo Habkost
  1 sibling, 1 reply; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:06 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> As qtest_availble() returns 1 only when CONFIG_POSIX is set, keep
> setting AccelClass.available to keep current behavior (this is different
> from what we did for KVM and Xen).

Hmm... as extra patches, could we only register the type on CONFIG_POSIX
and thus get rid of available completely?

Paolo

> This also allows us to make qtest_init_accel() static.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c        | 18 ------------------
>  include/sysemu/qtest.h |  1 -
>  qtest.c                | 27 ++++++++++++++++++++++++++-
>  3 files changed, 26 insertions(+), 20 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index ecd1efa..5853551 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -132,28 +132,10 @@ static const TypeInfo tcg_accel_type = {
>      .class_init = tcg_accel_class_init,
>  };
>  
> -static void qtest_accel_class_init(ObjectClass *oc, void *data)
> -{
> -    AccelClass *ac = ACCEL_CLASS(oc);
> -    ac->name = "QTest";
> -    ac->available = qtest_available;
> -    ac->init = qtest_init_accel;
> -    ac->allowed = &qtest_allowed;
> -}
> -
> -#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
> -
> -static const TypeInfo qtest_accel_type = {
> -    .name = TYPE_QTEST_ACCEL,
> -    .parent = TYPE_ACCEL,
> -    .class_init = qtest_accel_class_init,
> -};
> -
>  static void register_accel_types(void)
>  {
>      type_register_static(&accel_type);
>      type_register_static(&tcg_accel_type);
> -    type_register_static(&qtest_accel_type);
>  }
>  
>  type_init(register_accel_types);
> diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
> index 95c9ade..05473b7 100644
> --- a/include/sysemu/qtest.h
> +++ b/include/sysemu/qtest.h
> @@ -26,7 +26,6 @@ static inline bool qtest_enabled(void)
>  
>  bool qtest_driver(void);
>  
> -int qtest_init_accel(MachineClass *mc);
>  void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
>  
>  static inline int qtest_available(void)
> diff --git a/qtest.c b/qtest.c
> index ef0d991..829128e 100644
> --- a/qtest.c
> +++ b/qtest.c
> @@ -17,6 +17,7 @@
>  #include "exec/ioport.h"
>  #include "exec/memory.h"
>  #include "hw/irq.h"
> +#include "hw/accel.h"
>  #include "sysemu/sysemu.h"
>  #include "sysemu/cpus.h"
>  #include "qemu/config-file.h"
> @@ -519,7 +520,7 @@ static void configure_qtest_icount(const char *options)
>      qemu_opts_del(opts);
>  }
>  
> -int qtest_init_accel(MachineClass *mc)
> +static int qtest_init_accel(MachineClass *mc)
>  {
>      configure_qtest_icount("0");
>      return 0;
> @@ -557,3 +558,27 @@ bool qtest_driver(void)
>  {
>      return qtest_chr;
>  }
> +
> +static void qtest_accel_class_init(ObjectClass *oc, void *data)
> +{
> +    AccelClass *ac = ACCEL_CLASS(oc);
> +    ac->name = "QTest";
> +    ac->available = qtest_available;
> +    ac->init = qtest_init_accel;
> +    ac->allowed = &qtest_allowed;
> +}
> +
> +#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
> +
> +static const TypeInfo qtest_accel_type = {
> +    .name = TYPE_QTEST_ACCEL,
> +    .parent = TYPE_ACCEL,
> +    .class_init = qtest_accel_class_init,
> +};
> +
> +static void qtest_type_init(void)
> +{
> +    type_register_static(&qtest_accel_type);
> +}
> +
> +type_init(qtest_type_init);
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine'
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
@ 2014-09-26 15:09   ` Paolo Bonzini
  2014-09-26 16:42     ` Eduardo Habkost
  0 siblings, 1 reply; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:09 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> This makes explicit the fact that the method is for machine
> initialization, not just for accelerator object initialization.

No, it is not for machine initialization.  It just picks defaults if
necessary from the passed machine class.

So I don't think this patch is needed.

Paolo

> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c    | 8 ++++----
>  include/hw/accel.h | 2 +-
>  kvm-all.c          | 2 +-
>  qtest.c            | 2 +-
>  xen-common.c       | 2 +-
>  5 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 5817c3c..55378f3 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -57,11 +57,11 @@ static AccelClass *accel_find(const char *opt_name)
>      return ac;
>  }
>  
> -static int accel_init(AccelClass *acc, MachineClass *mc)
> +static int accel_init_machine(AccelClass *acc, MachineClass *mc)
>  {
>      int ret;
>      *(acc->allowed) = true;
> -    ret = acc->init(mc);
> +    ret = acc->init_machine(mc);
>      if (ret < 0) {
>          *(acc->allowed) = false;
>      }
> @@ -98,7 +98,7 @@ int configure_accelerator(MachineClass *mc)
>                     acc->name);
>              continue;
>          }
> -        ret = accel_init(acc, mc);
> +        ret = accel_init_machine(acc, mc);
>          if (ret < 0) {
>              init_failed = true;
>              fprintf(stderr, "failed to initialize %s: %s\n",
> @@ -128,7 +128,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "tcg";
> -    ac->init = tcg_init;
> +    ac->init_machine = tcg_init;
>      ac->allowed = &tcg_allowed;
>  }
>  
> diff --git a/include/hw/accel.h b/include/hw/accel.h
> index 120ca0e..8812cda 100644
> --- a/include/hw/accel.h
> +++ b/include/hw/accel.h
> @@ -39,7 +39,7 @@ typedef struct AccelClass {
>      const char *opt_name;
>      const char *name;
>      int (*available)(void);
> -    int (*init)(MachineClass *mc);
> +    int (*init_machine)(MachineClass *mc);
>      bool *allowed;
>  } AccelClass;
>  
> diff --git a/kvm-all.c b/kvm-all.c
> index 7db966e..dd03dc4 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -2221,7 +2221,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "KVM";
> -    ac->init = kvm_init;
> +    ac->init_machine = kvm_init;
>      ac->allowed = &kvm_allowed;
>  }
>  
> diff --git a/qtest.c b/qtest.c
> index 829128e..4051868 100644
> --- a/qtest.c
> +++ b/qtest.c
> @@ -564,7 +564,7 @@ static void qtest_accel_class_init(ObjectClass *oc, void *data)
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "QTest";
>      ac->available = qtest_available;
> -    ac->init = qtest_init_accel;
> +    ac->init_machine = qtest_init_accel;
>      ac->allowed = &qtest_allowed;
>  }
>  
> diff --git a/xen-common.c b/xen-common.c
> index f0b34be..246d76b 100644
> --- a/xen-common.c
> +++ b/xen-common.c
> @@ -126,7 +126,7 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)
>  {
>      AccelClass *ac = ACCEL_CLASS(oc);
>      ac->name = "Xen";
> -    ac->init = xen_init;
> +    ac->init_machine = xen_init;
>      ac->allowed = &xen_allowed;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
@ 2014-09-26 15:10   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:10 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Most of the machine options and machine state information is in the
> MachineState object, not on the MachineClass. This will allow init
> functions to use the MachineState object directly instead of
> qemu_get_machine_opts() or the current_machine global.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c         | 11 ++++++-----
>  include/hw/accel.h      |  4 ++--
>  include/qemu/typedefs.h |  1 +
>  kvm-all.c               |  3 ++-
>  qtest.c                 |  2 +-
>  vl.c                    |  2 +-
>  xen-common.c            |  2 +-
>  7 files changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 55378f3..98fcf0d 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -24,6 +24,7 @@
>   */
>  
>  #include "hw/accel.h"
> +#include "hw/boards.h"
>  #include "qemu-common.h"
>  #include "sysemu/arch_init.h"
>  #include "sysemu/sysemu.h"
> @@ -35,7 +36,7 @@
>  int tcg_tb_size;
>  static bool tcg_allowed = true;
>  
> -static int tcg_init(MachineClass *mc)
> +static int tcg_init(MachineState *ms)
>  {
>      tcg_exec_init(tcg_tb_size * 1024 * 1024);
>      return 0;
> @@ -57,18 +58,18 @@ static AccelClass *accel_find(const char *opt_name)
>      return ac;
>  }
>  
> -static int accel_init_machine(AccelClass *acc, MachineClass *mc)
> +static int accel_init_machine(AccelClass *acc, MachineState *ms)
>  {
>      int ret;
>      *(acc->allowed) = true;
> -    ret = acc->init_machine(mc);
> +    ret = acc->init_machine(ms);
>      if (ret < 0) {
>          *(acc->allowed) = false;
>      }
>      return ret;
>  }
>  
> -int configure_accelerator(MachineClass *mc)
> +int configure_accelerator(MachineState *ms)
>  {
>      const char *p;
>      char buf[10];
> @@ -98,7 +99,7 @@ int configure_accelerator(MachineClass *mc)
>                     acc->name);
>              continue;
>          }
> -        ret = accel_init_machine(acc, mc);
> +        ret = accel_init_machine(acc, ms);
>          if (ret < 0) {
>              init_failed = true;
>              fprintf(stderr, "failed to initialize %s: %s\n",
> diff --git a/include/hw/accel.h b/include/hw/accel.h
> index 8812cda..997720f 100644
> --- a/include/hw/accel.h
> +++ b/include/hw/accel.h
> @@ -39,7 +39,7 @@ typedef struct AccelClass {
>      const char *opt_name;
>      const char *name;
>      int (*available)(void);
> -    int (*init_machine)(MachineClass *mc);
> +    int (*init_machine)(MachineState *ms);
>      bool *allowed;
>  } AccelClass;
>  
> @@ -57,6 +57,6 @@ typedef struct AccelClass {
>  
>  extern int tcg_tb_size;
>  
> -int configure_accelerator(MachineClass *mc);
> +int configure_accelerator(MachineState *ms);
>  
>  #endif
> diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
> index 5f20b0e..04df51b 100644
> --- a/include/qemu/typedefs.h
> +++ b/include/qemu/typedefs.h
> @@ -32,6 +32,7 @@ typedef struct MemoryMappingList MemoryMappingList;
>  
>  typedef struct QEMUMachine QEMUMachine;
>  typedef struct MachineClass MachineClass;
> +typedef struct MachineState MachineState;
>  typedef struct NICInfo NICInfo;
>  typedef struct HCIInfo HCIInfo;
>  typedef struct AudioState AudioState;
> diff --git a/kvm-all.c b/kvm-all.c
> index dd03dc4..9815eaf 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1371,8 +1371,9 @@ static int kvm_max_vcpus(KVMState *s)
>      return (ret) ? ret : kvm_recommended_vcpus(s);
>  }
>  
> -static int kvm_init(MachineClass *mc)
> +static int kvm_init(MachineState *ms)
>  {
> +    MachineClass *mc = MACHINE_GET_CLASS(ms);
>      static const char upgrade_note[] =
>          "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
>          "(see http://sourceforge.net/projects/kvm).\n";
> diff --git a/qtest.c b/qtest.c
> index 4051868..0dbcb58 100644
> --- a/qtest.c
> +++ b/qtest.c
> @@ -520,7 +520,7 @@ static void configure_qtest_icount(const char *options)
>      qemu_opts_del(opts);
>  }
>  
> -static int qtest_init_accel(MachineClass *mc)
> +static int qtest_init_accel(MachineState *ms)
>  {
>      configure_qtest_icount("0");
>      return 0;
> diff --git a/vl.c b/vl.c
> index 911de91..8c52092 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4177,7 +4177,7 @@ int main(int argc, char **argv, char **envp)
>          exit(1);
>      }
>  
> -    configure_accelerator(machine_class);
> +    configure_accelerator(current_machine);
>  
>      if (qtest_chrdev) {
>          Error *local_err = NULL;
> diff --git a/xen-common.c b/xen-common.c
> index 246d76b..5616f0c 100644
> --- a/xen-common.c
> +++ b/xen-common.c
> @@ -110,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running,
>      }
>  }
>  
> -static int xen_init(MachineClass *mc)
> +static int xen_init(MachineState *ms)
>  {
>      xen_xc = xen_xc_interface_open(0, 0, 0);
>      if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine Eduardo Habkost
@ 2014-09-26 15:10   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:10 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Create an actual TYPE_ACCEL object when initializing a machine. This
> will allow accelerator classes to implement some initialization on
> instance_init, and to save state on the TYPE_ACCEL object.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 98fcf0d..66ee1fa 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -60,11 +60,15 @@ static AccelClass *accel_find(const char *opt_name)
>  
>  static int accel_init_machine(AccelClass *acc, MachineState *ms)
>  {
> +    ObjectClass *oc = OBJECT_CLASS(acc);
> +    const char *cname = object_class_get_name(oc);
> +    AccelState *accel = ACCEL(object_new(cname));
>      int ret;
>      *(acc->allowed) = true;
>      ret = acc->init_machine(ms);
>      if (ret < 0) {
>          *(acc->allowed) = false;
> +        object_unref(OBJECT(accel));
>      }
>      return ret;
>  }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing Eduardo Habkost
@ 2014-09-26 15:11   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:11 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> This will allow machine initialization code to get the accelerator
> object if necessary.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/accel.c         | 3 +++
>  include/hw/boards.h     | 1 +
>  include/qemu/typedefs.h | 2 ++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/hw/core/accel.c b/hw/core/accel.c
> index 66ee1fa..2e1ea76 100644
> --- a/hw/core/accel.c
> +++ b/hw/core/accel.c
> @@ -32,6 +32,7 @@
>  #include "sysemu/qtest.h"
>  #include "hw/xen/xen.h"
>  #include "qom/object.h"
> +#include "hw/boards.h"
>  
>  int tcg_tb_size;
>  static bool tcg_allowed = true;
> @@ -64,9 +65,11 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)
>      const char *cname = object_class_get_name(oc);
>      AccelState *accel = ACCEL(object_new(cname));
>      int ret;
> +    ms->accelerator = accel;
>      *(acc->allowed) = true;
>      ret = acc->init_machine(ms);
>      if (ret < 0) {
> +        ms->accelerator = NULL;
>          *(acc->allowed) = false;
>          object_unref(OBJECT(accel));
>      }
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index 605a970..1cff2b4 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -132,6 +132,7 @@ struct MachineState {
>      char *kernel_cmdline;
>      char *initrd_filename;
>      const char *cpu_model;
> +    AccelState *accelerator;
>  };
>  
>  #endif
> diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
> index 04df51b..446af93 100644
> --- a/include/qemu/typedefs.h
> +++ b/include/qemu/typedefs.h
> @@ -30,6 +30,8 @@ typedef struct MemoryListener MemoryListener;
>  
>  typedef struct MemoryMappingList MemoryMappingList;
>  
> +typedef struct AccelState AccelState;
> +
>  typedef struct QEMUMachine QEMUMachine;
>  typedef struct MachineClass MachineClass;
>  typedef struct MachineState MachineState;
> 

I would just squash this with the previous patch.  Apart from this,

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
@ 2014-09-26 15:11   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:11 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Now that we create an accel object before calling machine_init, we can
> simply use the accel object to save all KVMState data, instead of
> allocationg KVMState manually.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  kvm-all.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index 9815eaf..8a25f79 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -75,8 +75,10 @@ typedef struct KVMSlot
>  
>  typedef struct kvm_dirty_log KVMDirtyLog;
>  
> -struct KVMState
> +typedef struct KVMState
>  {
> +    AccelState parent_obj;
> +
>      KVMSlot *slots;
>      int nr_slots;
>      int fd;
> @@ -109,10 +111,13 @@ struct KVMState
>      QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
>      bool direct_msi;
>  #endif
> -};
> +} KVMState;
>  
>  #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
>  
> +#define KVM_STATE(obj) \
> +    OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL)
> +
>  KVMState *kvm_state;
>  bool kvm_kernel_irqchip;
>  bool kvm_async_interrupts_allowed;
> @@ -1392,7 +1397,7 @@ static int kvm_init(MachineState *ms)
>      int i, type = 0;
>      const char *kvm_type;
>  
> -    s = g_malloc0(sizeof(KVMState));
> +    s = KVM_STATE(ms->accelerator);
>  
>      /*
>       * On systems where the kernel can support different base page
> @@ -1581,7 +1586,6 @@ err:
>          close(s->fd);
>      }
>      g_free(s->slots);
> -    g_free(s);
>  
>      return ret;
>  }
> @@ -2230,6 +2234,7 @@ static const TypeInfo kvm_accel_type = {
>      .name = TYPE_KVM_ACCEL,
>      .parent = TYPE_ACCEL,
>      .class_init = kvm_accel_class_init,
> +    .instance_size = sizeof(KVMState),
>  };
>  
>  static void kvm_type_init(void)
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix Eduardo Habkost
@ 2014-09-26 15:11   ` Paolo Bonzini
  0 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:11 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> Just to make checkpatch.pl happy when moving the code.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  vl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/vl.c b/vl.c
> index 95be92d..e49c115 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2711,7 +2711,7 @@ static int configure_accelerator(MachineClass *mc)
>          if (*p == ':') {
>              p++;
>          }
> -        p = get_opt_name(buf, sizeof (buf), p, ':');
> +        p = get_opt_name(buf, sizeof(buf), p, ':');
>          for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
>              if (strcmp(accel_list[i].opt_name, buf) == 0) {
>                  if (!accel_list[i].available()) {
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code
  2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
                   ` (16 preceding siblings ...)
  2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
@ 2014-09-26 15:12 ` Paolo Bonzini
  17 siblings, 0 replies; 40+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:12 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Michael Mueller, Michael S. Tsirkin, Marcel Apfelbaum,
	Alexander Graf, Christian Borntraeger, Jason J. Herne,
	Andreas Färber

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> This is an attempt to convert the accel initialization and registration code
> to be QOM-based. Some use cases for this are:
> 
>  * Isolating KVM-specific CPU initialization and compatibility code;
>  * Use compat_props to implement accelrator-specific compatibility code
>    on machine-types;
>  * Returning accelerator-specific information on the "query-cpu-definitions"
>    QMP command (e.g. "runnable" information; CPU features).
> 
> Changes v1 -> v2:
>  * Remove the TYPE_X86_ACCEL interface and KVM-specific changes, by now
>    (they will be submitted later).
>  * Introduce ACCEL_CLASS_NAME(s) macro.
> 
> Cc: Michael Mueller <mimu@linux.vnet.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: Alexander Graf <agraf@suse.de>
> Cc: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Andreas Färber <afaerber@suse.de>
> Cc: Marcel Apfelbaum <marcel.a@redhat.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> 
> Eduardo Habkost (17):
>   vl.c: Small coding style fix
>   accel: Move accel code to accel.c
>   accel: Create AccelType typedef
>   accel: Simplify configure_accelerator() using AccelType *acc variable
>   accel: Move accel name lookup to separate function
>   accel: Use QOM classes for accel types
>   accel: Make AccelClass.available() optional
>   accel: Move KVM accel registration to kvm-all.c
>   accel: Move Xen registration code to xen-common.c
>   accel: Move qtest accel registration to qtest.c
>   accel: Remove tcg_available() function
>   accel: Move accel init/allowed code to separate function
>   accel: Rename 'init' method to 'init_machine'
>   accel: Pass MachineState object to accel init functions
>   accel: Create accel object when initializing machine
>   accel: Save AccelState on MachineState when initializing
>   kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
> 
>  arch_init.c                |   5 --
>  hw/core/Makefile.objs      |   1 +
>  hw/core/accel.c            | 157 +++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/accel.h         |  62 ++++++++++++++++++
>  include/hw/boards.h        |   1 +
>  include/hw/xen/xen.h       |   1 -
>  include/qemu/typedefs.h    |   3 +
>  include/sysemu/arch_init.h |   1 -
>  include/sysemu/kvm.h       |   2 -
>  include/sysemu/qtest.h     |   1 -
>  kvm-all.c                  |  40 ++++++++++--
>  kvm-stub.c                 |   5 --
>  qtest.c                    |  27 +++++++-
>  vl.c                       |  83 +-----------------------
>  xen-common-stub.c          |   6 --
>  xen-common.c               |  25 +++++++-
>  16 files changed, 311 insertions(+), 109 deletions(-)
>  create mode 100644 hw/core/accel.c
>  create mode 100644 include/hw/accel.h
> 

Just few small remarks, otherwise looks good.

Thanks!

Paolo

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine'
  2014-09-26 15:09   ` Paolo Bonzini
@ 2014-09-26 16:42     ` Eduardo Habkost
  0 siblings, 0 replies; 40+ messages in thread
From: Eduardo Habkost @ 2014-09-26 16:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, qemu-devel, Christian Borntraeger,
	Jason J. Herne, Andreas Färber

On Fri, Sep 26, 2014 at 05:09:06PM +0200, Paolo Bonzini wrote:
> Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> > This makes explicit the fact that the method is for machine
> > initialization, not just for accelerator object initialization.
> 
> No, it is not for machine initialization.  It just picks defaults if
> necessary from the passed machine class.

The problem is that lots of the accelerator initialization code changes
global state or machine state. But I want to be able to create
accelerator objects usable for probing without affecting any
global/machine state. The use case I have in mind is to return
accelerator-specific runnable/features information when listing CPU
model information.

My plan here is to split accelerator initialization into:

* instance_init(), which won't affect any machine/global state, and can
  be safely run multiple times;
* machine_init(), which may affect machine/global state.

In a perfect world, machine_init() wouldn't even exist because
accelerators would never affect machine/global state, but we are a long
way from that.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c
  2014-09-26 15:06   ` Paolo Bonzini
@ 2014-09-26 19:37     ` Eduardo Habkost
  0 siblings, 0 replies; 40+ messages in thread
From: Eduardo Habkost @ 2014-09-26 19:37 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Michael Mueller, Marcel Apfelbaum, Michael S. Tsirkin,
	Alexander Graf, qemu-devel, Christian Borntraeger,
	Jason J. Herne, Andreas Färber

On Fri, Sep 26, 2014 at 05:06:43PM +0200, Paolo Bonzini wrote:
> Il 29/08/2014 22:31, Eduardo Habkost ha scritto:
> > As qtest_availble() returns 1 only when CONFIG_POSIX is set, keep
> > setting AccelClass.available to keep current behavior (this is different
> > from what we did for KVM and Xen).
> 
> Hmm... as extra patches, could we only register the type on CONFIG_POSIX
> and thus get rid of available completely?

I am a bit confused about qtest support on Windows: is the "-qtest"
option supposed to be working (without accel=qtest) on !CONFIG_POSIX?

I see that you made qtest_init() not be a NOP anymore on !CONFIG_POSIX
on commit d4fce24f3a59eda081cdf2e38e7001591b95d173, but I don't know if
it makes sense to try to use it on Windows.

I was going to simply not compile accel.o at all on !CONFIG_POSIX, but I
don't know if it would break use cases that are expected to work.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2014-09-26 19:37 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-29 20:31 [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Eduardo Habkost
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix Eduardo Habkost
2014-09-26 15:11   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c Eduardo Habkost
2014-09-26 15:00   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef Eduardo Habkost
2014-09-26 15:00   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
2014-09-26 15:00   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
2014-09-26 15:01   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types Eduardo Habkost
2014-09-26 15:02   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
2014-09-26 15:02   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
2014-09-26 15:03   ` Paolo Bonzini
2014-09-26 15:03   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
2014-09-26 15:04   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
2014-09-26 15:04   ` Paolo Bonzini
2014-09-26 15:06   ` Paolo Bonzini
2014-09-26 19:37     ` Eduardo Habkost
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function Eduardo Habkost
2014-09-26 15:05   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
2014-09-26 15:05   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
2014-09-26 15:09   ` Paolo Bonzini
2014-09-26 16:42     ` Eduardo Habkost
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
2014-09-26 15:10   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine Eduardo Habkost
2014-09-26 15:10   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing Eduardo Habkost
2014-09-26 15:11   ` Paolo Bonzini
2014-08-29 20:31 ` [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
2014-09-26 15:11   ` Paolo Bonzini
2014-09-26 15:12 ` [Qemu-devel] [PATCH v2 00/17] QOMify accelerator code Paolo Bonzini

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.