From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1gN2-00029L-I8 for qemu-devel@nongnu.org; Wed, 15 Aug 2012 12:23:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1gN1-0006hN-0P for qemu-devel@nongnu.org; Wed, 15 Aug 2012 12:23:00 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:49164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1gN0-0006ge-NS for qemu-devel@nongnu.org; Wed, 15 Aug 2012 12:22:58 -0400 Received: from eusync3.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8T003CH1IXNZ60@mailout1.w1.samsung.com> for qemu-devel@nongnu.org; Wed, 15 Aug 2012 17:23:21 +0100 (BST) Received: from [106.109.9.191] by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0M8T00MXY1I5L410@eusync3.samsung.com> for qemu-devel@nongnu.org; Wed, 15 Aug 2012 17:22:54 +0100 (BST) Date: Wed, 15 Aug 2012 20:22:51 +0400 From: Igor Mitsyanko In-reply-to: <1343227834-5400-8-git-send-email-owasserm@redhat.com> Message-id: <502BCCDB.8090708@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: QUOTED-PRINTABLE References: <1343227834-5400-1-git-send-email-owasserm@redhat.com> <1343227834-5400-8-git-send-email-owasserm@redhat.com> Subject: Re: [Qemu-devel] [PATCH 06/11] Add xbzrle_encode_buffer and xbzrle_decode_buffer functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Orit Wasserman Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org, eblake@redhat.com, mdroth@linux.vnet.ibm.com, blauwirbel@gmail.com, Petter Svard , Benoit Hudzia , avi@redhat.com, Aidan Shribman , pbonzini@redhat.com, lcapitulino@redhat.com, chegu_vinod@hp.com This patch broke master build, it causes compilation error with gcc 4= .6.1: /home/mackross/eclipse_linux_cdt_space/qemu_exynos4/savevm.c: In=20 function =91xbzrle_encode_buffer=92: /home/mackross/eclipse_linux_cdt_space/qemu_exynos4/savevm.c:2476:13:= =20 error: overflow in implicit constant conversion [-Werror=3Doverflow] cc1: all warnings being treated as errors make[1]: *** [savevm.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [subdir-arm-softmmu] Error 2 On 07/25/2012 06:50 PM, Orit Wasserman wrote: > For performance we are encoding long word at a time. > For nzrun we use long-word-at-a-time NULL-detection tricks from str= cmp(): > using ((lword - 0x0101010101010101) & (~lword) & 0x8080808080808080= ) test > to find out if any byte in the long word is zero. > > Signed-off-by: Benoit Hudzia > Signed-off-by: Petter Svard > Signed-off-by: Aidan Shribman > Signed-off-by: Orit Wasserman > Signed-off-by: Eric Blake > --- > migration.h | 4 ++ > savevm.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++ > 2 files changed, 163 insertions(+), 0 deletions(-) > > diff --git a/migration.h b/migration.h > index 713aae0..743c366 100644 > --- a/migration.h > +++ b/migration.h > @@ -100,4 +100,8 @@ void migrate_add_blocker(Error *reason); > */ > void migrate_del_blocker(Error *reason); > > +int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int s= len, > + uint8_t *dst, int dlen); > +int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int= dlen); > + > #endif > diff --git a/savevm.c b/savevm.c > index 6e82b2d..c5fd13f 100644 > --- a/savevm.c > +++ b/savevm.c > @@ -2392,3 +2392,162 @@ void vmstate_register_ram_global(MemoryRegi= on *mr) > { > vmstate_register_ram(mr, NULL); > } > + > +/* > + page =3D zrun nzrun > + | zrun nzrun page > + > + zrun =3D length > + > + nzrun =3D length byte... > + > + length =3D uleb128 encoded integer > + */ > +int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int s= len, > + uint8_t *dst, int dlen) > +{ > + uint32_t zrun_len =3D 0, nzrun_len =3D 0; > + int d =3D 0, i =3D 0; > + long res, xor; > + uint8_t *nzrun_start =3D NULL; > + > + g_assert(!(((uintptr_t)old_buf | (uintptr_t)new_buf | slen) % > + sizeof(long))); > + > + while (i < slen) { > + /* overflow */ > + if (d + 2 > dlen) { > + return -1; > + } > + > + /* not aligned to sizeof(long) */ > + res =3D (slen - i) % sizeof(long); > + while (res && old_buf[i] =3D=3D new_buf[i]) { > + zrun_len++; > + i++; > + res--; > + } > + > + /* word at a time for speed */ > + if (!res) { > + while (i < slen && > + (*(long *)(old_buf + i)) =3D=3D (*(long *)(new_= buf + i))) { > + i +=3D sizeof(long); > + zrun_len +=3D sizeof(long); > + } > + > + /* go over the rest */ > + while (i < slen && old_buf[i] =3D=3D new_buf[i]) { > + zrun_len++; > + i++; > + } > + } > + > + /* buffer unchanged */ > + if (zrun_len =3D=3D slen) { > + return 0; > + } > + > + /* skip last zero run */ > + if (i =3D=3D slen) { > + return d; > + } > + > + d +=3D uleb128_encode_small(dst + d, zrun_len); > + > + zrun_len =3D 0; > + nzrun_start =3D new_buf + i; > + > + /* overflow */ > + if (d + 2 > dlen) { > + return -1; > + } > + /* not aligned to sizeof(long) */ > + res =3D (slen - i) % sizeof(long); > + while (res && old_buf[i] !=3D new_buf[i]) { > + i++; > + nzrun_len++; > + res--; > + } > + > + /* word at a time for speed, use of 32-bit long okay */ > + if (!res) { > + /* truncation to 32-bit long okay */ > + long mask =3D 0x0101010101010101ULL; > + while (i < slen) { > + xor =3D *(long *)(old_buf + i) ^ *(long *)(new_buf= + i); > + if ((xor - mask) & ~xor & (mask << 7)) { > + /* found the end of an nzrun within the curren= t long */ > + while (old_buf[i] !=3D new_buf[i]) { > + nzrun_len++; > + i++; > + } > + break; > + } else { > + i +=3D sizeof(long); > + nzrun_len +=3D sizeof(long); > + } > + } > + } > + > + d +=3D uleb128_encode_small(dst + d, nzrun_len); > + /* overflow */ > + if (d + nzrun_len > dlen) { > + return -1; > + } > + memcpy(dst + d, nzrun_start, nzrun_len); > + d +=3D nzrun_len; > + nzrun_len =3D 0; > + } > + > + return d; > +} > + > +int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int= dlen) > +{ > + int i =3D 0, d =3D 0; > + int ret; > + uint32_t count =3D 0; > + > + while (i < slen) { > + > + /* zrun */ > + if ((slen - i) < 2) { > + return -1; > + } > + > + ret =3D uleb128_decode_small(src + i, &count); > + if (ret < 0 || (i && !count)) { > + return -1; > + } > + i +=3D ret; > + d +=3D count; > + > + /* overflow */ > + if (d > dlen) { > + return -1; > + } > + > + /* nzrun */ > + if ((slen - i) < 2) { > + return -1; > + } > + > + ret =3D uleb128_decode_small(src + i, &count); > + if (ret < 0 || !count) { > + return -1; > + } > + i +=3D ret; > + > + /* overflow */ > + if (d + count > dlen || i + count > slen) { > + return -1; > + } > + > + memcpy(dst + d , src + i, count); > + d +=3D count; > + i +=3D count; > + } > + > + return d; > +} >