ram-compress.c: Make target independent

Make ram-compress.c target independent.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
Lukas Straub 2023-04-20 11:48:35 +02:00 committed by Juan Quintela
parent 4024cc8506
commit 52623f23b0
2 changed files with 12 additions and 8 deletions

View File

@ -23,6 +23,8 @@ softmmu_ss.add(files(
'migration.c', 'migration.c',
'multifd.c', 'multifd.c',
'multifd-zlib.c', 'multifd-zlib.c',
'multifd-zlib.c',
'ram-compress.c',
'options.c', 'options.c',
'postcopy-ram.c', 'postcopy-ram.c',
'savevm.c', 'savevm.c',
@ -40,5 +42,4 @@ softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c'))
specific_ss.add(when: 'CONFIG_SOFTMMU', specific_ss.add(when: 'CONFIG_SOFTMMU',
if_true: files('dirtyrate.c', if_true: files('dirtyrate.c',
'ram.c', 'ram.c',
'ram-compress.c',
'target.c')) 'target.c'))

View File

@ -35,7 +35,8 @@
#include "migration.h" #include "migration.h"
#include "options.h" #include "options.h"
#include "io/channel-null.h" #include "io/channel-null.h"
#include "exec/ram_addr.h" #include "exec/target_page.h"
#include "exec/ramblock.h"
CompressionStats compression_counters; CompressionStats compression_counters;
@ -156,7 +157,7 @@ int compress_threads_save_setup(void)
qemu_cond_init(&comp_done_cond); qemu_cond_init(&comp_done_cond);
qemu_mutex_init(&comp_done_lock); qemu_mutex_init(&comp_done_lock);
for (i = 0; i < thread_count; i++) { for (i = 0; i < thread_count; i++) {
comp_param[i].originbuf = g_try_malloc(TARGET_PAGE_SIZE); comp_param[i].originbuf = g_try_malloc(qemu_target_page_size());
if (!comp_param[i].originbuf) { if (!comp_param[i].originbuf) {
goto exit; goto exit;
} }
@ -192,11 +193,12 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
uint8_t *source_buf) uint8_t *source_buf)
{ {
uint8_t *p = block->host + offset; uint8_t *p = block->host + offset;
size_t page_size = qemu_target_page_size();
int ret; int ret;
assert(qemu_file_buffer_empty(f)); assert(qemu_file_buffer_empty(f));
if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { if (buffer_is_zero(p, page_size)) {
return RES_ZEROPAGE; return RES_ZEROPAGE;
} }
@ -205,8 +207,8 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
* so that we can catch up the error during compression and * so that we can catch up the error during compression and
* decompression * decompression
*/ */
memcpy(source_buf, p, TARGET_PAGE_SIZE); memcpy(source_buf, p, page_size);
ret = qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_SIZE); ret = qemu_put_compression_data(f, stream, source_buf, page_size);
if (ret < 0) { if (ret < 0) {
qemu_file_set_error(migrate_get_current()->to_dst_file, ret); qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
error_report("compressed data failed!"); error_report("compressed data failed!");
@ -336,7 +338,7 @@ static void *do_data_decompress(void *opaque)
param->des = 0; param->des = 0;
qemu_mutex_unlock(&param->mutex); qemu_mutex_unlock(&param->mutex);
pagesize = TARGET_PAGE_SIZE; pagesize = qemu_target_page_size();
ret = qemu_uncompress_data(&param->stream, des, pagesize, ret = qemu_uncompress_data(&param->stream, des, pagesize,
param->compbuf, len); param->compbuf, len);
@ -439,7 +441,8 @@ int compress_threads_load_setup(QEMUFile *f)
goto exit; goto exit;
} }
decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE)); size_t compbuf_size = compressBound(qemu_target_page_size());
decomp_param[i].compbuf = g_malloc0(compbuf_size);
qemu_mutex_init(&decomp_param[i].mutex); qemu_mutex_init(&decomp_param[i].mutex);
qemu_cond_init(&decomp_param[i].cond); qemu_cond_init(&decomp_param[i].cond);
decomp_param[i].done = true; decomp_param[i].done = true;