Skip to contentSkip to conversation

buildsys: Start shrinking qemu-user build process

PATCH In review Philippe Mathieu-Daudé 4 participants 19 messages Apr 4, 2024 – Apr 8, 2024 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover buildsys: Start shrinking qemu-user build process

Hi,

While reworking include/exec/ I have to build many configs to be sure nothing breaks. qemu-user is particularly sensitive to changes in this directory (mostly because all user-specific files include "qemu.h", itself including various exec/ headers). Getting tired of this waste I had a look at what we pointlessly build. This series is the beginning of yet another cleanup set.

Regards,

Phil.

Philippe Mathieu-Daudé (7):
ebpf: Restrict to system emulation
yank: Restrict to system emulation
monitor: Rework stubs to simplify user emulation linking util/qemu-config: Extract QMP commands to qemu-config-qmp.c hw/core: Restrict reset handlers API to system emulation hw/core: Move reset.c to hwcore_ss[] source set
hw: Include minimal source set in user emulation build

 meson.build                |   6 +-
 include/qemu/config-file.h |   3 +
 hw/core/reset.c            |   4 +
 stubs/fdset.c              |  17 ---
 stubs/monitor-core.c       |  20 +++-
 stubs/monitor.c            |   8 +-
 util/qemu-config-qmp.c     | 206 +++++++++++++++++++++++++++++++++++++
 util/qemu-config.c         | 204 +-----------------------------------
 ebpf/meson.build           |   2 +-
 hw/core/meson.build        |   2 +-
 stubs/meson.build          |   5 +-
 util/meson.build           |   3 +-
 12 files changed, 248 insertions(+), 232 deletions(-)
 delete mode 100644 stubs/fdset.c
 create mode 100644 util/qemu-config-qmp.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/7 ebpf: Restrict to system emulation

eBPF is not used in user emulation.

---
 ebpf/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ebpf/meson.build +1 -1
index c5bf9295a2..bff6156f51 100644
@@ -1 +1 @@
-common_ss.add(when: libbpf, if_true: files('ebpf.c', 'ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
+system_ss.add(when: libbpf, if_true: files('ebpf.c', 'ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
Signature · 1 line
2.41.0
#3 lore raw

Re: [PATCH-for-9.1 1/7] ebpf: Restrict to system emulation

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

eBPF is not used in user emulation.

Queued for 9.1.

Thanks

Quoted 14 lines
---
 ebpf/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ebpf/meson.build +1 -2
index c5bf9295a2..bff6156f51 100644
@@ -1 +1 @@
-common_ss.add(when: libbpf, if_true: files('ebpf.c', 'ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
+system_ss.add(when: libbpf, if_true: files('ebpf.c', 'ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
--

2.41.0

#4 lore raw

PATCH 2/7 yank: Restrict to system emulation

In reply to Philippe Mathieu-Daudé

The yank feature is not used in user emulation.

---
 util/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/meson.build +1 -1
index 0ef9886be0..247f55a80d 100644
@@ -60,7 +60,6 @@ util_ss.add(files('stats64.c'))
 util_ss.add(files('systemd.c'))
 util_ss.add(files('transactions.c'))
 util_ss.add(files('guest-random.c'))
-util_ss.add(files('yank.c'))
 util_ss.add(files('int128.c'))
 util_ss.add(files('memalign.c'))
 util_ss.add(files('interval-tree.c'))
@@ -76,6 +75,7 @@ if have_system
   if host_os == 'linux'
     util_ss.add(files('userfaultfd.c'))
   endif
+  util_ss.add(files('yank.c'))
 endif
 
 if have_block or have_ga
Signature · 1 line
2.41.0
#6 lore raw

Re: [PATCH-for-9.1 2/7] yank: Restrict to system emulation

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

The yank feature is not used in user emulation.

But it is used in block layer tools. The simplest thing here is probably to move it under have_block instead.

Paolo

Quoted 28 lines
---
 util/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/meson.build +1 -2
index 0ef9886be0..247f55a80d 100644
@@ -60,7 +60,6 @@ util_ss.add(files('stats64.c'))
 util_ss.add(files('systemd.c'))
 util_ss.add(files('transactions.c'))
 util_ss.add(files('guest-random.c'))
-util_ss.add(files('yank.c'))
 util_ss.add(files('int128.c'))
 util_ss.add(files('memalign.c'))
 util_ss.add(files('interval-tree.c'))
@@ -76,6 +75,7 @@ if have_system
   if host_os == 'linux'
     util_ss.add(files('userfaultfd.c'))
   endif
+  util_ss.add(files('yank.c'))
 endif
 
 if have_block or have_ga
--

2.41.0

#7 lore raw

PATCH 3/7 monitor: Rework stubs to simplify user emulation linking

In reply to Philippe Mathieu-Daudé

Currently monitor stubs are scattered in 3 files.

Merge these stubs in 2 files, a generic one (monitor-core) included in all builds (in particular user emulation), and a less generic one to be included by tools and system emulation.

---
 stubs/fdset.c        | 17 -----------------
 stubs/monitor-core.c | 20 +++++++++++++++-----
 stubs/monitor.c      |  8 ++++++--
 stubs/meson.build    |  5 +++--
 4 files changed, 24 insertions(+), 26 deletions(-)
 delete mode 100644 stubs/fdset.c
stubs/fdset.c deleted +0 -17
deleted file mode 100644
index 56b3663d58..0000000000
@@ -1,17 +0,0 @@
-#include "qemu/osdep.h"
-#include "monitor/monitor.h"
-
-int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
-{
-    errno = ENOSYS;
-    return -1;
-}
-
-int64_t monitor_fdset_dup_fd_find(int dup_fd)
-{
-    return -1;
-}
-
-void monitor_fdset_dup_fd_remove(int dupfd)
-{
-}
stubs/monitor-core.c +15 -5
index afa477aae6..72e40bcc15 100644
@@ -1,6 +1,7 @@
+/* Monitor stub required for user emulation */
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
-#include "qapi/qapi-emit-events.h"
+#include "../monitor/monitor-internal.h"
 
 Monitor *monitor_cur(void)
 {
@@ -12,11 +13,22 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
     return NULL;
 }
 
-void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
+int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
+int64_t monitor_fdset_dup_fd_find(int dup_fd)
+{
+    return -1;
+}
+
+void monitor_fdset_dup_fd_remove(int dupfd)
 {
 }
 
-void qapi_event_emit(QAPIEvent event, QDict *qdict)
+void monitor_fdsets_cleanup(void)
 {
 }
 
@@ -24,5 +36,3 @@ int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
     abort();
 }
-
-
stubs/monitor.c +6 -2
index 20786ac4ff..2fc4dc1493 100644
@@ -1,7 +1,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-emit-events.h"
 #include "monitor/monitor.h"
-#include "../monitor/monitor-internal.h"
 
 int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 {
@@ -13,6 +13,10 @@ void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
 {
 }
 
-void monitor_fdsets_cleanup(void)
+void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
+{
+}
+
+void qapi_event_emit(QAPIEvent event, QDict *qdict)
 {
 }
stubs/meson.build +3 -2
index 0bf25e6ca5..ca1bc07d30 100644
@@ -10,7 +10,6 @@ stub_ss.add(files('qemu-timer-notify-cb.c'))
 stub_ss.add(files('icount.c'))
 stub_ss.add(files('dump.c'))
 stub_ss.add(files('error-printf.c'))
-stub_ss.add(files('fdset.c'))
 stub_ss.add(files('gdbstub.c'))
 stub_ss.add(files('get-vm-name.c'))
 stub_ss.add(files('graph-lock.c'))
@@ -28,7 +27,9 @@ if libaio.found()
 endif
 stub_ss.add(files('migr-blocker.c'))
 stub_ss.add(files('module-opts.c'))
-stub_ss.add(files('monitor.c'))
+if have_system or have_tools
+  stub_ss.add(files('monitor.c'))
+endif
 stub_ss.add(files('monitor-core.c'))
 stub_ss.add(files('physmem.c'))
 stub_ss.add(files('qemu-timer-notify-cb.c'))
Signature · 1 line
2.41.0
#8 lore raw

Re: [PATCH-for-9.1 3/7] monitor: Rework stubs to simplify user emulation linking

Quoted 10 lines · Philippe Mathieu-Daudé

Currently monitor stubs are scattered in 3 files.

Merge these stubs in 2 files, a generic one (monitor-core) included in all builds (in particular user emulation), and a less generic one to be included by tools and system emulation.

---
 stubs/fdset.c        | 17 -----------------

Oops, merging fdset.c breaks storage-daemon linking.

But it is not needed, all I need is

stubs/meson.build +4 -2
index 0bf25e6ca53..67cf80aa846 100644
@@ -10,7 +10,6 @@ stub_ss.add(files('qemu-timer-notify-cb.c'))
 stub_ss.add(files('icount.c'))
 stub_ss.add(files('dump.c'))
 stub_ss.add(files('error-printf.c'))
-stub_ss.add(files('fdset.c'))
 stub_ss.add(files('gdbstub.c'))
 stub_ss.add(files('get-vm-name.c'))
 stub_ss.add(files('graph-lock.c'))
@@ -28,7 +27,10 @@ if libaio.found()
 endif
 stub_ss.add(files('migr-blocker.c'))
 stub_ss.add(files('module-opts.c'))
-stub_ss.add(files('monitor.c'))
+if have_system or have_tools
+  stub_ss.add(files('monitor.c'))
+  stub_ss.add(files('fdset.c'))
+endif
 stub_ss.add(files('monitor-core.c'))
 stub_ss.add(files('physmem.c'))
 stub_ss.add(files('qemu-timer-notify-cb.c'))

Paolo

Quoted 124 lines
 stubs/monitor-core.c | 20 +++++++++++++++-----
 stubs/monitor.c      |  8 ++++++--
 stubs/meson.build    |  5 +++--
 4 files changed, 24 insertions(+), 26 deletions(-)
 delete mode 100644 stubs/fdset.c
stubs/fdset.c deleted +0 -17
deleted file mode 100644
index 56b3663d58..0000000000
@@ -1,17 +0,0 @@
-#include "qemu/osdep.h"
-#include "monitor/monitor.h"
-
-int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
-{
-    errno = ENOSYS;
-    return -1;
-}
-
-int64_t monitor_fdset_dup_fd_find(int dup_fd)
-{
-    return -1;
-}
-
-void monitor_fdset_dup_fd_remove(int dupfd)
-{
-}
stubs/monitor-core.c +15 -5
index afa477aae6..72e40bcc15 100644
@@ -1,6 +1,7 @@
+/* Monitor stub required for user emulation */
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
-#include "qapi/qapi-emit-events.h"
+#include "../monitor/monitor-internal.h"
 
 Monitor *monitor_cur(void)
 {
@@ -12,11 +13,22 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
     return NULL;
 }
 
-void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
+int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
+int64_t monitor_fdset_dup_fd_find(int dup_fd)
+{
+    return -1;
+}
+
+void monitor_fdset_dup_fd_remove(int dupfd)
 {
 }
 
-void qapi_event_emit(QAPIEvent event, QDict *qdict)
+void monitor_fdsets_cleanup(void)
 {
 }
 
@@ -24,5 +36,3 @@ int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
     abort();
 }
-
-
stubs/monitor.c +6 -2
index 20786ac4ff..2fc4dc1493 100644
@@ -1,7 +1,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qapi/qapi-emit-events.h"
 #include "monitor/monitor.h"
-#include "../monitor/monitor-internal.h"
 
 int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 {
@@ -13,6 +13,10 @@ void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
 {
 }
 
-void monitor_fdsets_cleanup(void)
+void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
+{
+}
+
+void qapi_event_emit(QAPIEvent event, QDict *qdict)
 {
 }
stubs/meson.build +3 -3
index 0bf25e6ca5..ca1bc07d30 100644
@@ -10,7 +10,6 @@ stub_ss.add(files('qemu-timer-notify-cb.c'))
 stub_ss.add(files('icount.c'))
 stub_ss.add(files('dump.c'))
 stub_ss.add(files('error-printf.c'))
-stub_ss.add(files('fdset.c'))
 stub_ss.add(files('gdbstub.c'))
 stub_ss.add(files('get-vm-name.c'))
 stub_ss.add(files('graph-lock.c'))
@@ -28,7 +27,9 @@ if libaio.found()
 endif
 stub_ss.add(files('migr-blocker.c'))
 stub_ss.add(files('module-opts.c'))
-stub_ss.add(files('monitor.c'))
+if have_system or have_tools
+  stub_ss.add(files('monitor.c'))
+endif
 stub_ss.add(files('monitor-core.c'))
 stub_ss.add(files('physmem.c'))
 stub_ss.add(files('qemu-timer-notify-cb.c'))
--

2.41.0

#9 lore raw

Re: [PATCH-for-9.1 3/7] monitor: Rework stubs to simplify user emulation linking

Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Philippe Mathieu-Daudé

Currently monitor stubs are scattered in 3 files.

Merge these stubs in 2 files, a generic one (monitor-core) included in all builds (in particular user emulation), and a less generic one to be included by tools and system emulation.

Quoted 5 lines
Quoted 3 lines
---
  stubs/fdset.c        | 17 -----------------

Oops, merging fdset.c breaks storage-daemon linking.

Odd. My 'tools_only' build directory is configured with:

'--enable-tools' '--disable-docs' '--disable-system' '--disable-user'

I was building qemu-img & co. I just checked it isn't anymore, the directory only contains libqemuutil.a, libqom.fa, libevent-loop-base.fa and tests/unit (I'm on macOS host).

This explained why I missed the link failure. I'll dig to see when these tools disappeared on macOS.

Regards,

Phil.

#10 lore raw

PATCH 4/7 util/qemu-config: Extract QMP commands to qemu-config-qmp.c

In reply to Philippe Mathieu-Daudé

QMP is irrelevant for user emulation. Extract the code related to QMP in a different source file, which won't be build for user emulation binaries. This avoid pulling pointless code.

---
 include/qemu/config-file.h |   3 +
 util/qemu-config-qmp.c     | 206 +++++++++++++++++++++++++++++++++++++
 util/qemu-config.c         | 204 +-----------------------------------
 util/meson.build           |   1 +
 4 files changed, 212 insertions(+), 202 deletions(-)
 create mode 100644 util/qemu-config-qmp.c
include/qemu/config-file.h +3 -0
index b82a778123..8b9d6df173 100644
@@ -8,6 +8,9 @@ QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
 QemuOpts *qemu_find_opts_singleton(const char *group);
 
+extern QemuOptsList *vm_config_groups[48];
+extern QemuOptsList *drive_config_groups[5];
+
 void qemu_add_opts(QemuOptsList *list);
 void qemu_add_drive_opts(QemuOptsList *list);
 int qemu_global_option(const char *str);
util/qemu-config-qmp.c new file +206 -0

206 lines not on this page · raw message

util/qemu-config.c +2 -202

222 lines not on this page · raw message

util/meson.build +1 -0
index 247f55a80d..636b17a414 100644
@@ -75,6 +75,7 @@ if have_system
   if host_os == 'linux'
     util_ss.add(files('userfaultfd.c'))
   endif
+  util_ss.add(files('qemu-config-qmp.c'))
   util_ss.add(files('yank.c'))
 endif
 
Signature · 1 line
2.41.0
#11 lore raw

Re: [PATCH-for-9.1 4/7] util/qemu-config: Extract QMP commands to qemu-config-qmp.c

Quoted 10 lines · Philippe Mathieu-Daudé

QMP is irrelevant for user emulation. Extract the code related to QMP in a different source file, which won't be build for user emulation binaries. This avoid pulling pointless code.

---
 include/qemu/config-file.h |   3 +
 util/qemu-config-qmp.c     | 206 +++++++++++++++++++++++++++++++++++++

This should go under monitor/.

Queued all except patch 2, please resubmit that and send it to [email protected].

Quoted 474 lines
 util/qemu-config.c         | 204 +-----------------------------------
 util/meson.build           |   1 +
 4 files changed, 212 insertions(+), 202 deletions(-)
 create mode 100644 util/qemu-config-qmp.c
include/qemu/config-file.h +3 -0
index b82a778123..8b9d6df173 100644
@@ -8,6 +8,9 @@ QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
 QemuOpts *qemu_find_opts_singleton(const char *group);
 
+extern QemuOptsList *vm_config_groups[48];
+extern QemuOptsList *drive_config_groups[5];
+
 void qemu_add_opts(QemuOptsList *list);
 void qemu_add_drive_opts(QemuOptsList *list);
 int qemu_global_option(const char *str);
util/qemu-config-qmp.c new file +206 -0
new file mode 100644
index 0000000000..24477a0e44
@@ -0,0 +1,206 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qmp/qlist.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "hw/boards.h"
+
+static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
+{
+    CommandLineParameterInfoList *param_list = NULL;
+    CommandLineParameterInfo *info;
+    int i;
+
+    for (i = 0; desc[i].name != NULL; i++) {
+        info = g_malloc0(sizeof(*info));
+        info->name = g_strdup(desc[i].name);
+
+        switch (desc[i].type) {
+        case QEMU_OPT_STRING:
+            info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
+            break;
+        case QEMU_OPT_BOOL:
+            info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
+            break;
+        case QEMU_OPT_NUMBER:
+            info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
+            break;
+        case QEMU_OPT_SIZE:
+            info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
+            break;
+        }
+
+        info->help = g_strdup(desc[i].help);
+        info->q_default = g_strdup(desc[i].def_value_str);
+
+        QAPI_LIST_PREPEND(param_list, info);
+    }
+
+    return param_list;
+}
+
+/* remove repeated entry from the info list */
+static void cleanup_infolist(CommandLineParameterInfoList *head)
+{
+    CommandLineParameterInfoList *pre_entry, *cur, *del_entry;
+
+    cur = head;
+    while (cur->next) {
+        pre_entry = head;
+        while (pre_entry != cur->next) {
+            if (!strcmp(pre_entry->value->name, cur->next->value->name)) {
+                del_entry = cur->next;
+                cur->next = cur->next->next;
+                del_entry->next = NULL;
+                qapi_free_CommandLineParameterInfoList(del_entry);
+                break;
+            }
+            pre_entry = pre_entry->next;
+        }
+        cur = cur->next;
+    }
+}
+
+/* merge the description items of two parameter infolists */
+static void connect_infolist(CommandLineParameterInfoList *head,
+                             CommandLineParameterInfoList *new)
+{
+    CommandLineParameterInfoList *cur;
+
+    cur = head;
+    while (cur->next) {
+        cur = cur->next;
+    }
+    cur->next = new;
+}
+
+/* access all the local QemuOptsLists for drive option */
+static CommandLineParameterInfoList *get_drive_infolist(void)
+{
+    CommandLineParameterInfoList *head = NULL, *cur;
+    int i;
+
+    for (i = 0; drive_config_groups[i] != NULL; i++) {
+        if (!head) {
+            head = query_option_descs(drive_config_groups[i]->desc);
+        } else {
+            cur = query_option_descs(drive_config_groups[i]->desc);
+            connect_infolist(head, cur);
+        }
+    }
+    cleanup_infolist(head);
+
+    return head;
+}
+
+static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop)
+{
+    CommandLineParameterInfo *info;
+
+    info = g_malloc0(sizeof(*info));
+    info->name = g_strdup(prop->name);
+
+    if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) {
+        info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
+    } else if (g_str_equal(prop->type, "int")) {
+        info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
+    } else if (g_str_equal(prop->type, "size")) {
+        info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
+    } else {
+        info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
+    }
+
+    if (prop->description) {
+        info->help = g_strdup(prop->description);
+    }
+
+    return info;
+}
+
+static CommandLineParameterInfoList *query_all_machine_properties(void)
+{
+    CommandLineParameterInfoList *params = NULL, *clpiter;
+    CommandLineParameterInfo *info;
+    GSList *machines, *curr_mach;
+    ObjectPropertyIterator op_iter;
+    ObjectProperty *prop;
+    bool is_new;
+
+    machines = object_class_get_list(TYPE_MACHINE, false);
+    assert(machines);
+
+    /* Loop over all machine classes */
+    for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) {
+        object_class_property_iter_init(&op_iter, curr_mach->data);
+        /* ... and over the properties of each machine: */
+        while ((prop = object_property_iter_next(&op_iter))) {
+            if (!prop->set) {
+                continue;
+            }
+            /*
+             * Check whether the property has already been put into the list
+             * (via another machine class)
+             */
+            is_new = true;
+            for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) {
+                if (g_str_equal(clpiter->value->name, prop->name)) {
+                    is_new = false;
+                    break;
+                }
+            }
+            /* If it hasn't been added before, add it now to the list */
+            if (is_new) {
+                info = objprop_to_cmdline_prop(prop);
+                QAPI_LIST_PREPEND(params, info);
+            }
+        }
+    }
+
+    g_slist_free(machines);
+
+    /* Add entry for the "type" parameter */
+    info = g_malloc0(sizeof(*info));
+    info->name = g_strdup("type");
+    info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
+    info->help = g_strdup("machine type");
+    QAPI_LIST_PREPEND(params, info);
+
+    return params;
+}
+
+CommandLineOptionInfoList *qmp_query_command_line_options(const char *option,
+                                                          Error **errp)
+{
+    CommandLineOptionInfoList *conf_list = NULL;
+    CommandLineOptionInfo *info;
+    int i;
+
+    for (i = 0; vm_config_groups[i] != NULL; i++) {
+        if (!option || !strcmp(option, vm_config_groups[i]->name)) {
+            info = g_malloc0(sizeof(*info));
+            info->option = g_strdup(vm_config_groups[i]->name);
+            if (!strcmp("drive", vm_config_groups[i]->name)) {
+                info->parameters = get_drive_infolist();
+            } else {
+                info->parameters =
+                    query_option_descs(vm_config_groups[i]->desc);
+            }
+            QAPI_LIST_PREPEND(conf_list, info);
+        }
+    }
+
+    if (!option || !strcmp(option, "machine")) {
+        info = g_malloc0(sizeof(*info));
+        info->option = g_strdup("machine");
+        info->parameters = query_all_machine_properties();
+        QAPI_LIST_PREPEND(conf_list, info);
+    }
+
+    if (conf_list == NULL) {
+        error_setg(errp, "invalid option name: %s", option);
+    }
+
+    return conf_list;
+}
util/qemu-config.c +2 -202
index 42076efe1e..a90c18dad2 100644
@@ -1,16 +1,14 @@
 #include "qemu/osdep.h"
 #include "block/qdict.h" /* for qdict_extract_subqdict() */
 #include "qapi/error.h"
-#include "qapi/qapi-commands-misc.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qlist.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "hw/boards.h"
 
-static QemuOptsList *vm_config_groups[48];
-static QemuOptsList *drive_config_groups[5];
+QemuOptsList *vm_config_groups[48];
+QemuOptsList *drive_config_groups[5];
 
 static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
                                Error **errp)
@@ -55,204 +53,6 @@ QemuOpts *qemu_find_opts_singleton(const char *group)
     return opts;
 }
 
-static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
-{
-    CommandLineParameterInfoList *param_list = NULL;
-    CommandLineParameterInfo *info;
-    int i;
-
-    for (i = 0; desc[i].name != NULL; i++) {
-        info = g_malloc0(sizeof(*info));
-        info->name = g_strdup(desc[i].name);
-
-        switch (desc[i].type) {
-        case QEMU_OPT_STRING:
-            info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
-            break;
-        case QEMU_OPT_BOOL:
-            info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
-            break;
-        case QEMU_OPT_NUMBER:
-            info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
-            break;
-        case QEMU_OPT_SIZE:
-            info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
-            break;
-        }
-
-        info->help = g_strdup(desc[i].help);
-        info->q_default = g_strdup(desc[i].def_value_str);
-
-        QAPI_LIST_PREPEND(param_list, info);
-    }
-
-    return param_list;
-}
-
-/* remove repeated entry from the info list */
-static void cleanup_infolist(CommandLineParameterInfoList *head)
-{
-    CommandLineParameterInfoList *pre_entry, *cur, *del_entry;
-
-    cur = head;
-    while (cur->next) {
-        pre_entry = head;
-        while (pre_entry != cur->next) {
-            if (!strcmp(pre_entry->value->name, cur->next->value->name)) {
-                del_entry = cur->next;
-                cur->next = cur->next->next;
-                del_entry->next = NULL;
-                qapi_free_CommandLineParameterInfoList(del_entry);
-                break;
-            }
-            pre_entry = pre_entry->next;
-        }
-        cur = cur->next;
-    }
-}
-
-/* merge the description items of two parameter infolists */
-static void connect_infolist(CommandLineParameterInfoList *head,
-                             CommandLineParameterInfoList *new)
-{
-    CommandLineParameterInfoList *cur;
-
-    cur = head;
-    while (cur->next) {
-        cur = cur->next;
-    }
-    cur->next = new;
-}
-
-/* access all the local QemuOptsLists for drive option */
-static CommandLineParameterInfoList *get_drive_infolist(void)
-{
-    CommandLineParameterInfoList *head = NULL, *cur;
-    int i;
-
-    for (i = 0; drive_config_groups[i] != NULL; i++) {
-        if (!head) {
-            head = query_option_descs(drive_config_groups[i]->desc);
-        } else {
-            cur = query_option_descs(drive_config_groups[i]->desc);
-            connect_infolist(head, cur);
-        }
-    }
-    cleanup_infolist(head);
-
-    return head;
-}
-
-static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop)
-{
-    CommandLineParameterInfo *info;
-
-    info = g_malloc0(sizeof(*info));
-    info->name = g_strdup(prop->name);
-
-    if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) {
-        info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
-    } else if (g_str_equal(prop->type, "int")) {
-        info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
-    } else if (g_str_equal(prop->type, "size")) {
-        info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
-    } else {
-        info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
-    }
-
-    if (prop->description) {
-        info->help = g_strdup(prop->description);
-    }
-
-    return info;
-}
-
-static CommandLineParameterInfoList *query_all_machine_properties(void)
-{
-    CommandLineParameterInfoList *params = NULL, *clpiter;
-    CommandLineParameterInfo *info;
-    GSList *machines, *curr_mach;
-    ObjectPropertyIterator op_iter;
-    ObjectProperty *prop;
-    bool is_new;
-
-    machines = object_class_get_list(TYPE_MACHINE, false);
-    assert(machines);
-
-    /* Loop over all machine classes */
-    for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) {
-        object_class_property_iter_init(&op_iter, curr_mach->data);
-        /* ... and over the properties of each machine: */
-        while ((prop = object_property_iter_next(&op_iter))) {
-            if (!prop->set) {
-                continue;
-            }
-            /*
-             * Check whether the property has already been put into the list
-             * (via another machine class)
-             */
-            is_new = true;
-            for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) {
-                if (g_str_equal(clpiter->value->name, prop->name)) {
-                    is_new = false;
-                    break;
-                }
-            }
-            /* If it hasn't been added before, add it now to the list */
-            if (is_new) {
-                info = objprop_to_cmdline_prop(prop);
-                QAPI_LIST_PREPEND(params, info);
-            }
-        }
-    }
-
-    g_slist_free(machines);
-
-    /* Add entry for the "type" parameter */
-    info = g_malloc0(sizeof(*info));
-    info->name = g_strdup("type");
-    info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
-    info->help = g_strdup("machine type");
-    QAPI_LIST_PREPEND(params, info);
-
-    return params;
-}
-
-CommandLineOptionInfoList *qmp_query_command_line_options(const char *option,
-                                                          Error **errp)
-{
-    CommandLineOptionInfoList *conf_list = NULL;
-    CommandLineOptionInfo *info;
-    int i;
-
-    for (i = 0; vm_config_groups[i] != NULL; i++) {
-        if (!option || !strcmp(option, vm_config_groups[i]->name)) {
-            info = g_malloc0(sizeof(*info));
-            info->option = g_strdup(vm_config_groups[i]->name);
-            if (!strcmp("drive", vm_config_groups[i]->name)) {
-                info->parameters = get_drive_infolist();
-            } else {
-                info->parameters =
-                    query_option_descs(vm_config_groups[i]->desc);
-            }
-            QAPI_LIST_PREPEND(conf_list, info);
-        }
-    }
-
-    if (!option || !strcmp(option, "machine")) {
-        info = g_malloc0(sizeof(*info));
-        info->option = g_strdup("machine");
-        info->parameters = query_all_machine_properties();
-        QAPI_LIST_PREPEND(conf_list, info);
-    }
-
-    if (conf_list == NULL) {
-        error_setg(errp, "invalid option name: %s", option);
-    }
-
-    return conf_list;
-}
-
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
 {
     return find_list(vm_config_groups, group, errp);
util/meson.build +1 -1
index 247f55a80d..636b17a414 100644
@@ -75,6 +75,7 @@ if have_system
   if host_os == 'linux'
     util_ss.add(files('userfaultfd.c'))
   endif
+  util_ss.add(files('qemu-config-qmp.c'))
   util_ss.add(files('yank.c'))
 endif
 
--

2.41.0

#12 lore raw

PATCH 5/7 hw/core: Restrict reset handlers API to system emulation

In reply to Philippe Mathieu-Daudé

Headers in include/sysemu/ are specific to system emulation and should not be used in user emulation.

---
 hw/core/reset.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/core/reset.c +4 -0
index d50da7e304..167c8bf1a9 100644
@@ -24,7 +24,9 @@
  */
 
 #include "qemu/osdep.h"
+#ifndef CONFIG_USER_ONLY
 #include "sysemu/reset.h"
+#endif
 #include "hw/resettable.h"
 #include "hw/core/resetcontainer.h"
 
@@ -43,6 +45,7 @@ static ResettableContainer *get_root_reset_container(void)
     return root_reset_container;
 }
 
+#ifndef CONFIG_USER_ONLY
 /*
  * Reason why the currently in-progress qemu_devices_reset() was called.
  * If we made at least SHUTDOWN_CAUSE_SNAPSHOT_LOAD have a corresponding
@@ -185,3 +188,4 @@ void qemu_devices_reset(ShutdownCause reason)
     /* Reset the simulation */
     resettable_reset(OBJECT(get_root_reset_container()), RESET_TYPE_COLD);
 }
+#endif
Signature · 1 line
2.41.0
#13 lore raw

Re: [PATCH-for-9.1 5/7] hw/core: Restrict reset handlers API to system emulation

Quoted 24 lines · Philippe Mathieu-Daudé

Headers in include/sysemu/ are specific to system emulation and should not be used in user emulation.

---
 hw/core/reset.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/core/reset.c +2 -0
index d50da7e304..167c8bf1a9 100644
@@ -24,7 +24,9 @@
  */
 
 #include "qemu/osdep.h"
+#ifndef CONFIG_USER_ONLY
 #include "sysemu/reset.h"
+#endif
 #include "hw/resettable.h"
 #include "hw/core/resetcontainer.h"
 

hw/core/reset.c static ResettableContainer *get_root_reset_container(void) · line 48

Quoted 4 lines
hw/core/reset.c +1 -0
@@ -43,6 +45,7 @@ static ResettableContainer *get_root_reset_container(void)
     return root_reset_container;
 }
 
+#ifndef CONFIG_USER_ONLY

Wait, this does not make sense. The only thing left in the file is a single static function, which contradicts the other patch's commit message "reset.c contains core code used by any CPU,".

Let me rework these two patches so that reset.c, qdev-hotplug.c and hotplug.c can be moved to system_ss. I'll post a v2 shortly.

Paolo

Quoted 11 lines
hw/core/reset.c +1 -1
 /*
  * Reason why the currently in-progress qemu_devices_reset() was called.
  * If we made at least SHUTDOWN_CAUSE_SNAPSHOT_LOAD have a corresponding
@@ -185,3 +188,4 @@ void qemu_devices_reset(ShutdownCause reason)
     /* Reset the simulation */
     resettable_reset(OBJECT(get_root_reset_container()), RESET_TYPE_COLD);
 }
+#endif
--

2.41.0

#14 lore raw

PATCH 6/7 hw/core: Move reset.c to hwcore_ss[] source set

In reply to Philippe Mathieu-Daudé

reset.c contains core code used by any CPU, required by user emulation. Move it to hwcore_ss[] where it belongs.

---
 hw/core/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/meson.build +1 -1
index e26f2e088c..1389f1b339 100644
@@ -3,7 +3,6 @@ hwcore_ss.add(files(
   'bus.c',
   'qdev-properties.c',
   'qdev.c',
-  'reset.c',
   'resetcontainer.c',
   'resettable.c',
   'vmstate-if.c',
@@ -16,6 +15,7 @@ if have_system
   hwcore_ss.add(files(
     'hotplug.c',
     'qdev-hotplug.c',
+    'reset.c',
   ))
 else
   hwcore_ss.add(files(
Signature · 1 line
2.41.0
#15 lore raw

Re: [PATCH-for-9.1 6/7] hw/core: Move reset.c to hwcore_ss[] source set

Quoted 22 lines · Philippe Mathieu-Daudé

reset.c contains core code used by any CPU, required by user emulation. Move it to hwcore_ss[] where it belongs.

---
  hw/core/meson.build | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/meson.build +0 -1
index e26f2e088c..1389f1b339 100644
@@ -3,7 +3,6 @@ hwcore_ss.add(files(
    'bus.c',
    'qdev-properties.c',
    'qdev.c',
-  'reset.c',
    'resetcontainer.c',
    'resettable.c',
    'vmstate-if.c',

hw/core/meson.build if have_system · line 18

Quoted 4 lines
hw/core/meson.build +1 -0
@@ -16,6 +15,7 @@ if have_system
    hwcore_ss.add(files(
      'hotplug.c',
      'qdev-hotplug.c',
+    'reset.c',

This patch would seem to obviate the previous?

r~

#16 lore raw

Re: [PATCH-for-9.1 6/7] hw/core: Move reset.c to hwcore_ss[] source set

Quoted 21 lines · Richard Henderson
Quoted 20 lines · Philippe Mathieu-Daudé

reset.c contains core code used by any CPU, required by user emulation. Move it to hwcore_ss[] where it belongs.

---
  hw/core/meson.build | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/meson.build +0 -1
index e26f2e088c..1389f1b339 100644
@@ -3,7 +3,6 @@ hwcore_ss.add(files(
     'bus.c',
     'qdev-properties.c',
     'qdev.c',
-  'reset.c',
     'resetcontainer.c',
     'resettable.c',
Quoted 8 lines
Quoted 6 lines
hw/core/meson.build +0 -0
     'vmstate-if.c',
@@ -16,6 +15,7 @@ if have_system

    hwcore_ss.add(files(
      'hotplug.c',
      'qdev-hotplug.c',
+    'reset.c',

This patch would seem to obviate the previous?

No, hwcore_ss[] is used for both system/user.

As its name suggests, "sysemu/reset.h" is system specific. We don't want to compile its definitions and link them to a user-only build.

I can squash both if it makes it more obvious.

Regards,

Phil.

#17 lore raw

PATCH 7/7 hw: Include minimal source set in user emulation build

In reply to Philippe Mathieu-Daudé

Only the files in hwcore_ss[] are required to link a user emulation binary.

Have meson process the hw/ sub-directories if system emulation is selected, otherwise directly process hw/core/ to get hwcore_ss[], which is the only set required by user emulation.

---
 meson.build | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
meson.build +5 -1
index c9c3217ba4..68eecd1937 100644
@@ -3447,8 +3447,12 @@ subdir('qom')
 subdir('authz')
 subdir('crypto')
 subdir('ui')
-subdir('hw')
 subdir('gdbstub')
+if have_system
+  subdir('hw')
+else
+  subdir('hw/core')
+endif
 
 if enable_modules
   libmodulecommon = static_library('module-common', files('module-common.c') + genh, pic: true, c_args: '-DBUILD_DSO')
Signature · 1 line
2.41.0
Reviewed-by on v1 7/7
#18 lore raw

Re: [PATCH-for-9.1 7/7] hw: Include minimal source set in user emulation build

Quoted 8 lines · Philippe Mathieu-Daudé

Only the files in hwcore_ss[] are required to link a user emulation binary.

Have meson process the hw/ sub-directories if system emulation is selected, otherwise directly process hw/core/ to get hwcore_ss[], which is the only set required by user emulation.

Quoted 4 lines
---
  meson.build | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

r~