diff mbox series

[v2,13/13] ram-compress.c: Make target independent

Message ID aeb66513f419d1be4601393a20f73801ccfbe80d.1681983401.git.lukasstraub2@web.de (mailing list archive)
State New, archived
Headers show
Series migration/ram.c: Refactor compress code | expand

Commit Message

Lukas Straub April 20, 2023, 9:48 a.m. UTC
Make ram-compress.c target independent.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
---
 migration/meson.build    |  2 +-
 migration/ram-compress.c | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

--
2.40.0

Comments

Juan Quintela April 28, 2023, 5:29 p.m. UTC | #1
Lukas Straub <lukasstraub2@web.de> wrote:
> Make ram-compress.c target independent.
>
> Signed-off-by: Lukas Straub <lukasstraub2@web.de>

Reviewed-by: Juan Quintela <quintela@redhat.com>
diff mbox series

Patch

diff --git a/migration/meson.build b/migration/meson.build
index 262e3c9754..16f642031c 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -22,6 +22,7 @@  softmmu_ss.add(files(
   'migration.c',
   'multifd.c',
   'multifd-zlib.c',
+  'ram-compress.c',
   'postcopy-ram.c',
   'savevm.c',
   'socket.c',
@@ -38,5 +39,4 @@  softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c'))
 specific_ss.add(when: 'CONFIG_SOFTMMU',
                 if_true: files('dirtyrate.c',
                                'ram.c',
-                               'ram-compress.c',
                                'target.c'))
diff --git a/migration/ram-compress.c b/migration/ram-compress.c
index b75a9d2b9a..9f03c3cc66 100644
--- a/migration/ram-compress.c
+++ b/migration/ram-compress.c
@@ -34,7 +34,8 @@ 
 #include "qemu/error-report.h"
 #include "migration.h"
 #include "io/channel-null.h"
-#include "exec/ram_addr.h"
+#include "exec/target_page.h"
+#include "exec/ramblock.h"

 CompressionStats compression_counters;

@@ -155,7 +156,7 @@  int compress_threads_save_setup(void)
     qemu_cond_init(&comp_done_cond);
     qemu_mutex_init(&comp_done_lock);
     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) {
             goto exit;
         }
@@ -191,11 +192,12 @@  static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
                                            uint8_t *source_buf)
 {
     uint8_t *p = block->host + offset;
+    size_t page_size = qemu_target_page_size();
     int ret;

     assert(qemu_file_buffer_empty(f));

-    if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
+    if (buffer_is_zero(p, page_size)) {
         return RES_ZEROPAGE;
     }

@@ -204,8 +206,8 @@  static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
      * so that we can catch up the error during compression and
      * decompression
      */
-    memcpy(source_buf, p, TARGET_PAGE_SIZE);
-    ret = qemu_put_compression_data(f, stream, source_buf, TARGET_PAGE_SIZE);
+    memcpy(source_buf, p, page_size);
+    ret = qemu_put_compression_data(f, stream, source_buf, page_size);
     if (ret < 0) {
         qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
         error_report("compressed data failed!");
@@ -335,7 +337,7 @@  static void *do_data_decompress(void *opaque)
             param->des = 0;
             qemu_mutex_unlock(&param->mutex);

-            pagesize = TARGET_PAGE_SIZE;
+            pagesize = qemu_target_page_size();

             ret = qemu_uncompress_data(&param->stream, des, pagesize,
                                        param->compbuf, len);
@@ -438,7 +440,8 @@  int compress_threads_load_setup(QEMUFile *f)
             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_cond_init(&decomp_param[i].cond);
         decomp_param[i].done = true;