[PATCH 31/32] RFC: Simplify softmmu/main.c

marcandre.lureau@redhat.com posted 32 patches 2 years, 6 months ago
Maintainers: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <r.bolshakov@yadro.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, David Hildenbrand <david@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>, Aarushi Mehta <mehta.aaru20@gmail.com>, Julia Suvorova <jusual@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, Ronnie Sahlberg <ronniesahlberg@gmail.com>, Peter Lieven <pl@kamp.de>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Denis V. Lunev" <den@openvz.org>, Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Laurent Vivier <laurent@vivier.eu>, "Michael S. Tsirkin" <mst@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Greg Kurz <groug@kaod.org>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Alex Bennée" <alex.bennee@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Helge Deller <deller@gmx.de>, Cornelia Huck <cohuck@redhat.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, "Cédric Le Goater" <clg@kaod.org>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Huacai Chen <chenhuacai@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aurelien Jarno <aurelien@aurel32.net>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Pavel Pisa <pisa@cmp.felk.cvut.cz>, Vikram Garhwal <fnu.vikram@xilinx.com>, Jason Wang <jasowang@redhat.com>, Subbaraya Sundeep <sundeep.lkml@gmail.com>, Havard Skinnemoen <hskinnemoen@google.com>, Tyrone Ting <kfting@nuvoton.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, BALATON Zoltan <balaton@eik.bme.hu>, Elena Ufimtseva <elena.ufimtseva@oracle.com>, Jagannathan Raman <jag.raman@oracle.com>, John G Johnson <john.g.johnson@oracle.com>, Alexey Kardashevskiy <aik@ozlabs.ru>, Yuval Shaia <yuval.shaia.ml@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Bin Meng <bin.meng@windriver.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Eric Farman <farman@linux.ibm.com>, Fabien Chouteau <chouteau@adacore.com>, KONRAD Frederic <frederic.konrad@adacore.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, Eric Auger <eric.auger@redhat.com>, Max Filippov <jcmvbkbc@gmail.com>, Peter Xu <peterx@redhat.com>, Markus Armbruster <armbru@redhat.com>, Stefan Weil <sw@weilnetz.de>, Taylor Simpson <tsimpson@quicinc.com>, Juan Quintela <quintela@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Zhang Chen <chen.zhang@intel.com>, Li Zhijian <lizhijian@fujitsu.com>, Michael Roth <michael.roth@amd.com>, Alexander Graf <agraf@csgraf.de>, Wenchao Wang <wenchao.wang@intel.com>, Colin Xu <colin.xu@intel.com>, Marcelo Tosatti <mtosatti@redhat.com>, Kamil Rytarowski <kamil@netbsd.org>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>, Stafford Horne <shorne@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Ani Sinha <ani@anisinha.ca>, John Snow <jsnow@redhat.com>, Andrew Jeffery <andrew@aj.id.au>, Joel Stanley <joel@jms.id.au>, Alexander Bulekov <alxndr@bu.edu>, Bandan Das <bsd@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Corey Minyard <minyard@acm.org>, Coiby Xu <Coiby.Xu@gmail.com>, Akihiko Odaki <akihiko.odaki@gmail.com>
There is a newer version of this series
[PATCH 31/32] RFC: Simplify softmmu/main.c
Posted by marcandre.lureau@redhat.com 2 years, 6 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Move qemu_main() declaration to a new header.

Simplify main.c since both cocoa & sdl cannot be enabled together.

(there might be some small conflict with the RFC patch "cocoa: run qemu_init
in the main thread", but the two look like they could be used together
to improve the code)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu-common.h |  5 -----
 include/qemu-main.h   |  6 ++++++
 softmmu/main.c        | 25 +++++++++----------------
 ui/cocoa.m            |  1 +
 4 files changed, 16 insertions(+), 21 deletions(-)
 create mode 100644 include/qemu-main.h

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 65483f70d4fe..0498acd16b78 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -19,9 +19,4 @@
     "See <https://qemu.org/contribute/report-a-bug> for how to report bugs.\n" \
     "More information on the QEMU project at <https://qemu.org>."
 
-/* main function, renamed */
-#if defined(CONFIG_COCOA)
-int qemu_main(int argc, char **argv, char **envp);
-#endif
-
 #endif
diff --git a/include/qemu-main.h b/include/qemu-main.h
new file mode 100644
index 000000000000..74d670bbf9a7
--- /dev/null
+++ b/include/qemu-main.h
@@ -0,0 +1,6 @@
+#ifndef QEMU_MAIN_H
+#define QEMU_MAIN_H
+
+int qemu_main(int argc, char **argv, char **envp);
+
+#endif /* QEMU_MAIN_H */
diff --git a/softmmu/main.c b/softmmu/main.c
index 639c67ff4893..c00432ff098e 100644
--- a/softmmu/main.c
+++ b/softmmu/main.c
@@ -23,28 +23,14 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu-main.h"
 #include "sysemu/sysemu.h"
 
 #ifdef CONFIG_SDL
-#if defined(__APPLE__) || defined(main)
 #include <SDL.h>
-static int qemu_main(int argc, char **argv, char **envp);
-int main(int argc, char **argv)
-{
-    return qemu_main(argc, argv, NULL);
-}
-#undef main
-#define main qemu_main
 #endif
-#endif /* CONFIG_SDL */
-
-#ifdef CONFIG_COCOA
-#undef main
-#define main qemu_main
-#endif /* CONFIG_COCOA */
 
-int main(int argc, char **argv, char **envp)
+int qemu_main(int argc, char **argv, char **envp)
 {
     qemu_init(argc, argv, envp);
     qemu_main_loop();
@@ -52,3 +38,10 @@ int main(int argc, char **argv, char **envp)
 
     return 0;
 }
+
+#ifndef CONFIG_COCOA
+int main(int argc, char **argv)
+{
+    return qemu_main(argc, argv, NULL);
+}
+#endif
diff --git a/ui/cocoa.m b/ui/cocoa.m
index cb6e7c41dc6f..e566372b8f73 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -28,6 +28,7 @@
 #include <crt_externs.h>
 
 #include "qemu-common.h"
+#include "qemu-main.h"
 #include "ui/clipboard.h"
 #include "ui/console.h"
 #include "ui/input.h"
-- 
2.35.1.273.ge6ebfd0e8cbb


Re: [PATCH 31/32] RFC: Simplify softmmu/main.c
Posted by Paolo Bonzini 2 years, 6 months ago
On 3/23/22 16:57, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau<marcandre.lureau@redhat.com>
> 
> Move qemu_main() declaration to a new header.
> 
> Simplify main.c since both cocoa & sdl cannot be enabled together.
> 
> (there might be some small conflict with the RFC patch "cocoa: run qemu_init
> in the main thread", but the two look like they could be used together
> to improve the code)

That patch enables cocoa and SDL to be in the same binary, so I think 
this one (while a good idea in theory) should be the one that loses.

Akihiko has ideas on how to use the standard main() for Cocoa, by 
turning qemu_main_loop() into a function pointer, like

-void qemu_main_loop()
+static void (*qemu_main_loop)(void) = qemu_default_main_loop;
+void qemu_default_main_loop()
  {
      ...
  }

and cocoa_display_init() would do "qemu_main_loop = qemu_cocoa_main_loop;".

Paolo

Re: [PATCH 31/32] RFC: Simplify softmmu/main.c
Posted by Marc-André Lureau 2 years, 5 months ago
Hi

On Thu, Mar 24, 2022 at 11:52 AM Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 3/23/22 16:57, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau<marcandre.lureau@redhat.com>
> >
> > Move qemu_main() declaration to a new header.
> >
> > Simplify main.c since both cocoa & sdl cannot be enabled together.
> >
> > (there might be some small conflict with the RFC patch "cocoa: run
> qemu_init
> > in the main thread", but the two look like they could be used together
> > to improve the code)
>
> That patch enables cocoa and SDL to be in the same binary, so I think
> this one (while a good idea in theory) should be the one that loses.
>
> Akihiko has ideas on how to use the standard main() for Cocoa, by
> turning qemu_main_loop() into a function pointer, like
>
> -void qemu_main_loop()
> +static void (*qemu_main_loop)(void) = qemu_default_main_loop;
> +void qemu_default_main_loop()
>   {
>       ...
>   }
>
> and cocoa_display_init() would do "qemu_main_loop = qemu_cocoa_main_loop;".
>
>
Akihiko, do you have a patch ? Since you have reviewed this patch already,
are you willing to rebase on top of this one?

thanks

-- 
Marc-André Lureau
Re: [PATCH 31/32] RFC: Simplify softmmu/main.c
Posted by Akihiko Odaki 2 years, 5 months ago
On 2022/04/20 16:57, Marc-André Lureau wrote:
> Hi
> 
> On Thu, Mar 24, 2022 at 11:52 AM Paolo Bonzini <pbonzini@redhat.com 
> <mailto:pbonzini@redhat.com>> wrote:
> 
>     On 3/23/22 16:57, marcandre.lureau@redhat.com
>     <mailto:marcandre.lureau@redhat.com> wrote:
>      > From: Marc-André Lureau<marcandre.lureau@redhat.com
>     <mailto:marcandre.lureau@redhat.com>>
>      >
>      > Move qemu_main() declaration to a new header.
>      >
>      > Simplify main.c since both cocoa & sdl cannot be enabled together.
>      >
>      > (there might be some small conflict with the RFC patch "cocoa:
>     run qemu_init
>      > in the main thread", but the two look like they could be used
>     together
>      > to improve the code)
> 
>     That patch enables cocoa and SDL to be in the same binary, so I think
>     this one (while a good idea in theory) should be the one that loses.

The patch does *not* allow to enable cocoa and SDL to be in the same 
binary, but "[RFC PATCH-for-7.0 v4 0/2] cocoa: run qemu_init in the main 
thread" does.

https://patchew.org/QEMU/20220317125534.38706-1-philippe.mathieu.daude@gmail.com/

> 
>     Akihiko has ideas on how to use the standard main() for Cocoa, by
>     turning qemu_main_loop() into a function pointer, like
> 
>     -void qemu_main_loop()
>     +static void (*qemu_main_loop)(void) = qemu_default_main_loop;
>     +void qemu_default_main_loop()
>        {
>            ...
>        }
> 
>     and cocoa_display_init() would do "qemu_main_loop =
>     qemu_cocoa_main_loop;".
> 
> 
> Akihiko, do you have a patch ? Since you have reviewed this patch 
> already, are you willing to rebase on top of this one?
> 
> thanks
> 
> -- 
> Marc-André Lureau

No, I don't have but I'm willing to author one if nobody else is going to.

Regards,
Akihiko Odaki

Re: [PATCH 31/32] RFC: Simplify softmmu/main.c
Posted by Akihiko Odaki 2 years, 6 months ago
Reviewed-by: Akihiko Odaki <akihiko.odaki@gmail.com>

On 2022/03/24 0:57, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Move qemu_main() declaration to a new header.
> 
> Simplify main.c since both cocoa & sdl cannot be enabled together.
> 
> (there might be some small conflict with the RFC patch "cocoa: run qemu_init
> in the main thread", but the two look like they could be used together
> to improve the code)
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   include/qemu-common.h |  5 -----
>   include/qemu-main.h   |  6 ++++++
>   softmmu/main.c        | 25 +++++++++----------------
>   ui/cocoa.m            |  1 +
>   4 files changed, 16 insertions(+), 21 deletions(-)
>   create mode 100644 include/qemu-main.h
> 
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 65483f70d4fe..0498acd16b78 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -19,9 +19,4 @@
>       "See <https://qemu.org/contribute/report-a-bug> for how to report bugs.\n" \
>       "More information on the QEMU project at <https://qemu.org>."
>   
> -/* main function, renamed */
> -#if defined(CONFIG_COCOA)
> -int qemu_main(int argc, char **argv, char **envp);
> -#endif
> -
>   #endif
> diff --git a/include/qemu-main.h b/include/qemu-main.h
> new file mode 100644
> index 000000000000..74d670bbf9a7
> --- /dev/null
> +++ b/include/qemu-main.h
> @@ -0,0 +1,6 @@
> +#ifndef QEMU_MAIN_H
> +#define QEMU_MAIN_H
> +
> +int qemu_main(int argc, char **argv, char **envp);
> +
> +#endif /* QEMU_MAIN_H */
> diff --git a/softmmu/main.c b/softmmu/main.c
> index 639c67ff4893..c00432ff098e 100644
> --- a/softmmu/main.c
> +++ b/softmmu/main.c
> @@ -23,28 +23,14 @@
>    */
>   
>   #include "qemu/osdep.h"
> -#include "qemu-common.h"
> +#include "qemu-main.h"
>   #include "sysemu/sysemu.h"
>   
>   #ifdef CONFIG_SDL
> -#if defined(__APPLE__) || defined(main)
>   #include <SDL.h>
> -static int qemu_main(int argc, char **argv, char **envp);
> -int main(int argc, char **argv)
> -{
> -    return qemu_main(argc, argv, NULL);
> -}
> -#undef main
> -#define main qemu_main
>   #endif
> -#endif /* CONFIG_SDL */
> -
> -#ifdef CONFIG_COCOA
> -#undef main
> -#define main qemu_main
> -#endif /* CONFIG_COCOA */
>   
> -int main(int argc, char **argv, char **envp)
> +int qemu_main(int argc, char **argv, char **envp)
>   {
>       qemu_init(argc, argv, envp);
>       qemu_main_loop();
> @@ -52,3 +38,10 @@ int main(int argc, char **argv, char **envp)
>   
>       return 0;
>   }
> +
> +#ifndef CONFIG_COCOA
> +int main(int argc, char **argv)
> +{
> +    return qemu_main(argc, argv, NULL);
> +}
> +#endif
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index cb6e7c41dc6f..e566372b8f73 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -28,6 +28,7 @@
>   #include <crt_externs.h>
>   
>   #include "qemu-common.h"
> +#include "qemu-main.h"
>   #include "ui/clipboard.h"
>   #include "ui/console.h"
>   #include "ui/input.h"