From: Paolo Bonzini <pbonzini@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>, arei.gonglei@huawei.com
Cc: ChenLiang <chenliang88@huawei.com>,
weidong.huang@huawei.com, qemu-devel@nongnu.org,
quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/2] xbzrle: don't check the value in the vm ram repeatedly
Date: Mon, 31 Mar 2014 23:03:34 +0200 [thread overview]
Message-ID: <5339D826.6030305@redhat.com> (raw)
In-Reply-To: <20140331140028.GA11125@work-vm>
Il 31/03/2014 16:00, Dr. David Alan Gilbert ha scritto:
> * arei.gonglei@huawei.com (arei.gonglei@huawei.com) wrote:
>> From: ChenLiang <chenliang88@huawei.com>
>>
>> xbzrle_encode_buffer checks the value in the vm ram repeatedly.
>> It is risk if runs xbzrle_encode_buffer on changing data.
>> And it is not necessary.
>>
>> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>> Signed-off-by: ChenLiang <chenliang88@huawei.com>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> ---
>> xbzrle.c | 20 +++++++++++++++-----
>> 1 file changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/xbzrle.c b/xbzrle.c
>> index fbcb35d..bf08c56 100644
>> --- a/xbzrle.c
>> +++ b/xbzrle.c
>> @@ -27,7 +27,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
>> uint8_t *dst, int dlen)
>> {
>> uint32_t zrun_len = 0, nzrun_len = 0;
>> - int d = 0, i = 0;
>> + int d = 0, i = 0, j;
>> long res, xor;
>> uint8_t *nzrun_start = NULL;
>>
>> @@ -82,6 +82,8 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
>> if (d + 2 > dlen) {
>> return -1;
>> }
>> + i++;
>> + nzrun_len++;
>> /* not aligned to sizeof(long) */
>> res = (slen - i) % sizeof(long);
>> while (res && old_buf[i] != new_buf[i]) {
>> @@ -98,11 +100,17 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
>> xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);
>> if ((xor - mask) & ~xor & (mask << 7)) {
>> /* found the end of an nzrun within the current long */
>> - while (old_buf[i] != new_buf[i]) {
>> - nzrun_len++;
>> - i++;
>> + for (j = 0; j < sizeof(long); j++) {
>> + if (old_buf[i] != new_buf[i]) {
>> + nzrun_len++;
>> + i++;
>> + } else {
>> + break;
>> + }
>> + }
>> + if (j != sizeof(long)) {
>> + break;
>
> I wonder if it would be easier just to use the value of 'xor' - since that
> already contains the value that we read, and if we've got this far is guaranteed
> to have a none-equal byte in it. That would be something like (untested):
>
> for (j = 0; j < sizeof(long); j++) {
> if (get_byte(xor, j) != 0) {
> break;
> }
> }
> nzrun_len += j;
> i += j;
Or this:
#ifdef HOST_WORDS_BIGENDIAN
j = clzl(xor) >> 3;
#else
j = ctzl(xor) >> 3;
#endif
nzrun_len += j;
i += j;
Paolo
next prev parent reply other threads:[~2014-03-31 21:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-31 11:55 [Qemu-devel] [PATCH v2 0/2] xbzrle: fix one corruption issue arei.gonglei
2014-03-31 11:56 ` [Qemu-devel] [PATCH v2 1/2] xbzrle: don't check the value in the vm ram repeatedly arei.gonglei
2014-03-31 14:00 ` Dr. David Alan Gilbert
2014-03-31 21:03 ` Paolo Bonzini [this message]
2014-03-31 11:56 ` [Qemu-devel] [PATCH v2 2/2] xbzrle: check 8 bytes at a time after an concurrency scene arei.gonglei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5339D826.6030305@redhat.com \
--to=pbonzini@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=chenliang88@huawei.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=weidong.huang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).