Skip to contentSkip to conversation

Remove AccelClass::available field

PATCH In review Eduardo Habkost 3 participants 14 messages Apr 22, 2019 – Apr 23, 2019

lore
Share & tools
lore
#0 lore raw

cover Remove AccelClass::available field

The only user of AccelClass::available was the qtest accelerator, to make it unavailable on non-POSIX systems. We can drop the field if we simply not compile the accelerator code on those systems.

Eduardo Habkost (3):
qtest: Move accel code to accel/qtest.c
qtest: Don't compile qtest accel on non-POSIX systems
accel: Remove unused AccelClass::available field

 include/sysemu/accel.h |  1 -
 include/sysemu/qtest.h |  9 -------
 accel/accel.c          |  5 ----
 accel/qtest.c          | 54 ++++++++++++++++++++++++++++++++++++++++++
 qtest.c                | 34 --------------------------
 accel/Makefile.objs    |  1 +
 6 files changed, 55 insertions(+), 49 deletions(-)
 create mode 100644 accel/qtest.c
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#1 lore raw

PATCH 1/3 qtest: Move accel code to accel/qtest.c

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

---
 accel/qtest.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++
 qtest.c             | 34 ----------------------------
 accel/Makefile.objs |  1 +
 3 files changed, 56 insertions(+), 34 deletions(-)
 create mode 100644 accel/qtest.c
accel/qtest.c new file +55 -0
new file mode 100644
index 0000000000..a02b3c26c7
@@ -0,0 +1,55 @@
+/*
+ * QTest accelerator code
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "sysemu/accel.h"
+#include "sysemu/qtest.h"
+#include "sysemu/cpus.h"
+
+static int qtest_init_accel(MachineState *ms)
+{
+    QemuOpts *opts = qemu_opts_create(qemu_find_opts("icount"), NULL, 0,
+                                      &error_abort);
+    qemu_opt_set(opts, "shift", "0", &error_abort);
+    configure_icount(opts, &error_abort);
+    qemu_opts_del(opts);
+    return 0;
+}
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "QTest";
+    ac->available = qtest_available;
+    ac->init_machine = 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);
qtest.c +0 -34
index 527141785f..f2e2f27778 100644
@@ -749,16 +749,6 @@ static void qtest_event(void *opaque, int event)
     }
 }
 
-static int qtest_init_accel(MachineState *ms)
-{
-    QemuOpts *opts = qemu_opts_create(qemu_find_opts("icount"), NULL, 0,
-                                      &error_abort);
-    qemu_opt_set(opts, "shift", "0", &error_abort);
-    configure_icount(opts, &error_abort);
-    qemu_opts_del(opts);
-    return 0;
-}
-
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp)
 {
     Chardev *chr;
@@ -791,27 +781,3 @@ bool qtest_driver(void)
 {
     return qtest_chr.chr != NULL;
 }
-
-static void qtest_accel_class_init(ObjectClass *oc, void *data)
-{
-    AccelClass *ac = ACCEL_CLASS(oc);
-    ac->name = "QTest";
-    ac->available = qtest_available;
-    ac->init_machine = 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);
accel/Makefile.objs +1 -0
index c3718a10c5..2a5ed46940 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_SOFTMMU) += accel.o
+obj-$(CONFIG_SOFTMMU) += qtest.o
 obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Reviewed-by Tested-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] qtest: Move accel code to accel/qtest.c

Hi Eduardo,

Quoted 27 lines · Eduardo Habkost

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

---
 accel/qtest.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++
 qtest.c             | 34 ----------------------------
 accel/Makefile.objs |  1 +
 3 files changed, 56 insertions(+), 34 deletions(-)
 create mode 100644 accel/qtest.c
accel/qtest.c new file +6 -0
new file mode 100644
index 0000000000..a02b3c26c7
@@ -0,0 +1,55 @@
+/*
+ * QTest accelerator code
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:

accel/qtest.c line 16

Quoted 10 lines
accel/qtest.c new file +10 -0
+ *  Anthony Liguori   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/module.h"

Why include "qemu/module.h"?
I guess you don't need it.

Quoted 94 lines
accel/qtest.c new file +39 -0
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "sysemu/accel.h"
+#include "sysemu/qtest.h"
+#include "sysemu/cpus.h"
+
+static int qtest_init_accel(MachineState *ms)
+{
+    QemuOpts *opts = qemu_opts_create(qemu_find_opts("icount"), NULL, 0,
+                                      &error_abort);
+    qemu_opt_set(opts, "shift", "0", &error_abort);
+    configure_icount(opts, &error_abort);
+    qemu_opts_del(opts);
+    return 0;
+}
+
+static void qtest_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelClass *ac = ACCEL_CLASS(oc);
+    ac->name = "QTest";
+    ac->available = qtest_available;
+    ac->init_machine = 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);
qtest.c +0 -34
index 527141785f..f2e2f27778 100644
@@ -749,16 +749,6 @@ static void qtest_event(void *opaque, int event)
     }
 }
 
-static int qtest_init_accel(MachineState *ms)
-{
-    QemuOpts *opts = qemu_opts_create(qemu_find_opts("icount"), NULL, 0,
-                                      &error_abort);
-    qemu_opt_set(opts, "shift", "0", &error_abort);
-    configure_icount(opts, &error_abort);
-    qemu_opts_del(opts);
-    return 0;
-}
-
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp)
 {
     Chardev *chr;
@@ -791,27 +781,3 @@ bool qtest_driver(void)
 {
     return qtest_chr.chr != NULL;
 }
-
-static void qtest_accel_class_init(ObjectClass *oc, void *data)
-{
-    AccelClass *ac = ACCEL_CLASS(oc);
-    ac->name = "QTest";
-    ac->available = qtest_available;
-    ac->init_machine = 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);
accel/Makefile.objs +0 -0
index c3718a10c5..2a5ed46940 100644

accel/Makefile.objs line 5

Quoted 5 lines
accel/Makefile.objs +1 -0
@@ -1,4 +1,5 @@
 obj-$(CONFIG_SOFTMMU) += accel.o
+obj-$(CONFIG_SOFTMMU) += qtest.o
 obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] qtest: Move accel code to accel/qtest.c

Quoted 10 lines · Philippe Mathieu-Daudé

Hi Eduardo,

Quoted 7 lines · Eduardo Habkost

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

[...]

Quoted 4 lines
Quoted 1 line

+#include "qemu/module.h"

Why include "qemu/module.h"?
I guess you don't need it.

That's where the type_init() macro is defined.

Quoted 1 line
Quoted 1 line

+type_init(qtest_type_init);

[...]

Quoted 2 lines

Thanks!

Signature · 1 line
Eduardo
#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] qtest: Move accel code to accel/qtest.c

Quoted 11 lines · Eduardo Habkost
Quoted 10 lines · Philippe Mathieu-Daudé

Hi Eduardo,

Quoted 7 lines · Eduardo Habkost

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

Quoted 7 lines

[...]

Quoted 4 lines
Quoted 1 line

+#include "qemu/module.h"

Why include "qemu/module.h"?
I guess you don't need it.

That's where the type_init() macro is defined.

Oh correct...

I tried to remove it/compile and it worked because it is pulled by:

"sysemu/cpus.h"
-> "qemu/timer.h"

     -> "qemu-common.h"
         -> "qemu/module.h"

Thanks!

Quoted 9 lines
Quoted 1 line
Quoted 1 line

+type_init(qtest_type_init);

[...]

Quoted 2 lines

Thanks!

#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] qtest: Move accel code to accel/qtest.c

In reply to Eduardo Habkost
Quoted 10 lines · Eduardo Habkost

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

---
 accel/qtest.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++

New file ==> You should update MAINTAINERS here as well.

Thomas

#6 lore raw

PATCH 1/1 fixup! qtest: Move accel code to accel/qtest.c

Quoted 5 lines · Thomas Huth
Quoted 4 lines · Eduardo Habkost

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Quoted 8 lines
Quoted 6 lines

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

---
 accel/qtest.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++

New file ==> You should update MAINTAINERS here as well.

Oops, sorry! Fixup below.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 56139ac8ab..cf3156d952 100644
@@ -2024,6 +2024,7 @@ M: Laurent Vivier <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
 F: qtest.c
+F: accel/qtest.c
 F: tests/libqtest.*
 F: tests/libqos/
 F: tests/*-test.c
Signature · 4 lines
2.18.0.rc1.1.g3f1ff2140

-- 
Eduardo
#7 lore raw

Re: [Qemu-devel] [PATCH] fixup! qtest: Move accel code to accel/qtest.c

Quoted 27 lines · Eduardo Habkost
Quoted 5 lines · Thomas Huth
Quoted 4 lines · Eduardo Habkost

QTest has two parts: the server (-qtest) and the accelerator (-machine accel=qtest). The accelerator depends on CONFIG_POSIX due to its usage of sigwait(), but the server doesn't.

Quoted 8 lines
Quoted 6 lines

Move the accel code to accel/qtest.c. Later we will disable compilation of accel/qtest.c on non-POSIX systems.

---
 accel/qtest.c       | 55 +++++++++++++++++++++++++++++++++++++++++++++

New file ==> You should update MAINTAINERS here as well.

Oops, sorry! Fixup below.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +0 -0
index 56139ac8ab..cf3156d952 100644

MAINTAINERS M: Laurent Vivier <[email protected]> · line 2030

Quoted 7 lines
MAINTAINERS +1 -0
@@ -2024,6 +2024,7 @@ M: Laurent Vivier <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
 F: qtest.c
+F: accel/qtest.c
 F: tests/libqtest.*
 F: tests/libqos/
 F: tests/*-test.c

All right, queued the patches on my qtest-next branch:

https://gitlab.com/huth/qemu/tree/qtest-next

Thanks,
Thomas

#8 lore raw

PATCH 2/3 qtest: Don't compile qtest accel on non-POSIX systems

In reply to Eduardo Habkost

qtest_available() will always return 0 on non-POSIX systems. It's simpler to just not compile the accelerator code on those systems instead of relying on the AccelClass::available function.

---
 include/sysemu/qtest.h | 9 ---------
 accel/qtest.c          | 1 -
 accel/Makefile.objs    | 2 +-
 3 files changed, 1 insertion(+), 11 deletions(-)
include/sysemu/qtest.h +0 -9
index 70aa40aa72..096ddfc20c 100644
@@ -27,13 +27,4 @@ bool qtest_driver(void);
 
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
 
-static inline int qtest_available(void)
-{
-#ifdef CONFIG_POSIX
-    return 1;
-#else
-    return 0;
-#endif
-}
-
 #endif
accel/qtest.c +0 -1
index a02b3c26c7..5b88f55921 100644
@@ -34,7 +34,6 @@ static void qtest_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "QTest";
-    ac->available = qtest_available;
     ac->init_machine = qtest_init_accel;
     ac->allowed = &qtest_allowed;
 }
accel/Makefile.objs +1 -1
index 2a5ed46940..8b498d39d8 100644
@@ -1,5 +1,5 @@
 obj-$(CONFIG_SOFTMMU) += accel.o
-obj-$(CONFIG_SOFTMMU) += qtest.o
+obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o
 obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Reviewed-by Tested-by on v1 2/3
#9 lore raw

Re: [Qemu-devel] [PATCH 2/3] qtest: Don't compile qtest accel on non-POSIX systems

Quoted 5 lines · Eduardo Habkost

qtest_available() will always return 0 on non-POSIX systems. It's simpler to just not compile the accelerator code on those systems instead of relying on the AccelClass::available function.

mingw64:

Quoted 48 lines
---
 include/sysemu/qtest.h | 9 ---------
 accel/qtest.c          | 1 -
 accel/Makefile.objs    | 2 +-
 3 files changed, 1 insertion(+), 11 deletions(-)
include/sysemu/qtest.h +0 -9
index 70aa40aa72..096ddfc20c 100644
@@ -27,13 +27,4 @@ bool qtest_driver(void);
 
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
 
-static inline int qtest_available(void)
-{
-#ifdef CONFIG_POSIX
-    return 1;
-#else
-    return 0;
-#endif
-}
-
 #endif
accel/qtest.c +0 -1
index a02b3c26c7..5b88f55921 100644
@@ -34,7 +34,6 @@ static void qtest_accel_class_init(ObjectClass *oc, void *data)
 {
     AccelClass *ac = ACCEL_CLASS(oc);
     ac->name = "QTest";
-    ac->available = qtest_available;
     ac->init_machine = qtest_init_accel;
     ac->allowed = &qtest_allowed;
 }
accel/Makefile.objs +1 -1
index 2a5ed46940..8b498d39d8 100644
@@ -1,5 +1,5 @@
 obj-$(CONFIG_SOFTMMU) += accel.o
-obj-$(CONFIG_SOFTMMU) += qtest.o
+obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o
 obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
Reviewed-by on v1 2/3
#10 lore raw

Re: [Qemu-devel] [PATCH 2/3] qtest: Don't compile qtest accel on non-POSIX systems

In reply to Eduardo Habkost
Quoted 10 lines · Eduardo Habkost

qtest_available() will always return 0 on non-POSIX systems. It's simpler to just not compile the accelerator code on those systems instead of relying on the AccelClass::available function.

---
 include/sysemu/qtest.h | 9 ---------
 accel/qtest.c          | 1 -
 accel/Makefile.objs    | 2 +-
 3 files changed, 1 insertion(+), 11 deletions(-)
#11 lore raw

PATCH 3/3 accel: Remove unused AccelClass::available field

In reply to Eduardo Habkost

The field is not used anymore, we can remove it.

---
 include/sysemu/accel.h | 1 -
 accel/accel.c          | 5 -----
 2 files changed, 6 deletions(-)
include/sysemu/accel.h +0 -1
index 5565e00a96..70e9e2f2a1 100644
@@ -38,7 +38,6 @@ typedef struct AccelClass {
 
     const char *opt_name;
     const char *name;
-    int (*available)(void);
     int (*init_machine)(MachineState *ms);
     void (*setup_post)(MachineState *ms, AccelState *accel);
     bool *allowed;
accel/accel.c +0 -5
index 454fef9d92..5fa31717b4 100644
@@ -107,11 +107,6 @@ void configure_accelerator(MachineState *ms, const char *progname)
         if (!acc) {
             continue;
         }
-        if (acc->available && !acc->available()) {
-            printf("%s not supported for this target\n",
-                   acc->name);
-            continue;
-        }
         ret = accel_init_machine(acc, ms);
         if (ret < 0) {
             init_failed = true;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Reviewed-by Tested-by on v1 3/3
#12 lore raw

Re: [Qemu-devel] [PATCH 3/3] accel: Remove unused AccelClass::available field

Quoted 3 lines · Eduardo Habkost

The field is not used anymore, we can remove it.

mingw64:

Quoted 34 lines
---
 include/sysemu/accel.h | 1 -
 accel/accel.c          | 5 -----
 2 files changed, 6 deletions(-)
include/sysemu/accel.h +0 -1
index 5565e00a96..70e9e2f2a1 100644
@@ -38,7 +38,6 @@ typedef struct AccelClass {
 
     const char *opt_name;
     const char *name;
-    int (*available)(void);
     int (*init_machine)(MachineState *ms);
     void (*setup_post)(MachineState *ms, AccelState *accel);
     bool *allowed;
accel/accel.c +0 -5
index 454fef9d92..5fa31717b4 100644
@@ -107,11 +107,6 @@ void configure_accelerator(MachineState *ms, const char *progname)
         if (!acc) {
             continue;
         }
-        if (acc->available && !acc->available()) {
-            printf("%s not supported for this target\n",
-                   acc->name);
-            continue;
-        }
         ret = accel_init_machine(acc, ms);
         if (ret < 0) {
             init_failed = true;