Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be called
Signed-off-by: Chuan Zheng <zhengchuan@huawei.com>
---
migration/dirtyrate.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
qapi/migration.json | 42 ++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index 041d0c6..0e8c9c5 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -67,6 +67,39 @@ static int dirty_rate_set_state(int new_state)
return 0;
}
+static struct DirtyRateInfo *query_dirty_rate_info(void)
+{
+ int64_t dirty_rate = dirty_stat.dirty_rate;
+ struct DirtyRateInfo *info = g_malloc0(sizeof(DirtyRateInfo));
+
+ switch (CalculatingState) {
+ case CAL_DIRTY_RATE_INIT:
+ info->dirty_rate = -1;
+ info->status = g_strdup("Not start measuring");
+ break;
+ case CAL_DIRTY_RATE_ACTIVE:
+ info->dirty_rate = -1;
+ info->status = g_strdup("Still measuring");
+ break;
+ case CAL_DIRTY_RATE_END:
+ info->dirty_rate = dirty_rate;
+ info->status = g_strdup("Measured");
+ break;
+ default:
+ info->dirty_rate = -1;
+ info->status = g_strdup("Unknown status");
+ break;
+ }
+
+ /*
+ * Only support query once for each calculation,
+ * reset as CAL_DIRTY_RATE_INIT after query
+ */
+ (void)dirty_rate_set_state(CAL_DIRTY_RATE_INIT);
+
+ return info;
+}
+
static void reset_dirtyrate_stat(void)
{
dirty_stat.total_dirty_samples = 0;
@@ -403,3 +436,26 @@ void *get_dirtyrate_thread(void *arg)
return NULL;
}
+
+void qmp_calc_dirty_rate(int64_t calc_time, Error **errp)
+{
+ static struct DirtyRateConfig config;
+ QemuThread thread;
+
+ /*
+ * We don't begin calculating thread only when it's in calculating status.
+ */
+ if (CalculatingState == CAL_DIRTY_RATE_ACTIVE) {
+ return;
+ }
+
+ config.sample_period_seconds = get_sample_page_period(calc_time);
+ config.sample_pages_per_gigabytes = DIRTYRATE_DEFAULT_SAMPLE_PAGES;
+ qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread,
+ (void *)&config, QEMU_THREAD_DETACHED);
+}
+
+struct DirtyRateInfo *qmp_query_dirty_rate(Error **errp)
+{
+ return query_dirty_rate_info();
+}
diff --git a/qapi/migration.json b/qapi/migration.json
index d500055..ccc7a4e 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -1621,3 +1621,45 @@
##
{ 'event': 'UNPLUG_PRIMARY',
'data': { 'device-id': 'str' } }
+
+##
+# @DirtyRateInfo:
+#
+# Information about current dirty page rate of vm.
+#
+# @dirty-rate: @dirtyrate describing the dirty page rate of vm
+# in units of MB/s.
+# If this field return '-1', it means querying is not
+# start or not complete.
+#
+# @status: @status containing dirtyrate query status includes
+# status with 'not start measuring' or
+# 'Still measuring' or 'measured'(since 5.2)
+##
+{ 'struct': 'DirtyRateInfo',
+ 'data': {'dirty-rate': 'int64',
+ 'status': 'str'} }
+
+##
+# @calc-dirty-rate:
+#
+# start calculating dirty page rate for vm
+#
+# @calc-time: time in units of second for sample dirty pages
+#
+# Since: 5.2
+#
+# Example:
+# {"command": "cal-dirty-rate", "data": {"calc-time": 1} }
+#
+##
+{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} }
+
+##
+# @query-dirty-rate:
+#
+# query dirty page rate in units of MB/s for vm
+#
+# Since: 5.2
+##
+{ 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
--
1.8.3.1
On 8/16/20 10:20 PM, Chuan Zheng wrote:
> Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be called
>
> Signed-off-by: Chuan Zheng <zhengchuan@huawei.com>
> ---
> +++ b/qapi/migration.json
> @@ -1621,3 +1621,45 @@
> ##
> { 'event': 'UNPLUG_PRIMARY',
> 'data': { 'device-id': 'str' } }
> +
> +##
> +# @DirtyRateInfo:
> +#
> +# Information about current dirty page rate of vm.
> +#
> +# @dirty-rate: @dirtyrate describing the dirty page rate of vm
> +# in units of MB/s.
> +# If this field return '-1', it means querying is not
> +# start or not complete.
> +#
> +# @status: @status containing dirtyrate query status includes
> +# status with 'not start measuring' or
> +# 'Still measuring' or 'measured'(since 5.2)
Missing space before (
> +##
> +{ 'struct': 'DirtyRateInfo',
> + 'data': {'dirty-rate': 'int64',
> + 'status': 'str'} }
Based on your description, this should be an enum type rather than an
open-coded string. Something like:
{ 'enum': 'DirtyRateStatus', 'data': [ 'unstarted', 'measuring',
'measured' ] }
{ 'struct': 'DirtyRateInfo', 'data': { 'dirty-rate': 'int64', 'status':
'DirtyRateStatus' } }
> +
> +##
> +# @calc-dirty-rate:
> +#
> +# start calculating dirty page rate for vm
> +#
> +# @calc-time: time in units of second for sample dirty pages
> +#
> +# Since: 5.2
> +#
> +# Example:
> +# {"command": "cal-dirty-rate", "data": {"calc-time": 1} }
> +#
> +##
> +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} }
> +
> +##
> +# @query-dirty-rate:
> +#
> +# query dirty page rate in units of MB/s for vm
> +#
> +# Since: 5.2
> +##
> +{ 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
* Eric Blake (eblake@redhat.com) wrote:
> On 8/16/20 10:20 PM, Chuan Zheng wrote:
> > Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be called
> >
> > Signed-off-by: Chuan Zheng <zhengchuan@huawei.com>
> > ---
>
> > +++ b/qapi/migration.json
> > @@ -1621,3 +1621,45 @@
> > ##
> > { 'event': 'UNPLUG_PRIMARY',
> > 'data': { 'device-id': 'str' } }
> > +
> > +##
> > +# @DirtyRateInfo:
> > +#
> > +# Information about current dirty page rate of vm.
> > +#
> > +# @dirty-rate: @dirtyrate describing the dirty page rate of vm
> > +# in units of MB/s.
> > +# If this field return '-1', it means querying is not
> > +# start or not complete.
> > +#
> > +# @status: @status containing dirtyrate query status includes
> > +# status with 'not start measuring' or
> > +# 'Still measuring' or 'measured'(since 5.2)
>
> Missing space before (
>
> > +##
> > +{ 'struct': 'DirtyRateInfo',
> > + 'data': {'dirty-rate': 'int64',
> > + 'status': 'str'} }
>
> Based on your description, this should be an enum type rather than an
> open-coded string. Something like:
>
> { 'enum': 'DirtyRateStatus', 'data': [ 'unstarted', 'measuring', 'measured'
> ] }
> { 'struct': 'DirtyRateInfo', 'data': { 'dirty-rate': 'int64', 'status':
> 'DirtyRateStatus' } }
Yes, and if you do that I think you'll find qmp would automatically
define a C enum type for you, so you don't need to define the
CalculatingDirtyRateStage yourself; see how MigrationStatus works.
Dave
>
> > +
> > +##
> > +# @calc-dirty-rate:
> > +#
> > +# start calculating dirty page rate for vm
> > +#
> > +# @calc-time: time in units of second for sample dirty pages
> > +#
> > +# Since: 5.2
> > +#
> > +# Example:
> > +# {"command": "cal-dirty-rate", "data": {"calc-time": 1} }
> > +#
> > +##
> > +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} }
> > +
> > +##
> > +# @query-dirty-rate:
> > +#
> > +# query dirty page rate in units of MB/s for vm
> > +#
> > +# Since: 5.2
> > +##
> > +{ 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
> >
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3226
> Virtualization: qemu.org | libvirt.org
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
On 2020/8/21 2:00, Dr. David Alan Gilbert wrote:
> * Eric Blake (eblake@redhat.com) wrote:
>> On 8/16/20 10:20 PM, Chuan Zheng wrote:
>>> Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be called
>>>
>>> Signed-off-by: Chuan Zheng <zhengchuan@huawei.com>
>>> ---
>>
>>> +++ b/qapi/migration.json
>>> @@ -1621,3 +1621,45 @@
>>> ##
>>> { 'event': 'UNPLUG_PRIMARY',
>>> 'data': { 'device-id': 'str' } }
>>> +
>>> +##
>>> +# @DirtyRateInfo:
>>> +#
>>> +# Information about current dirty page rate of vm.
>>> +#
>>> +# @dirty-rate: @dirtyrate describing the dirty page rate of vm
>>> +# in units of MB/s.
>>> +# If this field return '-1', it means querying is not
>>> +# start or not complete.
>>> +#
>>> +# @status: @status containing dirtyrate query status includes
>>> +# status with 'not start measuring' or
>>> +# 'Still measuring' or 'measured'(since 5.2)
>>
>> Missing space before (
>>
>>> +##
>>> +{ 'struct': 'DirtyRateInfo',
>>> + 'data': {'dirty-rate': 'int64',
>>> + 'status': 'str'} }
>>
>> Based on your description, this should be an enum type rather than an
>> open-coded string. Something like:
>>
>> { 'enum': 'DirtyRateStatus', 'data': [ 'unstarted', 'measuring', 'measured'
>> ] }
>> { 'struct': 'DirtyRateInfo', 'data': { 'dirty-rate': 'int64', 'status':
>> 'DirtyRateStatus' } }
>
> Yes, and if you do that I think you'll find qmp would automatically
> define a C enum type for you, so you don't need to define the
> CalculatingDirtyRateStage yourself; see how MigrationStatus works.
>
> Dave
>
Sure, it could be better,will fix it in V4:)
>
>>
>>> +
>>> +##
>>> +# @calc-dirty-rate:
>>> +#
>>> +# start calculating dirty page rate for vm
>>> +#
>>> +# @calc-time: time in units of second for sample dirty pages
>>> +#
>>> +# Since: 5.2
>>> +#
>>> +# Example:
>>> +# {"command": "cal-dirty-rate", "data": {"calc-time": 1} }
>>> +#
>>> +##
>>> +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} }
>>> +
>>> +##
>>> +# @query-dirty-rate:
>>> +#
>>> +# query dirty page rate in units of MB/s for vm
>>> +#
>>> +# Since: 5.2
>>> +##
>>> +{ 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
>>>
>>
>> --
>> Eric Blake, Principal Software Engineer
>> Red Hat, Inc. +1-919-301-3226
>> Virtualization: qemu.org | libvirt.org
© 2016 - 2026 Red Hat, Inc.