From patchwork Mon Mar 6 05:25:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 735542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vc7gP1YWsz9s7Z for ; Mon, 6 Mar 2017 16:31:13 +1100 (AEDT) Received: from localhost ([::1]:41796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklEk-00033W-IG for incoming@patchwork.ozlabs.org; Mon, 06 Mar 2017 00:31:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklA4-0007tF-QD for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklA3-00016e-JE for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41854) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklA3-00016S-AH for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:19 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E863C04B317; Mon, 6 Mar 2017 05:26:19 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu1031786; Mon, 6 Mar 2017 00:26:17 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:42 +0800 Message-Id: <1488777954-4578-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 07/19] 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: Jason Wang , zhanghailiang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: zhanghailiang 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 Signed-off-by: Jason Wang --- 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);