Skip to contentSkip to conversation

QOMify accelerator code

PATCH In review Eduardo Habkost 2 participants 19 messages Sep 26, 2014 – Sep 29, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 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 v2 -> v3:
* Rename hw/core/accel.c to accel.c
* Rename include/hw/accel.h to include/sysemu/accel.h
* Report unknown accelerator as "not found" instead of "does not exist"
* Squashed "accel: Create accel object when initializing machine" and "accel: Save AccelState on MachineState when initializing" in a single patch

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

Cc Michael Mueller <[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: Report unknown accelerator as "not found" instead of "does not
exist"
accel: Move KVM accel registration to kvm-all.c
accel: Move Xen registration code to xen-common.c
accel: Move qtest accel registration to qtest.c
accel: Remove tcg_available() function
accel: Move accel init/allowed code to separate function
accel: Rename 'init' method to 'init_machine'
accel: Pass MachineState object to accel init functions
accel: Create accel object when initializing machine
kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

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

PATCH v3 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 dbdca59..ce606a6 100644
@@ -2715,7 +2715,7 @@ static int configure_accelerator(MachineClass *mc)
         if (*p == ':') {
             p++;
         }
-        p = get_opt_name(buf, sizeof (buf), p, ':');
+        p = get_opt_name(buf, sizeof(buf), p, ':');
         for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
             if (strcmp(accel_list[i].opt_name, buf) == 0) {
                 if (!accel_list[i].available()) {
Signature · 1 line
1.9.3
#2 lore raw

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

In reply to Eduardo Habkost

---
Changes v2 -> v3:

* Rename hw/core/accel.c -> accel.c,
* Rename include/hw/accel.h -> include/sysemu/accel.h

---
 Makefile.objs          |   1 +
 accel.c                | 113 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/accel.h |  32 ++++++++++++++
 vl.c                   |  81 +----------------------------------
 4 files changed, 147 insertions(+), 80 deletions(-)
 create mode 100644 accel.c
 create mode 100644 include/sysemu/accel.h
Makefile.objs +1 -0
index 97db978..add8375 100644
@@ -62,6 +62,7 @@ common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
 
 common-obj-y += audio/
 common-obj-y += hw/
+common-obj-y += accel.o
 
 common-obj-y += ui/
 common-obj-y += bt-host.o bt-vhci.o
accel.c new file +113 -0

113 lines not on this page · raw message

include/sysemu/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
#3 lore raw

PATCH v3 3/17 accel: Create AccelType typedef

In reply to Eduardo Habkost
---
 accel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
accel.c +4 -2
index 9424796..3cefd74 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
#4 lore raw

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

In reply to Eduardo Habkost
---
 accel.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
accel.c +10 -8
index 3cefd74..fc8c551 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
#5 lore raw

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

In reply to Eduardo Habkost
---
 accel.c | 57 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 24 deletions(-)
accel.c +33 -24
index fc8c551..c752fcc 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
#6 lore raw

PATCH v3 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.

---
 accel.c                | 117 +++++++++++++++++++++++++++++++++++++++----------
 include/sysemu/accel.h |  30 +++++++++++++
 2 files changed, 123 insertions(+), 24 deletions(-)
accel.c +93 -24
index c752fcc..a3e2fd9 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/sysemu/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
#7 lore raw

PATCH v3 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.

---
 accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel.c +1 -1
index a3e2fd9..85177f1 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
#8 lore raw

PATCH v3 8/17 accel: Report unknown accelerator as "not found" instead of "does not exist"

In reply to Eduardo Habkost

As the accelerator classes won't be registered anymore if they are not enabled at compile time, saying "does not exist" may be misleading, as the accelerator may be simply disabled. Change the wording to just say "not found".

---
 accel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel.c +1 -1
index 85177f1..fce6eab 100644
@@ -79,7 +79,7 @@ int configure_accelerator(MachineClass *mc)
         p = get_opt_name(buf, sizeof(buf), p, ':');
         acc = accel_find(buf);
         if (!acc) {
-            fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
+            fprintf(stderr, "\"%s\" accelerator not found.\n", buf);
             continue;
         }
         if (acc->available && !acc->available()) {
Signature · 1 line
1.9.3
#9 lore raw

PATCH v3 9/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.

---
 accel.c              | 18 ------------------
 include/sysemu/kvm.h |  2 --
 kvm-all.c            | 26 +++++++++++++++++++++++++-
 kvm-stub.c           |  5 -----
 4 files changed, 25 insertions(+), 26 deletions(-)
accel.c +0 -18
index fce6eab..a20e427 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 d2000af..7f34006 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 8b9e66d..009c0dc 100644
@@ -25,6 +25,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/accel.h"
 #include "hw/hw.h"
 #include "hw/pci/msi.h"
 #include "hw/s390x/adapter.h"
@@ -110,6 +111,8 @@ struct KVMState
 #endif
 };
 
+#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
+
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
@@ -1381,7 +1384,7 @@ static int kvm_max_vcpus(KVMState *s)
     return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-int kvm_init(MachineClass *mc)
+static int kvm_init(MachineClass *mc)
 {
     static const char upgrade_note[] =
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
@@ -2227,3 +2230,24 @@ int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target)
     }
     return r;
 }
+
+static void kvm_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "KVM";
+    ac->init = kvm_init;
+    ac->allowed = &kvm_allowed;
+}
+
+static const TypeInfo kvm_accel_type = {
+    .name = TYPE_KVM_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = kvm_accel_class_init,
+};
+
+static void kvm_type_init(void)
+{
+    type_register_static(&kvm_accel_type);
+}
+
+type_init(kvm_type_init);
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
#10 lore raw

PATCH v3 10/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.

---
 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(-)
accel.c +0 -18
index a20e427..2cefbb0 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..acc64d5 100644
@@ -11,6 +11,7 @@
 #include "hw/xen/xen_backend.h"
 #include "qmp-commands.h"
 #include "sysemu/char.h"
+#include "sysemu/accel.h"
 
 //#define DEBUG_XEN
 
@@ -109,7 +110,7 @@ static void xen_change_state_handler(void *opaque, int running,
     }
 }
 
-int xen_init(MachineClass *mc)
+static int xen_init(MachineClass *mc)
 {
     xen_xc = xen_xc_interface_open(0, 0, 0);
     if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
@@ -121,3 +122,25 @@ int xen_init(MachineClass *mc)
     return 0;
 }
 
+static void xen_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "Xen";
+    ac->init = xen_init;
+    ac->allowed = &xen_allowed;
+}
+
+#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
+
+static const TypeInfo xen_accel_type = {
+    .name = TYPE_XEN_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = xen_accel_class_init,
+};
+
+static void xen_type_init(void)
+{
+    type_register_static(&xen_accel_type);
+}
+
+type_init(xen_type_init);
Signature · 1 line
1.9.3
#11 lore raw

PATCH v3 11/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.

---
 accel.c                | 18 ------------------
 include/sysemu/qtest.h |  1 -
 qtest.c                | 27 ++++++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 20 deletions(-)
accel.c +0 -18
index 2cefbb0..2cf47337 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..0af8b74 100644
@@ -17,6 +17,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
+#include "sysemu/accel.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/cpus.h"
 #include "qemu/config-file.h"
@@ -519,7 +520,7 @@ static void configure_qtest_icount(const char *options)
     qemu_opts_del(opts);
 }
 
-int qtest_init_accel(MachineClass *mc)
+static int qtest_init_accel(MachineClass *mc)
 {
     configure_qtest_icount("0");
     return 0;
@@ -557,3 +558,27 @@ bool qtest_driver(void)
 {
     return qtest_chr;
 }
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "QTest";
+    ac->available = qtest_available;
+    ac->init = qtest_init_accel;
+    ac->allowed = &qtest_allowed;
+}
+
+#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
+
+static const TypeInfo qtest_accel_type = {
+    .name = TYPE_QTEST_ACCEL,
+    .parent = TYPE_ACCEL,
+    .class_init = qtest_accel_class_init,
+};
+
+static void qtest_type_init(void)
+{
+    type_register_static(&qtest_accel_type);
+}
+
+type_init(qtest_type_init);
Signature · 1 line
1.9.3
#12 lore raw

PATCH v3 12/17 accel: Remove tcg_available() function

In reply to Eduardo Habkost

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

---
 accel.c                    | 1 -
 arch_init.c                | 5 -----
 include/sysemu/arch_init.h | 1 -
 3 files changed, 7 deletions(-)
accel.c +0 -1
index 2cf47337..0f3fcee 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;
 }
arch_init.c +0 -5
index c974f3f..9b3e25d 100644
@@ -1337,11 +1337,6 @@ void cpudef_init(void)
 #endif
 }
 
-int tcg_available(void)
-{
-    return 1;
-}
-
 int kvm_available(void)
 {
 #ifdef CONFIG_KVM
include/sysemu/arch_init.h +0 -1
index 769ec06..54b36c1 100644
@@ -33,7 +33,6 @@ void do_smbios_option(QemuOpts *opts);
 void ram_mig_init(void);
 void cpudef_init(void);
 void audio_init(void);
-int tcg_available(void);
 int kvm_available(void);
 int xen_available(void);
 
Signature · 1 line
1.9.3
#13 lore raw

PATCH v3 13/17 accel: Move accel init/allowed code to separate function

In reply to Eduardo Habkost
---
 accel.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
accel.c +12 -3
index 0f3fcee..9241967 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
#14 lore raw

PATCH v3 14/17 accel: Rename 'init' method to 'init_machine'

In reply to Eduardo Habkost

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

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

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

---
Changes v2 -> v3:
* Clarify reasoning for the method rename on commit message.

---
 accel.c                | 8 ++++----
 include/sysemu/accel.h | 2 +-
 kvm-all.c              | 2 +-
 qtest.c                | 2 +-
 xen-common.c           | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
accel.c +4 -4
index 9241967..b151d55 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/sysemu/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 009c0dc..97f1261 100644
@@ -2235,7 +2235,7 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "KVM";
-    ac->init = kvm_init;
+    ac->init_machine = kvm_init;
     ac->allowed = &kvm_allowed;
 }
 
qtest.c +1 -1
index 0af8b74..18e26fc 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 acc64d5..acb738f 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
#15 lore raw

PATCH v3 15/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.

---
 accel.c                 | 11 ++++++-----
 include/qemu/typedefs.h |  1 +
 include/sysemu/accel.h  |  4 ++--
 kvm-all.c               |  3 ++-
 qtest.c                 |  2 +-
 vl.c                    |  2 +-
 xen-common.c            |  2 +-
 7 files changed, 14 insertions(+), 11 deletions(-)
accel.c +6 -5
index b151d55..6087ab3 100644
@@ -24,6 +24,7 @@
  */
 
 #include "sysemu/accel.h"
+#include "hw/boards.h"
 #include "qemu-common.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
@@ -35,7 +36,7 @@
 int tcg_tb_size;
 static bool tcg_allowed = true;
 
-static int tcg_init(MachineClass *mc)
+static int tcg_init(MachineState *ms)
 {
     tcg_exec_init(tcg_tb_size * 1024 * 1024);
     return 0;
@@ -57,18 +58,18 @@ static AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
-static int accel_init_machine(AccelClass *acc, MachineClass *mc)
+static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
     int ret;
     *(acc->allowed) = true;
-    ret = acc->init_machine(mc);
+    ret = acc->init_machine(ms);
     if (ret < 0) {
         *(acc->allowed) = false;
     }
     return ret;
 }
 
-int configure_accelerator(MachineClass *mc)
+int configure_accelerator(MachineState *ms)
 {
     const char *p;
     char buf[10];
@@ -98,7 +99,7 @@ int configure_accelerator(MachineClass *mc)
                    acc->name);
             continue;
         }
-        ret = accel_init_machine(acc, mc);
+        ret = accel_init_machine(acc, ms);
         if (ret < 0) {
             init_failed = true;
             fprintf(stderr, "failed to initialize %s: %s\n",
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;
include/sysemu/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
kvm-all.c +2 -1
index 97f1261..8de1a83 100644
@@ -1384,8 +1384,9 @@ static int kvm_max_vcpus(KVMState *s)
     return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-static int kvm_init(MachineClass *mc)
+static int kvm_init(MachineState *ms)
 {
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
     static const char upgrade_note[] =
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
         "(see http://sourceforge.net/projects/kvm).\n";
qtest.c +1 -1
index 18e26fc..4b85995 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 92dfb5c..1dd0e7d 100644
@@ -4182,7 +4182,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    configure_accelerator(machine_class);
+    configure_accelerator(current_machine);
 
     if (qtest_chrdev) {
         Error *local_err = NULL;
xen-common.c +1 -1
index acb738f..56359ca 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
#16 lore raw

PATCH v3 16/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.

---
Changes v2 -> v3:
* Squashed "accel: Create accel object when initializing machine" and "accel: Save AccelState on MachineState when initializing" in a single patch

---
 accel.c                 | 7 +++++++
 include/hw/boards.h     | 1 +
 include/qemu/typedefs.h | 2 ++
 3 files changed, 10 insertions(+)
accel.c +7 -0
index 6087ab3..74e41da 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;
@@ -60,11 +61,17 @@ static AccelClass *accel_find(const char *opt_name)
 
 static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
+    ObjectClass *oc = OBJECT_CLASS(acc);
+    const char *cname = object_class_get_name(oc);
+    AccelState *accel = ACCEL(object_new(cname));
     int ret;
+    ms->accelerator = accel;
     *(acc->allowed) = true;
     ret = acc->init_machine(ms);
     if (ret < 0) {
+        ms->accelerator = NULL;
         *(acc->allowed) = false;
+        object_unref(OBJECT(accel));
     }
     return ret;
 }
include/hw/boards.h +1 -0
index dfb6718..8f0eeaf 100644
@@ -133,6 +133,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
#17 lore raw

PATCH v3 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 8de1a83..3ab1b4e 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;
@@ -1405,7 +1410,7 @@ static int kvm_init(MachineState *ms)
     int i, type = 0;
     const char *kvm_type;
 
-    s = g_malloc0(sizeof(KVMState));
+    s = KVM_STATE(ms->accelerator);
 
     /*
      * On systems where the kernel can support different base page
@@ -1594,7 +1599,6 @@ err:
         close(s->fd);
     }
     g_free(s->slots);
-    g_free(s);
 
     return ret;
 }
@@ -2244,6 +2248,7 @@ static const TypeInfo kvm_accel_type = {
     .name = TYPE_KVM_ACCEL,
     .parent = TYPE_ACCEL,
     .class_init = kvm_accel_class_init,
+    .instance_size = sizeof(KVMState),
 };
 
 static void kvm_type_init(void)
Signature · 1 line
1.9.3
Reviewed-by on the v3 series
#18 lore raw
In reply to Eduardo Habkost

Il 26/09/2014 22:45, Eduardo Habkost ha scritto:

Quoted 62 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 v2 -> v3:
* Rename hw/core/accel.c to accel.c
* Rename include/hw/accel.h to include/sysemu/accel.h
* Report unknown accelerator as "not found" instead of "does not exist"
* Squashed "accel: Create accel object when initializing machine" and "accel: Save AccelState on MachineState when initializing" in a single patch

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

Cc Michael Mueller <[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: Report unknown accelerator as "not found" instead of "does not
exist"
accel: Move KVM accel registration to kvm-all.c
accel: Move Xen registration code to xen-common.c
accel: Move qtest accel registration to qtest.c
accel: Remove tcg_available() function
accel: Move accel init/allowed code to separate function
accel: Rename 'init' method to 'init_machine'
accel: Pass MachineState object to accel init functions
accel: Create accel object when initializing machine
kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

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