{"id":811300,"url":"http://patchwork.ozlabs.org/api/1.2/patches/811300/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1504836324-4871-18-git-send-email-jasowang@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504836324-4871-18-git-send-email-jasowang@redhat.com>","list_archive_url":null,"date":"2017-09-08T02:05:23","name":"[PULL,17/18] colo-compare: Use IOThread to Check old packet regularly and Process pactkets of the primary","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"aab5f599a7eb3c1fbc62f0c2cef73524f4b4a97c","submitter":{"id":5225,"url":"http://patchwork.ozlabs.org/api/1.2/people/5225/?format=json","name":"Jason Wang","email":"jasowang@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1504836324-4871-18-git-send-email-jasowang@redhat.com/mbox/","series":[{"id":2087,"url":"http://patchwork.ozlabs.org/api/1.2/series/2087/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2087","date":"2017-09-08T02:05:06","name":"[PULL,01/18] net/filter-rewriter.c: Fix rewirter checksum bug when use virtio-net","version":1,"mbox":"http://patchwork.ozlabs.org/series/2087/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811300/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811300/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=jasowang@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpLYl3L7Tz9s83\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 12:17:14 +1000 (AEST)","from localhost ([::1]:42991 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dq8r2-0004aa-1S\n\tfor incoming@patchwork.ozlabs.org; Thu, 07 Sep 2017 22:17:12 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:33065)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <jasowang@redhat.com>) id 1dq8gz-0003qR-Mg\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:54 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <jasowang@redhat.com>) id 1dq8gu-0002kw-LZ\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:49 -0400","from mx1.redhat.com ([209.132.183.28]:51620)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <jasowang@redhat.com>) id 1dq8gu-0002kJ-Ct\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:44 -0400","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 7848F5F7A9;\n\tFri,  8 Sep 2017 02:06:43 +0000 (UTC)","from jason-ThinkPad-T450s.redhat.com (ovpn-12-98.pek2.redhat.com\n\t[10.72.12.98])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 9B78F600C2;\n\tFri,  8 Sep 2017 02:06:38 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 7848F5F7A9","From":"Jason Wang <jasowang@redhat.com>","To":"peter.maydell@linaro.org,\n\tqemu-devel@nongnu.org","Date":"Fri,  8 Sep 2017 10:05:23 +0800","Message-Id":"<1504836324-4871-18-git-send-email-jasowang@redhat.com>","In-Reply-To":"<1504836324-4871-1-git-send-email-jasowang@redhat.com>","References":"<1504836324-4871-1-git-send-email-jasowang@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.11","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.39]);\n\tFri, 08 Sep 2017 02:06:43 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PULL 17/18] colo-compare: Use IOThread to Check old\n\tpacket regularly and Process pactkets of the primary","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Jason Wang <jasowang@redhat.com>, Wang Yong <wang.yong155@zte.com.cn>,\n\tWang Guang <wang.guang55@zte.com.cn>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"From: Wang Yong <wang.yong155@zte.com.cn>\n\nRemove the task which check old packet in the comparing thread,\nthen use IOthread context timer to handle it.\n\nProcess pactkets in the IOThread which arrived over the socket.\nwe use iothread_get_g_main_context to create a new g_main_loop in\nthe IOThread.then the packets from the primary and the secondary\nare processed in the IOThread.\n\nFinally remove the colo-compare thread using the IOThread instead.\n\nReviewed-by: Zhang Chen<zhangchen.fnst@cn.fujitsu.com>\nSigned-off-by: Wang Yong <wang.yong155@zte.com.cn>\nSigned-off-by: Wang Guang <wang.guang55@zte.com.cn>\nSigned-off-by: Jason Wang <jasowang@redhat.com>\n---\n net/colo-compare.c | 83 +++++++++++++++++++++++++++++-------------------------\n 1 file changed, 45 insertions(+), 38 deletions(-)","diff":"diff --git a/net/colo-compare.c b/net/colo-compare.c\nindex eee33b8..b3f35d7 100644\n--- a/net/colo-compare.c\n+++ b/net/colo-compare.c\n@@ -29,6 +29,7 @@\n #include \"qemu/sockets.h\"\n #include \"qapi-visit.h\"\n #include \"net/colo.h\"\n+#include \"sysemu/iothread.h\"\n \n #define TYPE_COLO_COMPARE \"colo-compare\"\n #define COLO_COMPARE(obj) \\\n@@ -82,11 +83,10 @@ typedef struct CompareState {\n     GQueue conn_list;\n     /* Record the connection without repetition */\n     GHashTable *connection_track_table;\n-    /* This thread just do packet compare job */\n-    QemuThread thread;\n \n+    IOThread *iothread;\n     GMainContext *worker_context;\n-    GMainLoop *compare_loop;\n+    QEMUTimer *packet_check_timer;\n } CompareState;\n \n typedef struct CompareClass {\n@@ -615,22 +615,40 @@ static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size)\n  * Check old packet regularly so it can watch for any packets\n  * that the secondary hasn't produced equivalents of.\n  */\n-static gboolean check_old_packet_regular(void *opaque)\n+static void check_old_packet_regular(void *opaque)\n {\n     CompareState *s = opaque;\n \n     /* if have old packet we will notify checkpoint */\n     colo_old_packet_check(s);\n+    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +\n+                REGULAR_PACKET_CHECK_MS);\n+}\n+\n+static void colo_compare_timer_init(CompareState *s)\n+{\n+    AioContext *ctx = iothread_get_aio_context(s->iothread);\n \n-    return TRUE;\n+    s->packet_check_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL,\n+                                SCALE_MS, check_old_packet_regular,\n+                                s);\n+    timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +\n+                    REGULAR_PACKET_CHECK_MS);\n }\n \n-static void *colo_compare_thread(void *opaque)\n+static void colo_compare_timer_del(CompareState *s)\n {\n-    CompareState *s = opaque;\n-    GSource *timeout_source;\n+    if (s->packet_check_timer) {\n+        timer_del(s->packet_check_timer);\n+        timer_free(s->packet_check_timer);\n+        s->packet_check_timer = NULL;\n+    }\n+ }\n \n-    s->worker_context = g_main_context_new();\n+static void colo_compare_iothread(CompareState *s)\n+{\n+    object_ref(OBJECT(s->iothread));\n+    s->worker_context = iothread_get_g_main_context(s->iothread);\n \n     qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read,\n                              compare_pri_chr_in, NULL, NULL,\n@@ -639,20 +657,7 @@ static void *colo_compare_thread(void *opaque)\n                              compare_sec_chr_in, NULL, NULL,\n                              s, s->worker_context, true);\n \n-    s->compare_loop = g_main_loop_new(s->worker_context, FALSE);\n-\n-    /* To kick any packets that the secondary doesn't match */\n-    timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS);\n-    g_source_set_callback(timeout_source,\n-                          (GSourceFunc)check_old_packet_regular, s, NULL);\n-    g_source_attach(timeout_source, s->worker_context);\n-\n-    g_main_loop_run(s->compare_loop);\n-\n-    g_source_unref(timeout_source);\n-    g_main_loop_unref(s->compare_loop);\n-    g_main_context_unref(s->worker_context);\n-    return NULL;\n+    colo_compare_timer_init(s);\n }\n \n static char *compare_get_pri_indev(Object *obj, Error **errp)\n@@ -777,12 +782,10 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)\n {\n     CompareState *s = COLO_COMPARE(uc);\n     Chardev *chr;\n-    char thread_name[64];\n-    static int compare_id;\n \n-    if (!s->pri_indev || !s->sec_indev || !s->outdev) {\n+    if (!s->pri_indev || !s->sec_indev || !s->outdev || !s->iothread) {\n         error_setg(errp, \"colo compare needs 'primary_in' ,\"\n-                   \"'secondary_in','outdev' property set\");\n+                   \"'secondary_in','outdev','iothread' property set\");\n         return;\n     } else if (!strcmp(s->pri_indev, s->outdev) ||\n                !strcmp(s->sec_indev, s->outdev) ||\n@@ -817,12 +820,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)\n                                                       g_free,\n                                                       connection_destroy);\n \n-    sprintf(thread_name, \"colo-compare %d\", compare_id);\n-    qemu_thread_create(&s->thread, thread_name,\n-                       colo_compare_thread, s,\n-                       QEMU_THREAD_JOINABLE);\n-    compare_id++;\n-\n+    colo_compare_iothread(s);\n     return;\n }\n \n@@ -866,6 +864,10 @@ static void colo_compare_init(Object *obj)\n     object_property_add_str(obj, \"outdev\",\n                             compare_get_outdev, compare_set_outdev,\n                             NULL);\n+    object_property_add_link(obj, \"iothread\", TYPE_IOTHREAD,\n+                            (Object **)&s->iothread,\n+                            object_property_allow_set_link,\n+                            OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);\n \n     s->vnet_hdr = false;\n     object_property_add_bool(obj, \"vnet_hdr_support\", compare_get_vnet_hdr,\n@@ -879,16 +881,21 @@ static void colo_compare_finalize(Object *obj)\n     qemu_chr_fe_deinit(&s->chr_pri_in, false);\n     qemu_chr_fe_deinit(&s->chr_sec_in, false);\n     qemu_chr_fe_deinit(&s->chr_out, false);\n-\n-    g_main_loop_quit(s->compare_loop);\n-    qemu_thread_join(&s->thread);\n-\n+    if (s->iothread) {\n+        colo_compare_timer_del(s);\n+    }\n     /* Release all unhandled packets after compare thead exited */\n     g_queue_foreach(&s->conn_list, colo_flush_packets, s);\n \n     g_queue_clear(&s->conn_list);\n \n-    g_hash_table_destroy(s->connection_track_table);\n+    if (s->connection_track_table) {\n+        g_hash_table_destroy(s->connection_track_table);\n+    }\n+\n+    if (s->iothread) {\n+        object_unref(OBJECT(s->iothread));\n+    }\n     g_free(s->pri_indev);\n     g_free(s->sec_indev);\n     g_free(s->outdev);\n","prefixes":["PULL","17/18"]}