[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 4/7] migration/dirtyrate: add per-vcpu option for calc-dirty-r
From: |
huangy81 |
Subject: |
[PATCH v3 4/7] migration/dirtyrate: add per-vcpu option for calc-dirty-rate |
Date: |
Mon, 7 Jun 2021 09:12:36 +0800 |
From: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
calculate dirtyrate for each vcpu if vcpu is true, add the
dirtyrate of each vcpu to the return value also.
Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
---
migration/dirtyrate.c | 45 ++++++++++++++++++++++++++++++++++++++-----
migration/dirtyrate.h | 1 +
qapi/migration.json | 29 ++++++++++++++++++++++++++--
3 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index 320c56ba2c..5947c688f6 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -397,8 +397,11 @@ void *get_dirtyrate_thread(void *arg)
return NULL;
}
-void qmp_calc_dirty_rate(int64_t calc_time, bool has_sample_pages,
- int64_t sample_pages, Error **errp)
+void qmp_calc_dirty_rate(int64_t calc_time,
+ bool per_vcpu,
+ bool has_sample_pages,
+ int64_t sample_pages,
+ Error **errp)
{
static struct DirtyRateConfig config;
QemuThread thread;
@@ -419,6 +422,12 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool
has_sample_pages,
return;
}
+ if (has_sample_pages && per_vcpu) {
+ error_setg(errp, "per-vcpu and sample-pages are mutually exclusive, "
+ "only one of then can be specified!\n");
+ return;
+ }
+
if (has_sample_pages) {
if (!is_sample_pages_valid(sample_pages)) {
error_setg(errp, "sample-pages is out of range[%d, %d].",
@@ -430,6 +439,15 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool
has_sample_pages,
sample_pages = DIRTYRATE_DEFAULT_SAMPLE_PAGES;
}
+ /*
+ * Vcpu method only works when kvm dirty ring is enabled.
+ */
+ if (per_vcpu && !kvm_dirty_ring_enabled()) {
+ error_setg(errp, "dirty ring is disabled or conflict with migration"
+ "use sample method or remeasure later.");
+ return;
+ }
+
/*
* Init calculation state as unstarted.
*/
@@ -442,6 +460,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool
has_sample_pages,
config.sample_period_seconds = calc_time;
config.sample_pages_per_gigabytes = sample_pages;
+ config.per_vcpu = per_vcpu;
qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread,
(void *)&config, QEMU_THREAD_DETACHED);
}
@@ -459,13 +478,22 @@ void hmp_info_dirty_rate(Monitor *mon, const QDict *qdict)
DirtyRateStatus_str(info->status));
monitor_printf(mon, "Start Time: %"PRIi64" (ms)\n",
info->start_time);
- monitor_printf(mon, "Sample Pages: %"PRIu64" (per GB)\n",
- info->sample_pages);
monitor_printf(mon, "Period: %"PRIi64" (sec)\n",
info->calc_time);
+ if (info->has_sample_pages) {
+ monitor_printf(mon, "Sample Pages: %"PRIu64" (per GB)\n",
+ info->sample_pages);
+ }
monitor_printf(mon, "Dirty rate: ");
if (info->has_dirty_rate) {
monitor_printf(mon, "%"PRIi64" (MB/s)\n", info->dirty_rate);
+ if (info->per_vcpu && info->has_vcpu_dirty_rate) {
+ DirtyRateVcpuList *rate, *head = info->vcpu_dirty_rate;
+ for (rate = head; rate != NULL; rate = rate->next) {
+ monitor_printf(mon, "vcpu[%"PRIi64"], Dirty rate: %"PRIi64"\n",
+ rate->value->id, rate->value->dirty_rate);
+ }
+ }
} else {
monitor_printf(mon, "(not ready)\n");
}
@@ -477,6 +505,7 @@ void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdict)
int64_t sec = qdict_get_try_int(qdict, "second", 0);
int64_t sample_pages = qdict_get_try_int(qdict, "sample_pages_per_GB", -1);
bool has_sample_pages = (sample_pages != -1);
+ bool per_vcpu = qdict_get_try_bool(qdict, "per_vcpu", false);
Error *err = NULL;
if (!sec) {
@@ -484,7 +513,13 @@ void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdict)
return;
}
- qmp_calc_dirty_rate(sec, has_sample_pages, sample_pages, &err);
+ if (has_sample_pages && per_vcpu) {
+ monitor_printf(mon, "per_vcpu and sample_pages are mutually exclusive,
"
+ "only one of then can be specified!\n");
+ return;
+ }
+
+ qmp_calc_dirty_rate(sec, per_vcpu, has_sample_pages, sample_pages, &err);
if (err) {
hmp_handle_error(mon, err);
return;
diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h
index e1fd29089e..ec82716b40 100644
--- a/migration/dirtyrate.h
+++ b/migration/dirtyrate.h
@@ -43,6 +43,7 @@
struct DirtyRateConfig {
uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
int64_t sample_period_seconds; /* time duration between two sampling */
+ bool per_vcpu; /* calculate dirtyrate for each vcpu using dirty ring */
};
/*
diff --git a/qapi/migration.json b/qapi/migration.json
index 770ae54c17..7eef988182 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -1708,6 +1708,21 @@
{ 'event': 'UNPLUG_PRIMARY',
'data': { 'device-id': 'str' } }
+##
+# @DirtyRateVcpu:
+#
+# Dirty rate of vcpu.
+#
+# @id: vcpu index.
+#
+# @dirty-rate: dirty rate.
+#
+# Since: 6.1
+#
+##
+{ 'struct': 'DirtyRateVcpu',
+ 'data': { 'id': 'int', 'dirty-rate': 'int64' } }
+
##
# @DirtyRateStatus:
#
@@ -1743,6 +1758,10 @@
# @sample-pages: page count per GB for sample dirty pages
# the default value is 512 (since 6.1)
#
+# @per-vcpu: calculate dirtyrate for each vcpu (Since 6.1)
+#
+# @vcpu-dirty-rate: dirtyrate for each vcpu (Since 6.1)
+#
# Since: 5.2
#
##
@@ -1751,7 +1770,9 @@
'status': 'DirtyRateStatus',
'start-time': 'int64',
'calc-time': 'int64',
- 'sample-pages': 'uint64'} }
+ '*sample-pages': 'uint64',
+ 'per-vcpu': 'bool',
+ '*vcpu-dirty-rate': [ 'DirtyRateVcpu' ] } }
##
# @calc-dirty-rate:
@@ -1760,6 +1781,10 @@
#
# @calc-time: time in units of second for sample dirty pages
#
+# @per-vcpu: calculate vcpu dirty rate if true, the default value is
+# false, note that the per-vcpu and sample-pages are mutually
+# exclusive (since 6.1)
+#
# @sample-pages: page count per GB for sample dirty pages
# the default value is 512 (since 6.1)
#
@@ -1769,7 +1794,7 @@
# {"command": "calc-dirty-rate", "data": {"calc-time": 1, 'sample-pages':
512} }
#
##
-{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64',
'*sample-pages': 'int'} }
+{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64', 'per-vcpu':
'bool', '*sample-pages': 'int'} }
##
# @query-dirty-rate:
--
2.18.2
[PATCH v3 1/7] migration/dirtyrate: make sample page count configurable, huangy81, 2021/06/06
[PATCH v3 2/7] hmp: Add "calc_dirty_rate" and "info dirty_rate" cmds, huangy81, 2021/06/06
[PATCH v3 5/7] migration/dirtyrate: adjust struct DirtyRateStat, huangy81, 2021/06/06