qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine'
@ 2020-03-13 17:24 Peter Maydell
  2020-03-14 11:36 ` Markus Armbruster
  2020-03-16 11:00 ` Kashyap Chamarthy
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2020-03-13 17:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Kashyap Chamarthy

Currently if you try to ask for the list of CPUs for a target
architecture which does not specify a default machine type
you just get an error:

  $ qemu-system-arm -cpu help
  qemu-system-arm: No machine specified, and there is no default
  Use -machine help to list supported machines

Since the list of CPUs doesn't depend on the machine, this is
unnecessarily unhelpful. "-device help" has a similar problem.

Move the checks for "did the user ask for -cpu help or -device help"
up so they precede the select_machine() call which checks that the
user specified a valid machine type.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This has been on-and-off irritating me for years, and it's
embarrassing how simple the fix turns out to be...
---
 softmmu/vl.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index ff2685dff84..6a285925b37 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3789,6 +3789,22 @@ void qemu_init(int argc, char **argv, char **envp)
      */
     loc_set_none();
 
+    /*
+     * Check for -cpu help and -device help before we call select_machine(),
+     * which will return an error if the architecture has no default machine
+     * type and the user did not specify one, so that the user doesn't need
+     * to say '-cpu help -machine something'.
+     */
+    if (cpu_option && is_help_option(cpu_option)) {
+        list_cpus(cpu_option);
+        exit(0);
+    }
+
+    if (qemu_opts_foreach(qemu_find_opts("device"),
+                          device_help_func, NULL, NULL)) {
+        exit(0);
+    }
+
     user_register_global_props();
 
     replay_configure(icount_opts);
@@ -3877,11 +3893,6 @@ void qemu_init(int argc, char **argv, char **envp)
         qemu_set_hw_version(machine_class->hw_version);
     }
 
-    if (cpu_option && is_help_option(cpu_option)) {
-        list_cpus(cpu_option);
-        exit(0);
-    }
-
     if (!trace_init_backends()) {
         exit(1);
     }
@@ -4112,11 +4123,6 @@ void qemu_init(int argc, char **argv, char **envp)
                       fsdev_init_func, NULL, &error_fatal);
 #endif
 
-    if (qemu_opts_foreach(qemu_find_opts("device"),
-                          device_help_func, NULL, NULL)) {
-        exit(0);
-    }
-
     /*
      * Note: we need to create block backends before
      * machine_set_property(), so machine properties can refer to
-- 
2.20.1



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

* Re: [PATCH] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine'
  2020-03-13 17:24 [PATCH] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine' Peter Maydell
@ 2020-03-14 11:36 ` Markus Armbruster
  2020-03-16 11:00 ` Kashyap Chamarthy
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2020-03-14 11:36 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Paolo Bonzini, qemu-devel, Kashyap Chamarthy

Peter Maydell <peter.maydell@linaro.org> writes:

> Currently if you try to ask for the list of CPUs for a target
> architecture which does not specify a default machine type
> you just get an error:
>
>   $ qemu-system-arm -cpu help
>   qemu-system-arm: No machine specified, and there is no default
>   Use -machine help to list supported machines
>
> Since the list of CPUs doesn't depend on the machine, this is
> unnecessarily unhelpful. "-device help" has a similar problem.
>
> Move the checks for "did the user ask for -cpu help or -device help"
> up so they precede the select_machine() call which checks that the
> user specified a valid machine type.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> This has been on-and-off irritating me for years, and it's
> embarrassing how simple the fix turns out to be...

Same here.  The patch works as advertized, thus:
Reviewed-by: Markus Armbruster <armbru@redhat.com>

Can you offer a completeness argument?  We call is_help_option() and
qemu_opt_has_help_opt() from quite a few places.



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

* Re: [PATCH] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine'
  2020-03-13 17:24 [PATCH] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine' Peter Maydell
  2020-03-14 11:36 ` Markus Armbruster
@ 2020-03-16 11:00 ` Kashyap Chamarthy
  1 sibling, 0 replies; 3+ messages in thread
From: Kashyap Chamarthy @ 2020-03-16 11:00 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Paolo Bonzini, qemu-devel, armbru

[Cc: Markus; he'd be pleasantly surprised with this, if he already
hadn't noticed this, as he was also mildly annoyed about this the other
day.]

On Fri, Mar 13, 2020 at 05:24:47PM +0000, Peter Maydell wrote:
> Currently if you try to ask for the list of CPUs for a target
> architecture which does not specify a default machine type
> you just get an error:
> 
>   $ qemu-system-arm -cpu help
>   qemu-system-arm: No machine specified, and there is no default
>   Use -machine help to list supported machines

I just applied the patch and built on QEMU.

With `qemu-system-arm`:

    $> ./arm-softmmu/qemu-system-arm -cpu help | head -5
    Available CPUs:
      arm1026
      arm1136
      arm1136-r2
      arm1176

    $> ./arm-softmmu/qemu-system-arm -device help | head -5
    Controller/Bridge/Hub devices:
    name "i82801b11-bridge", bus PCI
    name "ioh3420", bus PCI, desc "Intel IOH device id 3420 PCIE Root Port"
    name "pci-bridge", bus PCI, desc "Standard PCI Bridge"
    name "pci-bridge-seat", bus PCI, desc "Standard PCI Bridge (multiseat)"

With `qemu-system-aarch64`:

    $> ./aarch64-softmmu/qemu-system-aarch64 -cpu help | head -5
    Available CPUs:
      arm1026
      arm1136
      arm1136-r2
      arm1176

    $> ./aarch64-softmmu/qemu-system-aarch64 -device help | head -5
    Controller/Bridge/Hub devices:
    name "i82801b11-bridge", bus PCI
    name "ioh3420", bus PCI, desc "Intel IOH device id 3420 PCIE Root Port"
    name "pci-bridge", bus PCI, desc "Standard PCI Bridge"
    name "pci-bridge-seat", bus PCI, desc "Standard PCI Bridge (multiseat)"

> Since the list of CPUs doesn't depend on the machine, this is
> unnecessarily unhelpful. "-device help" has a similar problem.
> 
> Move the checks for "did the user ask for -cpu help or -device help"
> up so they precede the select_machine() call which checks that the
> user specified a valid machine type.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Tested-by: Kashyap Chamarthy <kchamart@redhat.com>

> ---
> This has been on-and-off irritating me for years, and it's
> embarrassing how simple the fix turns out to be...
> ---
>  softmmu/vl.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)

[...] 

Thanks. :)

-- 
/kashyap



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

end of thread, other threads:[~2020-03-16 11:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-13 17:24 [PATCH] softmmu/vl.c: Handle '-cpu help' and '-device help' before 'no default machine' Peter Maydell
2020-03-14 11:36 ` Markus Armbruster
2020-03-16 11:00 ` Kashyap Chamarthy

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