From patchwork Fri Feb 17 02:53:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9578661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 842F560586 for ; Fri, 17 Feb 2017 02:54:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7811C2861F for ; Fri, 17 Feb 2017 02:54:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CF3828687; Fri, 17 Feb 2017 02:54:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4CB902861F for ; Fri, 17 Feb 2017 02:54:20 +0000 (UTC) Received: from localhost ([::1]:51305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceYgd-0001Ug-8N for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Feb 2017 21:54:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceYg1-0001UO-Pf for qemu-devel@nongnu.org; Thu, 16 Feb 2017 21:53:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceYfy-0005Pn-RU for qemu-devel@nongnu.org; Thu, 16 Feb 2017 21:53:41 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:33272) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceYfy-0005Kn-1E for qemu-devel@nongnu.org; Thu, 16 Feb 2017 21:53:38 -0500 Received: from 172.24.1.137 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.137]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DUO65060; Fri, 17 Feb 2017 10:53:29 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Fri, 17 Feb 2017 10:53:22 +0800 From: zhanghailiang To: , , Date: Fri, 17 Feb 2017 10:53:11 +0800 Message-ID: <1487299994-98348-2-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487299994-98348-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487299994-98348-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0206.58A665AB.0003, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 07c3518ad94ee7720e6386c7e32fa1ed X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH v3 1/4] colo-compare: use g_timeout_source_new() to process the stale packets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhanghailiang , xuquan8@huawei.com, qemu-devel@nongnu.org, pss.wulizhen@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of using qemu timer to process the stale packets, We re-use the colo compare thread to process these packets by creating a new timeout coroutine. Besides, since we process all the same vNIC's net connection/packets in one thread, it is safe to remove the timer_check_lock. Signed-off-by: zhanghailiang Reviewed-by: Zhang Chen --- net/colo-compare.c | 62 +++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 162fd6a..fdde788 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -83,9 +83,6 @@ typedef struct CompareState { GHashTable *connection_track_table; /* compare thread, a thread for each NIC */ QemuThread thread; - /* Timer used on the primary to find packets that are never matched */ - QEMUTimer *timer; - QemuMutex timer_check_lock; } CompareState; typedef struct CompareClass { @@ -374,9 +371,7 @@ static void colo_compare_connection(void *opaque, void *user_data) while (!g_queue_is_empty(&conn->primary_list) && !g_queue_is_empty(&conn->secondary_list)) { - qemu_mutex_lock(&s->timer_check_lock); pkt = g_queue_pop_tail(&conn->primary_list); - qemu_mutex_unlock(&s->timer_check_lock); switch (conn->ip_proto) { case IPPROTO_TCP: result = g_queue_find_custom(&conn->secondary_list, @@ -411,9 +406,7 @@ static void colo_compare_connection(void *opaque, void *user_data) * until next comparison. */ trace_colo_compare_main("packet different"); - qemu_mutex_lock(&s->timer_check_lock); g_queue_push_tail(&conn->primary_list, pkt); - qemu_mutex_unlock(&s->timer_check_lock); /* TODO: colo_notify_checkpoint();*/ break; } @@ -486,11 +479,26 @@ static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size) } } +/* + * Check old packet regularly so it can watch for any packets + * that the secondary hasn't produced equivalents of. + */ +static gboolean check_old_packet_regular(void *opaque) +{ + CompareState *s = opaque; + + /* if have old packet we will notify checkpoint */ + colo_old_packet_check(s); + + return TRUE; +} + static void *colo_compare_thread(void *opaque) { GMainContext *worker_context; GMainLoop *compare_loop; CompareState *s = opaque; + GSource *timeout_source; worker_context = g_main_context_new(); @@ -501,8 +509,15 @@ static void *colo_compare_thread(void *opaque) compare_loop = g_main_loop_new(worker_context, FALSE); + /* To kick any packets that the secondary doesn't match */ + timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS); + g_source_set_callback(timeout_source, + (GSourceFunc)check_old_packet_regular, s, NULL); + g_source_attach(timeout_source, worker_context); + g_main_loop_run(compare_loop); + g_source_unref(timeout_source); g_main_loop_unref(compare_loop); g_main_context_unref(worker_context); return NULL; @@ -604,26 +619,6 @@ static int find_and_check_chardev(Chardev **chr, } /* - * Check old packet regularly so it can watch for any packets - * that the secondary hasn't produced equivalents of. - */ -static void check_old_packet_regular(void *opaque) -{ - CompareState *s = opaque; - - timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - REGULAR_PACKET_CHECK_MS); - /* if have old packet we will notify checkpoint */ - /* - * TODO: Make timer handler run in compare thread - * like qemu_chr_add_handlers_full. - */ - qemu_mutex_lock(&s->timer_check_lock); - colo_old_packet_check(s); - qemu_mutex_unlock(&s->timer_check_lock); -} - -/* * Called from the main thread on the primary * to setup colo-compare. */ @@ -665,7 +660,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); g_queue_init(&s->conn_list); - qemu_mutex_init(&s->timer_check_lock); s->connection_track_table = g_hash_table_new_full(connection_key_hash, connection_key_equal, @@ -678,12 +672,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) QEMU_THREAD_JOINABLE); compare_id++; - /* A regular timer to kick any packets that the secondary doesn't match */ - s->timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, /* Only when guest runs */ - check_old_packet_regular, s); - timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - REGULAR_PACKET_CHECK_MS); - return; } @@ -723,12 +711,6 @@ static void colo_compare_finalize(Object *obj) qemu_thread_join(&s->thread); } - if (s->timer) { - timer_del(s->timer); - } - - qemu_mutex_destroy(&s->timer_check_lock); - g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev);