From patchwork Mon Mar 6 05:25:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 735553 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 3vc7sw5lSWz9s7Z for ; Mon, 6 Mar 2017 16:40:20 +1100 (AEDT) Received: from localhost ([::1]:41847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklNa-0001i1-1A for incoming@patchwork.ozlabs.org; Mon, 06 Mar 2017 00:40:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAV-0008HG-V5 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAU-0001Mm-Or for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41956) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAU-0001MG-GA for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:46 -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 A7D30C04B31F; Mon, 6 Mar 2017 05:26:46 +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 v265PvuB031786; Mon, 6 Mar 2017 00:26:44 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:52 +0800 Message-Id: <1488777954-4578-18-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:46 +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 17/19] COLO-compare: Optimize compare_common and compare_tcp 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 , Zhang Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Zhang Chen Add offset args for colo_packet_compare_common, optimize colo_packet_compare_icmp() and colo_packet_compare_udp() just compare the IP payload. Before compare all tcp packet, we compare tcp checksum firstly, this function can get better performance. Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 602a758..9f5968d 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -180,7 +180,7 @@ static int packet_enqueue(CompareState *s, int mode) * return: 0 means packet same * > 0 || < 0 means packet different */ -static int colo_packet_compare_common(Packet *ppkt, Packet *spkt) +static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset) { trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src), inet_ntoa(ppkt->ip->ip_dst), spkt->size, @@ -188,7 +188,8 @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt) inet_ntoa(spkt->ip->ip_dst)); if (ppkt->size == spkt->size) { - return memcmp(ppkt->data, spkt->data, spkt->size); + return memcmp(ppkt->data + offset, spkt->data + offset, + spkt->size - offset); } else { trace_colo_compare_main("Net packet size are not the same"); return -1; @@ -207,13 +208,6 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) trace_colo_compare_main("compare tcp"); - if (ppkt->size != spkt->size) { - if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { - trace_colo_compare_main("pkt size not same"); - } - return -1; - } - ptcp = (struct tcphdr *)ppkt->transport_header; stcp = (struct tcphdr *)spkt->transport_header; @@ -231,8 +225,11 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) spkt->ip->ip_sum = ppkt->ip->ip_sum; } - res = memcmp(ppkt->data + ETH_HLEN, spkt->data + ETH_HLEN, - (spkt->size - ETH_HLEN)); + if (ptcp->th_sum == stcp->th_sum) { + res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN); + } else { + res = -1; + } if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { trace_colo_compare_pkt_info_src(inet_ntoa(ppkt->ip->ip_src), @@ -263,10 +260,22 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) { int ret; + int network_header_length = ppkt->ip->ip_hl * 4; trace_colo_compare_main("compare udp"); - ret = colo_packet_compare_common(ppkt, spkt); + /* + * Because of ppkt and spkt are both in the same connection, + * The ppkt's src ip, dst ip, src port, dst port, ip_proto all are + * same with spkt. In addition, IP header's Identification is a random + * field, we can handle it in IP fragmentation function later. + * COLO just concern the response net packet payload from primary guest + * and secondary guest are same or not, So we ignored all IP header include + * other field like TOS,TTL,IP Checksum. we only need to compare + * the ip payload here. + */ + ret = colo_packet_compare_common(ppkt, spkt, + network_header_length + ETH_HLEN); if (ret) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); @@ -284,9 +293,22 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) */ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt) { + int network_header_length = ppkt->ip->ip_hl * 4; + trace_colo_compare_main("compare icmp"); - if (colo_packet_compare_common(ppkt, spkt)) { + /* + * Because of ppkt and spkt are both in the same connection, + * The ppkt's src ip, dst ip, src port, dst port, ip_proto all are + * same with spkt. In addition, IP header's Identification is a random + * field, we can handle it in IP fragmentation function later. + * COLO just concern the response net packet payload from primary guest + * and secondary guest are same or not, So we ignored all IP header include + * other field like TOS,TTL,IP Checksum. we only need to compare + * the ip payload here. + */ + if (colo_packet_compare_common(ppkt, spkt, + network_header_length + ETH_HLEN)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", @@ -312,7 +334,7 @@ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt) inet_ntoa(ppkt->ip->ip_dst), spkt->size, inet_ntoa(spkt->ip->ip_src), inet_ntoa(spkt->ip->ip_dst)); - return colo_packet_compare_common(ppkt, spkt); + return colo_packet_compare_common(ppkt, spkt, 0); } static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time)