diff mbox

[04/12] migration: introduce migration_update_rates

Message ID 20180604095520.8563-5-xiaoguangrong@tencent.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xiao Guangrong June 4, 2018, 9:55 a.m. UTC
From: Xiao Guangrong <xiaoguangrong@tencent.com>

It is used to slightly clean the code up, no logic is changed

Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
---
 migration/ram.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

Comments

Dr. David Alan Gilbert June 13, 2018, 4:17 p.m. UTC | #1
* guangrong.xiao@gmail.com (guangrong.xiao@gmail.com) wrote:
> From: Xiao Guangrong <xiaoguangrong@tencent.com>
> 
> It is used to slightly clean the code up, no logic is changed

Actually, there is a slight change; iterations_prev is always updated
when previously it was only updated with xbzrle on; still the change
makes more sense.


Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
> ---
>  migration/ram.c | 35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index dd1283dd45..ee03b28435 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -1130,6 +1130,25 @@ uint64_t ram_pagesize_summary(void)
>      return summary;
>  }
>  
> +static void migration_update_rates(RAMState *rs, int64_t end_time)
> +{
> +    uint64_t iter_count = rs->iterations - rs->iterations_prev;
> +
> +    /* calculate period counters */
> +    ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
> +                / (end_time - rs->time_last_bitmap_sync);
> +
> +    if (!iter_count) {
> +        return;
> +    }
> +
> +    if (migrate_use_xbzrle()) {
> +        xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss -
> +            rs->xbzrle_cache_miss_prev) / iter_count;
> +        rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
> +    }
> +}
> +
>  static void migration_bitmap_sync(RAMState *rs)
>  {
>      RAMBlock *block;
> @@ -1159,9 +1178,6 @@ static void migration_bitmap_sync(RAMState *rs)
>  
>      /* more than 1 second = 1000 millisecons */
>      if (end_time > rs->time_last_bitmap_sync + 1000) {
> -        /* calculate period counters */
> -        ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
> -            / (end_time - rs->time_last_bitmap_sync);
>          bytes_xfer_now = ram_counters.transferred;
>  
>          /* During block migration the auto-converge logic incorrectly detects
> @@ -1183,16 +1199,9 @@ static void migration_bitmap_sync(RAMState *rs)
>              }
>          }
>  
> -        if (migrate_use_xbzrle()) {
> -            if (rs->iterations_prev != rs->iterations) {
> -                xbzrle_counters.cache_miss_rate =
> -                   (double)(xbzrle_counters.cache_miss -
> -                            rs->xbzrle_cache_miss_prev) /
> -                   (rs->iterations - rs->iterations_prev);
> -                rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
> -            }
> -            rs->iterations_prev = rs->iterations;
> -        }
> +        migration_update_rates(rs, end_time);
> +
> +        rs->iterations_prev = rs->iterations;
>  
>          /* reset period counters */
>          rs->time_last_bitmap_sync = end_time;
> -- 
> 2.14.4
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Xiao Guangrong June 14, 2018, 3:35 a.m. UTC | #2
On 06/14/2018 12:17 AM, Dr. David Alan Gilbert wrote:
> * guangrong.xiao@gmail.com (guangrong.xiao@gmail.com) wrote:
>> From: Xiao Guangrong <xiaoguangrong@tencent.com>
>>
>> It is used to slightly clean the code up, no logic is changed
> 
> Actually, there is a slight change; iterations_prev is always updated
> when previously it was only updated with xbzrle on; still the change
> makes more sense.

Yes, indeed. I will update the changelog.
Dr. David Alan Gilbert June 15, 2018, 11:32 a.m. UTC | #3
* Dr. David Alan Gilbert (dgilbert@redhat.com) wrote:
> * guangrong.xiao@gmail.com (guangrong.xiao@gmail.com) wrote:
> > From: Xiao Guangrong <xiaoguangrong@tencent.com>
> > 
> > It is used to slightly clean the code up, no logic is changed
> 
> Actually, there is a slight change; iterations_prev is always updated
> when previously it was only updated with xbzrle on; still the change
> makes more sense.
> 
> 
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

This patch queued.

> > Signed-off-by: Xiao Guangrong <xiaoguangrong@tencent.com>
> > ---
> >  migration/ram.c | 35 ++++++++++++++++++++++-------------
> >  1 file changed, 22 insertions(+), 13 deletions(-)
> > 
> > diff --git a/migration/ram.c b/migration/ram.c
> > index dd1283dd45..ee03b28435 100644
> > --- a/migration/ram.c
> > +++ b/migration/ram.c
> > @@ -1130,6 +1130,25 @@ uint64_t ram_pagesize_summary(void)
> >      return summary;
> >  }
> >  
> > +static void migration_update_rates(RAMState *rs, int64_t end_time)
> > +{
> > +    uint64_t iter_count = rs->iterations - rs->iterations_prev;
> > +
> > +    /* calculate period counters */
> > +    ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
> > +                / (end_time - rs->time_last_bitmap_sync);
> > +
> > +    if (!iter_count) {
> > +        return;
> > +    }
> > +
> > +    if (migrate_use_xbzrle()) {
> > +        xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss -
> > +            rs->xbzrle_cache_miss_prev) / iter_count;
> > +        rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
> > +    }
> > +}
> > +
> >  static void migration_bitmap_sync(RAMState *rs)
> >  {
> >      RAMBlock *block;
> > @@ -1159,9 +1178,6 @@ static void migration_bitmap_sync(RAMState *rs)
> >  
> >      /* more than 1 second = 1000 millisecons */
> >      if (end_time > rs->time_last_bitmap_sync + 1000) {
> > -        /* calculate period counters */
> > -        ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
> > -            / (end_time - rs->time_last_bitmap_sync);
> >          bytes_xfer_now = ram_counters.transferred;
> >  
> >          /* During block migration the auto-converge logic incorrectly detects
> > @@ -1183,16 +1199,9 @@ static void migration_bitmap_sync(RAMState *rs)
> >              }
> >          }
> >  
> > -        if (migrate_use_xbzrle()) {
> > -            if (rs->iterations_prev != rs->iterations) {
> > -                xbzrle_counters.cache_miss_rate =
> > -                   (double)(xbzrle_counters.cache_miss -
> > -                            rs->xbzrle_cache_miss_prev) /
> > -                   (rs->iterations - rs->iterations_prev);
> > -                rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
> > -            }
> > -            rs->iterations_prev = rs->iterations;
> > -        }
> > +        migration_update_rates(rs, end_time);
> > +
> > +        rs->iterations_prev = rs->iterations;
> >  
> >          /* reset period counters */
> >          rs->time_last_bitmap_sync = end_time;
> > -- 
> > 2.14.4
> > 
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff mbox

Patch

diff --git a/migration/ram.c b/migration/ram.c
index dd1283dd45..ee03b28435 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1130,6 +1130,25 @@  uint64_t ram_pagesize_summary(void)
     return summary;
 }
 
+static void migration_update_rates(RAMState *rs, int64_t end_time)
+{
+    uint64_t iter_count = rs->iterations - rs->iterations_prev;
+
+    /* calculate period counters */
+    ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
+                / (end_time - rs->time_last_bitmap_sync);
+
+    if (!iter_count) {
+        return;
+    }
+
+    if (migrate_use_xbzrle()) {
+        xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss -
+            rs->xbzrle_cache_miss_prev) / iter_count;
+        rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
+    }
+}
+
 static void migration_bitmap_sync(RAMState *rs)
 {
     RAMBlock *block;
@@ -1159,9 +1178,6 @@  static void migration_bitmap_sync(RAMState *rs)
 
     /* more than 1 second = 1000 millisecons */
     if (end_time > rs->time_last_bitmap_sync + 1000) {
-        /* calculate period counters */
-        ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000
-            / (end_time - rs->time_last_bitmap_sync);
         bytes_xfer_now = ram_counters.transferred;
 
         /* During block migration the auto-converge logic incorrectly detects
@@ -1183,16 +1199,9 @@  static void migration_bitmap_sync(RAMState *rs)
             }
         }
 
-        if (migrate_use_xbzrle()) {
-            if (rs->iterations_prev != rs->iterations) {
-                xbzrle_counters.cache_miss_rate =
-                   (double)(xbzrle_counters.cache_miss -
-                            rs->xbzrle_cache_miss_prev) /
-                   (rs->iterations - rs->iterations_prev);
-                rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
-            }
-            rs->iterations_prev = rs->iterations;
-        }
+        migration_update_rates(rs, end_time);
+
+        rs->iterations_prev = rs->iterations;
 
         /* reset period counters */
         rs->time_last_bitmap_sync = end_time;