qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time
@ 2023-09-05  9:18 Andrei Gudkov via
  2023-09-05  9:39 ` Philippe Mathieu-Daudé
  2023-09-25  0:53 ` Yong Huang
  0 siblings, 2 replies; 5+ messages in thread
From: Andrei Gudkov via @ 2023-09-05  9:18 UTC (permalink / raw)
  To: qemu-devel
  Cc: yong.huang, quintela, peterx, leobras, eblake, armbru,
	Andrei Gudkov

Currently query-dirty-rate uses QEMU_CLOCK_REALTIME as
the source for start-time field. This translates to
clock_gettime(CLOCK_MONOTONIC), i.e. number of seconds
since host boot. This is not very useful. The only
reasonable use case of start-time I can imagine is to
check whether previously completed measurements are
too old or not. But this makes sense only if start-time
is reported as host wall-clock time.

This patch replaces source of start-time from
QEMU_CLOCK_REALTIME to QEMU_CLOCK_HOST.

Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com>
---
 qapi/migration.json   |  4 ++--
 migration/dirtyrate.c | 15 ++++++---------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/qapi/migration.json b/qapi/migration.json
index 8843e74b59..63deb8e387 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -1941,12 +1941,12 @@
 # 1. Measurement is in progress:
 #
 # <- {"status": "measuring", "sample-pages": 512,
-#     "mode": "page-sampling", "start-time": 3665220, "calc-time": 10}
+#     "mode": "page-sampling", "start-time": 1693900454, "calc-time": 10}
 #
 # 2. Measurement has been completed:
 #
 # <- {"status": "measured", "sample-pages": 512, "dirty-rate": 108,
-#     "mode": "page-sampling", "start-time": 3665220, "calc-time": 10}
+#     "mode": "page-sampling", "start-time": 1693900454, "calc-time": 10}
 ##
 { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
 
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index bccb3515e3..0510d68765 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -259,11 +259,10 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
     return info;
 }
 
-static void init_dirtyrate_stat(int64_t start_time,
-                                struct DirtyRateConfig config)
+static void init_dirtyrate_stat(struct DirtyRateConfig config)
 {
     DirtyStat.dirty_rate = -1;
-    DirtyStat.start_time = start_time;
+    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
     DirtyStat.calc_time = config.sample_period_seconds;
     DirtyStat.sample_pages = config.sample_pages_per_gigabytes;
 
@@ -600,7 +599,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
     record_dirtypages_bitmap(&dirty_pages, true);
 
     start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
-    DirtyStat.start_time = start_time / 1000;
+    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
 
     msec = config.sample_period_seconds * 1000;
     msec = dirty_stat_wait(msec, start_time);
@@ -628,7 +627,7 @@ static void calculate_dirtyrate_dirty_ring(struct DirtyRateConfig config)
     /* start log sync */
     global_dirty_log_change(GLOBAL_DIRTY_DIRTY_RATE, true);
 
-    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
+    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
 
     /* calculate vcpu dirtyrate */
     duration = vcpu_calculate_dirtyrate(config.sample_period_seconds * 1000,
@@ -657,6 +656,7 @@ static void calculate_dirtyrate_sample_vm(struct DirtyRateConfig config)
 
     rcu_read_lock();
     initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
     if (!record_ramblock_hash_info(&block_dinfo, config, &block_count)) {
         goto out;
     }
@@ -664,7 +664,6 @@ static void calculate_dirtyrate_sample_vm(struct DirtyRateConfig config)
 
     msec = config.sample_period_seconds * 1000;
     msec = dirty_stat_wait(msec, initial_time);
-    DirtyStat.start_time = initial_time / 1000;
     DirtyStat.calc_time = msec / 1000;
 
     rcu_read_lock();
@@ -727,7 +726,6 @@ void qmp_calc_dirty_rate(int64_t calc_time,
     static struct DirtyRateConfig config;
     QemuThread thread;
     int ret;
-    int64_t start_time;
 
     /*
      * If the dirty rate is already being measured, don't attempt to start.
@@ -799,8 +797,7 @@ void qmp_calc_dirty_rate(int64_t calc_time,
      **/
     dirtyrate_mode = mode;
 
-    start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
-    init_dirtyrate_stat(start_time, config);
+    init_dirtyrate_stat(config);
 
     qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread,
                        (void *)&config, QEMU_THREAD_DETACHED);
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time
  2023-09-05  9:18 [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time Andrei Gudkov via
@ 2023-09-05  9:39 ` Philippe Mathieu-Daudé
  2023-09-19  9:14   ` Markus Armbruster
  2023-09-25  0:53 ` Yong Huang
  1 sibling, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-05  9:39 UTC (permalink / raw)
  To: Andrei Gudkov, qemu-devel
  Cc: yong.huang, quintela, peterx, leobras, eblake, armbru

Hi Andrei,

On 5/9/23 11:18, Andrei Gudkov via wrote:
> Currently query-dirty-rate uses QEMU_CLOCK_REALTIME as
> the source for start-time field. This translates to
> clock_gettime(CLOCK_MONOTONIC), i.e. number of seconds
> since host boot. This is not very useful. The only
> reasonable use case of start-time I can imagine is to
> check whether previously completed measurements are
> too old or not. But this makes sense only if start-time
> is reported as host wall-clock time.
> 
> This patch replaces source of start-time from
> QEMU_CLOCK_REALTIME to QEMU_CLOCK_HOST.
> 
> Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com>
> ---
>   qapi/migration.json   |  4 ++--
>   migration/dirtyrate.c | 15 ++++++---------
>   2 files changed, 8 insertions(+), 11 deletions(-)


> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index bccb3515e3..0510d68765 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -259,11 +259,10 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
>       return info;
>   }
>   
> -static void init_dirtyrate_stat(int64_t start_time,
> -                                struct DirtyRateConfig config)
> +static void init_dirtyrate_stat(struct DirtyRateConfig config)
>   {
>       DirtyStat.dirty_rate = -1;
> -    DirtyStat.start_time = start_time;
> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>       DirtyStat.calc_time = config.sample_period_seconds;
>       DirtyStat.sample_pages = config.sample_pages_per_gigabytes;
>   
> @@ -600,7 +599,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
>       record_dirtypages_bitmap(&dirty_pages, true);
>   
>       start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> -    DirtyStat.start_time = start_time / 1000;
> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;

You can directly use qemu_clock_get_us().



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time
  2023-09-05  9:39 ` Philippe Mathieu-Daudé
@ 2023-09-19  9:14   ` Markus Armbruster
  2023-09-19  9:44     ` gudkov.andrei--- via
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2023-09-19  9:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Andrei Gudkov, qemu-devel, yong.huang, quintela, peterx, leobras,
	eblake

Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Hi Andrei,
>
> On 5/9/23 11:18, Andrei Gudkov via wrote:
>> Currently query-dirty-rate uses QEMU_CLOCK_REALTIME as
>> the source for start-time field. This translates to
>> clock_gettime(CLOCK_MONOTONIC), i.e. number of seconds
>> since host boot. This is not very useful. The only
>> reasonable use case of start-time I can imagine is to
>> check whether previously completed measurements are
>> too old or not. But this makes sense only if start-time
>> is reported as host wall-clock time.
>> This patch replaces source of start-time from
>> QEMU_CLOCK_REALTIME to QEMU_CLOCK_HOST.
>> Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com>
>> ---
>>   qapi/migration.json   |  4 ++--
>>   migration/dirtyrate.c | 15 ++++++---------
>>   2 files changed, 8 insertions(+), 11 deletions(-)
>
>
>> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
>> index bccb3515e3..0510d68765 100644
>> --- a/migration/dirtyrate.c
>> +++ b/migration/dirtyrate.c
>> @@ -259,11 +259,10 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
>>       return info;
>>   }
>>   -static void init_dirtyrate_stat(int64_t start_time,
>> -                                struct DirtyRateConfig config)
>> +static void init_dirtyrate_stat(struct DirtyRateConfig config)
>>   {
>>       DirtyStat.dirty_rate = -1;
>> -    DirtyStat.start_time = start_time;
>> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>>       DirtyStat.calc_time = config.sample_period_seconds;
>>       DirtyStat.sample_pages = config.sample_pages_per_gigabytes;
>>   @@ -600,7 +599,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
>>       record_dirtypages_bitmap(&dirty_pages, true);
>>         start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
>> -    DirtyStat.start_time = start_time / 1000;
>> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>
> You can directly use qemu_clock_get_us().

Andrei, care to respin?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time
  2023-09-19  9:14   ` Markus Armbruster
@ 2023-09-19  9:44     ` gudkov.andrei--- via
  0 siblings, 0 replies; 5+ messages in thread
From: gudkov.andrei--- via @ 2023-09-19  9:44 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé, qemu-devel, yong.huang, quintela,
	peterx, leobras, eblake

On Tue, Sep 19, 2023 at 11:14:52AM +0200, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
> > Hi Andrei,
> >
> > On 5/9/23 11:18, Andrei Gudkov via wrote:
> >> Currently query-dirty-rate uses QEMU_CLOCK_REALTIME as
> >> the source for start-time field. This translates to
> >> clock_gettime(CLOCK_MONOTONIC), i.e. number of seconds
> >> since host boot. This is not very useful. The only
> >> reasonable use case of start-time I can imagine is to
> >> check whether previously completed measurements are
> >> too old or not. But this makes sense only if start-time
> >> is reported as host wall-clock time.
> >> This patch replaces source of start-time from
> >> QEMU_CLOCK_REALTIME to QEMU_CLOCK_HOST.
> >> Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com>
> >> ---
> >>   qapi/migration.json   |  4 ++--
> >>   migration/dirtyrate.c | 15 ++++++---------
> >>   2 files changed, 8 insertions(+), 11 deletions(-)
> >
> >
> >> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> >> index bccb3515e3..0510d68765 100644
> >> --- a/migration/dirtyrate.c
> >> +++ b/migration/dirtyrate.c
> >> @@ -259,11 +259,10 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
> >>       return info;
> >>   }
> >>   -static void init_dirtyrate_stat(int64_t start_time,
> >> -                                struct DirtyRateConfig config)
> >> +static void init_dirtyrate_stat(struct DirtyRateConfig config)
> >>   {
> >>       DirtyStat.dirty_rate = -1;
> >> -    DirtyStat.start_time = start_time;
> >> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
> >>       DirtyStat.calc_time = config.sample_period_seconds;
> >>       DirtyStat.sample_pages = config.sample_pages_per_gigabytes;
> >>   @@ -600,7 +599,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
> >>       record_dirtypages_bitmap(&dirty_pages, true);
> >>         start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >> -    DirtyStat.start_time = start_time / 1000;
> >> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
> >
> > You can directly use qemu_clock_get_us().
> 
> Andrei, care to respin?

But why? Here we need seconds, not microseconds. If there were a function
called qemu_clock_get_seconds(QEMUClockType) then we could use it here directly.
But there is no such function.

If you wish, we can do one of the following:
1) introduce qemu_clock_get_seconds(QEMUClockType) and use it directly
   without scaling
2) change the unit of DirtyStat.start_time from seconds to milliseconds
   and use qemu_clock_get_ms(QEMUClockType) directly without scaling



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time
  2023-09-05  9:18 [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time Andrei Gudkov via
  2023-09-05  9:39 ` Philippe Mathieu-Daudé
@ 2023-09-25  0:53 ` Yong Huang
  1 sibling, 0 replies; 5+ messages in thread
From: Yong Huang @ 2023-09-25  0:53 UTC (permalink / raw)
  To: Andrei Gudkov; +Cc: qemu-devel, quintela, peterx, leobras, eblake, armbru

[-- Attachment #1: Type: text/plain, Size: 4784 bytes --]

On Tue, Sep 5, 2023 at 5:19 PM Andrei Gudkov <gudkov.andrei@huawei.com>
wrote:

> Currently query-dirty-rate uses QEMU_CLOCK_REALTIME as
> the source for start-time field. This translates to
> clock_gettime(CLOCK_MONOTONIC), i.e. number of seconds
> since host boot. This is not very useful. The only
> reasonable use case of start-time I can imagine is to
> check whether previously completed measurements are
> too old or not. But this makes sense only if start-time
> is reported as host wall-clock time.
>
> This patch replaces source of start-time from
> QEMU_CLOCK_REALTIME to QEMU_CLOCK_HOST.
>
> Signed-off-by: Andrei Gudkov <gudkov.andrei@huawei.com>
> ---
>  qapi/migration.json   |  4 ++--
>  migration/dirtyrate.c | 15 ++++++---------
>  2 files changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/qapi/migration.json b/qapi/migration.json
> index 8843e74b59..63deb8e387 100644
> --- a/qapi/migration.json
> +++ b/qapi/migration.json
> @@ -1941,12 +1941,12 @@
>  # 1. Measurement is in progress:
>  #
>  # <- {"status": "measuring", "sample-pages": 512,
> -#     "mode": "page-sampling", "start-time": 3665220, "calc-time": 10}
> +#     "mode": "page-sampling", "start-time": 1693900454, "calc-time": 10}
>  #
>  # 2. Measurement has been completed:
>  #
>  # <- {"status": "measured", "sample-pages": 512, "dirty-rate": 108,
> -#     "mode": "page-sampling", "start-time": 3665220, "calc-time": 10}
> +#     "mode": "page-sampling", "start-time": 1693900454, "calc-time": 10}
>  ##
>  { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' }
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index bccb3515e3..0510d68765 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -259,11 +259,10 @@ static struct DirtyRateInfo
> *query_dirty_rate_info(void)
>      return info;
>  }
>
> -static void init_dirtyrate_stat(int64_t start_time,
> -                                struct DirtyRateConfig config)
> +static void init_dirtyrate_stat(struct DirtyRateConfig config)
>  {
>      DirtyStat.dirty_rate = -1;
> -    DirtyStat.start_time = start_time;
> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>      DirtyStat.calc_time = config.sample_period_seconds;
>      DirtyStat.sample_pages = config.sample_pages_per_gigabytes;
>
> @@ -600,7 +599,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct
> DirtyRateConfig config)
>      record_dirtypages_bitmap(&dirty_pages, true);
>
>      start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> -    DirtyStat.start_time = start_time / 1000;
> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>
>      msec = config.sample_period_seconds * 1000;
>      msec = dirty_stat_wait(msec, start_time);
> @@ -628,7 +627,7 @@ static void calculate_dirtyrate_dirty_ring(struct
> DirtyRateConfig config)
>      /* start log sync */
>      global_dirty_log_change(GLOBAL_DIRTY_DIRTY_RATE, true);
>
> -    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>
>      /* calculate vcpu dirtyrate */
>      duration = vcpu_calculate_dirtyrate(config.sample_period_seconds *
> 1000,
> @@ -657,6 +656,7 @@ static void calculate_dirtyrate_sample_vm(struct
> DirtyRateConfig config)
>
>      rcu_read_lock();
>      initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> +    DirtyStat.start_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
>      if (!record_ramblock_hash_info(&block_dinfo, config, &block_count)) {
>          goto out;
>      }
> @@ -664,7 +664,6 @@ static void calculate_dirtyrate_sample_vm(struct
> DirtyRateConfig config)
>
>      msec = config.sample_period_seconds * 1000;
>      msec = dirty_stat_wait(msec, initial_time);
> -    DirtyStat.start_time = initial_time / 1000;
>      DirtyStat.calc_time = msec / 1000;
>
>      rcu_read_lock();
> @@ -727,7 +726,6 @@ void qmp_calc_dirty_rate(int64_t calc_time,
>      static struct DirtyRateConfig config;
>      QemuThread thread;
>      int ret;
> -    int64_t start_time;
>
>      /*
>       * If the dirty rate is already being measured, don't attempt to
> start.
> @@ -799,8 +797,7 @@ void qmp_calc_dirty_rate(int64_t calc_time,
>       **/
>      dirtyrate_mode = mode;
>
> -    start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
> -    init_dirtyrate_stat(start_time, config);
> +    init_dirtyrate_stat(config);
>
>      qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread,
>                         (void *)&config, QEMU_THREAD_DETACHED);
> --
> 2.30.2
>
>

Reviewed-by: Hyman Huang <yong.huang@smartx.com>

-- 
Best regards

[-- Attachment #2: Type: text/html, Size: 6521 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-25  0:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-05  9:18 [PATCH] migration/dirtyrate: use QEMU_CLOCK_HOST to report start-time Andrei Gudkov via
2023-09-05  9:39 ` Philippe Mathieu-Daudé
2023-09-19  9:14   ` Markus Armbruster
2023-09-19  9:44     ` gudkov.andrei--- via
2023-09-25  0:53 ` Yong Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).