Skip to contentSkip to conversation

QOMify accelerator code

PATCH Superseded Eduardo Habkost 2 participants 40 messages Aug 29, 2014 – Sep 26, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover QOMify accelerator code

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 <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Alexander Graf <[email protected]>
Cc "Jason J. Herne" <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Andreas Färber <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

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
Signature · 1 line
1.9.3
#1 lore raw

PATCH v2 1/17 vl.c: Small coding style fix

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

---
 vl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +1 -1
index 95be92d..e49c115 100644
@@ -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()) {
Signature · 1 line
1.9.3
Reviewed-by on v2 1/17
#2 lore raw

Re: [Qemu-devel] [PATCH v2 01/17] vl.c: Small coding style fix

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 13 lines

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

---
 vl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vl.c +0 -0
index 95be92d..e49c115 100644

vl.c static int configure_accelerator(MachineClass *mc) · line 2717

Quoted 8 lines
vl.c +1 -1
@@ -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()) {
#3 lore raw

PATCH v2 2/17 accel: Move accel code to accel.c

In reply to Eduardo Habkost
---
 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
hw/core/Makefile.objs +1 -0
index 17845df..6e56e47 100644
@@ -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
hw/core/accel.c new file +113 -0

113 lines not on this page · raw message

include/hw/accel.h new file +32 -0
new file mode 100644
index 0000000..5537d74
@@ -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
vl.c +1 -80

102 lines not on this page · raw message

Signature · 1 line
1.9.3
Reviewed-by on v2 2/17
#4 lore raw

Re: [Qemu-devel] [PATCH v2 02/17] accel: Move accel code to accel.c

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 4 lines
---
 hw/core/Makefile.objs |   1 +
 hw/core/accel.c       | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++

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

Quoted 1 line
 include/hw/accel.h    |  32 ++++++++++++++

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

Apart from this,

Quoted 281 lines
 vl.c                  |  81 +-----------------------------------
 4 files changed, 147 insertions(+), 80 deletions(-)
 create mode 100644 hw/core/accel.c
 create mode 100644 include/hw/accel.h
hw/core/Makefile.objs +1 -0
index 17845df..6e56e47 100644
@@ -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
hw/core/accel.c new file +113 -0
new file mode 100644
index 0000000..04da696
@@ -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;
+}
include/hw/accel.h new file +32 -0
new file mode 100644
index 0000000..5537d74
@@ -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
vl.c +1 -80
index e49c115..911de91 100644
@@ -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);
#5 lore raw

PATCH v2 3/17 accel: Create AccelType typedef

In reply to Eduardo Habkost
---
 hw/core/accel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/core/accel.c +4 -2
index 04da696..c23c04b 100644
@@ -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 },
Signature · 1 line
1.9.3
Reviewed-by on v2 3/17
#6 lore raw

Re: [Qemu-devel] [PATCH v2 03/17] accel: Create AccelType typedef

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 18 lines
---
 hw/core/accel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/core/accel.c +1 -1
index 04da696..c23c04b 100644
@@ -40,13 +40,15 @@ static int tcg_init(MachineClass *mc)
     return 0;
 }
 
-static struct {
+typedef struct AccelType {
     const char *opt_name;
     const char *name;

hw/core/accel.c static int tcg_init(MachineClass *mc) · line 54

Quoted 10 lines
hw/core/accel.c +3 -1
     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 },
#7 lore raw

PATCH v2 4/17 accel: Simplify configure_accelerator() using AccelType *acc variable

In reply to Eduardo Habkost
---
 hw/core/accel.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/core/accel.c +10 -8
index c23c04b..00a71c0 100644
@@ -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;
Signature · 1 line
1.9.3
Reviewed-by on v2 4/17
#8 lore raw

Re: [Qemu-devel] [PATCH v2 04/17] accel: Simplify configure_accelerator() using AccelType *acc variable

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 48 lines
---
 hw/core/accel.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/core/accel.c +9 -7
index c23c04b..00a71c0 100644
@@ -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;
                 }

hw/core/accel.c int configure_accelerator(MachineClass *mc) · line 116

Quoted 8 lines
hw/core/accel.c +1 -1
@@ -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;
#9 lore raw

PATCH v2 5/17 accel: Move accel name lookup to separate function

In reply to Eduardo Habkost
---
 hw/core/accel.c | 57 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 24 deletions(-)
hw/core/accel.c +33 -24
index 00a71c0..7f9b715 100644
@@ -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;
         }
     }
 
Signature · 1 line
1.9.3
Reviewed-by on v2 5/17
#10 lore raw

Re: [Qemu-devel] [PATCH v2 05/17] accel: Move accel name lookup to separate function

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 76 lines
---
 hw/core/accel.c | 57 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 24 deletions(-)
hw/core/accel.c +26 -24
index 00a71c0..7f9b715 100644
@@ -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) {

hw/core/accel.c int configure_accelerator(MachineClass *mc) · line 113

Quoted 10 lines
hw/core/accel.c +7 -0
+            init_failed = true;
+            fprintf(stderr, "failed to initialize %s: %s\n",
+                    acc->name,
+                    strerror(-ret));
+            *(acc->allowed) = false;
+        } else {
+            accel_initialised = true;
         }
     }
 
#11 lore raw

PATCH v2 6/17 accel: Use QOM classes for accel types

In reply to Eduardo Habkost

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

---
 hw/core/accel.c    | 117 ++++++++++++++++++++++++++++++++++++++++++-----------
 include/hw/accel.h |  30 ++++++++++++++
 2 files changed, 123 insertions(+), 24 deletions(-)
hw/core/accel.c +93 -24
index 7f9b715..01cdbc3 100644
@@ -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);
include/hw/accel.h +30 -0
index 5537d74..120ca0e 100644
@@ -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;
 
Signature · 1 line
1.9.3
Reviewed-by on v2 6/17
#12 lore raw

Re: [Qemu-devel] [PATCH v2 06/17] accel: Use QOM classes for accel types

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 191 lines

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

---
 hw/core/accel.c    | 117 ++++++++++++++++++++++++++++++++++++++++++-----------
 include/hw/accel.h |  30 ++++++++++++++
 2 files changed, 123 insertions(+), 24 deletions(-)
hw/core/accel.c +93 -24
index 7f9b715..01cdbc3 100644
@@ -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);
include/hw/accel.h +23 -0
index 5537d74..120ca0e 100644
@@ -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)

include/hw/accel.h line 59

Quoted 10 lines
include/hw/accel.h +7 -0
+
+#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;
 
#13 lore raw

PATCH v2 7/17 accel: Make AccelClass.available() optional

In reply to Eduardo Habkost

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.

---
 hw/core/accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/accel.c +1 -1
index 01cdbc3..483bbe8 100644
@@ -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;
Signature · 1 line
1.9.3
Reviewed-by on v2 7/17
#14 lore raw

Re: [Qemu-devel] [PATCH v2 07/17] accel: Make AccelClass.available() optional

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 3 lines

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. :)

Quoted 11 lines
---
 hw/core/accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/accel.c +0 -0
index 01cdbc3..483bbe8 100644

hw/core/accel.c int configure_accelerator(MachineClass *mc) · line 88

Quoted 8 lines
hw/core/accel.c +1 -1
@@ -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;
#15 lore raw

PATCH v2 8/17 accel: Move KVM accel registration to kvm-all.c

In reply to Eduardo Habkost

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.

---
 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(-)
hw/core/accel.c +0 -18
index 483bbe8..61dafcb 100644
@@ -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);
 }
 
include/sysemu/kvm.h +0 -2
index 174ea36..7b95bfd 100644
@@ -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);
kvm-all.c +25 -1
index b240bf8..7db966e 100644
@@ -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);
kvm-stub.c +0 -5
index 8e7737c..43fc0dd 100644
@@ -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)
 {
 }
Signature · 1 line
1.9.3
Reviewed-by on v2 8/17
#16 lore raw

Re: [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 129 lines

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.

---
 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(-)
hw/core/accel.c +0 -18
index 483bbe8..61dafcb 100644
@@ -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);
 }
 
include/sysemu/kvm.h +0 -2
index 174ea36..7b95bfd 100644
@@ -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);
kvm-all.c +25 -1
index b240bf8..7db966e 100644
@@ -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);
kvm-stub.c +0 -0
index 8e7737c..43fc0dd 100644
@@ -35,11 +35,6 @@ int kvm_init_vcpu(CPUState *cpu)
     return -ENOSYS;

kvm-stub.c int kvm_init_vcpu(CPUState *cpu) · line 40

Quoted 10 lines
kvm-stub.c +0 -5
 }
 
-int kvm_init(MachineClass *mc)
-{
-    return -ENOSYS;
-}
-
 void kvm_flush_coalesced_mmio_buffer(void)
 {
 }
#17 lore raw

Re: [Qemu-devel] [PATCH v2 08/17] accel: Move KVM accel registration to kvm-all.c

In reply to Eduardo Habkost

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 3 lines

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

#18 lore raw

PATCH v2 9/17 accel: Move Xen registration code to xen-common.c

In reply to Eduardo Habkost

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.

---
 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(-)
hw/core/accel.c +0 -18
index 61dafcb..ecd1efa 100644
@@ -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);
 }
 
include/hw/xen/xen.h +0 -1
index f71f2d8..b0ed04c 100644
@@ -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)
xen-common-stub.c +0 -6
index bd56ca2..906f991 100644
@@ -11,9 +11,3 @@
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
 }
-
-int xen_init(MachineClass *mc)
-{
-    return -ENOSYS;
-}
-
xen-common.c +24 -1
index f07b35e..f0b34be 100644
@@ -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);
Signature · 1 line
1.9.3
Reviewed-by on v2 9/17
#19 lore raw

Re: [Qemu-devel] [PATCH v2 09/17] accel: Move Xen registration code to xen-common.c

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 118 lines

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.

---
 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(-)
hw/core/accel.c +0 -18
index 61dafcb..ecd1efa 100644
@@ -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);
 }
 
include/hw/xen/xen.h +0 -1
index f71f2d8..b0ed04c 100644
@@ -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)
xen-common-stub.c +0 -6
index bd56ca2..906f991 100644
@@ -11,9 +11,3 @@
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
 }
-
-int xen_init(MachineClass *mc)
-{
-    return -ENOSYS;
-}
-
xen-common.c +14 -1
index f07b35e..f0b34be 100644
@@ -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,

xen-common.c int xen_init(MachineClass *mc) · line 146

Quoted 10 lines
xen-common.c +10 -0
+    .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);
#20 lore raw

PATCH v2 10/17 accel: Move qtest accel registration to qtest.c

In reply to Eduardo Habkost

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.

---
 hw/core/accel.c        | 18 ------------------
 include/sysemu/qtest.h |  1 -
 qtest.c                | 27 ++++++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 20 deletions(-)
hw/core/accel.c +0 -18
index ecd1efa..5853551 100644
@@ -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);
include/sysemu/qtest.h +0 -1
index 95c9ade..05473b7 100644
@@ -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)
qtest.c +26 -1
index ef0d991..829128e 100644
@@ -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);
Signature · 1 line
1.9.3
Reviewed-by on v2 10/17
#21 lore raw

Re: [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 98 lines

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.

---
 hw/core/accel.c        | 18 ------------------
 include/sysemu/qtest.h |  1 -
 qtest.c                | 27 ++++++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 20 deletions(-)
hw/core/accel.c +0 -18
index ecd1efa..5853551 100644
@@ -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);
include/sysemu/qtest.h +0 -1
index 95c9ade..05473b7 100644
@@ -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)
qtest.c +16 -1
index ef0d991..829128e 100644
@@ -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,

qtest.c bool qtest_driver(void) · line 584

Quoted 10 lines
qtest.c +10 -0
+    .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);
#22 lore raw

Re: [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c

In reply to Eduardo Habkost

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 3 lines

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

Quoted 104 lines

This also allows us to make qtest_init_accel() static.

---
 hw/core/accel.c        | 18 ------------------
 include/sysemu/qtest.h |  1 -
 qtest.c                | 27 ++++++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 20 deletions(-)
hw/core/accel.c +0 -18
index ecd1efa..5853551 100644
@@ -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);
include/sysemu/qtest.h +0 -1
index 95c9ade..05473b7 100644
@@ -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)
qtest.c +26 -1
index ef0d991..829128e 100644
@@ -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);
#23 lore raw

Re: [Qemu-devel] [PATCH v2 10/17] accel: Move qtest accel registration to qtest.c

Quoted 7 lines · Paolo Bonzini

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 3 lines

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.

Signature · 1 line
Eduardo
#24 lore raw

PATCH v2 11/17 accel: Remove tcg_available() function

In reply to Eduardo Habkost

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

---
 arch_init.c                | 5 -----
 hw/core/accel.c            | 1 -
 include/sysemu/arch_init.h | 1 -
 3 files changed, 7 deletions(-)
arch_init.c +0 -5
index 28ece76..4cd21c9 100644
@@ -1335,11 +1335,6 @@ void cpudef_init(void)
 #endif
 }
 
-int tcg_available(void)
-{
-    return 1;
-}
-
 int kvm_available(void)
 {
 #ifdef CONFIG_KVM
hw/core/accel.c +0 -1
index 5853551..aeb779a 100644
@@ -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;
 }
include/sysemu/arch_init.h +0 -1
index 182d48d..5968837 100644
@@ -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);
 
Signature · 1 line
1.9.3
Reviewed-by on v2 11/17
#25 lore raw

Re: [Qemu-devel] [PATCH v2 11/17] accel: Remove tcg_available() function

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 43 lines

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

---
 arch_init.c                | 5 -----
 hw/core/accel.c            | 1 -
 include/sysemu/arch_init.h | 1 -
 3 files changed, 7 deletions(-)
arch_init.c +0 -5
index 28ece76..4cd21c9 100644
@@ -1335,11 +1335,6 @@ void cpudef_init(void)
 #endif
 }
 
-int tcg_available(void)
-{
-    return 1;
-}
-
 int kvm_available(void)
 {
 #ifdef CONFIG_KVM
hw/core/accel.c +0 -1
index 5853551..aeb779a 100644
@@ -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;
 }
include/sysemu/arch_init.h +0 -0
index 182d48d..5968837 100644

include/sysemu/arch_init.h void do_smbios_option(QemuOpts *opts); · line 37

Quoted 7 lines
include/sysemu/arch_init.h +0 -1
@@ -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.

Paolo

#26 lore raw

PATCH v2 12/17 accel: Move accel init/allowed code to separate function

In reply to Eduardo Habkost
---
 hw/core/accel.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
hw/core/accel.c +12 -3
index aeb779a..5817c3c 100644
@@ -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;
         }
Signature · 1 line
1.9.3
Reviewed-by on v2 12/17
#27 lore raw

Re: [Qemu-devel] [PATCH v2 12/17] accel: Move accel init/allowed code to separate function

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 34 lines
---
 hw/core/accel.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
hw/core/accel.c +11 -2
index aeb779a..5817c3c 100644
@@ -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);

hw/core/accel.c int configure_accelerator(MachineClass *mc) · line 109

Quoted 10 lines
hw/core/accel.c +1 -1
+        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;
         }
#28 lore raw

PATCH v2 13/17 accel: Rename 'init' method to 'init_machine'

In reply to Eduardo Habkost

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

---
 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(-)
hw/core/accel.c +4 -4
index 5817c3c..55378f3 100644
@@ -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;
 }
 
include/hw/accel.h +1 -1
index 120ca0e..8812cda 100644
@@ -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;
 
kvm-all.c +1 -1
index 7db966e..dd03dc4 100644
@@ -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;
 }
 
qtest.c +1 -1
index 829128e..4051868 100644
@@ -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;
 }
 
xen-common.c +1 -1
index f0b34be..246d76b 100644
@@ -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;
 }
 
Signature · 1 line
1.9.3
#29 lore raw

Re: [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine'

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 2 lines

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

Quoted 98 lines
---
 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(-)
hw/core/accel.c +4 -4
index 5817c3c..55378f3 100644
@@ -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;
 }
 
include/hw/accel.h +1 -1
index 120ca0e..8812cda 100644
@@ -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;
 
kvm-all.c +1 -1
index 7db966e..dd03dc4 100644
@@ -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;
 }
 
qtest.c +1 -1
index 829128e..4051868 100644
@@ -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;
 }
 
xen-common.c +1 -1
index f0b34be..246d76b 100644
@@ -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;
 }
 
#30 lore raw

Re: [Qemu-devel] [PATCH v2 13/17] accel: Rename 'init' method to 'init_machine'

Quoted 6 lines · Paolo Bonzini

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 2 lines

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.

Signature · 1 line
Eduardo
#31 lore raw

PATCH v2 14/17 accel: Pass MachineState object to accel init functions

In reply to Eduardo Habkost

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.

---
 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(-)
hw/core/accel.c +6 -5
index 55378f3..98fcf0d 100644
@@ -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",
include/hw/accel.h +2 -2
index 8812cda..997720f 100644
@@ -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
include/qemu/typedefs.h +1 -0
index 5f20b0e..04df51b 100644
@@ -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;
kvm-all.c +2 -1
index dd03dc4..9815eaf 100644
@@ -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";
qtest.c +1 -1
index 4051868..0dbcb58 100644
@@ -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;
vl.c +1 -1
index 911de91..8c52092 100644
@@ -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;
xen-common.c +1 -1
index 246d76b..5616f0c 100644
@@ -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) {
Signature · 1 line
1.9.3
Reviewed-by on v2 14/17
#32 lore raw

Re: [Qemu-devel] [PATCH v2 14/17] accel: Pass MachineState object to accel init functions

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 148 lines

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.

---
 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(-)
hw/core/accel.c +6 -5
index 55378f3..98fcf0d 100644
@@ -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",
include/hw/accel.h +2 -2
index 8812cda..997720f 100644
@@ -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
include/qemu/typedefs.h +1 -0
index 5f20b0e..04df51b 100644
@@ -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;
kvm-all.c +2 -1
index dd03dc4..9815eaf 100644
@@ -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";
qtest.c +1 -1
index 4051868..0dbcb58 100644
@@ -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;
vl.c +1 -1
index 911de91..8c52092 100644
@@ -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;
xen-common.c +0 -0
index 246d76b..5616f0c 100644

xen-common.c static void xen_change_state_handler(void *opaque, int running, · line 116

Quoted 8 lines
xen-common.c +1 -1
@@ -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) {
#33 lore raw

PATCH v2 15/17 accel: Create accel object when initializing machine

In reply to Eduardo Habkost

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.

---
 hw/core/accel.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/core/accel.c +4 -0
index 98fcf0d..66ee1fa 100644
@@ -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;
 }
Signature · 1 line
1.9.3
Reviewed-by on v2 15/17
#34 lore raw

Re: [Qemu-devel] [PATCH v2 15/17] accel: Create accel object when initializing machine

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 20 lines

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.

---
 hw/core/accel.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/core/accel.c +2 -0
index 98fcf0d..66ee1fa 100644
@@ -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);

hw/core/accel.c static AccelClass *accel_find(const char *opt_name) · line 74

Quoted 10 lines
hw/core/accel.c +2 -0
+    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;
 }
#35 lore raw

PATCH v2 16/17 accel: Save AccelState on MachineState when initializing

In reply to Eduardo Habkost

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

---
 hw/core/accel.c         | 3 +++
 include/hw/boards.h     | 1 +
 include/qemu/typedefs.h | 2 ++
 3 files changed, 6 insertions(+)
hw/core/accel.c +3 -0
index 66ee1fa..2e1ea76 100644
@@ -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));
     }
include/hw/boards.h +1 -0
index 605a970..1cff2b4 100644
@@ -132,6 +132,7 @@ struct MachineState {
     char *kernel_cmdline;
     char *initrd_filename;
     const char *cpu_model;
+    AccelState *accelerator;
 };
 
 #endif
include/qemu/typedefs.h +2 -0
index 04df51b..446af93 100644
@@ -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;
Signature · 1 line
1.9.3
Reviewed-by on v2 16/17
#36 lore raw

Re: [Qemu-devel] [PATCH v2 16/17] accel: Save AccelState on MachineState when initializing

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 52 lines

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

---
 hw/core/accel.c         | 3 +++
 include/hw/boards.h     | 1 +
 include/qemu/typedefs.h | 2 ++
 3 files changed, 6 insertions(+)
hw/core/accel.c +3 -0
index 66ee1fa..2e1ea76 100644
@@ -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));
     }
include/hw/boards.h +1 -0
index 605a970..1cff2b4 100644
@@ -132,6 +132,7 @@ struct MachineState {
     char *kernel_cmdline;
     char *initrd_filename;
     const char *cpu_model;
+    AccelState *accelerator;
 };
 
 #endif
include/qemu/typedefs.h +0 -0
index 04df51b..446af93 100644

include/qemu/typedefs.h typedef struct MemoryListener MemoryListener; · line 37

Quoted 8 lines
include/qemu/typedefs.h +2 -0
@@ -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,

Paolo

#37 lore raw

PATCH v2 17/17 kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

In reply to Eduardo Habkost

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.

---
 kvm-all.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
kvm-all.c +9 -4
index 9815eaf..8a25f79 100644
@@ -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)
Signature · 1 line
1.9.3
Reviewed-by on v2 17/17
#38 lore raw

Re: [Qemu-devel] [PATCH v2 17/17] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 59 lines

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.

---
 kvm-all.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
kvm-all.c +8 -4
index 9815eaf..8a25f79 100644
@@ -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;
 }

kvm-all.c static const TypeInfo kvm_accel_type = { · line 2240

Quoted 7 lines
kvm-all.c +1 -0
@@ -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)
#39 lore raw
In reply to Eduardo Habkost

Il 29/08/2014 22:31, Eduardo Habkost ha scritto:

Quoted 53 lines

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 <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Alexander Graf <[email protected]>
Cc "Jason J. Herne" <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Andreas Färber <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

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 ++++++++++--
Quoted 9 lines
 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