qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v7 05/11] Add XBZRLE to ram_save_block and ram_s


From: Avi Kivity
Subject: Re: [Qemu-devel] [PATCH v7 05/11] Add XBZRLE to ram_save_block and ram_save_live
Date: Sun, 29 Jan 2012 12:52:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0

On 01/26/2012 04:24 PM, Orit Wasserman wrote:
> Add migration state to store XBRLE params (enablement and cache size).
> In the outgoing migration check to see if the page is cached and
> changed than send compressed page by using save_xbrle_page function.
> In the incoming migration check to see if RAM_SAVE_FLAG_XBRLE is set
> and decompress the page (by using load_xbrle function).
>
> +/* XBZRLE (Xor Based Zero Length Encoding */
> +typedef struct XBZRLEHeader {
> +    uint8_t xh_flags;
> +    uint16_t xh_len;
> +    uint32_t xh_cksum;
> +} XBZRLEHeader;

__attribute__((packed))

> +
> +/* RAM Migration State */
> +typedef struct ArchMigrationState {
> +    int use_xbzrle;
> +    int64_t xbzrle_cache_size;
> +} ArchMigrationState;
> +
> +static ArchMigrationState arch_mig_state;

Strange name.

>  
> +#define ENCODING_FLAG_XBZRLE 0x1
> +
> +static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
> +                            ram_addr_t current_addr, RAMBlock *block,
> +                            ram_addr_t offset, int cont)
> +{

...

> +    /* Send XBZRLE based compressed page */
> +    save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
> +    qemu_put_buffer(f, (uint8_t *) &hdr, sizeof(hdr));

Or better, encode the members separately so they get proper endian encoding.

> +    qemu_put_buffer(f, encoded_buf, encoded_len);
> +    bytes_sent = encoded_len + sizeof(hdr);
> +
> +done:
> +    g_free(encoded_buf);
> +    return bytes_sent;
> +}
> +
>  static RAMBlock *last_block;
>  static ram_addr_t last_offset;
>  
>
>  
> +/*
> +  page = zrun
> +       | zrun nzrun
> +       | zrun nzrun page

This is no longer accurate.

> +
> +  zrun = length
> +
> +  nzrun = length byte...
> +
> +  length = uleb128 encoded integer
> + */
> +int encode_page(uint8_t *old_buf, uint8_t *new_buf, int slen, uint8_t *dst,
> +                int dlen)
> +{
...
> +}
> +
> +int decode_page(uint8_t *src, int slen, uint8_t *dst, int dlen)
> +{
> +    int i = 0, d = 0;
> +    uint32_t count = 0;
> +
> +    while (i < slen - 1) {
> +        /* zrun */
> +        i += uleb128_decode_small(src + i, &count);
> +        d += count;
> +
> +        /* overflow */
> +        if (d > dlen) {
> +            return -1;

assert instead?

> +        }
> +
> +        /* completed decoding */
> +        if (i == slen) {
> +            return d + 1;
> +        }
> +
> +        /* nzrun */
> +        i += uleb128_decode_small(src + i, &count);
> +        /* overflow */
> +        if (d + count > dlen) {
> +            return -1;
> +        }
> +        memcpy(dst + d, src + i, count);
> +        d += count;
> +        i += count;
> +    }
> +

memset() for the tail?

> +    return d + 1;
> +}


-- 
error compiling committee.c: too many arguments to function




reply via email to

[Prev in Thread] Current Thread [Next in Thread]