From patchwork Wed Feb 15 03:53:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 728042 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 3vNQbn0zJYz9s0m for ; Wed, 15 Feb 2017 15:02:29 +1100 (AEDT) Received: from localhost ([::1]:38386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdqnS-0000uj-On for incoming@patchwork.ozlabs.org; Tue, 14 Feb 2017 23:02:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdqeu-00027k-LG for qemu-devel@nongnu.org; Tue, 14 Feb 2017 22:53:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdqet-0008QE-M3 for qemu-devel@nongnu.org; Tue, 14 Feb 2017 22:53:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdqet-0008Q9-G0 for qemu-devel@nongnu.org; Tue, 14 Feb 2017 22:53:35 -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 833717FB69; Wed, 15 Feb 2017 03:53:35 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-4-152.pek2.redhat.com [10.72.4.152]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1F3rP5o027443; Tue, 14 Feb 2017 22:53:33 -0500 From: Jason Wang To: peter.maydell@linaro.org Date: Wed, 15 Feb 2017 11:53:20 +0800 Message-Id: <1487130802-27953-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1487130802-27953-1-git-send-email-jasowang@redhat.com> References: <1487130802-27953-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.25]); Wed, 15 Feb 2017 03:53:35 +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 3/5] colo-compare: sort TCP packet queue by sequence number 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 , Li Zhijian , qemu-devel@nongnu.org, Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Zhang Chen Improve efficiency of TCP packet comparison. Signed-off-by: Zhang Chen Signed-off-by: Li Zhijian Signed-off-by: Jason Wang --- net/colo-compare.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/colo-compare.c b/net/colo-compare.c index 4962976..162fd6a 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -101,6 +101,15 @@ static int compare_chr_send(CharBackend *out, const uint8_t *buf, uint32_t size); +static gint seq_sorter(Packet *a, Packet *b, gpointer data) +{ + struct tcphdr *atcp, *btcp; + + atcp = (struct tcphdr *)(a->transport_header); + btcp = (struct tcphdr *)(b->transport_header); + return ntohl(atcp->th_seq) - ntohl(btcp->th_seq); +} + /* * Return 0 on success, if return -1 means the pkt * is unsupported(arp and ipv6) and will be sent later @@ -137,6 +146,11 @@ static int packet_enqueue(CompareState *s, int mode) 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 { error_report("colo compare primary queue size too big," "drop packet"); @@ -145,6 +159,11 @@ static int packet_enqueue(CompareState *s, int mode) 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 { error_report("colo compare secondary queue size too big," "drop packet");