From patchwork Tue Nov 14 02:11:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 837666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3ybWHf6lpHz9s7c for ; Tue, 14 Nov 2017 13:12:46 +1100 (AEDT) Received: from localhost ([::1]:57259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEQiT-0004mo-0T for incoming@patchwork.ozlabs.org; Mon, 13 Nov 2017 21:12:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEQhg-0004Z7-9C for qemu-devel@nongnu.org; Mon, 13 Nov 2017 21:11:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEQhd-0000l1-1m for qemu-devel@nongnu.org; Mon, 13 Nov 2017 21:11:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEQhc-0000ka-PO for qemu-devel@nongnu.org; Mon, 13 Nov 2017 21:11:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04D39C0587DF; Tue, 14 Nov 2017 02:11:52 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-130.pek2.redhat.com [10.72.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 782E4173A5; Tue, 14 Nov 2017 02:11:49 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 14 Nov 2017 10:11:32 +0800 Message-Id: <1510625498-4821-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1510625498-4821-1-git-send-email-jasowang@redhat.com> References: <1510625498-4821-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 14 Nov 2017 02:11:52 +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 2/8] colo-compare: Insert packet into the suitable position of packet queue directly 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: Mao Zhongyi , Jason Wang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mao Zhongyi Currently, a packet from pri_dev or sec_dev is fristly pushed at the tail of the primary or secondary packet queue then sorted by the tcp sequence number. Now, this patch use g_queue_insert_sorted to insert the packet directly into the suitable position to avoid ordering all packets each time when a new packet is comming, thereby increasing efficiency. In addition, consolidate the code that add a packet to the list of Connection (primary or secondary) into a separate routine colo_insert_packet() since the same chunk of code is called from two place. Cc: Zhang Chen Cc: Li Zhijian Cc: Jason Wang Signed-off-by: Mao Zhongyi Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index b3f35d7..54b6347 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -113,6 +113,26 @@ static gint seq_sorter(Packet *a, Packet *b, gpointer data) } /* + * Return 1 on success, if return 0 means the + * packet will be dropped + */ +static int colo_insert_packet(GQueue *queue, Packet *pkt) +{ + if (g_queue_get_length(queue) <= MAX_QUEUE_SIZE) { + if (pkt->ip->ip_p == IPPROTO_TCP) { + g_queue_insert_sorted(queue, + pkt, + (GCompareDataFunc)seq_sorter, + NULL); + } else { + g_queue_push_tail(queue, pkt); + } + return 1; + } + return 0; +} + +/* * Return 0 on success, if return -1 means the pkt * is unsupported(arp and ipv6) and will be sent later */ @@ -149,28 +169,12 @@ static int packet_enqueue(CompareState *s, int mode) } if (mode == PRIMARY_IN) { - if (g_queue_get_length(&conn->primary_list) <= - MAX_QUEUE_SIZE) { - g_queue_push_tail(&conn->primary_list, pkt); - if (conn->ip_proto == IPPROTO_TCP) { - g_queue_sort(&conn->primary_list, - (GCompareDataFunc)seq_sorter, - NULL); - } - } else { + if (!colo_insert_packet(&conn->primary_list, pkt)) { error_report("colo compare primary queue size too big," "drop packet"); } } else { - if (g_queue_get_length(&conn->secondary_list) <= - MAX_QUEUE_SIZE) { - g_queue_push_tail(&conn->secondary_list, pkt); - if (conn->ip_proto == IPPROTO_TCP) { - g_queue_sort(&conn->secondary_list, - (GCompareDataFunc)seq_sorter, - NULL); - } - } else { + if (!colo_insert_packet(&conn->secondary_list, pkt)) { error_report("colo compare secondary queue size too big," "drop packet"); }