qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH] vl: only display available accelerators
@ 2017-10-30  4:00 Philippe Mathieu-Daudé
  2017-10-30  4:13 ` no-reply
  2017-10-30  8:20 ` Eduardo Habkost
  0 siblings, 2 replies; 19+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-30  4:00 UTC (permalink / raw)
  To: Paolo Bonzini, Thomas Huth, Eduardo Habkost, Peter Xu,
	Markus Armbruster, Stefano Stabellini, Anthony Perard
  Cc: Philippe Mathieu-Daudé, qemu-devel, Emilio G . Cota,
	Eric Blake, Richard Henderson

examples configuring with '--enable-kvm --disable-tcg'

- before

  $ qemu-system-x86_64 -accel help
  Possible accelerators: kvm, xen, hax, tcg

  $ qemu-system-x86_64 -accel tcg
  qemu-system-x86_64: -machine accel=tcg: No accelerator found

  # qemu-system-x86_64 -accel hax
  qemu-system-x86_64: -machine accel=hax: No accelerator found

  # qemu-system-x86_64 -accel xen
  xencall: error: Could not obtain handle on privileged command interface: No such file or directory
  xen be core: xen be core: can't open xen interface
  can't open xen interface
  qemu-system-x86_64: failed to initialize Xen: Operation not permitted

- after

  $ qemu-system-x86_64 -accel help
  Possible accelerators: kvm

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
RFC because:
    - I don't think this is the nicest way, too much #ifdef'fery in main()
    - I'm not sure the correct use of CONFIG_KVM_IS_POSSIBLE
    - shouldn't CONFIG_XEN/CONFIG_HAX be as poisoned as CONFIG_KVM?

 vl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index ec299099ff..13fce86a6e 100644
--- a/vl.c
+++ b/vl.c
@@ -3883,7 +3883,20 @@ int main(int argc, char **argv, char **envp)
                                                      optarg, true);
                 optarg = qemu_opt_get(accel_opts, "accel");
                 if (!optarg || is_help_option(optarg)) {
-                    error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
+                    error_printf("Possible accelerators: ");
+#ifdef CONFIG_KVM_IS_POSSIBLE
+                    error_printf("kvm ");
+#endif
+#ifdef CONFIG_XEN
+                    error_printf("xen ");
+#endif
+#ifdef CONFIG_HAX
+                    error_printf("hax ");
+#endif
+#ifdef CONFIG_TCG
+                    error_printf("tcg ");
+#endif
+                    error_printf("\n");
                     exit(0);
                 }
                 opts = qemu_opts_create(qemu_find_opts("machine"), NULL,
-- 
2.15.0.rc2

^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [Qemu-devel] [RFC PATCH] vl: only display available accelerators
@ 2017-10-30 18:14 Philippe Mathieu-Daudé
  2017-10-30 18:18 ` Philippe Mathieu-Daudé
  2017-11-03  0:35 ` Eduardo Habkost
  0 siblings, 2 replies; 19+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-10-30 18:14 UTC (permalink / raw)
  To: Paolo Bonzini, Thomas Huth, Eduardo Habkost, Peter Xu,
	Markus Armbruster, Stefano Stabellini, Anthony Perard
  Cc: Philippe Mathieu-Daudé, qemu-devel, qemu-trivial,
	Emilio G . Cota, Eric Blake, Richard Henderson

examples configuring with '--enable-kvm --disable-tcg'

- before

  $ qemu-system-x86_64 -accel help
  Possible accelerators: kvm, xen, hax, tcg

  $ qemu-system-x86_64 -accel tcg
  qemu-system-x86_64: -machine accel=tcg: No accelerator found

  # qemu-system-x86_64 -accel hax
  qemu-system-x86_64: -machine accel=hax: No accelerator found

- after

  $ qemu-system-x86_64 -accel help
  Possible accelerators:
    xen
    kvm

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
since RFC:
  - use much cleaner object_class_get_list(TYPE_ACCEL, false)

 vl.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/vl.c b/vl.c
index ec299099ff..0f13641715 100644
--- a/vl.c
+++ b/vl.c
@@ -2764,6 +2764,39 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b)
     exit(!name || !is_help_option(name));
 }
 
+static void accel_list_entry(gpointer data, gpointer user_data)
+{
+    ObjectClass *oc = data;
+    const char *typename = object_class_get_name(oc);
+    int len;
+
+    if (!qtest_driver() && !g_strcmp0(typename, ACCEL_CLASS_NAME("qtest"))) {
+        return; /* used by test cases */
+    }
+
+    len = strlen(typename) - strlen("-" TYPE_ACCEL);
+    if (len > 0) {
+        error_printf("  %.*s\n", len, typename);
+    }
+}
+
+static void accel_parse(const char *name, QemuOpts *accel_opts)
+{
+    const char *optarg = qemu_opt_get(accel_opts, "accel");
+    GSList *list;
+
+    if (!is_help_option(optarg)) {
+        return;
+    }
+
+    list = object_class_get_list(TYPE_ACCEL, false);
+    error_printf("Possible accelerators:\n");
+    g_slist_foreach(list, accel_list_entry, NULL);
+    g_slist_free(list);
+
+    exit(0);
+}
+
 void qemu_add_exit_notifier(Notifier *notify)
 {
     notifier_list_add(&exit_notifiers, notify);
@@ -3881,11 +3914,7 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_accel:
                 accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"),
                                                      optarg, true);
-                optarg = qemu_opt_get(accel_opts, "accel");
-                if (!optarg || is_help_option(optarg)) {
-                    error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
-                    exit(0);
-                }
+                accel_parse(optarg, accel_opts);
                 opts = qemu_opts_create(qemu_find_opts("machine"), NULL,
                                         false, &error_abort);
                 qemu_opt_set(opts, "accel", optarg, &error_abort);
-- 
2.15.0.rc2

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

end of thread, other threads:[~2017-11-08 19:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-30  4:00 [Qemu-devel] [RFC PATCH] vl: only display available accelerators Philippe Mathieu-Daudé
2017-10-30  4:13 ` no-reply
2017-10-30  8:20 ` Eduardo Habkost
2017-10-30 15:01   ` Philippe Mathieu-Daudé
2017-10-30 15:34     ` Peter Maydell
2017-11-08 13:28   ` Daniel P. Berrange
2017-11-08 16:21     ` Philippe Mathieu-Daudé
2017-11-08 16:59       ` Eduardo Habkost
2017-11-08 17:06         ` Daniel P. Berrange
2017-11-08 17:25           ` Eduardo Habkost
2017-11-08 17:28             ` Daniel P. Berrange
2017-11-08 18:03             ` Philippe Mathieu-Daudé
2017-11-08 18:35               ` Eduardo Habkost
2017-11-08 19:41                 ` Philippe Mathieu-Daudé
  -- strict thread matches above, loose matches on Subject: below --
2017-10-30 18:14 Philippe Mathieu-Daudé
2017-10-30 18:18 ` Philippe Mathieu-Daudé
2017-11-03  0:35 ` Eduardo Habkost
2017-11-08 16:20   ` Philippe Mathieu-Daudé
2017-11-08 16:56     ` Eduardo Habkost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).