Skip to contentSkip to conversation

Several optimization and bugfix for COLO compare.

PATCH In review Zhang Chen 2 participants 10 messages Sep 18, 2020 – Sep 24, 2020 Networking

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

cover Several optimization and bugfix for COLO compare.

From: Zhang Chen <[email protected]>

Add COLO secondary old packet detection and fix some bugs.

Zhang Chen (4):
net/colo-compare.c: Fix compare_timeout format issue net/colo-compare.c: Change the timer clock type net/colo-compare.c: Add secondary old packet detection net/colo-compare.c: Increase default queued packet scan frequency

 net/colo-compare.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/4 net/colo-compare.c: Fix compare_timeout format issue

From: Zhang Chen <[email protected]>

This parameter need compare with the return of qemu_clock_get_ms(), it is uinit64_t. So we need fix this issue here.

---
 net/colo-compare.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/colo-compare.c +6 -6
index 3a45d64175..7cba573dae 100644
@@ -120,7 +120,7 @@ struct CompareState {
     SendCo out_sendco;
     SendCo notify_sendco;
     bool vnet_hdr;
-    uint32_t compare_timeout;
+    uint64_t compare_timeout;
     uint32_t expired_scan_cycle;
 
     /*
@@ -1081,9 +1081,9 @@ static void compare_get_timeout(Object *obj, Visitor *v,
                                 Error **errp)
 {
     CompareState *s = COLO_COMPARE(obj);
-    uint32_t value = s->compare_timeout;
+    uint64_t value = s->compare_timeout;
 
-    visit_type_uint32(v, name, &value, errp);
+    visit_type_uint64(v, name, &value, errp);
 }
 
 static void compare_set_timeout(Object *obj, Visitor *v,
@@ -1146,9 +1146,9 @@ static void set_max_queue_size(Object *obj, Visitor *v,
                                Error **errp)
 {
     Error *local_err = NULL;
-    uint32_t value;
+    uint64_t value;
 
-    visit_type_uint32(v, name, &value, &local_err);
+    visit_type_uint64(v, name, &value, &local_err);
     if (local_err) {
         goto out;
     }
@@ -1396,7 +1396,7 @@ static void colo_compare_init(Object *obj)
     object_property_add_str(obj, "notify_dev",
                             compare_get_notify_dev, compare_set_notify_dev);
 
-    object_property_add(obj, "compare_timeout", "uint32",
+    object_property_add(obj, "compare_timeout", "uint64",
                         compare_get_timeout,
                         compare_set_timeout, NULL, NULL);
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] net/colo-compare.c: Fix compare_timeout format issue

Quoted 7 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This parameter need compare with the return of qemu_clock_get_ms(), it is uinit64_t. So we need fix this issue here.

Quoted 50 lines
---
  net/colo-compare.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
net/colo-compare.c +6 -6
index 3a45d64175..7cba573dae 100644
@@ -120,7 +120,7 @@ struct CompareState {
      SendCo out_sendco;
      SendCo notify_sendco;
      bool vnet_hdr;
-    uint32_t compare_timeout;
+    uint64_t compare_timeout;
      uint32_t expired_scan_cycle;
 
      /*
@@ -1081,9 +1081,9 @@ static void compare_get_timeout(Object *obj, Visitor *v,
                                  Error **errp)
  {
      CompareState *s = COLO_COMPARE(obj);
-    uint32_t value = s->compare_timeout;
+    uint64_t value = s->compare_timeout;
 
-    visit_type_uint32(v, name, &value, errp);
+    visit_type_uint64(v, name, &value, errp);
  }
 
  static void compare_set_timeout(Object *obj, Visitor *v,
@@ -1146,9 +1146,9 @@ static void set_max_queue_size(Object *obj, Visitor *v,
                                 Error **errp)
  {
      Error *local_err = NULL;
-    uint32_t value;
+    uint64_t value;
 
-    visit_type_uint32(v, name, &value, &local_err);
+    visit_type_uint64(v, name, &value, &local_err);
      if (local_err) {
          goto out;
      }
@@ -1396,7 +1396,7 @@ static void colo_compare_init(Object *obj)
      object_property_add_str(obj, "notify_dev",
                              compare_get_notify_dev, compare_set_notify_dev);
 
-    object_property_add(obj, "compare_timeout", "uint32",
+    object_property_add(obj, "compare_timeout", "uint64",
                          compare_get_timeout,
                          compare_set_timeout, NULL, NULL);
 
author
#3 lore raw

PATCH 2/4 net/colo-compare.c: Change the timer clock type

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

The virtual clock only runs during the emulation. It stops when the virtual machine is stopped.
The host clock should be used for device models that emulate accurate real time sources. It will continue to run when the virtual machine is suspended. COLO need to know the host time here.

---
 net/colo-compare.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/colo-compare.c +3 -3
index 7cba573dae..3b72309d08 100644
@@ -905,7 +905,7 @@ static void check_old_packet_regular(void *opaque)
 
     /* if have old packet we will notify checkpoint */
     colo_old_packet_check(s);
-    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
               s->expired_scan_cycle);
 }
 
@@ -939,10 +939,10 @@ static void colo_compare_timer_init(CompareState *s)
 {
     AioContext *ctx = iothread_get_aio_context(s->iothread);
 
-    s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL,
+    s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_HOST,
                                 SCALE_MS, check_old_packet_regular,
                                 s);
-    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
               s->expired_scan_cycle);
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] net/colo-compare.c: Change the timer clock type

Quoted 10 lines · Zhang Chen

From: Zhang Chen <[email protected]>

The virtual clock only runs during the emulation. It stops when the virtual machine is stopped.
The host clock should be used for device models that emulate accurate real time sources. It will continue to run when the virtual machine is suspended. COLO need to know the host time here.

Quoted 30 lines
---
  net/colo-compare.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
net/colo-compare.c +3 -3
index 7cba573dae..3b72309d08 100644
@@ -905,7 +905,7 @@ static void check_old_packet_regular(void *opaque)
 
      /* if have old packet we will notify checkpoint */
      colo_old_packet_check(s);
-    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
                s->expired_scan_cycle);
  }
 
@@ -939,10 +939,10 @@ static void colo_compare_timer_init(CompareState *s)
  {
      AioContext *ctx = iothread_get_aio_context(s->iothread);
 
-    s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL,
+    s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_HOST,
                                  SCALE_MS, check_old_packet_regular,
                                  s);
-    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
                s->expired_scan_cycle);
  }
 
author
#5 lore raw

PATCH 3/4 net/colo-compare.c: Add secondary old packet detection

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

Detect queued secondary packet to sync VM state in time.

---
 net/colo-compare.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
net/colo-compare.c +16 -9
index 3b72309d08..f7271b976f 100644
@@ -641,19 +641,26 @@ void colo_compare_unregister_notifier(Notifier *notify)
 static int colo_old_packet_check_one_conn(Connection *conn,
                                           CompareState *s)
 {
-    GList *result = NULL;
-
-    result = g_queue_find_custom(&conn->primary_list,
-                                 &s->compare_timeout,
-                                 (GCompareFunc)colo_old_packet_check_one);
+    if (!g_queue_is_empty(&conn->primary_list)) {
+        if (g_queue_find_custom(&conn->primary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
+    }
 
-    if (result) {
-        /* Do checkpoint will flush old packet */
-        colo_compare_inconsistency_notify(s);
-        return 0;
+    if (!g_queue_is_empty(&conn->secondary_list)) {
+        if (g_queue_find_custom(&conn->secondary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
     }
 
     return 1;
+
+out:
+    /* Do checkpoint will flush old packet */
+    colo_compare_inconsistency_notify(s);
+    return 0;
 }
 
 /*
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH 3/4] net/colo-compare.c: Add secondary old packet detection

Quoted 14 lines · Zhang Chen

From: Zhang Chen <[email protected]>

Detect queued secondary packet to sync VM state in time.

---
  net/colo-compare.c | 25 ++++++++++++++++---------
  1 file changed, 16 insertions(+), 9 deletions(-)
net/colo-compare.c +0 -0
index 3b72309d08..f7271b976f 100644

net/colo-compare.c void colo_compare_unregister_notifier(Notifier *notify) · line 644

Quoted 9 lines
net/colo-compare.c +1 -5
@@ -641,19 +641,26 @@ void colo_compare_unregister_notifier(Notifier *notify)
  static int colo_old_packet_check_one_conn(Connection *conn,
                                            CompareState *s)
  {
-    GList *result = NULL;
-
-    result = g_queue_find_custom(&conn->primary_list,
-                                 &s->compare_timeout,
-                                 (GCompareFunc)colo_old_packet_check_one);
+    if (!g_queue_is_empty(&conn->primary_list)) {

Looks we don't need to check is_empty

net/colo-compare.c void colo_compare_unregister_notifier(Notifier *notify) · line 651

Quoted 11 lines
net/colo-compare.c +6 -4
+        if (g_queue_find_custom(&conn->primary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
+    }
 
-    if (result) {
-        /* Do checkpoint will flush old packet */
-        colo_compare_inconsistency_notify(s);
-        return 0;
+    if (!g_queue_is_empty(&conn->secondary_list)) {

Ditto

Thanks

Quoted 15 lines
net/colo-compare.c +9 -0
+        if (g_queue_find_custom(&conn->secondary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
      }
 
      return 1;
+
+out:
+    /* Do checkpoint will flush old packet */
+    colo_compare_inconsistency_notify(s);
+    return 0;
  }
 
  /*
#7 lore raw

RE: [PATCH 3/4] net/colo-compare.c: Add secondary old packet detection

Quoted 38 lines

-----Original Message-----
From: Li Zhijian <[email protected]>
Sent: Tuesday, September 22, 2020 2:47 PM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [PATCH 3/4] net/colo-compare.c: Add secondary old packet detection

net/colo-compare.c void colo_compare_unregister_notifier(Notifier

Quoted 14 lines · Zhang Chen

From: Zhang Chen <[email protected]>

Detect queued secondary packet to sync VM state in time.

---
  net/colo-compare.c | 25 ++++++++++++++++---------
  1 file changed, 16 insertions(+), 9 deletions(-)
net/colo-compare.c index renamed from net/colo-compare.c +0 -0

3b72309d08..f7271b976f 100644

net/colo-compare.c +0 -0
@@ -641,19 +641,26 @@ void colo_compare_unregister_notifier(Notifier

*notify)

net/colo-compare.c void colo_compare_unregister_notifier(Notifier *notify) · line 644

Quoted 9 lines
net/colo-compare.c +1 -5
  static int colo_old_packet_check_one_conn(Connection *conn,
                                            CompareState *s)
  {
-    GList *result = NULL;
-
-    result = g_queue_find_custom(&conn->primary_list,
-                                 &s->compare_timeout,
-                                 (GCompareFunc)colo_old_packet_check_one);
+    if (!g_queue_is_empty(&conn->primary_list)) {
Quoted 1 line

Looks we don't need to check is_empty

Re-checked glib code, it just checked the queue rather than inside content. Maybe check empty before that will benefit performance.

Thanks
Zhang Chen

Quoted 32 lines

net/colo-compare.c void colo_compare_unregister_notifier(Notifier *notify) · line 651

Quoted 12 lines
net/colo-compare.c +6 -4
+        if (g_queue_find_custom(&conn->primary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
+    }
 
-    if (result) {
-        /* Do checkpoint will flush old packet */
-        colo_compare_inconsistency_notify(s);
-        return 0;
+    if (!g_queue_is_empty(&conn->secondary_list)) {

Ditto

Thanks

Quoted 15 lines
net/colo-compare.c +9 -0
+        if (g_queue_find_custom(&conn->secondary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
      }
 
      return 1;
+
+out:
+    /* Do checkpoint will flush old packet */
+    colo_compare_inconsistency_notify(s);
+    return 0;
  }
 
  /*
Reviewed-by
#8 lore raw

Re: [PATCH 3/4] net/colo-compare.c: Add secondary old packet detection

Quoted 37 lines · Chen
Quoted 37 lines

-----Original Message-----
From: Li Zhijian <[email protected]>
Sent: Tuesday, September 22, 2020 2:47 PM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [PATCH 3/4] net/colo-compare.c: Add secondary old packet detection

net/colo-compare.c void colo_compare_unregister_notifier(Notifier

Quoted 14 lines · Zhang Chen

From: Zhang Chen <[email protected]>

Detect queued secondary packet to sync VM state in time.

---
   net/colo-compare.c | 25 ++++++++++++++++---------
   1 file changed, 16 insertions(+), 9 deletions(-)
net/colo-compare.c index renamed from net/colo-compare.c +0 -0

3b72309d08..f7271b976f 100644

net/colo-compare.c +0 -0
@@ -641,19 +641,26 @@ void colo_compare_unregister_notifier(Notifier

*notify)

Quoted 9 lines
net/colo-compare.c +1 -5
   static int colo_old_packet_check_one_conn(Connection *conn,
                                             CompareState *s)
   {
-    GList *result = NULL;
-
-    result = g_queue_find_custom(&conn->primary_list,
-                                 &s->compare_timeout,
-                                 (GCompareFunc)colo_old_packet_check_one);
+    if (!g_queue_is_empty(&conn->primary_list)) {
Quoted 3 lines
Quoted 1 line

Looks we don't need to check is_empty

Re-checked glib code, it just checked the queue rather than inside content. Maybe check empty before that will benefit performance.

Yeah,  you are right

Thank

Quoted 36 lines

Thanks
Zhang Chen

Quoted 30 lines

net/colo-compare.c void colo_compare_unregister_notifier(Notifier *notify) · line 651

Quoted 11 lines
net/colo-compare.c +6 -4
+        if (g_queue_find_custom(&conn->primary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
+    }
 
-    if (result) {
-        /* Do checkpoint will flush old packet */
-        colo_compare_inconsistency_notify(s);
-        return 0;
+    if (!g_queue_is_empty(&conn->secondary_list)) {

Ditto

Thanks

Quoted 15 lines
net/colo-compare.c +9 -0
+        if (g_queue_find_custom(&conn->secondary_list,
+                                &s->compare_timeout,
+                                (GCompareFunc)colo_old_packet_check_one))
+            goto out;
       }
 
       return 1;
+
+out:
+    /* Do checkpoint will flush old packet */
+    colo_compare_inconsistency_notify(s);
+    return 0;
   }
 
   /*
author
#9 lore raw

PATCH 4/4 net/colo-compare.c: Increase default queued packet scan frequency

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

In my test, use this default parameter looks better.

---
 net/colo-compare.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/colo-compare.c +1 -1
index f7271b976f..6df6a7e66f 100644
@@ -52,7 +52,7 @@ static NotifierList colo_compare_notifiers =
 #define COLO_COMPARE_FREE_PRIMARY     0x01
 #define COLO_COMPARE_FREE_SECONDARY   0x02
 
-#define REGULAR_PACKET_CHECK_MS 3000
+#define REGULAR_PACKET_CHECK_MS 1000
 #define DEFAULT_TIME_OUT_MS 3000
 
 /* #define DEBUG_COLO_PACKETS */
Signature · 1 line
2.17.1