@samitouri / QOSamiQemu / commits / c339d8459e

system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Hyman Huang <yong.huang@bitdeer.com> Message-Id: <20260812211708.92824-14-philmd@oss.qualcomm.com>

Philippe Mathieu-Daudé committed Aug 12, 2026 at 10:39 UTC c339d8459e9dce4d1ccd1e8f636138c348d00f37
4 files changed +76 -60
MAINTAINERS
+1
@@ -3875,6 +3875,7 @@ Migration dirty limit and dirty page rate
3875 M: Hyman Huang <infra.ai.cloud@bitdeer.com>
3876 S: Maintained
3877 F: system/dirtylimit.c
3878 +F: system/dirtylimit-hmp-cmds.c
3879 F: include/system/dirtylimit.h
3880 F: migration/dirtyrate.c
3881 F: migration/dirtyrate.h
system/dirtylimit-hmp-cmds.c new
+74
@@ -0,0 +1,74 @@
1 +/*
2 + * HMP commands related to migration dirty page rate limit
3 + *
4 + * Copyright (c) 2022 CHINA TELECOM CO.,LTD.
5 + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
6 + *
7 + * SPDX-License-Identifier: GPL-2.0-or-later
8 + */
9 +
10 +#include "qemu/osdep.h"
11 +#include "qapi/error.h"
12 +#include "qapi/qapi-commands-migration.h"
13 +#include "qobject/qdict.h"
14 +#include "monitor/hmp.h"
15 +#include "monitor/monitor.h"
16 +#include "system/dirtylimit.h"
17 +
18 +void hmp_cancel_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
19 +{
20 + int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
21 + Error *err = NULL;
22 +
23 + qmp_cancel_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, &err);
24 + if (err) {
25 + hmp_handle_error(mon, err);
26 + return;
27 + }
28 +
29 + monitor_printf(mon, "[Please use 'info vcpu_dirty_limit' to query "
30 + "dirty limit for virtual CPU]\n");
31 +}
32 +
33 +void hmp_set_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
34 +{
35 + int64_t dirty_rate = qdict_get_int(qdict, "dirty_rate");
36 + int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
37 + Error *err = NULL;
38 +
39 + if (dirty_rate < 0) {
40 + error_setg(&err, "invalid dirty page limit %" PRId64, dirty_rate);
41 + goto out;
42 + }
43 +
44 + qmp_set_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, dirty_rate, &err);
45 +
46 +out:
47 + hmp_handle_error(mon, err);
48 +}
49 +
50 +void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
51 +{
52 + DirtyLimitInfoList *info;
53 + g_autoptr(DirtyLimitInfoList) head = NULL;
54 + Error *err = NULL;
55 +
56 + if (!dirtylimit_in_service()) {
57 + monitor_printf(mon, "Dirty page limit not enabled!\n");
58 + return;
59 + }
60 +
61 + head = qmp_query_vcpu_dirty_limit(&err);
62 + if (err) {
63 + hmp_handle_error(mon, err);
64 + return;
65 + }
66 +
67 + for (info = head; info != NULL; info = info->next) {
68 + monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s),"
69 + " current rate %"PRIi64 " (MB/s)\n",
70 + info->value->cpu_index,
71 + info->value->limit_rate,
72 + info->value->current_rate);
73 + }
74 +}
system/dirtylimit.c
-60
@@ -17,8 +17,6 @@
17 #include "qapi/error.h"
18 #include "system/dirtyrate.h"
19 #include "system/dirtylimit.h"
20 -#include "monitor/hmp.h"
21 -#include "monitor/monitor.h"
20 #include "system/memory.h"
21 #include "exec/target_page.h"
22 #include "hw/core/boards.h"
@@ -491,21 +489,6 @@ void qmp_cancel_vcpu_dirty_limit(bool has_cpu_index,
489 dirtylimit_state_unlock();
490 }
491
494 -void hmp_cancel_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
495 -{
496 - int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
497 - Error *err = NULL;
498 -
499 - qmp_cancel_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, &err);
500 - if (err) {
501 - hmp_handle_error(mon, err);
502 - return;
503 - }
504 -
505 - monitor_printf(mon, "[Please use 'info vcpu_dirty_limit' to query "
506 - "dirty limit for virtual CPU]\n");
507 -}
508 -
492 void qmp_set_vcpu_dirty_limit(bool has_cpu_index,
493 int64_t cpu_index,
494 uint64_t dirty_rate,
@@ -548,23 +531,6 @@ void qmp_set_vcpu_dirty_limit(bool has_cpu_index,
531 dirtylimit_state_unlock();
532 }
533
551 -void hmp_set_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
552 -{
553 - int64_t dirty_rate = qdict_get_int(qdict, "dirty_rate");
554 - int64_t cpu_index = qdict_get_try_int(qdict, "cpu_index", -1);
555 - Error *err = NULL;
556 -
557 - if (dirty_rate < 0) {
558 - error_setg(&err, "invalid dirty page limit %" PRId64, dirty_rate);
559 - goto out;
560 - }
561 -
562 - qmp_set_vcpu_dirty_limit(!!(cpu_index != -1), cpu_index, dirty_rate, &err);
563 -
564 -out:
565 - hmp_handle_error(mon, err);
566 -}
567 -
534 /* Return the max throttle time of each virtual CPU */
535 uint64_t dirtylimit_throttle_time_per_round(void)
536 {
@@ -646,29 +612,3 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp)
612 {
613 return dirtylimit_query_all();
614 }
649 -
650 -void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict)
651 -{
652 - DirtyLimitInfoList *info;
653 - g_autoptr(DirtyLimitInfoList) head = NULL;
654 - Error *err = NULL;
655 -
656 - if (!dirtylimit_in_service()) {
657 - monitor_printf(mon, "Dirty page limit not enabled!\n");
658 - return;
659 - }
660 -
661 - head = qmp_query_vcpu_dirty_limit(&err);
662 - if (err) {
663 - hmp_handle_error(mon, err);
664 - return;
665 - }
666 -
667 - for (info = head; info != NULL; info = info->next) {
668 - monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s),"
669 - " current rate %"PRIi64 " (MB/s)\n",
670 - info->value->cpu_index,
671 - info->value->limit_rate,
672 - info->value->current_rate);
673 - }
674 -}
system/meson.build
+1
@@ -9,6 +9,7 @@ system_ss.add(files(
9 'cpus.c',
10 'cpu-timers.c',
11 'dirtylimit.c',
12 + 'dirtylimit-hmp-cmds.c',
13 'dma-helpers.c',
14 'exit-with-parent.c',
15 'globals.c',