From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyee6-0003ms-0c for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:37:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xyee1-0000iB-5s for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:37:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyee0-0000ht-VT for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:37:21 -0500 Date: Wed, 10 Dec 2014 10:37:09 +0000 From: "Dr. David Alan Gilbert" Message-ID: <20141210103709.GB2311@work-vm> References: <1416830152-524-1-git-send-email-arei.gonglei@huawei.com> <1416830152-524-5-git-send-email-arei.gonglei@huawei.com> <20141210031810.GC27208@grmbl.mre> <5487C445.9030506@huawei.com> <20141210100242.GE27208@grmbl.mre> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141210100242.GE27208@grmbl.mre> Subject: Re: [Qemu-devel] [PATCH RESEND for 2.3 4/6] xbzrle: check 8 bytes at a time after an concurrency scene List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah Cc: ChenLiang , weidong.huang@huawei.com, quintela@redhat.com, qemu-devel@nongnu.org, peter.huangpeng@huawei.com, arei.gonglei@huawei.com, pbonzini@redhat.com * Amit Shah (amit.shah@redhat.com) wrote: > On (Wed) 10 Dec 2014 [11:55:49], ChenLiang wrote: > > On 2014/12/10 11:18, Amit Shah wrote: > > > > > On (Mon) 24 Nov 2014 [19:55:50], arei.gonglei@huawei.com wrote: > > >> From: ChenLiang > > >> > > >> The logic of old code is correct. But Checking byte by byte will > > >> consume time after an concurrency scene. > > >> > > >> 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 d27a140..0477367 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++; > > > > > > I don't see how this is different from the code it's replacing. The > > > check and increments are all the same. Difficult to see why there'll > > > be a speed benefit. Can you please explain? Do you have any > > > performance numbers for before/after? > > > > > > Thanks, > > > > > > Amit > > > > > > . > > > > > > > Hi Amit: > > > > + for (j = 0; j < sizeof(long); j++) { > > + if (old_buf[i] == new_buf[i]) { > > + i++; > > + zrun_len++; > > + } else { > > + break; > > + } > > + } > > + if (j != sizeof(long)) { > > + break; > > + } > > > > The branch of *j != sizeof(long)* may not be hit after an concurrency scene. > > so we can continue doing "(*(long *)(old_buf + i)) == (*(long *)(new_buf + i))". > > On the another side the old code does "old_buf[i] == new_buf[i]". > > Frankly, I still don't see it. > > Earlier: > > while.. > match words > while.. > match bytes > > Now: > > while.. > match words > if word mismatch > match bytes > > to me, essentially looks the same. > > I'll propose to drop this patch till we have a proper justification. Watch for the next patch; - patch 5 makes new_buf be the live, volatile memory, when that happens you could end up falling into the 'match bytes' and getting a whole word matching again because it had changed while you were processing it, and that's the change this loop does, it would flip back to processing whole words at a time again instead of getting stuck in the byte loop. (It would be rare I guess) Dave > > > Amit -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK