All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code
@ 2014-09-26 20:45 Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 01/17] vl.c: Small coding style fix Eduardo Habkost
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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 v2 -> v3:
 * Rename hw/core/accel.c to accel.c
 * Rename include/hw/accel.h to include/sysemu/accel.h
 * Report unknown accelerator as "not found" instead of "does not exist"
 * Squashed "accel: Create accel object when initializing machine" and
   "accel: Save AccelState on MachineState when initializing" in a single
   patch

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: Report unknown accelerator as "not found" instead of "does not
    exist"
  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
  kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

 Makefile.objs              |   1 +
 accel.c                    | 157 +++++++++++++++++++++++++++++++++++++++++++++
 arch_init.c                |   5 --
 include/hw/boards.h        |   1 +
 include/hw/xen/xen.h       |   1 -
 include/qemu/typedefs.h    |   3 +
 include/sysemu/accel.h     |  62 ++++++++++++++++++
 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 accel.c
 create mode 100644 include/sysemu/accel.h

-- 
1.9.3

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

* [Qemu-devel] [PATCH v3 01/17] vl.c: Small coding style fix
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 02/17] accel: Move accel code to accel.c Eduardo Habkost
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
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 dbdca59..ce606a6 100644
--- a/vl.c
+++ b/vl.c
@@ -2715,7 +2715,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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 02/17] accel: Move accel code to accel.c
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 01/17] vl.c: Small coding style fix Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 03/17] accel: Create AccelType typedef Eduardo Habkost
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2 -> v3:
 Suggested-by: Paolo Bonzini <pbonzini@redhat.com>:
 * Rename hw/core/accel.c -> accel.c,
 * Rename include/hw/accel.h -> include/sysemu/accel.h
---
 Makefile.objs          |   1 +
 accel.c                | 113 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/accel.h |  32 ++++++++++++++
 vl.c                   |  81 +----------------------------------
 4 files changed, 147 insertions(+), 80 deletions(-)
 create mode 100644 accel.c
 create mode 100644 include/sysemu/accel.h

diff --git a/Makefile.objs b/Makefile.objs
index 97db978..add8375 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -62,6 +62,7 @@ common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
 
 common-obj-y += audio/
 common-obj-y += hw/
+common-obj-y += accel.o
 
 common-obj-y += ui/
 common-obj-y += bt-host.o bt-vhci.o
diff --git a/accel.c b/accel.c
new file mode 100644
index 0000000..9424796
--- /dev/null
+++ b/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 "sysemu/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/sysemu/accel.h b/include/sysemu/accel.h
new file mode 100644
index 0000000..5537d74
--- /dev/null
+++ b/include/sysemu/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 ce606a6..92dfb5c 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 "sysemu/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;
@@ -2678,84 +2677,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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 03/17] accel: Create AccelType typedef
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 01/17] vl.c: Small coding style fix Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 02/17] accel: Move accel code to accel.c Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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

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

diff --git a/accel.c b/accel.c
index 9424796..3cefd74 100644
--- a/accel.c
+++ b/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (2 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 03/17] accel: Create AccelType typedef Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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

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

diff --git a/accel.c b/accel.c
index 3cefd74..fc8c551 100644
--- a/accel.c
+++ b/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 05/17] accel: Move accel name lookup to separate function
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (3 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 06/17] accel: Use QOM classes for accel types Eduardo Habkost
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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

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

diff --git a/accel.c b/accel.c
index fc8c551..c752fcc 100644
--- a/accel.c
+++ b/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 06/17] accel: Use QOM classes for accel types
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (4 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

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

diff --git a/accel.c b/accel.c
index c752fcc..a3e2fd9 100644
--- a/accel.c
+++ b/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/sysemu/accel.h b/include/sysemu/accel.h
index 5537d74..120ca0e 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 07/17] accel: Make AccelClass.available() optional
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (5 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 06/17] accel: Use QOM classes for accel types Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 08/17] accel: Report unknown accelerator as "not found" instead of "does not exist" Eduardo Habkost
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

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

diff --git a/accel.c b/accel.c
index a3e2fd9..85177f1 100644
--- a/accel.c
+++ b/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 08/17] accel: Report unknown accelerator as "not found" instead of "does not exist"
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (6 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 09/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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 accelerator classes won't be registered anymore if they are not
enabled at compile time, saying "does not exist" may be misleading, as
the accelerator may be simply disabled. Change the wording to just say
"not found".

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

diff --git a/accel.c b/accel.c
index 85177f1..fce6eab 100644
--- a/accel.c
+++ b/accel.c
@@ -79,7 +79,7 @@ int configure_accelerator(MachineClass *mc)
         p = get_opt_name(buf, sizeof(buf), p, ':');
         acc = accel_find(buf);
         if (!acc) {
-            fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+            fprintf(stderr, "\"%s\" accelerator not found.\n", buf);
             continue;
         }
         if (acc->available && !acc->available()) {
-- 
1.9.3

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

* [Qemu-devel] [PATCH v3 09/17] accel: Move KVM accel registration to kvm-all.c
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (7 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 08/17] accel: Report unknown accelerator as "not found" instead of "does not exist" Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 10/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 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/accel.c b/accel.c
index fce6eab..a20e427 100644
--- a/accel.c
+++ b/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 d2000af..7f34006 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 8b9e66d..009c0dc 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -25,6 +25,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/accel.h"
 #include "hw/hw.h"
 #include "hw/pci/msi.h"
 #include "hw/s390x/adapter.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;
@@ -1381,7 +1384,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"
@@ -2227,3 +2230,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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 10/17] accel: Move Xen registration code to xen-common.c
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (8 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 09/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 11/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 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/accel.c b/accel.c
index a20e427..2cefbb0 100644
--- a/accel.c
+++ b/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..acc64d5 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -11,6 +11,7 @@
 #include "hw/xen/xen_backend.h"
 #include "qmp-commands.h"
 #include "sysemu/char.h"
+#include "sysemu/accel.h"
 
 //#define DEBUG_XEN
 
@@ -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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 11/17] accel: Move qtest accel registration to qtest.c
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (9 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 10/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 12/17] accel: Remove tcg_available() function Eduardo Habkost
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

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

diff --git a/accel.c b/accel.c
index 2cefbb0..2cf47337 100644
--- a/accel.c
+++ b/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..0af8b74 100644
--- a/qtest.c
+++ b/qtest.c
@@ -17,6 +17,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
+#include "sysemu/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 12/17] accel: Remove tcg_available() function
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (10 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 11/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 13/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
 accel.c                    | 1 -
 arch_init.c                | 5 -----
 include/sysemu/arch_init.h | 1 -
 3 files changed, 7 deletions(-)

diff --git a/accel.c b/accel.c
index 2cf47337..0f3fcee 100644
--- a/accel.c
+++ b/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/arch_init.c b/arch_init.c
index c974f3f..9b3e25d 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1337,11 +1337,6 @@ void cpudef_init(void)
 #endif
 }
 
-int tcg_available(void)
-{
-    return 1;
-}
-
 int kvm_available(void)
 {
 #ifdef CONFIG_KVM
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 769ec06..54b36c1 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -33,7 +33,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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 13/17] accel: Move accel init/allowed code to separate function
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (11 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 12/17] accel: Remove tcg_available() function Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 14/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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

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

diff --git a/accel.c b/accel.c
index 0f3fcee..9241967 100644
--- a/accel.c
+++ b/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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 14/17] accel: Rename 'init' method to 'init_machine'
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (12 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 13/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 15/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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

Today, all accelerator init functions affect some global state:
* tcg_init() calls tcg_exec_init() and affects globals such as tcg_tcx,
  page size globals, and possibly others;
* kvm_init() changes the kvm_state global, cpu_interrupt_handler, and possibly
  others;
* xen_init() changes the xen_xc global, and registers a change state handler.

With the new accelerator QOM classes, initialization may now be split in two
steps:
* instance_init() will do basic initialization that doesn't affect any global
  state and don't need MachineState or MachineClass data. This will allow
  probing code to safely create multiple accelerator objects on the fly just
  for reporting host/accelerator capabilities, for example.
* accel_init_machine()/init_machine() will save the accelerator object in
  MachineState, and do initialization steps which still affect global state,
  machine state, or that need data from MachineClass or MachineState.

To clarify the difference between those two steps, rename init() to
init_machine().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2 -> v3:
 * Clarify reasoning for the method rename on commit message.
---
 accel.c                | 8 ++++----
 include/sysemu/accel.h | 2 +-
 kvm-all.c              | 2 +-
 qtest.c                | 2 +-
 xen-common.c           | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/accel.c b/accel.c
index 9241967..b151d55 100644
--- a/accel.c
+++ b/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/sysemu/accel.h b/include/sysemu/accel.h
index 120ca0e..8812cda 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/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 009c0dc..97f1261 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2235,7 +2235,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 0af8b74..18e26fc 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 acc64d5..acb738f 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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 15/17] accel: Pass MachineState object to accel init functions
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (13 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 14/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 16/17] accel: Create accel object when initializing machine Eduardo Habkost
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

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

diff --git a/accel.c b/accel.c
index b151d55..6087ab3 100644
--- a/accel.c
+++ b/accel.c
@@ -24,6 +24,7 @@
  */
 
 #include "sysemu/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/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/include/sysemu/accel.h b/include/sysemu/accel.h
index 8812cda..997720f 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/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/kvm-all.c b/kvm-all.c
index 97f1261..8de1a83 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1384,8 +1384,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 18e26fc..4b85995 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 92dfb5c..1dd0e7d 100644
--- a/vl.c
+++ b/vl.c
@@ -4182,7 +4182,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 acb738f..56359ca 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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 16/17] accel: Create accel object when initializing machine
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (14 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 15/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
  2014-09-29 21:56 ` [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Paolo Bonzini
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2 -> v3:
* Squashed "accel: Create accel object when initializing machine" and
  "accel: Save AccelState on MachineState when initializing" in a single
  patch
---
 accel.c                 | 7 +++++++
 include/hw/boards.h     | 1 +
 include/qemu/typedefs.h | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/accel.c b/accel.c
index 6087ab3..74e41da 100644
--- a/accel.c
+++ b/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;
@@ -60,11 +61,17 @@ 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;
+    ms->accelerator = accel;
     *(acc->allowed) = true;
     ret = acc->init_machine(ms);
     if (ret < 0) {
+        ms->accelerator = NULL;
         *(acc->allowed) = false;
+        object_unref(OBJECT(accel));
     }
     return ret;
 }
diff --git a/include/hw/boards.h b/include/hw/boards.h
index dfb6718..8f0eeaf 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -133,6 +133,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] 19+ messages in thread

* [Qemu-devel] [PATCH v3 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (15 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 16/17] accel: Create accel object when initializing machine Eduardo Habkost
@ 2014-09-26 20:45 ` Eduardo Habkost
  2014-09-29 21:56 ` [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Paolo Bonzini
  17 siblings, 0 replies; 19+ messages in thread
From: Eduardo Habkost @ 2014-09-26 20:45 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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
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 8de1a83..3ab1b4e 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;
@@ -1405,7 +1410,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
@@ -1594,7 +1599,6 @@ err:
         close(s->fd);
     }
     g_free(s->slots);
-    g_free(s);
 
     return ret;
 }
@@ -2244,6 +2248,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] 19+ messages in thread

* Re: [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code
  2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
                   ` (16 preceding siblings ...)
  2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
@ 2014-09-29 21:56 ` Paolo Bonzini
  17 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2014-09-29 21:56 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 26/09/2014 22:45, 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 v2 -> v3:
>  * Rename hw/core/accel.c to accel.c
>  * Rename include/hw/accel.h to include/sysemu/accel.h
>  * Report unknown accelerator as "not found" instead of "does not exist"
>  * Squashed "accel: Create accel object when initializing machine" and
>    "accel: Save AccelState on MachineState when initializing" in a single
>    patch
> 
> 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: Report unknown accelerator as "not found" instead of "does not
>     exist"
>   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
>   kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct
> 
>  Makefile.objs              |   1 +
>  accel.c                    | 157 +++++++++++++++++++++++++++++++++++++++++++++
>  arch_init.c                |   5 --
>  include/hw/boards.h        |   1 +
>  include/hw/xen/xen.h       |   1 -
>  include/qemu/typedefs.h    |   3 +
>  include/sysemu/accel.h     |  62 ++++++++++++++++++
>  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 accel.c
>  create mode 100644 include/sysemu/accel.h
> 

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

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

end of thread, other threads:[~2014-09-29 21:56 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26 20:45 [Qemu-devel] [PATCH v3 00/17] QOMify accelerator code Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 01/17] vl.c: Small coding style fix Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 02/17] accel: Move accel code to accel.c Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 03/17] accel: Create AccelType typedef Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 05/17] accel: Move accel name lookup to separate function Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 06/17] accel: Use QOM classes for accel types Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 07/17] accel: Make AccelClass.available() optional Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 08/17] accel: Report unknown accelerator as "not found" instead of "does not exist" Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 09/17] accel: Move KVM accel registration to kvm-all.c Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 10/17] accel: Move Xen registration code to xen-common.c Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 11/17] accel: Move qtest accel registration to qtest.c Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 12/17] accel: Remove tcg_available() function Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 13/17] accel: Move accel init/allowed code to separate function Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 14/17] accel: Rename 'init' method to 'init_machine' Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 15/17] accel: Pass MachineState object to accel init functions Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 16/17] accel: Create accel object when initializing machine Eduardo Habkost
2014-09-26 20:45 ` [Qemu-devel] [PATCH v3 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct Eduardo Habkost
2014-09-29 21:56 ` [Qemu-devel] [PATCH v3 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.