From: Orit Wasserman <owasserm@redhat.com>
To: qemu-devel@nongnu.org
Cc: blauwirbel@gmail.com, stefanha@gmail.com,
Orit Wasserman <owasserm@redhat.com>,
quintela@redhat.com
Subject: [Qemu-devel] [PATCH v5 2/9] Add rle_encode and rle_decode functions Implement Run Length Encoding compression
Date: Tue, 3 Jan 2012 15:35:38 +0200 [thread overview]
Message-ID: <1325597745-29293-3-git-send-email-owasserm@redhat.com> (raw)
In-Reply-To: <1325597745-29293-1-git-send-email-owasserm@redhat.com>
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
arch_init.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index fdda277..426b34d 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -139,6 +139,9 @@ typedef struct XBRLEHeader {
uint32_t xh_cksum;
} XBRLEHeader;
+static int rle_encode(uint8_t *src, int slen, uint8_t *dst, int dlen);
+static int rle_decode(uint8_t *src, int slen, uint8_t *dst, int dlen);
+
/***********************************************************/
/* XBRLE page cache implementation */
static CacheItem *cache_item_get(unsigned long pos, int item)
@@ -277,6 +280,61 @@ static void cache_insert(unsigned long addr, uint8_t *pdata)
it->it_addr = addr;
}
+/* XBRLE (Xor Based Run-Length Encoding) */
+static int rle_encode(uint8_t *src, int slen, uint8_t *dst, int dlen)
+{
+ int d = 0, ch_run = 0, i;
+ uint8_t prev = 0, ch = 0;
+
+ for (i = 0; i <= slen; i++) {
+ if (i != slen) {
+ ch = src[i];
+ }
+
+ if (!i || (i != slen && ch == prev && ch_run < 255)) {
+ ch_run++;
+ } else {
+ if (d+2 > dlen) {
+ return -1;
+ }
+ *dst++ = ch_run;
+ *dst++ = prev;
+ d += 2;
+ ch_run = 1;
+ }
+
+ prev = ch;
+ }
+ return d;
+}
+
+static int rle_decode(uint8_t *src, int slen, uint8_t *dst, int dlen)
+{
+ int d = 0, s;
+
+ for (s = 0; s < slen-1; s += 2) {
+ uint8_t ch_run = src[s];
+ uint8_t ch = src[s+1];
+ while (ch_run--) {
+ if (d == dlen) {
+ return -1;
+ }
+ dst[d] = ch;
+ d++;
+ }
+ }
+ return d;
+}
+
+static void xor_encode(uint8_t *dst, uint8_t *src1, uint8_t *src2)
+{
+ int i;
+
+ for (i = 0; i < TARGET_PAGE_SIZE; i++) {
+ dst[i] = src1[i] ^ src2[i];
+ }
+}
+
static int is_dup_page(uint8_t *page, uint8_t ch)
{
uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
--
1.7.6.5
next prev parent reply other threads:[~2012-01-03 21:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-03 13:35 [Qemu-devel] [PATCH v5 0/9] XBZRLE delta for live migration of large memory apps Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 1/9] Add cache handling functions Orit Wasserman
2012-01-03 13:35 ` Orit Wasserman [this message]
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 3/9] Add save_block_hdr function Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 4/9] Add host_from_stream_offset_versioned function Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 5/9] Add XBRLE to ram_save_block and ram_save_live Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 6/9] Add xbrle parameters to MigrationState Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 7/9] Add set_cachesize to change XBRLE cache size Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 8/9] QMP commands changes Orit Wasserman
2012-01-03 13:35 ` [Qemu-devel] [PATCH v5 9/9] Add XBRLE statistics information Orit Wasserman
-- strict thread matches above, loose matches on Subject: below --
2012-01-03 15:34 [Qemu-devel] [PATCH v5 0/9] XBZRLE delta for live migration of large memory apps Orit Wasserman
2012-01-03 15:34 ` [Qemu-devel] [PATCH v5 2/9] Add rle_encode and rle_decode functions Implement Run Length Encoding compression Orit Wasserman
2012-01-03 19:57 ` Anthony Liguori
2012-01-04 9:31 ` Orit Wasserman
2012-01-04 16:52 ` Paolo Bonzini
2012-01-04 12:59 ` Avi Kivity
2012-01-04 13:35 ` Stefan Hajnoczi
2012-01-04 13:45 ` Avi Kivity
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=1325597745-29293-3-git-send-email-owasserm@redhat.com \
--to=owasserm@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@gmail.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).