Skip to contentSkip to conversation

chardev: Reduce system emulation specific code

PATCH In review Philippe Mathieu-Daudé 4 participants 16 messages Apr 23, 2020 – Apr 24, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

cover chardev: Reduce system emulation specific code

chardev cleanup while reviewing 'Refactor machine_init and exit notifiers' from the multi-process series:
https://www.mail-archive.com/[email protected]/msg697510.html

Elena Ufimtseva (1):
multi-process: Refactor machine_init and exit notifiers

Philippe Mathieu-Daudé (6):
monitor/misc: Remove unused "chardev/char-mux.h" include tests/test-char: Remove unused "chardev/char-mux.h" include
chardev: Restrict msmouse / wctablet / testdev to system emulation
chardev: Reduce "char-mux.h" scope, rename it "chardev-internal.h"
chardev: Extract system emulation specific code
stubs: Split machine-init-done as machine-init and machine-notify

 Makefile.objs                                 |  1 +
 .../char-mux.h => chardev/chardev-internal.h  | 10 ++-
 include/sysemu/sysemu.h                       |  2 +
 chardev/char-fe.c                             |  2 +-
 chardev/char-mux.c                            |  2 +-
 chardev/char.c                                | 37 +---------
 chardev/chardev-sysemu.c                      | 69 +++++++++++++++++++
 monitor/misc.c                                |  1 -
 softmmu/vl.c                                  | 42 -----------
 stubs/machine-init.c                          |  4 ++
 .../{machine-init-done.c => machine-notify.c} |  6 +-
 tests/test-char.c                             |  1 -
 util/machine-notify.c                         | 69 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 chardev/Makefile.objs                         |  3 +-
 stubs/Makefile.objs                           |  3 +-
 16 files changed, 165 insertions(+), 88 deletions(-)
 rename include/chardev/char-mux.h => chardev/chardev-internal.h (93%)
 create mode 100644 chardev/chardev-sysemu.c
 create mode 100644 stubs/machine-init.c
 rename stubs/{machine-init-done.c => machine-notify.c} (63%)
 create mode 100644 util/machine-notify.c
Signature · 1 line
2.21.1
#1 lore raw

PATCH 1/7 monitor/misc: Remove unused "chardev/char-mux.h" include

monitor/misc.c never required "chardev/char-mux.h", remove it.

---
 monitor/misc.c | 1 -
 1 file changed, 1 deletion(-)
monitor/misc.c +0 -1
index 6c45fa490f..5d68026a7f 100644
@@ -33,7 +33,6 @@
 #include "exec/gdbstub.h"
 #include "net/net.h"
 #include "net/slirp.h"
-#include "chardev/char-mux.h"
 #include "ui/qemu-spice.h"
 #include "qemu/config-file.h"
 #include "qemu/ctype.h"
Signature · 1 line
2.21.1
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] monitor/misc: Remove unused "chardev/char-mux.h" include

Quoted 4 lines · Philippe Mathieu-Daudé

monitor/misc.c never required "chardev/char-mux.h", remove it.

Quoted 20 lines
---
 monitor/misc.c | 1 -
 1 file changed, 1 deletion(-)
monitor/misc.c +0 -2
index 6c45fa490f..5d68026a7f 100644
@@ -33,7 +33,6 @@
 #include "exec/gdbstub.h"
 #include "net/net.h"
 #include "net/slirp.h"
-#include "chardev/char-mux.h"
 #include "ui/qemu-spice.h"
 #include "qemu/config-file.h"
 #include "qemu/ctype.h"
--

2.21.1

Signature · 1 line
Marc-André Lureau
#3 lore raw

PATCH 2/7 tests/test-char: Remove unused "chardev/char-mux.h" include

In reply to Philippe Mathieu-Daudé

This test never required "chardev/char-mux.h", remove it.

---
 tests/test-char.c | 1 -
 1 file changed, 1 deletion(-)
tests/test-char.c +0 -1
index 3afc9b1b8d..f08a39790e 100644
@@ -6,7 +6,6 @@
 #include "qemu/option.h"
 #include "qemu/sockets.h"
 #include "chardev/char-fe.h"
-#include "chardev/char-mux.h"
 #include "sysemu/sysemu.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-char.h"
Signature · 1 line
2.21.1
Reviewed-by on v1 2/7
#4 lore raw

Re: [PATCH 2/7] tests/test-char: Remove unused "chardev/char-mux.h" include

Quoted 4 lines · Philippe Mathieu-Daudé

This test never required "chardev/char-mux.h", remove it.

Quoted 20 lines
---
 tests/test-char.c | 1 -
 1 file changed, 1 deletion(-)
tests/test-char.c +0 -2
index 3afc9b1b8d..f08a39790e 100644
@@ -6,7 +6,6 @@
 #include "qemu/option.h"
 #include "qemu/sockets.h"
 #include "chardev/char-fe.h"
-#include "chardev/char-mux.h"
 #include "sysemu/sysemu.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-char.h"
--

2.21.1

Signature · 1 line
Marc-André Lureau
#5 lore raw

PATCH 3/7 chardev: Restrict msmouse / wctablet / testdev to system emulation

In reply to Philippe Mathieu-Daudé

The msmouse / wctablet / testdev character devices are only used by system emulation. Remove them from user mode and tools.

---
 chardev/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/Makefile.objs +1 -1
index d68e1347f9..15ee7f47da 100644
@@ -17,7 +17,7 @@ chardev-obj-y += char-udp.o
 chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
 
-common-obj-y += msmouse.o wctablet.o testdev.o
+common-obj-$(CONFIG_SOFTMMU) += msmouse.o wctablet.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 baum.o-cflags := $(SDL_CFLAGS)
 baum.o-libs := $(BRLAPI_LIBS)
Signature · 1 line
2.21.1
Reviewed-by on v1 3/7
#6 lore raw

Re: [PATCH 3/7] chardev: Restrict msmouse / wctablet / testdev to system emulation

Quoted 5 lines · Philippe Mathieu-Daudé

The msmouse / wctablet / testdev character devices are only used by system emulation. Remove them from user mode and tools.

Quoted 21 lines
---
 chardev/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/Makefile.objs +1 -2
index d68e1347f9..15ee7f47da 100644
@@ -17,7 +17,7 @@ chardev-obj-y += char-udp.o
 chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
 
-common-obj-y += msmouse.o wctablet.o testdev.o
+common-obj-$(CONFIG_SOFTMMU) += msmouse.o wctablet.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 baum.o-cflags := $(SDL_CFLAGS)
 baum.o-libs := $(BRLAPI_LIBS)
--

2.21.1

Signature · 1 line
Marc-André Lureau
#7 lore raw

PATCH 4/7 chardev: Reduce "char-mux.h" scope, rename it "chardev-internal.h"

In reply to Philippe Mathieu-Daudé

No file out of chardev/ requires access to this header, restrict its scope.

---
 include/chardev/char-mux.h => chardev/chardev-internal.h | 7 ++++---
 chardev/char-fe.c                                        | 2 +-
 chardev/char-mux.c                                       | 2 +-
 chardev/char.c                                           | 2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)
 rename include/chardev/char-mux.h => chardev/chardev-internal.h (96%)
chardev/chardev-internal.h renamed from include/chardev/char-mux.h +4 -3
similarity index 96%
rename from include/chardev/char-mux.h
rename to chardev/chardev-internal.h
index 417fe32eed..e0264ac349 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator
+ * QEMU Character device internals
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  *
@@ -21,8 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef CHAR_MUX_H
-#define CHAR_MUX_H
+#ifndef CHARDEV_INTERNAL_H
+#define CHARDEV_INTERNAL_H
 
 #include "chardev/char.h"
 #include "chardev/char-fe.h"
@@ -30,6 +30,7 @@
 #define MAX_MUX 4
 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2.  */
 #define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1)
+
 typedef struct MuxChardev {
     Chardev parent;
     CharBackend *backends[MAX_MUX];
chardev/char-fe.c +1 -1
index f3530a90e6..474715c5a9 100644
@@ -29,7 +29,7 @@
 
 #include "chardev/char-fe.h"
 #include "chardev/char-io.h"
-#include "chardev/char-mux.h"
+#include "chardev-internal.h"
 
 int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
 {
chardev/char-mux.c +1 -1
index 46c44af67c..6f980bb836 100644
@@ -29,7 +29,7 @@
 #include "chardev/char.h"
 #include "sysemu/block-backend.h"
 #include "sysemu/sysemu.h"
-#include "chardev/char-mux.h"
+#include "chardev-internal.h"
 
 /* MUX driver for serial I/O splitting */
 
chardev/char.c +1 -1
index e77564060d..b672a41150 100644
@@ -39,7 +39,7 @@
 #include "qemu/option.h"
 #include "qemu/id.h"
 
-#include "chardev/char-mux.h"
+#include "chardev-internal.h"
 
 /***********************************************************/
 /* character device */
Signature · 1 line
2.21.1
Reviewed-by on v1 4/7
#8 lore raw

Re: [PATCH 4/7] chardev: Reduce "char-mux.h" scope, rename it "chardev-internal.h"

Quoted 5 lines · Philippe Mathieu-Daudé

No file out of chardev/ requires access to this header, restrict its scope.

Quoted 84 lines
---
 include/chardev/char-mux.h => chardev/chardev-internal.h | 7 ++++---
 chardev/char-fe.c                                        | 2 +-
 chardev/char-mux.c                                       | 2 +-
 chardev/char.c                                           | 2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)
 rename include/chardev/char-mux.h => chardev/chardev-internal.h (96%)
chardev/chardev-internal.h renamed from include/chardev/char-mux.h +4 -3
similarity index 96%
rename from include/chardev/char-mux.h
rename to chardev/chardev-internal.h
index 417fe32eed..e0264ac349 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator
+ * QEMU Character device internals
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  *
@@ -21,8 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef CHAR_MUX_H
-#define CHAR_MUX_H
+#ifndef CHARDEV_INTERNAL_H
+#define CHARDEV_INTERNAL_H
 
 #include "chardev/char.h"
 #include "chardev/char-fe.h"
@@ -30,6 +30,7 @@
 #define MAX_MUX 4
 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2.  */
 #define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1)
+
 typedef struct MuxChardev {
     Chardev parent;
     CharBackend *backends[MAX_MUX];
chardev/char-fe.c +1 -1
index f3530a90e6..474715c5a9 100644
@@ -29,7 +29,7 @@
 
 #include "chardev/char-fe.h"
 #include "chardev/char-io.h"
-#include "chardev/char-mux.h"
+#include "chardev-internal.h"
 
 int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
 {
chardev/char-mux.c +1 -1
index 46c44af67c..6f980bb836 100644
@@ -29,7 +29,7 @@
 #include "chardev/char.h"
 #include "sysemu/block-backend.h"
 #include "sysemu/sysemu.h"
-#include "chardev/char-mux.h"
+#include "chardev-internal.h"
 
 /* MUX driver for serial I/O splitting */
 
chardev/char.c +1 -2
index e77564060d..b672a41150 100644
@@ -39,7 +39,7 @@
 #include "qemu/option.h"
 #include "qemu/id.h"
 
-#include "chardev/char-mux.h"
+#include "chardev-internal.h"
 
 /***********************************************************/
 /* character device */
--

2.21.1

Signature · 1 line
Marc-André Lureau
#9 lore raw

PATCH 5/7 chardev: Extract system emulation specific code

In reply to Philippe Mathieu-Daudé

Split out code only used during system emulation, to reduce code pulled in user emulation and tools.

---
 chardev/chardev-internal.h |  3 ++
 chardev/char.c             | 35 +------------------
 chardev/chardev-sysemu.c   | 69 ++++++++++++++++++++++++++++++++++++++
 chardev/Makefile.objs      |  1 +
 4 files changed, 74 insertions(+), 34 deletions(-)
 create mode 100644 chardev/chardev-sysemu.c
chardev/chardev-internal.h +3 -0
index e0264ac349..f4d0429763 100644
@@ -26,6 +26,7 @@
 
 #include "chardev/char.h"
 #include "chardev/char-fe.h"
+#include "qom/object.h"
 
 #define MAX_MUX 4
 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2.  */
@@ -59,4 +60,6 @@ typedef struct MuxChardev {
 void mux_set_focus(Chardev *chr, int focus);
 void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
 
+Object *get_chardevs_root(void);
+
 #endif /* CHAR_MUX_H */
chardev/char.c +1 -34
index b672a41150..555bb0448e 100644
@@ -44,7 +44,7 @@
 /***********************************************************/
 /* character device */
 
-static Object *get_chardevs_root(void)
+Object *get_chardevs_root(void)
 {
     return container_get(object_get_root(), "/chardevs");
 }
@@ -300,33 +300,6 @@ static const TypeInfo char_type_info = {
     .class_init = char_class_init,
 };
 
-static int chardev_machine_done_notify_one(Object *child, void *opaque)
-{
-    Chardev *chr = (Chardev *)child;
-    ChardevClass *class = CHARDEV_GET_CLASS(chr);
-
-    if (class->chr_machine_done) {
-        return class->chr_machine_done(chr);
-    }
-
-    return 0;
-}
-
-static void chardev_machine_done_hook(Notifier *notifier, void *unused)
-{
-    int ret = object_child_foreach(get_chardevs_root(),
-                                   chardev_machine_done_notify_one, NULL);
-
-    if (ret) {
-        error_report("Failed to call chardev machine_done hooks");
-        exit(1);
-    }
-}
-
-static Notifier chardev_machine_done_notify = {
-    .notify = chardev_machine_done_hook,
-};
-
 static bool qemu_chr_is_busy(Chardev *s)
 {
     if (CHARDEV_IS_MUX(s)) {
@@ -1187,12 +1160,6 @@ void qemu_chr_cleanup(void)
 static void register_types(void)
 {
     type_register_static(&char_type_info);
-
-    /* this must be done after machine init, since we register FEs with muxes
-     * as part of realize functions like serial_isa_realizefn when -nographic
-     * is specified
-     */
-    qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
 type_init(register_types);
chardev/chardev-sysemu.c new file +69 -0

69 lines not on this page · raw message

chardev/Makefile.objs +1 -0
index 15ee7f47da..a10acbc2b8 100644
@@ -1,4 +1,5 @@
 chardev-obj-y += char.o
+chardev-obj-$(CONFIG_SOFTMMU) += chardev-sysemu.o
 chardev-obj-$(CONFIG_WIN32) += char-console.o
 chardev-obj-$(CONFIG_POSIX) += char-fd.o
 chardev-obj-y += char-fe.o
Signature · 1 line
2.21.1
Reviewed-by on v1 5/7
#10 lore raw

Re: [PATCH 5/7] chardev: Extract system emulation specific code

Quoted 5 lines · Philippe Mathieu-Daudé

Split out code only used during system emulation, to reduce code pulled in user emulation and tools.

Quoted 176 lines
---
 chardev/chardev-internal.h |  3 ++
 chardev/char.c             | 35 +------------------
 chardev/chardev-sysemu.c   | 69 ++++++++++++++++++++++++++++++++++++++
 chardev/Makefile.objs      |  1 +
 4 files changed, 74 insertions(+), 34 deletions(-)
 create mode 100644 chardev/chardev-sysemu.c
chardev/chardev-internal.h +3 -0
index e0264ac349..f4d0429763 100644
@@ -26,6 +26,7 @@
 
 #include "chardev/char.h"
 #include "chardev/char-fe.h"
+#include "qom/object.h"
 
 #define MAX_MUX 4
 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2.  */
@@ -59,4 +60,6 @@ typedef struct MuxChardev {
 void mux_set_focus(Chardev *chr, int focus);
 void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
 
+Object *get_chardevs_root(void);
+
 #endif /* CHAR_MUX_H */
chardev/char.c +1 -34
index b672a41150..555bb0448e 100644
@@ -44,7 +44,7 @@
 /***********************************************************/
 /* character device */
 
-static Object *get_chardevs_root(void)
+Object *get_chardevs_root(void)
 {
     return container_get(object_get_root(), "/chardevs");
 }
@@ -300,33 +300,6 @@ static const TypeInfo char_type_info = {
     .class_init = char_class_init,
 };
 
-static int chardev_machine_done_notify_one(Object *child, void *opaque)
-{
-    Chardev *chr = (Chardev *)child;
-    ChardevClass *class = CHARDEV_GET_CLASS(chr);
-
-    if (class->chr_machine_done) {
-        return class->chr_machine_done(chr);
-    }
-
-    return 0;
-}
-
-static void chardev_machine_done_hook(Notifier *notifier, void *unused)
-{
-    int ret = object_child_foreach(get_chardevs_root(),
-                                   chardev_machine_done_notify_one, NULL);
-
-    if (ret) {
-        error_report("Failed to call chardev machine_done hooks");
-        exit(1);
-    }
-}
-
-static Notifier chardev_machine_done_notify = {
-    .notify = chardev_machine_done_hook,
-};
-
 static bool qemu_chr_is_busy(Chardev *s)
 {
     if (CHARDEV_IS_MUX(s)) {
@@ -1187,12 +1160,6 @@ void qemu_chr_cleanup(void)
 static void register_types(void)
 {
     type_register_static(&char_type_info);
-
-    /* this must be done after machine init, since we register FEs with muxes
-     * as part of realize functions like serial_isa_realizefn when -nographic
-     * is specified
-     */
-    qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
 type_init(register_types);
chardev/chardev-sysemu.c new file +69 -0
new file mode 100644
index 0000000000..eecdc615ee
@@ -0,0 +1,69 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * 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.
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+#include "chardev/char.h"
+#include "qemu/error-report.h"
+#include "chardev-internal.h"
+
+static int chardev_machine_done_notify_one(Object *child, void *opaque)
+{
+    Chardev *chr = (Chardev *)child;
+    ChardevClass *class = CHARDEV_GET_CLASS(chr);
+
+    if (class->chr_machine_done) {
+        return class->chr_machine_done(chr);
+    }
+
+    return 0;
+}
+
+static void chardev_machine_done_hook(Notifier *notifier, void *unused)
+{
+    int ret = object_child_foreach(get_chardevs_root(),
+                                   chardev_machine_done_notify_one, NULL);
+
+    if (ret) {
+        error_report("Failed to call chardev machine_done hooks");
+        exit(1);
+    }
+}
+
+
+static Notifier chardev_machine_done_notify = {
+    .notify = chardev_machine_done_hook,
+};
+
+static void register_types(void)
+{
+    /*
+     * This must be done after machine init, since we register FEs with muxes
+     * as part of realize functions like serial_isa_realizefn when -nographic
+     * is specified.
+     */
+    qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
+}
+
+type_init(register_types);
chardev/Makefile.objs +1 -1
index 15ee7f47da..a10acbc2b8 100644
@@ -1,4 +1,5 @@
 chardev-obj-y += char.o
+chardev-obj-$(CONFIG_SOFTMMU) += chardev-sysemu.o
 chardev-obj-$(CONFIG_WIN32) += char-console.o
 chardev-obj-$(CONFIG_POSIX) += char-fd.o
 chardev-obj-y += char-fe.o
--

2.21.1

Signature · 1 line
Marc-André Lureau
#11 lore raw

Re: [PATCH 5/7] chardev: Extract system emulation specific code

In reply to Philippe Mathieu-Daudé
Quoted 160 lines · Philippe Mathieu-Daudé

Split out code only used during system emulation, to reduce code pulled in user emulation and tools.

---

chardev/chardev-internal.h |  3 ++
chardev/char.c             | 35 +------------------
chardev/chardev-sysemu.c   | 69 ++++++++++++++++++++++++++++++++++++++
chardev/Makefile.objs      |  1 +
4 files changed, 74 insertions(+), 34 deletions(-)

create mode 100644 chardev/chardev-sysemu.c

chardev/chardev-internal.h +3 -0
index e0264ac349..f4d0429763 100644
@@ -26,6 +26,7 @@
 
 #include "chardev/char.h"
 #include "chardev/char-fe.h"
+#include "qom/object.h"
 
 #define MAX_MUX 4
 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2.  */
@@ -59,4 +60,6 @@ typedef struct MuxChardev {
 void mux_set_focus(Chardev *chr, int focus);
 void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
 
+Object *get_chardevs_root(void);
+
 #endif /* CHAR_MUX_H */
chardev/char.c +1 -34
index b672a41150..555bb0448e 100644
@@ -44,7 +44,7 @@
 /***********************************************************/
 /* character device */
 
-static Object *get_chardevs_root(void)
+Object *get_chardevs_root(void)
 {
    return container_get(object_get_root(), "/chardevs");
 }
@@ -300,33 +300,6 @@ static const TypeInfo char_type_info = {
    .class_init = char_class_init,
 };
 
-static int chardev_machine_done_notify_one(Object *child, void *opaque)
-{
-    Chardev *chr = (Chardev *)child;
-    ChardevClass *class = CHARDEV_GET_CLASS(chr);
-
-    if (class->chr_machine_done) {
-        return class->chr_machine_done(chr);
-    }
-
-    return 0;
-}
-
-static void chardev_machine_done_hook(Notifier *notifier, void *unused)
-{
-    int ret = object_child_foreach(get_chardevs_root(),
-                                   chardev_machine_done_notify_one, NULL);
-
-    if (ret) {
-        error_report("Failed to call chardev machine_done hooks");
-        exit(1);
-    }
-}
-
-static Notifier chardev_machine_done_notify = {
-    .notify = chardev_machine_done_hook,
-};
-
 static bool qemu_chr_is_busy(Chardev *s)
 {
    if (CHARDEV_IS_MUX(s)) {
@@ -1187,12 +1160,6 @@ void qemu_chr_cleanup(void)
 static void register_types(void)
 {
    type_register_static(&char_type_info);
-
-    /* this must be done after machine init, since we register FEs with muxes
-     * as part of realize functions like serial_isa_realizefn when -nographic
-     * is specified
-     */
-    qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
 type_init(register_types);
chardev/chardev-sysemu.c new file +59 -0
new file mode 100644
index 0000000000..eecdc615ee
@@ -0,0 +1,69 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * 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.
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+#include "chardev/char.h"
+#include "qemu/error-report.h"
+#include "chardev-internal.h"
+
+static int chardev_machine_done_notify_one(Object *child, void *opaque)
+{
+    Chardev *chr = (Chardev *)child;
+    ChardevClass *class = CHARDEV_GET_CLASS(chr);
+
+    if (class->chr_machine_done) {
+        return class->chr_machine_done(chr);
+    }
+
+    return 0;
+}
+
+static void chardev_machine_done_hook(Notifier *notifier, void *unused)
+{
+    int ret = object_child_foreach(get_chardevs_root(),
+                                   chardev_machine_done_notify_one, NULL);
+
+    if (ret) {
+        error_report("Failed to call chardev machine_done hooks");
+        exit(1);
+    }
+}
+
+
+static Notifier chardev_machine_done_notify = {
+    .notify = chardev_machine_done_hook,
+};
+
+static void register_types(void)

chardev/chardev-sysemu.c line 69

Quoted 10 lines
chardev/chardev-sysemu.c new file +10 -0
+{
+    /*
+     * This must be done after machine init, since we register FEs with muxes
+     * as part of realize functions like serial_isa_realizefn when -nographic
+     * is specified.
+     */
+    qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
+}
+
+type_init(register_types);

Could you please confirm if we could use “type_init” for something other than a class?

May be the chardev machine init notified could be initialized by vl.c?

Quoted 13 lines
chardev/Makefile.objs +0 -0
index 15ee7f47da..a10acbc2b8 100644
@@ -1,4 +1,5 @@

chardev-obj-y += char.o +chardev-obj-$(CONFIG_SOFTMMU) += chardev-sysemu.o chardev-obj-$(CONFIG_WIN32) += char-console.o chardev-obj-$(CONFIG_POSIX) += char-fd.o chardev-obj-y += char-fe.o

Signature · 1 line
2.21.1
#12 lore raw

PATCH 6/7 stubs: Split machine-init-done as machine-init and machine-notify

In reply to Philippe Mathieu-Daudé

As the machine notify handlers are only used in system emulation, split the current file in two, and only build the notifier when system emulation is used.

---
 stubs/machine-init.c                            | 4 ++++
 stubs/{machine-init-done.c => machine-notify.c} | 2 --
 stubs/Makefile.objs                             | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
 create mode 100644 stubs/machine-init.c
 rename stubs/{machine-init-done.c => machine-notify.c} (78%)
stubs/machine-init.c new file +4 -0
new file mode 100644
index 0000000000..7622930ee0
@@ -0,0 +1,4 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+bool machine_init_done = true;
stubs/machine-notify.c renamed from stubs/machine-init-done.c +0 -2
similarity index 78%
rename from stubs/machine-init-done.c
rename to stubs/machine-notify.c
index cd8e81392d..d164ecccb9 100644
@@ -1,8 +1,6 @@
 #include "qemu/osdep.h"
 #include "sysemu/sysemu.h"
 
-bool machine_init_done = true;
-
 void qemu_add_machine_init_done_notifier(Notifier *notify)
 {
 }
stubs/Makefile.objs +2 -1
index 45be5dc0ed..765659a3f9 100644
@@ -15,7 +15,8 @@ stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
-stub-obj-y += machine-init-done.o
+stub-obj-y += machine-init.o
+stub-obj-$(CONFIG_SOFTMMU) += machine-notify.o
 stub-obj-y += migr-blocker.o
 stub-obj-y += change-state-handler.o
 stub-obj-y += monitor.o
Signature · 1 line
2.21.1
Reviewed-by on v1 6/7
#13 lore raw

Re: [PATCH 6/7] stubs: Split machine-init-done as machine-init and machine-notify

Quoted 6 lines · Philippe Mathieu-Daudé

As the machine notify handlers are only used in system emulation, split the current file in two, and only build the notifier when system emulation is used.

Quoted 52 lines
---
 stubs/machine-init.c                            | 4 ++++
 stubs/{machine-init-done.c => machine-notify.c} | 2 --
 stubs/Makefile.objs                             | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
 create mode 100644 stubs/machine-init.c
 rename stubs/{machine-init-done.c => machine-notify.c} (78%)
stubs/machine-init.c new file +4 -0
new file mode 100644
index 0000000000..7622930ee0
@@ -0,0 +1,4 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+bool machine_init_done = true;
stubs/machine-notify.c renamed from stubs/machine-init-done.c +0 -2
similarity index 78%
rename from stubs/machine-init-done.c
rename to stubs/machine-notify.c
index cd8e81392d..d164ecccb9 100644
@@ -1,8 +1,6 @@
 #include "qemu/osdep.h"
 #include "sysemu/sysemu.h"
 
-bool machine_init_done = true;
-
 void qemu_add_machine_init_done_notifier(Notifier *notify)
 {
 }
stubs/Makefile.objs +2 -2
index 45be5dc0ed..765659a3f9 100644
@@ -15,7 +15,8 @@ stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
-stub-obj-y += machine-init-done.o
+stub-obj-y += machine-init.o
+stub-obj-$(CONFIG_SOFTMMU) += machine-notify.o
 stub-obj-y += migr-blocker.o
 stub-obj-y += change-state-handler.o
 stub-obj-y += monitor.o
--

2.21.1

Signature · 1 line
Marc-André Lureau
#14 lore raw

PATCH 7/7 multi-process: Refactor machine_init and exit notifiers

In reply to Philippe Mathieu-Daudé

From: Elena Ufimtseva <[email protected]>

Relocate machine_int and exit notifiers into common code

[PMD: Removed NotifierList machine_init_done_notifiers stub]
---
 Makefile.objs           |  1 +
 include/sysemu/sysemu.h |  2 ++
 softmmu/vl.c            | 42 -------------------------
 stubs/machine-notify.c  |  4 +++
 util/machine-notify.c   | 69 +++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS             |  1 +
 6 files changed, 77 insertions(+), 42 deletions(-)
 create mode 100644 util/machine-notify.c
Makefile.objs +1 -0
index a7c967633a..bfb9271862 100644
@@ -79,6 +79,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
 common-obj-$(CONFIG_FDT) += device_tree.o
 
 common-obj-y += qapi/
+common-obj-y += util/machine-notify.o
 
 endif # CONFIG_SOFTMMU
 
include/sysemu/sysemu.h +2 -0
index ef81302e1a..2438dd7bea 100644
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
 
 extern bool machine_init_done;
 
 void qemu_add_machine_init_done_notifier(Notifier *notify);
 void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
 
 extern int autostart;
 
softmmu/vl.c +0 -42

60 lines not on this page · raw message

stubs/machine-notify.c +4 -0
index d164ecccb9..71eba45b0f 100644
@@ -4,3 +4,7 @@
 void qemu_add_machine_init_done_notifier(Notifier *notify)
 {
 }
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+}
util/machine-notify.c new file +69 -0

69 lines not on this page · raw message

MAINTAINERS +1 -0
index 8cbc1fac2b..04b19ac56c 100644
@@ -2133,6 +2133,7 @@ F: util/qemu-timer.c
 F: softmmu/vl.c
 F: softmmu/main.c
 F: qapi/run-state.json
+F: util/machine-notify.c
 
 Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
Signature · 1 line
2.21.1
Reviewed-by on the v1 series
#15 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

chardev cleanup while reviewing 'Refactor machine_init and exit notifiers' from the multi-process series:
https://www.mail-archive.com/[email protected]/msg697510.html

Elena Ufimtseva (1):
multi-process: Refactor machine_init and exit notifiers

Quoted 7 lines

Philippe Mathieu-Daudé (6):
monitor/misc: Remove unused "chardev/char-mux.h" include tests/test-char: Remove unused "chardev/char-mux.h" include
chardev: Restrict msmouse / wctablet / testdev to system emulation
chardev: Reduce "char-mux.h" scope, rename it "chardev-internal.h"
chardev: Extract system emulation specific code
stubs: Split machine-init-done as machine-init and machine-notify

r~