From patchwork Mon Mar 31 11:56:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 335272 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 4C05A14003E for ; Mon, 31 Mar 2014 22:57:20 +1100 (EST) Received: from localhost ([::1]:48185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUaq5-0000Gi-7Y for incoming@patchwork.ozlabs.org; Mon, 31 Mar 2014 07:57:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUaph-0000El-RS for qemu-devel@nongnu.org; Mon, 31 Mar 2014 07:56:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUapZ-00060b-Mk for qemu-devel@nongnu.org; Mon, 31 Mar 2014 07:56:53 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:61469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUapY-0005yc-S8 for qemu-devel@nongnu.org; Mon, 31 Mar 2014 07:56:45 -0400 Received: from 172.24.2.119 (EHLO szxeml211-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BTK62277; Mon, 31 Mar 2014 19:56:32 +0800 (CST) Received: from SZXEML421-HUB.china.huawei.com (10.82.67.160) by szxeml211-edg.china.huawei.com (172.24.2.182) with Microsoft SMTP Server (TLS) id 14.3.158.1; Mon, 31 Mar 2014 19:56:32 +0800 Received: from localhost (10.177.19.102) by szxeml421-hub.china.huawei.com (10.82.67.160) with Microsoft SMTP Server id 14.3.158.1; Mon, 31 Mar 2014 19:56:23 +0800 From: To: Date: Mon, 31 Mar 2014 19:56:01 +0800 Message-ID: <1396266961-11044-3-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1396266961-11044-1-git-send-email-arei.gonglei@huawei.com> References: <1396266961-11044-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.64 Cc: ChenLiang , weidong.huang@huawei.com, quintela@redhat.com, dgilbert@redhat.com, owasserm@redhat.com, Gonglei , pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 2/2] xbzrle: check 8 bytes at a time after an concurrency scene X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: ChenLiang The logic of old code is correct. But Checking byte by byte will consume time after an concurrency scene. Reported-by: Dr. David Alan Gilbert Signed-off-by: ChenLiang Signed-off-by: Gonglei --- xbzrle.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/xbzrle.c b/xbzrle.c index bf08c56..f2824db 100644 --- a/xbzrle.c +++ b/xbzrle.c @@ -50,16 +50,24 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, /* word at a time for speed */ if (!res) { - while (i < slen && - (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { - i += sizeof(long); - zrun_len += sizeof(long); - } - - /* go over the rest */ - while (i < slen && old_buf[i] == new_buf[i]) { - zrun_len++; - i++; + while (i < slen) { + if ((*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { + i += sizeof(long); + zrun_len += sizeof(long); + } else { + /* go over the rest */ + for (j = 0; j < sizeof(long); j++) { + if (old_buf[i] == new_buf[i]) { + i++; + zrun_len++; + } else { + break; + } + } + if (j != sizeof(long)) { + break; + } + } } }