From nobody Sat Feb 7 06:49:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507876674513910.1617774866645; Thu, 12 Oct 2017 23:37:54 -0700 (PDT) Received: from localhost ([::1]:48620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2tbI-0000Yw-Qa for importer@patchew.org; Fri, 13 Oct 2017 02:37:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2tZf-00080j-3V for qemu-devel@nongnu.org; Fri, 13 Oct 2017 02:36:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2tZc-0004v4-8z for qemu-devel@nongnu.org; Fri, 13 Oct 2017 02:35:59 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:54764 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2tZb-0004sa-Ke for qemu-devel@nongnu.org; Fri, 13 Oct 2017 02:35:56 -0400 Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 13 Oct 2017 14:35:45 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 3EAFD47F13B0; Fri, 13 Oct 2017 14:35:45 +0800 (CST) Received: from localhost.localdomain (10.167.226.123) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 13 Oct 2017 14:35:45 +0800 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="29028899" From: Mao Zhongyi To: Date: Fri, 13 Oct 2017 14:32:06 +0800 Message-ID: <20171013063209.15617-2-maozy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20171013063209.15617-1-maozy.fnst@cn.fujitsu.com> References: <20171013063209.15617-1-maozy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.123] X-yoursite-MailScanner-ID: 3EAFD47F13B0.A2ED0 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: maozy.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 183.91.158.132 Subject: [Qemu-devel] [PATCH 1/4] 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: Jason Wang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_packe= t() 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 --- 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) } =20 /* + * 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) <=3D MAX_QUEUE_SIZE) { + if (pkt->ip->ip_p =3D=3D 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) } =20 if (mode =3D=3D PRIMARY_IN) { - if (g_queue_get_length(&conn->primary_list) <=3D - MAX_QUEUE_SIZE) { - g_queue_push_tail(&conn->primary_list, pkt); - if (conn->ip_proto =3D=3D 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) <=3D - MAX_QUEUE_SIZE) { - g_queue_push_tail(&conn->secondary_list, pkt); - if (conn->ip_proto =3D=3D 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"); } --=20 2.9.4