monitor: Reduce headers included in 'monitor/monitor.h'
cover monitor: Reduce headers included in 'monitor/monitor.h'
Another HMP cleanup series to help [1] Marc-André with his 'Make HMP optional' series [2].
We could also remove "exec/hwaddr.h" by moving gpa2hva() declaration elsewhere, and "qapi/qapi-types-misc.h" by moving monitor_fdset_add_fd() out to some "monitor/fdset.h" header.
[1] I expect his work to trivially rebase ;)
[2] [email protected]
Based-on: <[email protected]>
Philippe Mathieu-Daudé (14):
hexagon: Remove unnecessary 'monitor/monitor.h' header tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header migration/hmp-cmds: Include 'block/block-global-state.h' header
monitor: Include missing 'qemu/aio-wait.h' header
monitor: Include missing 'qemu/lockable.h' header
monitor: Include missing 'qemu/coroutine-core.h' header
monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header
monitor: Remove unnecessary 'block/block.h' header monitor/hmp: Remove unnecessary 'monitor/monitor.h' header
system: Remove unnecessary 'monitor/monitor.h' header
system: Move runstate-related code from cpus.c to runstate.c system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c
include/hw/hexagon/hexagon_tlb.h | 2 +- include/monitor/hmp.h | 1 - include/monitor/monitor.h | 3 +- include/qapi/qmp-registry.h | 1 - monitor/monitor-internal.h | 1 + target/hexagon/hex_mmu.h | 3 +- migration/migration-hmp-cmds.c | 1 + monitor/fds.c | 1 + monitor/monitor.c | 2 + monitor/qmp.c | 3 +- qapi/qmp-dispatch.c | 2 + system/cpus.c | 146 ------------------------------ system/device_tree.c | 1 - system/dirtylimit-hmp-cmds.c | 74 ++++++++++++++++ system/dirtylimit.c | 60 ------------- system/physmem.c | 2 - system/runstate.c | 148 +++++++++++++++++++++++++++++++ tests/unit/test-util-sockets.c | 1 + system/meson.build | 1 + 19 files changed, 237 insertions(+), 216 deletions(-) create mode 100644 system/dirtylimit-hmp-cmds.c
Signature · 1 line
2.53.0
PATCH 1/14 hexagon: Remove unnecessary 'monitor/monitor.h' header
The Monitor type is used in these 2 files, as a pointer. Since the type is forward-declared in "qemu/typedefs.h", which all source files include via "qemu/osdep.h", we do not need to include it.
Do however include "exec/hwaddr.h" and "exec/mmu-access-type.h" which declare the types used by hex_tlb_find_match prototype:
extern bool hex_tlb_find_match(CPUHexagonState *env, uint32_t VA,
MMUAccessType access_type, hwaddr *PA, int *prot,
^^^^^^^^^^^^^ ^^^^^^
uint64_t *size, int32_t *excp, int mmu_idx);--- include/hw/hexagon/hexagon_tlb.h | 2 +- target/hexagon/hex_mmu.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
include/hw/hexagon/hexagon_tlb.h +1 -1
@@ -12,7 +12,7 @@#include "qom/object.h" #include "exec/hwaddr.h" #include "exec/mmu-access-type.h" -#include "monitor/monitor.h" +#define TYPE_HEXAGON_TLB "hexagon-tlb"OBJECT_DECLARE_SIMPLE_TYPE (HexagonTLBState,HEXAGON_TLB )
target/hexagon/hex_mmu.h +2 -1
@@ -7,8 +7,9 @@#ifndef HEXAGON_MMU_H #define HEXAGON_MMU_H +#include "exec/hwaddr.h" +#include "exec/mmu-access-type.h" #include "cpu.h" -#include "monitor/monitor.h" extern void hex_tlbw (CPUHexagonState *env,uint32_t index,uint64_t value);extern uint32_t hex_tlb_lookup (CPUHexagonState *env,uint32_t ssr,uint32_t VA );
Signature · 1 line
2.53.0
PATCH 2/14 tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c
In reply to Philippe Mathieu-Daudétest-util-sockets.c calls qemu_init_main_loop(), itself declared in the "qemu/main-loop.h" header. Include the latter to avoid when refactoring unrelated headers:
../tests/unit/test-util-sockets.c:553:5: error: call to undeclared function 'qemu_init_main_loop'
553 | qemu_init_main_loop(&error_abort);
| ^--- tests/unit/test-util-sockets.c | 1 + 1 file changed, 1 insertion(+)
tests/unit/test-util-sockets.c +1 -0
@@ -19,6 +19,7 @@*/ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/sockets.h" #include "qapi/error.h" #include "socket-helpers.h"
Signature · 1 line
2.53.0
PATCH 3/14 qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h'
In reply to Philippe Mathieu-Daudéqmp-dispatch.c calls aio_wait_kick() and monitor_cur(). Include the header declaring them in order to avoid the following build failure when refactoring unrelated headers:
../qapi/qmp-dispatch.c:126:12: error: call to undeclared function 'monitor_cur'
126 | assert(monitor_cur() == NULL);
| ^
../qapi/qmp-dispatch.c:141:5: error: call to undeclared function 'aio_wait_kick'
141 | aio_wait_kick();
| ^--- qapi/qmp-dispatch.c | 2 ++ 1 file changed, 2 insertions(+)
qapi/qmp-dispatch.c +2 -0
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include "qemu/aio.h" +#include "qemu/aio-wait.h" #include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp-registry.h"
@@ -24,6 +25,7 @@#include "qobject/qbool.h" #include "qemu/coroutine.h" #include "qemu/main-loop.h" +#include "monitor/monitor.h" Visitor *qobject_input_visitor_new_qmp (QObject *obj) {
Signature · 1 line
2.53.0
PATCH 4/14 qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header
In reply to Philippe Mathieu-Daudé--- include/qapi/qmp-registry.h | 1 - 1 file changed, 1 deletion(-)
include/qapi/qmp-registry.h +0 -1
@@ -14,7 +14,6 @@#ifndef QAPI_QMP_DISPATCH_H #define QAPI_QMP_DISPATCH_H -#include "monitor/monitor.h" #include "qemu/queue.h" typedef void (QmpCommandFunc )(QDict *,QObject **,Error **);
Signature · 1 line
2.53.0
PATCH 5/14 migration/hmp-cmds: Include 'block/block-global-state.h' header
In reply to Philippe Mathieu-Daudémigration-hmp-cmds.c uses types / methods declared in "block/block-global-state.h". Include the latter otherwise we get when refactoring unrelated headers:
../migration/migration-hmp-cmds.c:911:5: error: use of undeclared identifier 'BdrvNextIterator'
911 | BdrvNextIterator it;
| ^
../migration/migration-hmp-cmds.c:918:15: error: call to undeclared function 'bdrv_first'
918 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
| ^--- migration/migration-hmp-cmds.c | 1 + 1 file changed, 1 insertion(+)
migration/migration-hmp-cmds.c +1 -0
@@ -15,6 +15,7 @@#include "qemu/osdep.h" #include "block/qapi.h" +#include "block/block-global-state.h" #include "migration/snapshot.h" #include "monitor/hmp.h" #include "monitor/hmp-completion.h"
Signature · 1 line
2.53.0
PATCH 6/14 monitor: Include missing 'qemu/aio-wait.h' header
In reply to Philippe Mathieu-DaudéBoth monitor.c and qmp.c use types / methods declared in "qemu/aio-wait.h". Include the latter to avoid the following errors when refactoring unrelated headers:
../monitor/monitor.c:648:5: error: call to undeclared function 'AIO_WAIT_WHILE_UNLOCKED'
648 | AIO_WAIT_WHILE_UNLOCKED(NULL,
| ^
../monitor/qmp.c:792:9: error: call to undeclared function 'aio_wait_bh_oneshot'
792 | aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread),
| ^--- monitor/monitor.c | 1 + monitor/qmp.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
monitor/monitor.c +1 -0
@@ -30,6 +30,7 @@#include "qapi/qapi-visit-control.h" #include "qobject/qdict.h" #include "qom/object_interfaces.h" +#include "qemu/aio-wait.h" #include "qemu/error-report.h" #include "qemu/option.h" #include "system/qtest.h"
monitor/qmp.c +1 -1
@@ -23,7 +23,7 @@*/ #include "qemu/osdep.h" - +#include "qemu/aio-wait.h" #include "chardev/char-io.h" #include "monitor-internal.h" #include "qapi/error.h"
Signature · 1 line
2.53.0
PATCH 7/14 monitor: Include missing 'qemu/lockable.h' header
In reply to Philippe Mathieu-DaudéFiles in monitor/ use the QEMU_LOCK_GUARD() macros, which are declared in "qemu/lockable.h". Include the latter to avoid when refactoring unrelated headers:
../monitor/fds.c:146:5: error: call to undeclared function 'QEMU_LOCK_GUARD'
146 | QEMU_LOCK_GUARD(&mon->mon_lock);
| ^
../monitor/monitor.c:176:5: error: call to undeclared function 'QEMU_LOCK_GUARD'
176 | QEMU_LOCK_GUARD(&mon->mon_lock);
| ^
../monitor/qmp.c:164:5: error: call to undeclared function 'WITH_QEMU_LOCK_GUARD'
164 | WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
| ^--- monitor/fds.c | 1 + monitor/monitor.c | 1 + monitor/qmp.c | 1 + 3 files changed, 3 insertions(+)
monitor/fds.c +1 -0
@@ -29,6 +29,7 @@#include "qapi/qmp/qerror.h" #include "qemu/ctype.h" #include "qemu/cutils.h" +#include "qemu/lockable.h" #include "system/runstate.h" /* file descriptors passed via SCM_RIGHTS */
monitor/monitor.c +1 -0
@@ -32,6 +32,7 @@#include "qom/object_interfaces.h" #include "qemu/aio-wait.h" #include "qemu/error-report.h" +#include "qemu/lockable.h" #include "qemu/option.h" #include "system/qtest.h" #include "trace.h"
monitor/qmp.c +1 -0
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qemu/aio-wait.h" +#include "qemu/lockable.h" #include "chardev/char-io.h" #include "monitor-internal.h" #include "qapi/error.h"
Signature · 1 line
2.53.0
PATCH 8/14 monitor: Include missing 'qemu/coroutine-core.h' header
In reply to Philippe Mathieu-Daudé"monitor/monitor.h" declares monitor_set_cur() which use the 'Coroutine' type, itself declared in "qemu/coroutine-core.h". Include the latter to avoid when refactoring unrelated headers:
In file included from ../../target/sh4/monitor.c:26:
qemu/include/monitor/monitor.h:32:26: error: unknown type name 'Coroutine'
32 | Monitor *monitor_set_cur(Coroutine *co, Monitor *mon);
| ^--- include/monitor/monitor.h | 1 + 1 file changed, 1 insertion(+)
include/monitor/monitor.h +1 -0
@@ -4,6 +4,7 @@#include "block/block.h" #include "qapi/qapi-types-misc.h" #include "qapi/qapi-emit-events.h" +#include "qemu/coroutine-core.h" #include "qemu/readline.h" #include "exec/hwaddr.h" #include "qom/object.h"
Signature · 1 line
2.53.0
PATCH 9/14 monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header
In reply to Philippe Mathieu-Daudé"monitor/monitor.h" don't use anything declared in the generated "qapi/qapi-emit-events.h" header.
However the "monitor/monitor-internal.h" do:
107 struct MonitorClass {
...
116 /*
117 * If non-NULL, the monitor is able to send event
118 * notifications back to the client
119 */
120 void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict);
^^^^^^^^^Move the header inclusion to "monitor/monitor-internal.h" to avoid including / re-exposing unnecessary declarations in the global "monitor/monitor.h" header.
--- include/monitor/monitor.h | 1 - monitor/monitor-internal.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
include/monitor/monitor.h +0 -1
@@ -3,7 +3,6 @@#include "block/block.h" #include "qapi/qapi-types-misc.h" -#include "qapi/qapi-emit-events.h" #include "qemu/coroutine-core.h" #include "qemu/readline.h" #include "exec/hwaddr.h"
monitor/monitor-internal.h +1 -0
@@ -27,6 +27,7 @@#include "chardev/char-fe.h" #include "monitor/monitor.h" +#include "qapi/qapi-emit-events.h" #include "qapi/qapi-types-control.h" #include "qapi/qapi-types-qom.h" #include "qapi/qmp-registry.h"
Signature · 1 line
2.53.0
PATCH 10/14 monitor: Remove unnecessary 'block/block.h' header
In reply to Philippe Mathieu-DaudéNothing here requires declarations from "block/block.h".
--- include/monitor/monitor.h | 1 - 1 file changed, 1 deletion(-)
include/monitor/monitor.h +0 -1
@@ -1,7 +1,6 @@#ifndef MONITOR_H #define MONITOR_H -#include "block/block.h" #include "qapi/qapi-types-misc.h" #include "qemu/coroutine-core.h" #include "qemu/readline.h"
Signature · 1 line
2.53.0
PATCH 11/14 monitor/hmp: Remove unnecessary 'monitor/monitor.h' header
In reply to Philippe Mathieu-DaudéNothing here requires declarations from "monitor/monitor.h".
--- include/monitor/hmp.h | 1 - 1 file changed, 1 deletion(-)
include/monitor/hmp.h +0 -1
@@ -16,7 +16,6 @@#include "qemu/readline.h" #include "qapi/qapi-types-common.h" -#include "monitor/monitor.h" #define HMP_STUB (cmd) \ void hmp_##cmd(Monitor *mon, const QDict *qdict) \
Signature · 1 line
2.53.0
PATCH 12/14 system: Remove unnecessary 'monitor/monitor.h' header
In reply to Philippe Mathieu-DaudéNo code in device_tree.c or physmem.c require declarations from "monitor/monitor.h".
--- system/device_tree.c | 1 - system/physmem.c | 2 -- 2 files changed, 3 deletions(-)
system/device_tree.c +0 -1
@@ -29,7 +29,6 @@#include "qemu/config-file.h" #include "qapi/qapi-commands-machine.h" #include "qobject/qdict.h" -#include "monitor/hmp.h" #include <libfdt.h>
system/physmem.c +0 -2
@@ -84,8 +84,6 @@#include "qemu/mmap-alloc.h" #endif -#include "monitor/monitor.h" -#ifdef CONFIG_LIBDAXCTL #include <daxctl/libdaxctl.h> #endif
Signature · 1 line
2.53.0
PATCH 13/14 system: Move runstate-related code from cpus.c to runstate.c
In reply to Philippe Mathieu-Daudé--- system/cpus.c | 146 --------------------------------------------- system/runstate.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 146 deletions(-)
system/cpus.c +0 -146
@@ -277,58 +277,6 @@ void cpu_interrupt(CPUState *cpu, int mask) cpus_accel->handle_interrupt (cpu, mask); } -/* -* True if the vm was previously suspended, and has not been woken or reset. -*/ -static int vm_was_suspended; - -void vm_set_suspended (bool suspended) -{ - vm_was_suspended = suspended; -} - -bool vm_get_suspended (void ) -{ -return vm_was_suspended; -} - -static int do_vm_stop (RunState state,bool send_stop) -{ -int ret =0 ; -RunState oldstate =runstate_get (); - -if (runstate_is_live (oldstate)) { - vm_was_suspended = (oldstate ==RUN_STATE_SUSPENDED ); -runstate_set (state); -cpu_disable_ticks (); -if (oldstate ==RUN_STATE_RUNNING ) { -pause_all_vcpus (); - } - ret =vm_state_notify (0 , state); -if (send_stop) { -qapi_event_send_stop (); - } - } - -bdrv_drain_all (); -/* -* Even if vm_state_notify() return failure, -* it would be better to flush as before. -*/ - ret |=bdrv_flush_all (); -trace_vm_stop_flush_all (ret); - -return ret; -} - -/* Special vm_stop() variant for terminating the process. Historically clients -* did not expect a QMP STOP event and so we need to retain compatibility. -*/ -int vm_shutdown (void ) -{ -return do_vm_stop (RUN_STATE_SHUTDOWN , false); -} -bool cpu_can_run (CPUState *cpu) {if (cpu->stop) {
@@ -740,100 +688,6 @@ void cpu_stop_current(void) } } -int vm_stop (RunState state) -{ -if (qemu_in_vcpu_thread ()) { -qemu_system_vmstop_request_prepare (); -qemu_system_vmstop_request (state); -/* -* FIXME: should not return to device code in case -* vm_stop() has been requested. -*/ -cpu_stop_current (); -return 0 ; - } - -return do_vm_stop (state, true); -} - -/** -* Prepare for (re)starting the VM. -* Returns 0 if the vCPUs should be restarted, -1 on an error condition, -* and 1 otherwise. -*/ -int vm_prepare_start (bool step_pending) -{ -int ret = vm_was_suspended ?1 :0 ; -RunState state = vm_was_suspended ?RUN_STATE_SUSPENDED :RUN_STATE_RUNNING ; -RunState requested; - -qemu_vmstop_requested (&requested); -if (runstate_is_running () && requested ==RUN_STATE__MAX ) { -return -1 ; - } - -/* Ensure that a STOP/RESUME pair of events is emitted if a -* vmstop request was pending. The BLOCK_IO_ERROR event, for -* example, according to documentation is always followed by -* the STOP event. -*/ -if (runstate_is_running ()) { -qapi_event_send_stop (); -qapi_event_send_resume (); -return -1 ; - } - -/* -* WHPX accelerator needs to know whether we are going to step -* any CPUs, before starting the first one. -*/ -accel_pre_resume (MACHINE (qdev_get_machine ()), step_pending); - -/* We are sending this now, but the CPUs will be resumed shortly later */ -qapi_event_send_resume (); - -cpu_enable_ticks (); -runstate_set (state); -vm_state_notify (1 , state); - vm_was_suspended = false; -return ret; -} - -void vm_start (void ) -{ -if (!vm_prepare_start (false)) { -resume_all_vcpus (); - } -} - -void vm_resume (RunState state) -{ -if (runstate_is_live (state)) { -vm_start (); - }else { -runstate_set (state); - } -} - -/* does a state transition even if the VM is already stopped, -current state is forgotten forever */ -int vm_stop_force_state (RunState state) -{ -if (runstate_is_live (runstate_get ())) { -return vm_stop (state); - }else { -int ret; -runstate_set (state); - -bdrv_drain_all (); -/* Make sure to return an error if the flush in a previous vm_stop() -* failed. */ - ret =bdrv_flush_all (); -trace_vm_stop_flush_all (ret); -return ret; - } -} -void qmp_memsave (uint64_t addr,uint64_t size,const char *filename,bool has_cpu,int64_t cpu_index,Error **errp) {
system/runstate.c +148 -0
160 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 13/14] system: Move runstate-related code from cpus.c to runstate.c
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/cpus.c | 146 --------------------------------------------- system/runstate.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 146 deletions(-)
Wrong branch :/ This change will makes sense in v2.
PATCH 14/14 system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c
In reply to Philippe Mathieu-Daudé--- system/dirtylimit-hmp-cmds.c | 74 ++++++++++++++++++++++++++++++++++++ system/dirtylimit.c | 60 ----------------------------- system/meson.build | 1 + 3 files changed, 75 insertions(+), 60 deletions(-) create mode 100644 system/dirtylimit-hmp-cmds.c
system/dirtylimit-hmp-cmds.c new file +74 -0
@@ -0,0 +1,74 @@ +/* +* HMP commands related to migration dirty page rate limit +* +* Copyright (c) 2022 CHINA TELECOM CO.,LTD. +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-migration.h" +#include "qobject/qdict.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" +#include "system/dirtylimit.h" + +void hmp_cancel_vcpu_dirty_limit (Monitor *mon,const QDict *qdict) +{ +int64_t cpu_index =qdict_get_try_int (qdict,"cpu_index" ,-1 ); +Error *err =NULL ; + +qmp_cancel_vcpu_dirty_limit (!!(cpu_index !=-1 ), cpu_index, &err); +if (err) { +hmp_handle_error (mon, err); +return ; + } + +monitor_printf (mon,"[Please use 'info vcpu_dirty_limit' to query " +"dirty limit for virtual CPU]\n" ); +} + +void hmp_set_vcpu_dirty_limit (Monitor *mon,const QDict *qdict) +{ +int64_t dirty_rate =qdict_get_int (qdict,"dirty_rate" ); +int64_t cpu_index =qdict_get_try_int (qdict,"cpu_index" ,-1 ); +Error *err =NULL ; + +if (dirty_rate <0 ) { +error_setg (&err,"invalid dirty page limit %" PRId64, dirty_rate); + goto out; + } + +qmp_set_vcpu_dirty_limit (!!(cpu_index !=-1 ), cpu_index, dirty_rate, &err); + +out: +hmp_handle_error (mon, err); +} + +void hmp_info_vcpu_dirty_limit (Monitor *mon,const QDict *qdict) +{ +DirtyLimitInfoList *info; +g_autoptr (DirtyLimitInfoList) head =NULL ; +Error *err =NULL ; + +if (!dirtylimit_in_service ()) { +monitor_printf (mon,"Dirty page limit not enabled!\n" ); +return ; + } + + head =qmp_query_vcpu_dirty_limit (&err); +if (err) { +hmp_handle_error (mon, err); +return ; + } + +for (info = head; info !=NULL ; info = info->next) { +monitor_printf (mon,"vcpu[%" PRIi64"], limit rate %" PRIi64" (MB/s)," +" current rate %" PRIi64" (MB/s)\n" , + info->value->cpu_index, + info->value->limit_rate, + info->value->current_rate); + } +}
system/dirtylimit.c +0 -60
81 lines not on this page · raw message
system/meson.build +1 -0
@@ -9,6 +9,7 @@ system_ss.add(files( 'cpus.c', 'cpu-timers.c', 'dirtylimit.c', + 'dirtylimit-hmp-cmds.c', 'dma-helpers.c', 'exit-with-parent.c', 'globals.c',
Signature · 1 line
2.53.0