| 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(MonitorHMP *hmp, 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(hmp, err); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | monitor_hmp_printf(hmp, "[Please use 'info vcpu_dirty_limit' to query " |
| 30 | "dirty limit for virtual CPU]\n"); |
| 31 | } |
| 32 | |
| 33 | void hmp_set_vcpu_dirty_limit(MonitorHMP *hmp, 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(hmp, err); |
| 48 | } |
| 49 | |
| 50 | void hmp_info_vcpu_dirty_limit(MonitorHMP *hmp, 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_hmp_printf(hmp, "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(hmp, err); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | for (info = head; info != NULL; info = info->next) { |
| 68 | monitor_hmp_printf(hmp, "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 | } |