diff options
author | Anthony Liguori | 2012-08-13 23:02:11 +0200 |
---|---|---|
committer | Anthony Liguori | 2012-08-13 23:02:11 +0200 |
commit | ac839ccd8c30fe5706cc43f00e056049d6e55377 (patch) | |
tree | d2e37ee8bd7750ce1dd01c4dd6cec21a87551682 /cutils.c | |
parent | Merge remote-tracking branch 'pmaydell/arm-devs.next' into staging (diff) | |
parent | Restart optimization on stage3 update version (diff) | |
download | qemu-ac839ccd8c30fe5706cc43f00e056049d6e55377.tar.gz qemu-ac839ccd8c30fe5706cc43f00e056049d6e55377.tar.xz qemu-ac839ccd8c30fe5706cc43f00e056049d6e55377.zip |
Merge remote-tracking branch 'quintela/migration-next-20120808' into staging
* quintela/migration-next-20120808:
Restart optimization on stage3 update version
Add XBZRLE statistics
Add migration accounting for normal and duplicate pages
Change total_time to total-time in MigrationStats
Add migrate_set_cache_size command
Add XBZRLE to ram_save_block and ram_save_live
Add xbzrle_encode_buffer and xbzrle_decode_buffer functions
Add uleb encoding/decoding functions
Add cache handling functions
Add XBZRLE documentation
Add migrate-set-capabilities
Add migration capabilities
Diffstat (limited to 'cutils.c')
-rw-r--r-- | cutils.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -382,3 +382,45 @@ int qemu_parse_fd(const char *param) } return fd; } + +/* round down to the nearest power of 2*/ +int64_t pow2floor(int64_t value) +{ + if (!is_power_of_2(value)) { + value = 0x8000000000000000ULL >> clz64(value); + } + return value; +} + +/* + * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128) + * Input is limited to 14-bit numbers + */ +int uleb128_encode_small(uint8_t *out, uint32_t n) +{ + g_assert(n <= 0x3fff); + if (n < 0x80) { + *out++ = n; + return 1; + } else { + *out++ = (n & 0x7f) | 0x80; + *out++ = n >> 7; + return 2; + } +} + +int uleb128_decode_small(const uint8_t *in, uint32_t *n) +{ + if (!(*in & 0x80)) { + *n = *in++; + return 1; + } else { + *n = *in++ & 0x7f; + /* we exceed 14 bit number */ + if (*in & 0x80) { + return -1; + } + *n |= *in++ << 7; + return 2; + } +} |