qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 00/21] Migration 20230428 patches
@ 2023-04-28 19:11 Juan Quintela
  2023-04-28 19:11 ` [PULL 01/21] multifd: We already account for this packet on the multifd thread Juan Quintela
                   ` (21 more replies)
  0 siblings, 22 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu

The following changes since commit 05d50ba2d4668d43a835c5a502efdec9b92646e6:

  Merge tag 'migration-20230427-pull-request' of https://gitlab.com/juan.quintela/qemu into staging (2023-04-28 08:35:06 +0100)

are available in the Git repository at:

  https://gitlab.com/juan.quintela/qemu.git tags/migration-20230428-pull-request

for you to fetch changes up to 05ecac612ec6a4bdb358e68554b4406ac2c8e25a:

  migration: Initialize and cleanup decompression in migration.c (2023-04-28 20:54:53 +0200)

----------------------------------------------------------------
Migration Pull request (20230429 vintage)

Hi

In this series:
- compression code cleanup (lukas)
  nice, nice, nice.
- drop useless parameters from migration_tls* (juan)
- first part of remove QEMUFileHooks series (juan)

Please apply.

----------------------------------------------------------------

Juan Quintela (8):
  multifd: We already account for this packet on the multifd thread
  migration: Move ram_stats to its own file migration-stats.[ch]
  migration: Rename ram_counters to mig_stats
  migration: Rename RAMStats to MigrationAtomicStats
  migration/rdma: Split the zero page case from acct_update_position
  migration/rdma: Unfold last user of acct_update_position()
  migration: Drop unused parameter for migration_tls_get_creds()
  migration: Drop unused parameter for migration_tls_client_create()

Lukas Straub (13):
  qtest/migration-test.c: Add tests with compress enabled
  qtest/migration-test.c: Add postcopy tests with compress enabled
  ram.c: Let the compress threads return a CompressResult enum
  ram.c: Dont change param->block in the compress thread
  ram.c: Reset result after sending queued data
  ram.c: Do not call save_page_header() from compress threads
  ram.c: Call update_compress_thread_counts from
    compress_send_queued_data
  ram.c: Remove last ram.c dependency from the core compress code
  ram.c: Move core compression code into its own file
  ram.c: Move core decompression code into its own file
  ram compress: Assert that the file buffer matches the result
  ram-compress.c: Make target independent
  migration: Initialize and cleanup decompression in migration.c

 migration/meson.build        |   7 +-
 migration/migration-stats.c  |  17 ++
 migration/migration-stats.h  |  41 +++
 migration/migration.c        |  42 ++-
 migration/multifd.c          |  12 +-
 migration/postcopy-ram.c     |   2 +-
 migration/qemu-file.c        |  11 +
 migration/qemu-file.h        |   1 +
 migration/ram-compress.c     | 485 ++++++++++++++++++++++++++++++
 migration/ram-compress.h     |  70 +++++
 migration/ram.c              | 562 ++++-------------------------------
 migration/ram.h              |  24 --
 migration/rdma.c             |   9 +-
 migration/savevm.c           |   3 +-
 migration/tls.c              |  15 +-
 migration/tls.h              |   3 +-
 tests/qtest/migration-test.c | 126 ++++++++
 17 files changed, 870 insertions(+), 560 deletions(-)
 create mode 100644 migration/migration-stats.c
 create mode 100644 migration/migration-stats.h
 create mode 100644 migration/ram-compress.c
 create mode 100644 migration/ram-compress.h

-- 
2.40.0



^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PULL 01/21] multifd: We already account for this packet on the multifd thread
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 02/21] migration: Move ram_stats to its own file migration-stats.[ch] Juan Quintela
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
---
 migration/multifd.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/migration/multifd.c b/migration/multifd.c
index 6a59c03dd2..6053012ad9 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -626,10 +626,7 @@ int multifd_send_sync_main(QEMUFile *f)
         p->packet_num = multifd_send_state->packet_num++;
         p->flags |= MULTIFD_FLAG_SYNC;
         p->pending_job++;
-        qemu_file_acct_rate_limit(f, p->packet_len);
         qemu_mutex_unlock(&p->mutex);
-        stat64_add(&ram_counters.transferred, p->packet_len);
-        stat64_add(&ram_counters.multifd_bytes, p->packet_len);
         qemu_sem_post(&p->sem);
     }
     for (i = 0; i < migrate_multifd_channels(); i++) {
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 02/21] migration: Move ram_stats to its own file migration-stats.[ch]
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
  2023-04-28 19:11 ` [PULL 01/21] multifd: We already account for this packet on the multifd thread Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 03/21] migration: Rename ram_counters to mig_stats Juan Quintela
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

There is already include/qemu/stats.h, so stats.h was a bad idea.
We want this file to not depend on anything else, we will move all the
migration counters/stats to this struct.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
---
 migration/meson.build       |  1 +
 migration/migration-stats.c | 17 +++++++++++++++
 migration/migration-stats.h | 41 +++++++++++++++++++++++++++++++++++++
 migration/migration.c       |  1 +
 migration/multifd.c         |  1 +
 migration/ram.c             |  3 +--
 migration/ram.h             | 23 ---------------------
 migration/savevm.c          |  1 +
 8 files changed, 63 insertions(+), 25 deletions(-)
 create mode 100644 migration/migration-stats.c
 create mode 100644 migration/migration-stats.h

diff --git a/migration/meson.build b/migration/meson.build
index 480ff6854a..da1897fadf 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -19,6 +19,7 @@ softmmu_ss.add(files(
   'fd.c',
   'global_state.c',
   'migration-hmp-cmds.c',
+  'migration-stats.c',
   'migration.c',
   'multifd.c',
   'multifd-zlib.c',
diff --git a/migration/migration-stats.c b/migration/migration-stats.c
new file mode 100644
index 0000000000..b0eb5ae73c
--- /dev/null
+++ b/migration/migration-stats.c
@@ -0,0 +1,17 @@
+/*
+ * Migration stats
+ *
+ * Copyright (c) 2012-2023 Red Hat Inc
+ *
+ * Authors:
+ *  Juan Quintela <quintela@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/stats64.h"
+#include "migration-stats.h"
+
+RAMStats ram_counters;
diff --git a/migration/migration-stats.h b/migration/migration-stats.h
new file mode 100644
index 0000000000..2edea0c779
--- /dev/null
+++ b/migration/migration-stats.h
@@ -0,0 +1,41 @@
+/*
+ * Migration stats
+ *
+ * Copyright (c) 2012-2023 Red Hat Inc
+ *
+ * Authors:
+ *  Juan Quintela <quintela@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_MIGRATION_STATS_H
+#define QEMU_MIGRATION_STATS_H
+
+#include "qemu/stats64.h"
+
+/*
+ * These are the ram migration statistic counters.  It is loosely
+ * based on MigrationStats.  We change to Stat64 any counter that
+ * needs to be updated using atomic ops (can be accessed by more than
+ * one thread).
+ */
+typedef struct {
+    Stat64 dirty_bytes_last_sync;
+    Stat64 dirty_pages_rate;
+    Stat64 dirty_sync_count;
+    Stat64 dirty_sync_missed_zero_copy;
+    Stat64 downtime_bytes;
+    Stat64 zero_pages;
+    Stat64 multifd_bytes;
+    Stat64 normal_pages;
+    Stat64 postcopy_bytes;
+    Stat64 postcopy_requests;
+    Stat64 precopy_bytes;
+    Stat64 transferred;
+} RAMStats;
+
+extern RAMStats ram_counters;
+
+#endif
diff --git a/migration/migration.c b/migration/migration.c
index abcadbb619..5ecf3dc381 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -29,6 +29,7 @@
 #include "migration/global_state.h"
 #include "migration/misc.h"
 #include "migration.h"
+#include "migration-stats.h"
 #include "savevm.h"
 #include "qemu-file.h"
 #include "channel.h"
diff --git a/migration/multifd.c b/migration/multifd.c
index 6053012ad9..347999f84a 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -19,6 +19,7 @@
 #include "qapi/error.h"
 #include "ram.h"
 #include "migration.h"
+#include "migration-stats.h"
 #include "socket.h"
 #include "tls.h"
 #include "qemu-file.h"
diff --git a/migration/ram.c b/migration/ram.c
index 89be3e3320..a6d5478ef8 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -36,6 +36,7 @@
 #include "xbzrle.h"
 #include "ram.h"
 #include "migration.h"
+#include "migration-stats.h"
 #include "migration/register.h"
 #include "migration/misc.h"
 #include "qemu-file.h"
@@ -460,8 +461,6 @@ uint64_t ram_bytes_remaining(void)
                        0;
 }
 
-RAMStats ram_counters;
-
 void ram_transferred_add(uint64_t bytes)
 {
     if (runstate_is_running()) {
diff --git a/migration/ram.h b/migration/ram.h
index 04b05e1b2c..8692de6ba0 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -32,30 +32,7 @@
 #include "qapi/qapi-types-migration.h"
 #include "exec/cpu-common.h"
 #include "io/channel.h"
-#include "qemu/stats64.h"
 
-/*
- * These are the ram migration statistic counters.  It is loosely
- * based on MigrationStats.  We change to Stat64 any counter that
- * needs to be updated using atomic ops (can be accessed by more than
- * one thread).
- */
-typedef struct {
-    Stat64 dirty_bytes_last_sync;
-    Stat64 dirty_pages_rate;
-    Stat64 dirty_sync_count;
-    Stat64 dirty_sync_missed_zero_copy;
-    Stat64 downtime_bytes;
-    Stat64 zero_pages;
-    Stat64 multifd_bytes;
-    Stat64 normal_pages;
-    Stat64 postcopy_bytes;
-    Stat64 postcopy_requests;
-    Stat64 precopy_bytes;
-    Stat64 transferred;
-} RAMStats;
-
-extern RAMStats ram_counters;
 extern XBZRLECacheStats xbzrle_counters;
 extern CompressionStats compression_counters;
 
diff --git a/migration/savevm.c b/migration/savevm.c
index a9181b444b..8e2efb1a19 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -31,6 +31,7 @@
 #include "net/net.h"
 #include "migration.h"
 #include "migration/snapshot.h"
+#include "migration-stats.h"
 #include "migration/vmstate.h"
 #include "migration/misc.h"
 #include "migration/register.h"
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 03/21] migration: Rename ram_counters to mig_stats
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
  2023-04-28 19:11 ` [PULL 01/21] multifd: We already account for this packet on the multifd thread Juan Quintela
  2023-04-28 19:11 ` [PULL 02/21] migration: Move ram_stats to its own file migration-stats.[ch] Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 04/21] migration: Rename RAMStats to MigrationAtomicStats Juan Quintela
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

migration_stats is just too long, and it is going to have more than
ram counters in the near future.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
---
 migration/migration-stats.c |  2 +-
 migration/migration-stats.h |  2 +-
 migration/migration.c       | 32 ++++++++++++-------------
 migration/multifd.c         |  6 ++---
 migration/ram.c             | 48 ++++++++++++++++++-------------------
 migration/savevm.c          |  2 +-
 6 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/migration/migration-stats.c b/migration/migration-stats.c
index b0eb5ae73c..8c0af9b80a 100644
--- a/migration/migration-stats.c
+++ b/migration/migration-stats.c
@@ -14,4 +14,4 @@
 #include "qemu/stats64.h"
 #include "migration-stats.h"
 
-RAMStats ram_counters;
+RAMStats mig_stats;
diff --git a/migration/migration-stats.h b/migration/migration-stats.h
index 2edea0c779..197374b4f6 100644
--- a/migration/migration-stats.h
+++ b/migration/migration-stats.h
@@ -36,6 +36,6 @@ typedef struct {
     Stat64 transferred;
 } RAMStats;
 
-extern RAMStats ram_counters;
+extern RAMStats mig_stats;
 
 #endif
diff --git a/migration/migration.c b/migration/migration.c
index 5ecf3dc381..feb5ab7493 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -909,26 +909,26 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)
     size_t page_size = qemu_target_page_size();
 
     info->ram = g_malloc0(sizeof(*info->ram));
-    info->ram->transferred = stat64_get(&ram_counters.transferred);
+    info->ram->transferred = stat64_get(&mig_stats.transferred);
     info->ram->total = ram_bytes_total();
-    info->ram->duplicate = stat64_get(&ram_counters.zero_pages);
+    info->ram->duplicate = stat64_get(&mig_stats.zero_pages);
     /* legacy value.  It is not used anymore */
     info->ram->skipped = 0;
-    info->ram->normal = stat64_get(&ram_counters.normal_pages);
+    info->ram->normal = stat64_get(&mig_stats.normal_pages);
     info->ram->normal_bytes = info->ram->normal * page_size;
     info->ram->mbps = s->mbps;
     info->ram->dirty_sync_count =
-        stat64_get(&ram_counters.dirty_sync_count);
+        stat64_get(&mig_stats.dirty_sync_count);
     info->ram->dirty_sync_missed_zero_copy =
-        stat64_get(&ram_counters.dirty_sync_missed_zero_copy);
+        stat64_get(&mig_stats.dirty_sync_missed_zero_copy);
     info->ram->postcopy_requests =
-        stat64_get(&ram_counters.postcopy_requests);
+        stat64_get(&mig_stats.postcopy_requests);
     info->ram->page_size = page_size;
-    info->ram->multifd_bytes = stat64_get(&ram_counters.multifd_bytes);
+    info->ram->multifd_bytes = stat64_get(&mig_stats.multifd_bytes);
     info->ram->pages_per_second = s->pages_per_second;
-    info->ram->precopy_bytes = stat64_get(&ram_counters.precopy_bytes);
-    info->ram->downtime_bytes = stat64_get(&ram_counters.downtime_bytes);
-    info->ram->postcopy_bytes = stat64_get(&ram_counters.postcopy_bytes);
+    info->ram->precopy_bytes = stat64_get(&mig_stats.precopy_bytes);
+    info->ram->downtime_bytes = stat64_get(&mig_stats.downtime_bytes);
+    info->ram->postcopy_bytes = stat64_get(&mig_stats.postcopy_bytes);
 
     if (migrate_xbzrle()) {
         info->xbzrle_cache = g_malloc0(sizeof(*info->xbzrle_cache));
@@ -960,7 +960,7 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)
     if (s->state != MIGRATION_STATUS_COMPLETED) {
         info->ram->remaining = ram_bytes_remaining();
         info->ram->dirty_pages_rate =
-           stat64_get(&ram_counters.dirty_pages_rate);
+           stat64_get(&mig_stats.dirty_pages_rate);
     }
 }
 
@@ -1613,10 +1613,10 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
 
     migrate_init(s);
     /*
-     * set ram_counters compression_counters memory to zero for a
+     * set mig_stats compression_counters memory to zero for a
      * new migration
      */
-    memset(&ram_counters, 0, sizeof(ram_counters));
+    memset(&mig_stats, 0, sizeof(mig_stats));
     memset(&compression_counters, 0, sizeof(compression_counters));
 
     return true;
@@ -2627,7 +2627,7 @@ static MigThrError migration_detect_error(MigrationState *s)
 static uint64_t migration_total_bytes(MigrationState *s)
 {
     return qemu_file_total_transferred(s->to_dst_file) +
-        stat64_get(&ram_counters.multifd_bytes);
+        stat64_get(&mig_stats.multifd_bytes);
 }
 
 static void migration_calculate_complete(MigrationState *s)
@@ -2691,10 +2691,10 @@ static void migration_update_counters(MigrationState *s,
      * if we haven't sent anything, we don't want to
      * recalculate. 10000 is a small enough number for our purposes
      */
-    if (stat64_get(&ram_counters.dirty_pages_rate) &&
+    if (stat64_get(&mig_stats.dirty_pages_rate) &&
         transferred > 10000) {
         s->expected_downtime =
-            stat64_get(&ram_counters.dirty_bytes_last_sync) / bandwidth;
+            stat64_get(&mig_stats.dirty_bytes_last_sync) / bandwidth;
     }
 
     qemu_file_reset_rate_limit(s->to_dst_file);
diff --git a/migration/multifd.c b/migration/multifd.c
index 347999f84a..4a2e1a47ce 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -434,8 +434,8 @@ static int multifd_send_pages(QEMUFile *f)
     transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
     qemu_file_acct_rate_limit(f, transferred);
     qemu_mutex_unlock(&p->mutex);
-    stat64_add(&ram_counters.transferred, transferred);
-    stat64_add(&ram_counters.multifd_bytes, transferred);
+    stat64_add(&mig_stats.transferred, transferred);
+    stat64_add(&mig_stats.multifd_bytes, transferred);
     qemu_sem_post(&p->sem);
 
     return 1;
@@ -577,7 +577,7 @@ static int multifd_zero_copy_flush(QIOChannel *c)
         return -1;
     }
     if (ret == 1) {
-        stat64_add(&ram_counters.dirty_sync_missed_zero_copy, 1);
+        stat64_add(&mig_stats.dirty_sync_missed_zero_copy, 1);
     }
 
     return ret;
diff --git a/migration/ram.c b/migration/ram.c
index a6d5478ef8..c3981f64e4 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -464,13 +464,13 @@ uint64_t ram_bytes_remaining(void)
 void ram_transferred_add(uint64_t bytes)
 {
     if (runstate_is_running()) {
-        stat64_add(&ram_counters.precopy_bytes, bytes);
+        stat64_add(&mig_stats.precopy_bytes, bytes);
     } else if (migration_in_postcopy()) {
-        stat64_add(&ram_counters.postcopy_bytes, bytes);
+        stat64_add(&mig_stats.postcopy_bytes, bytes);
     } else {
-        stat64_add(&ram_counters.downtime_bytes, bytes);
+        stat64_add(&mig_stats.downtime_bytes, bytes);
     }
-    stat64_add(&ram_counters.transferred, bytes);
+    stat64_add(&mig_stats.transferred, bytes);
 }
 
 struct MigrationOps {
@@ -744,7 +744,7 @@ void mig_throttle_counter_reset(void)
 
     rs->time_last_bitmap_sync = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
     rs->num_dirty_pages_period = 0;
-    rs->bytes_xfer_prev = stat64_get(&ram_counters.transferred);
+    rs->bytes_xfer_prev = stat64_get(&mig_stats.transferred);
 }
 
 /**
@@ -764,7 +764,7 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr)
     /* We don't care if this fails to allocate a new cache page
      * as long as it updated an old one */
     cache_insert(XBZRLE.cache, current_addr, XBZRLE.zero_target_page,
-                 stat64_get(&ram_counters.dirty_sync_count));
+                 stat64_get(&mig_stats.dirty_sync_count));
 }
 
 #define ENCODING_FLAG_XBZRLE 0x1
@@ -790,7 +790,7 @@ static int save_xbzrle_page(RAMState *rs, PageSearchStatus *pss,
     int encoded_len = 0, bytes_xbzrle;
     uint8_t *prev_cached_page;
     QEMUFile *file = pss->pss_channel;
-    uint64_t generation = stat64_get(&ram_counters.dirty_sync_count);
+    uint64_t generation = stat64_get(&mig_stats.dirty_sync_count);
 
     if (!cache_is_cached(XBZRLE.cache, current_addr, generation)) {
         xbzrle_counters.cache_miss++;
@@ -1118,8 +1118,8 @@ uint64_t ram_pagesize_summary(void)
 
 uint64_t ram_get_total_transferred_pages(void)
 {
-    return stat64_get(&ram_counters.normal_pages) +
-        stat64_get(&ram_counters.zero_pages) +
+    return stat64_get(&mig_stats.normal_pages) +
+        stat64_get(&mig_stats.zero_pages) +
         compression_counters.pages + xbzrle_counters.pages;
 }
 
@@ -1129,7 +1129,7 @@ static void migration_update_rates(RAMState *rs, int64_t end_time)
     double compressed_size;
 
     /* calculate period counters */
-    stat64_set(&ram_counters.dirty_pages_rate,
+    stat64_set(&mig_stats.dirty_pages_rate,
                rs->num_dirty_pages_period * 1000 /
                (end_time - rs->time_last_bitmap_sync));
 
@@ -1180,7 +1180,7 @@ static void migration_trigger_throttle(RAMState *rs)
 {
     uint64_t threshold = migrate_throttle_trigger_threshold();
     uint64_t bytes_xfer_period =
-        stat64_get(&ram_counters.transferred) - rs->bytes_xfer_prev;
+        stat64_get(&mig_stats.transferred) - rs->bytes_xfer_prev;
     uint64_t bytes_dirty_period = rs->num_dirty_pages_period * TARGET_PAGE_SIZE;
     uint64_t bytes_dirty_threshold = bytes_xfer_period * threshold / 100;
 
@@ -1209,7 +1209,7 @@ static void migration_bitmap_sync(RAMState *rs)
     RAMBlock *block;
     int64_t end_time;
 
-    stat64_add(&ram_counters.dirty_sync_count, 1);
+    stat64_add(&mig_stats.dirty_sync_count, 1);
 
     if (!rs->time_last_bitmap_sync) {
         rs->time_last_bitmap_sync = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
@@ -1223,7 +1223,7 @@ static void migration_bitmap_sync(RAMState *rs)
         RAMBLOCK_FOREACH_NOT_IGNORED(block) {
             ramblock_sync_dirty_bitmap(rs, block);
         }
-        stat64_set(&ram_counters.dirty_bytes_last_sync, ram_bytes_remaining());
+        stat64_set(&mig_stats.dirty_bytes_last_sync, ram_bytes_remaining());
     }
     qemu_mutex_unlock(&rs->bitmap_mutex);
 
@@ -1243,10 +1243,10 @@ static void migration_bitmap_sync(RAMState *rs)
         /* reset period counters */
         rs->time_last_bitmap_sync = end_time;
         rs->num_dirty_pages_period = 0;
-        rs->bytes_xfer_prev = stat64_get(&ram_counters.transferred);
+        rs->bytes_xfer_prev = stat64_get(&mig_stats.transferred);
     }
     if (migrate_events()) {
-        uint64_t generation = stat64_get(&ram_counters.dirty_sync_count);
+        uint64_t generation = stat64_get(&mig_stats.dirty_sync_count);
         qapi_event_send_migration_pass(generation);
     }
 }
@@ -1320,7 +1320,7 @@ static int save_zero_page(PageSearchStatus *pss, QEMUFile *f, RAMBlock *block,
     int len = save_zero_page_to_file(pss, f, block, offset);
 
     if (len) {
-        stat64_add(&ram_counters.zero_pages, 1);
+        stat64_add(&mig_stats.zero_pages, 1);
         ram_transferred_add(len);
         return 1;
     }
@@ -1357,9 +1357,9 @@ static bool control_save_page(PageSearchStatus *pss, RAMBlock *block,
     }
 
     if (bytes_xmit > 0) {
-        stat64_add(&ram_counters.normal_pages, 1);
+        stat64_add(&mig_stats.normal_pages, 1);
     } else if (bytes_xmit == 0) {
-        stat64_add(&ram_counters.zero_pages, 1);
+        stat64_add(&mig_stats.zero_pages, 1);
     }
 
     return true;
@@ -1391,7 +1391,7 @@ static int save_normal_page(PageSearchStatus *pss, RAMBlock *block,
         qemu_put_buffer(file, buf, TARGET_PAGE_SIZE);
     }
     ram_transferred_add(TARGET_PAGE_SIZE);
-    stat64_add(&ram_counters.normal_pages, 1);
+    stat64_add(&mig_stats.normal_pages, 1);
     return 1;
 }
 
@@ -1447,7 +1447,7 @@ static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block,
     if (multifd_queue_page(file, block, offset) < 0) {
         return -1;
     }
-    stat64_add(&ram_counters.normal_pages, 1);
+    stat64_add(&mig_stats.normal_pages, 1);
 
     return 1;
 }
@@ -1486,7 +1486,7 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit)
     ram_transferred_add(bytes_xmit);
 
     if (param->zero_page) {
-        stat64_add(&ram_counters.zero_pages, 1);
+        stat64_add(&mig_stats.zero_pages, 1);
         return;
     }
 
@@ -2179,7 +2179,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
     RAMBlock *ramblock;
     RAMState *rs = ram_state;
 
-    stat64_add(&ram_counters.postcopy_requests, 1);
+    stat64_add(&mig_stats.postcopy_requests, 1);
     RCU_READ_LOCK_GUARD();
 
     if (!rbname) {
@@ -2634,9 +2634,9 @@ void acct_update_position(QEMUFile *f, size_t size, bool zero)
     uint64_t pages = size / TARGET_PAGE_SIZE;
 
     if (zero) {
-        stat64_add(&ram_counters.zero_pages, pages);
+        stat64_add(&mig_stats.zero_pages, pages);
     } else {
-        stat64_add(&ram_counters.normal_pages, pages);
+        stat64_add(&mig_stats.normal_pages, pages);
         ram_transferred_add(size);
         qemu_file_credit_transfer(f, size);
     }
diff --git a/migration/savevm.c b/migration/savevm.c
index 8e2efb1a19..a9d0a88e62 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1622,7 +1622,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
     }
 
     migrate_init(ms);
-    memset(&ram_counters, 0, sizeof(ram_counters));
+    memset(&mig_stats, 0, sizeof(mig_stats));
     memset(&compression_counters, 0, sizeof(compression_counters));
     ms->to_dst_file = f;
 
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 04/21] migration: Rename RAMStats to MigrationAtomicStats
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (2 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 03/21] migration: Rename ram_counters to mig_stats Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 05/21] migration/rdma: Split the zero page case from acct_update_position Juan Quintela
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

It is lousely based on MigrationStats, but that name is taken, so this
is the best one that I came with.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>

---

If you have any good suggestion for the name, I am all ears.
---
 migration/migration-stats.c | 2 +-
 migration/migration-stats.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/migration/migration-stats.c b/migration/migration-stats.c
index 8c0af9b80a..2f2cea965c 100644
--- a/migration/migration-stats.c
+++ b/migration/migration-stats.c
@@ -14,4 +14,4 @@
 #include "qemu/stats64.h"
 #include "migration-stats.h"
 
-RAMStats mig_stats;
+MigrationAtomicStats mig_stats;
diff --git a/migration/migration-stats.h b/migration/migration-stats.h
index 197374b4f6..149af932d7 100644
--- a/migration/migration-stats.h
+++ b/migration/migration-stats.h
@@ -34,8 +34,8 @@ typedef struct {
     Stat64 postcopy_requests;
     Stat64 precopy_bytes;
     Stat64 transferred;
-} RAMStats;
+} MigrationAtomicStats;
 
-extern RAMStats mig_stats;
+extern MigrationAtomicStats mig_stats;
 
 #endif
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 05/21] migration/rdma: Split the zero page case from acct_update_position
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (3 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 04/21] migration: Rename RAMStats to MigrationAtomicStats Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 06/21] migration/rdma: Unfold last user of acct_update_position() Juan Quintela
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

Now that we have atomic counters, we can do it on the place that we
need it, no need to do it inside ram.c.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
---
 migration/ram.c  | 12 ++++--------
 migration/ram.h  |  2 +-
 migration/rdma.c |  7 +++++--
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index c3981f64e4..c249a1f468 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2629,17 +2629,13 @@ static int ram_find_and_save_block(RAMState *rs)
     return pages;
 }
 
-void acct_update_position(QEMUFile *f, size_t size, bool zero)
+void acct_update_position(QEMUFile *f, size_t size)
 {
     uint64_t pages = size / TARGET_PAGE_SIZE;
 
-    if (zero) {
-        stat64_add(&mig_stats.zero_pages, pages);
-    } else {
-        stat64_add(&mig_stats.normal_pages, pages);
-        ram_transferred_add(size);
-        qemu_file_credit_transfer(f, size);
-    }
+    stat64_add(&mig_stats.normal_pages, pages);
+    ram_transferred_add(size);
+    qemu_file_credit_transfer(f, size);
 }
 
 static uint64_t ram_bytes_total_with_ignored(void)
diff --git a/migration/ram.h b/migration/ram.h
index 8692de6ba0..3804753ca3 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -53,7 +53,7 @@ void mig_throttle_counter_reset(void);
 
 uint64_t ram_pagesize_summary(void);
 int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len);
-void acct_update_position(QEMUFile *f, size_t size, bool zero);
+void acct_update_position(QEMUFile *f, size_t size);
 void ram_postcopy_migrated_memory_release(MigrationState *ms);
 /* For outgoing discard bitmap */
 void ram_postcopy_send_discard_bitmap(MigrationState *ms);
diff --git a/migration/rdma.c b/migration/rdma.c
index 0af5e944f0..7a9b284c3f 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -17,8 +17,10 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
+#include "exec/target_page.h"
 #include "rdma.h"
 #include "migration.h"
+#include "migration-stats.h"
 #include "qemu-file.h"
 #include "ram.h"
 #include "qemu/error-report.h"
@@ -2120,7 +2122,8 @@ retry:
                     return -EIO;
                 }
 
-                acct_update_position(f, sge.length, true);
+                stat64_add(&mig_stats.zero_pages,
+                           sge.length / qemu_target_page_size());
 
                 return 1;
             }
@@ -2228,7 +2231,7 @@ retry:
     }
 
     set_bit(chunk, block->transit_bitmap);
-    acct_update_position(f, sge.length, false);
+    acct_update_position(f, sge.length);
     rdma->total_writes++;
 
     return 0;
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 06/21] migration/rdma: Unfold last user of acct_update_position()
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (4 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 05/21] migration/rdma: Split the zero page case from acct_update_position Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 07/21] migration: Drop unused parameter for migration_tls_get_creds() Juan Quintela
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
---
 migration/ram.c  | 9 ---------
 migration/ram.h  | 1 -
 migration/rdma.c | 4 +++-
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index c249a1f468..7d81c4a39e 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2629,15 +2629,6 @@ static int ram_find_and_save_block(RAMState *rs)
     return pages;
 }
 
-void acct_update_position(QEMUFile *f, size_t size)
-{
-    uint64_t pages = size / TARGET_PAGE_SIZE;
-
-    stat64_add(&mig_stats.normal_pages, pages);
-    ram_transferred_add(size);
-    qemu_file_credit_transfer(f, size);
-}
-
 static uint64_t ram_bytes_total_with_ignored(void)
 {
     RAMBlock *block;
diff --git a/migration/ram.h b/migration/ram.h
index 3804753ca3..6fffbeb5f1 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -53,7 +53,6 @@ void mig_throttle_counter_reset(void);
 
 uint64_t ram_pagesize_summary(void);
 int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len);
-void acct_update_position(QEMUFile *f, size_t size);
 void ram_postcopy_migrated_memory_release(MigrationState *ms);
 /* For outgoing discard bitmap */
 void ram_postcopy_send_discard_bitmap(MigrationState *ms);
diff --git a/migration/rdma.c b/migration/rdma.c
index 7a9b284c3f..7e747b2595 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -2231,7 +2231,9 @@ retry:
     }
 
     set_bit(chunk, block->transit_bitmap);
-    acct_update_position(f, sge.length);
+    stat64_add(&mig_stats.normal_pages, sge.length / qemu_target_page_size());
+    ram_transferred_add(sge.length);
+    qemu_file_credit_transfer(f, sge.length);
     rdma->total_writes++;
 
     return 0;
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 07/21] migration: Drop unused parameter for migration_tls_get_creds()
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (5 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 06/21] migration/rdma: Unfold last user of acct_update_position() Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 08/21] migration: Drop unused parameter for migration_tls_client_create() Juan Quintela
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Vladimir Sementsov-Ogievskiy

It is not needed since we moved the accessor for tls properties to
options.c.

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 migration/tls.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/migration/tls.c b/migration/tls.c
index cd29177957..d4a76cf590 100644
--- a/migration/tls.c
+++ b/migration/tls.c
@@ -29,9 +29,7 @@
 #include "trace.h"
 
 static QCryptoTLSCreds *
-migration_tls_get_creds(MigrationState *s,
-                        QCryptoTLSCredsEndpoint endpoint,
-                        Error **errp)
+migration_tls_get_creds(QCryptoTLSCredsEndpoint endpoint, Error **errp)
 {
     Object *creds;
     const char *tls_creds = migrate_tls_creds();
@@ -80,8 +78,7 @@ void migration_tls_channel_process_incoming(MigrationState *s,
     QCryptoTLSCreds *creds;
     QIOChannelTLS *tioc;
 
-    creds = migration_tls_get_creds(
-        s, QCRYPTO_TLS_CREDS_ENDPOINT_SERVER, errp);
+    creds = migration_tls_get_creds(QCRYPTO_TLS_CREDS_ENDPOINT_SERVER, errp);
     if (!creds) {
         return;
     }
@@ -124,8 +121,7 @@ QIOChannelTLS *migration_tls_client_create(MigrationState *s,
 {
     QCryptoTLSCreds *creds;
 
-    creds = migration_tls_get_creds(
-        s, QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, errp);
+    creds = migration_tls_get_creds(QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, errp);
     if (!creds) {
         return NULL;
     }
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 08/21] migration: Drop unused parameter for migration_tls_client_create()
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (6 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 07/21] migration: Drop unused parameter for migration_tls_get_creds() Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 09/21] qtest/migration-test.c: Add tests with compress enabled Juan Quintela
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Vladimir Sementsov-Ogievskiy

It is not needed since we moved the accessor for tls properties to
options.c.

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 migration/multifd.c      | 2 +-
 migration/postcopy-ram.c | 2 +-
 migration/tls.c          | 5 ++---
 migration/tls.h          | 3 +--
 4 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/migration/multifd.c b/migration/multifd.c
index 4a2e1a47ce..4e71c19292 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -821,7 +821,7 @@ static void multifd_tls_channel_connect(MultiFDSendParams *p,
     const char *hostname = s->hostname;
     QIOChannelTLS *tioc;
 
-    tioc = migration_tls_client_create(s, ioc, hostname, errp);
+    tioc = migration_tls_client_create(ioc, hostname, errp);
     if (!tioc) {
         return;
     }
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 75aa276bb1..5615ec29eb 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -1632,7 +1632,7 @@ postcopy_preempt_send_channel_new(QIOTask *task, gpointer opaque)
     }
 
     if (migrate_channel_requires_tls_upgrade(ioc)) {
-        tioc = migration_tls_client_create(s, ioc, s->hostname, &local_err);
+        tioc = migration_tls_client_create(ioc, s->hostname, &local_err);
         if (!tioc) {
             goto out;
         }
diff --git a/migration/tls.c b/migration/tls.c
index d4a76cf590..fa03d9136c 100644
--- a/migration/tls.c
+++ b/migration/tls.c
@@ -114,8 +114,7 @@ static void migration_tls_outgoing_handshake(QIOTask *task,
     object_unref(OBJECT(ioc));
 }
 
-QIOChannelTLS *migration_tls_client_create(MigrationState *s,
-                                           QIOChannel *ioc,
+QIOChannelTLS *migration_tls_client_create(QIOChannel *ioc,
                                            const char *hostname,
                                            Error **errp)
 {
@@ -141,7 +140,7 @@ void migration_tls_channel_connect(MigrationState *s,
 {
     QIOChannelTLS *tioc;
 
-    tioc = migration_tls_client_create(s, ioc, hostname, errp);
+    tioc = migration_tls_client_create(ioc, hostname, errp);
     if (!tioc) {
         return;
     }
diff --git a/migration/tls.h b/migration/tls.h
index 98e23c9b0e..5797d153cb 100644
--- a/migration/tls.h
+++ b/migration/tls.h
@@ -28,8 +28,7 @@ void migration_tls_channel_process_incoming(MigrationState *s,
                                             QIOChannel *ioc,
                                             Error **errp);
 
-QIOChannelTLS *migration_tls_client_create(MigrationState *s,
-                                           QIOChannel *ioc,
+QIOChannelTLS *migration_tls_client_create(QIOChannel *ioc,
                                            const char *hostname,
                                            Error **errp);
 
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 09/21] qtest/migration-test.c: Add tests with compress enabled
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (7 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 08/21] migration: Drop unused parameter for migration_tls_client_create() Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 10/21] qtest/migration-test.c: Add postcopy " Juan Quintela
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

There has never been tests for migration with compress enabled.

Add suitable tests, testing with compress-wait-thread = false
too.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Acked-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 103 +++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 60dd53d3ec..d28b0d9880 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -406,6 +406,41 @@ static void migrate_set_parameter_str(QTestState *who, const char *parameter,
     migrate_check_parameter_str(who, parameter, value);
 }
 
+static long long migrate_get_parameter_bool(QTestState *who,
+                                           const char *parameter)
+{
+    QDict *rsp;
+    int result;
+
+    rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
+    result = qdict_get_bool(rsp, parameter);
+    qobject_unref(rsp);
+    return !!result;
+}
+
+static void migrate_check_parameter_bool(QTestState *who, const char *parameter,
+                                        int value)
+{
+    int result;
+
+    result = migrate_get_parameter_bool(who, parameter);
+    g_assert_cmpint(result, ==, value);
+}
+
+static void migrate_set_parameter_bool(QTestState *who, const char *parameter,
+                                      int value)
+{
+    QDict *rsp;
+
+    rsp = qtest_qmp(who,
+                    "{ 'execute': 'migrate-set-parameters',"
+                    "'arguments': { %s: %i } }",
+                    parameter, value);
+    g_assert(qdict_haskey(rsp, "return"));
+    qobject_unref(rsp);
+    migrate_check_parameter_bool(who, parameter, value);
+}
+
 static void migrate_ensure_non_converge(QTestState *who)
 {
     /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
@@ -1524,6 +1559,70 @@ static void test_precopy_unix_xbzrle(void)
     test_precopy_common(&args);
 }
 
+static void *
+test_migrate_compress_start(QTestState *from,
+                            QTestState *to)
+{
+    migrate_set_parameter_int(from, "compress-level", 1);
+    migrate_set_parameter_int(from, "compress-threads", 4);
+    migrate_set_parameter_bool(from, "compress-wait-thread", true);
+    migrate_set_parameter_int(to, "decompress-threads", 4);
+
+    migrate_set_capability(from, "compress", true);
+    migrate_set_capability(to, "compress", true);
+
+    return NULL;
+}
+
+static void test_precopy_unix_compress(void)
+{
+    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    MigrateCommon args = {
+        .connect_uri = uri,
+        .listen_uri = uri,
+        .start_hook = test_migrate_compress_start,
+        /*
+         * Test that no invalid thread state is left over from
+         * the previous iteration.
+         */
+        .iterations = 2,
+    };
+
+    test_precopy_common(&args);
+}
+
+static void *
+test_migrate_compress_nowait_start(QTestState *from,
+                                   QTestState *to)
+{
+    migrate_set_parameter_int(from, "compress-level", 9);
+    migrate_set_parameter_int(from, "compress-threads", 1);
+    migrate_set_parameter_bool(from, "compress-wait-thread", false);
+    migrate_set_parameter_int(to, "decompress-threads", 1);
+
+    migrate_set_capability(from, "compress", true);
+    migrate_set_capability(to, "compress", true);
+
+    return NULL;
+}
+
+static void test_precopy_unix_compress_nowait(void)
+{
+    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    MigrateCommon args = {
+        .connect_uri = uri,
+        .listen_uri = uri,
+        .start_hook = test_migrate_compress_nowait_start,
+        /*
+         * Test that no invalid thread state is left over from
+         * the previous iteration.
+         */
+        .iterations = 2,
+    };
+
+    test_precopy_common(&args);
+}
+
 static void test_precopy_tcp_plain(void)
 {
     MigrateCommon args = {
@@ -2530,6 +2629,10 @@ int main(int argc, char **argv)
     qtest_add_func("/migration/bad_dest", test_baddest);
     qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
     qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);
+    qtest_add_func("/migration/precopy/unix/compress/wait",
+                   test_precopy_unix_compress);
+    qtest_add_func("/migration/precopy/unix/compress/nowait",
+                   test_precopy_unix_compress_nowait);
 #ifdef CONFIG_GNUTLS
     qtest_add_func("/migration/precopy/unix/tls/psk",
                    test_precopy_unix_tls_psk);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 10/21] qtest/migration-test.c: Add postcopy tests with compress enabled
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (8 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 09/21] qtest/migration-test.c: Add tests with compress enabled Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 11/21] ram.c: Let the compress threads return a CompressResult enum Juan Quintela
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

Add postcopy tests with compress enabled to ensure nothing breaks
with the refactoring in the next commits.

preempt+compress is blocked, so no test needed for that case.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 tests/qtest/migration-test.c | 83 +++++++++++++++++++++++-------------
 1 file changed, 53 insertions(+), 30 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index d28b0d9880..996f5eceb0 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1127,6 +1127,36 @@ test_migrate_tls_x509_finish(QTestState *from,
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
 
+static void *
+test_migrate_compress_start(QTestState *from,
+                            QTestState *to)
+{
+    migrate_set_parameter_int(from, "compress-level", 1);
+    migrate_set_parameter_int(from, "compress-threads", 4);
+    migrate_set_parameter_bool(from, "compress-wait-thread", true);
+    migrate_set_parameter_int(to, "decompress-threads", 4);
+
+    migrate_set_capability(from, "compress", true);
+    migrate_set_capability(to, "compress", true);
+
+    return NULL;
+}
+
+static void *
+test_migrate_compress_nowait_start(QTestState *from,
+                                   QTestState *to)
+{
+    migrate_set_parameter_int(from, "compress-level", 9);
+    migrate_set_parameter_int(from, "compress-threads", 1);
+    migrate_set_parameter_bool(from, "compress-wait-thread", false);
+    migrate_set_parameter_int(to, "decompress-threads", 1);
+
+    migrate_set_capability(from, "compress", true);
+    migrate_set_capability(to, "compress", true);
+
+    return NULL;
+}
+
 static int migrate_postcopy_prepare(QTestState **from_ptr,
                                     QTestState **to_ptr,
                                     MigrateCommon *args)
@@ -1204,6 +1234,15 @@ static void test_postcopy(void)
     test_postcopy_common(&args);
 }
 
+static void test_postcopy_compress(void)
+{
+    MigrateCommon args = {
+        .start_hook = test_migrate_compress_start
+    };
+
+    test_postcopy_common(&args);
+}
+
 static void test_postcopy_preempt(void)
 {
     MigrateCommon args = {
@@ -1305,6 +1344,15 @@ static void test_postcopy_recovery(void)
     test_postcopy_recovery_common(&args);
 }
 
+static void test_postcopy_recovery_compress(void)
+{
+    MigrateCommon args = {
+        .start_hook = test_migrate_compress_start
+    };
+
+    test_postcopy_recovery_common(&args);
+}
+
 #ifdef CONFIG_GNUTLS
 static void test_postcopy_recovery_tls_psk(void)
 {
@@ -1338,6 +1386,7 @@ static void test_postcopy_preempt_all(void)
 
     test_postcopy_recovery_common(&args);
 }
+
 #endif
 
 static void test_baddest(void)
@@ -1559,21 +1608,6 @@ static void test_precopy_unix_xbzrle(void)
     test_precopy_common(&args);
 }
 
-static void *
-test_migrate_compress_start(QTestState *from,
-                            QTestState *to)
-{
-    migrate_set_parameter_int(from, "compress-level", 1);
-    migrate_set_parameter_int(from, "compress-threads", 4);
-    migrate_set_parameter_bool(from, "compress-wait-thread", true);
-    migrate_set_parameter_int(to, "decompress-threads", 4);
-
-    migrate_set_capability(from, "compress", true);
-    migrate_set_capability(to, "compress", true);
-
-    return NULL;
-}
-
 static void test_precopy_unix_compress(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
@@ -1591,21 +1625,6 @@ static void test_precopy_unix_compress(void)
     test_precopy_common(&args);
 }
 
-static void *
-test_migrate_compress_nowait_start(QTestState *from,
-                                   QTestState *to)
-{
-    migrate_set_parameter_int(from, "compress-level", 9);
-    migrate_set_parameter_int(from, "compress-threads", 1);
-    migrate_set_parameter_bool(from, "compress-wait-thread", false);
-    migrate_set_parameter_int(to, "decompress-threads", 1);
-
-    migrate_set_capability(from, "compress", true);
-    migrate_set_capability(to, "compress", true);
-
-    return NULL;
-}
-
 static void test_precopy_unix_compress_nowait(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
@@ -2619,8 +2638,12 @@ int main(int argc, char **argv)
 
     if (has_uffd) {
         qtest_add_func("/migration/postcopy/plain", test_postcopy);
+        qtest_add_func("/migration/postcopy/compress/plain",
+                       test_postcopy_compress);
         qtest_add_func("/migration/postcopy/recovery/plain",
                        test_postcopy_recovery);
+        qtest_add_func("/migration/postcopy/recovery/compress/plain",
+                       test_postcopy_recovery_compress);
         qtest_add_func("/migration/postcopy/preempt/plain", test_postcopy_preempt);
         qtest_add_func("/migration/postcopy/preempt/recovery/plain",
                        test_postcopy_preempt_recovery);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 11/21] ram.c: Let the compress threads return a CompressResult enum
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (9 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 10/21] qtest/migration-test.c: Add postcopy " Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 12/21] ram.c: Dont change param->block in the compress thread Juan Quintela
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

This will be used in the next commits to move save_page_header()
out of compress code.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 7d81c4a39e..2b213b923b 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -482,10 +482,17 @@ MigrationOps *migration_ops;
 
 CompressionStats compression_counters;
 
+enum CompressResult {
+    RES_NONE = 0,
+    RES_ZEROPAGE = 1,
+    RES_COMPRESS = 2
+};
+typedef enum CompressResult CompressResult;
+
 struct CompressParam {
     bool done;
     bool quit;
-    bool zero_page;
+    CompressResult result;
     QEMUFile *file;
     QemuMutex mutex;
     QemuCond cond;
@@ -527,8 +534,9 @@ static QemuCond decomp_done_cond;
 
 static int ram_save_host_page_urgent(PageSearchStatus *pss);
 
-static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block,
-                                 ram_addr_t offset, uint8_t *source_buf);
+static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
+                                           RAMBlock *block, ram_addr_t offset,
+                                           uint8_t *source_buf);
 
 /* NOTE: page is the PFN not real ram_addr_t. */
 static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page)
@@ -553,7 +561,7 @@ static void *do_data_compress(void *opaque)
     CompressParam *param = opaque;
     RAMBlock *block;
     ram_addr_t offset;
-    bool zero_page;
+    CompressResult result;
 
     qemu_mutex_lock(&param->mutex);
     while (!param->quit) {
@@ -563,12 +571,12 @@ static void *do_data_compress(void *opaque)
             param->block = NULL;
             qemu_mutex_unlock(&param->mutex);
 
-            zero_page = do_compress_ram_page(param->file, &param->stream,
-                                             block, offset, param->originbuf);
+            result = do_compress_ram_page(param->file, &param->stream,
+                                          block, offset, param->originbuf);
 
             qemu_mutex_lock(&comp_done_lock);
             param->done = true;
-            param->zero_page = zero_page;
+            param->result = result;
             qemu_cond_signal(&comp_done_cond);
             qemu_mutex_unlock(&comp_done_lock);
 
@@ -1452,8 +1460,9 @@ static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block,
     return 1;
 }
 
-static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block,
-                                 ram_addr_t offset, uint8_t *source_buf)
+static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
+                                           RAMBlock *block, ram_addr_t offset,
+                                           uint8_t *source_buf)
 {
     RAMState *rs = ram_state;
     PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY];
@@ -1461,7 +1470,7 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block,
     int ret;
 
     if (save_zero_page_to_file(pss, f, block, offset)) {
-        return true;
+        return RES_ZEROPAGE;
     }
 
     save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE);
@@ -1476,8 +1485,9 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block,
     if (ret < 0) {
         qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
         error_report("compressed data failed!");
+        return RES_NONE;
     }
-    return false;
+    return RES_COMPRESS;
 }
 
 static void
@@ -1485,7 +1495,7 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit)
 {
     ram_transferred_add(bytes_xmit);
 
-    if (param->zero_page) {
+    if (param->result == RES_ZEROPAGE) {
         stat64_add(&mig_stats.zero_pages, 1);
         return;
     }
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 12/21] ram.c: Dont change param->block in the compress thread
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (10 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 11/21] ram.c: Let the compress threads return a CompressResult enum Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 13/21] ram.c: Reset result after sending queued data Juan Quintela
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

Instead introduce a extra parameter to trigger the compress thread.
Now, when the compress thread is done, we know what RAMBlock and
offset it did compress.

This will be used in the next commits to move save_page_header()
out of compress code.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 2b213b923b..ebcde3dcd4 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -492,6 +492,7 @@ typedef enum CompressResult CompressResult;
 struct CompressParam {
     bool done;
     bool quit;
+    bool trigger;
     CompressResult result;
     QEMUFile *file;
     QemuMutex mutex;
@@ -565,10 +566,10 @@ static void *do_data_compress(void *opaque)
 
     qemu_mutex_lock(&param->mutex);
     while (!param->quit) {
-        if (param->block) {
+        if (param->trigger) {
             block = param->block;
             offset = param->offset;
-            param->block = NULL;
+            param->trigger = false;
             qemu_mutex_unlock(&param->mutex);
 
             result = do_compress_ram_page(param->file, &param->stream,
@@ -1545,6 +1546,7 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block,
 {
     param->block = block;
     param->offset = offset;
+    param->trigger = true;
 }
 
 static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset)
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 13/21] ram.c: Reset result after sending queued data
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (11 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 12/21] ram.c: Dont change param->block in the compress thread Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 14/21] ram.c: Do not call save_page_header() from compress threads Juan Quintela
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

And take the param->mutex lock for the whole section to ensure
thread-safety.
Now, it is explicitly clear if there is no queued data to send.
Before, this was handled by param->file stream being empty and thus
qemu_put_qemu_file() not sending anything.

This will be used in the next commits to move save_page_header()
out of compress code.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index ebcde3dcd4..b0b11f37fb 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1508,6 +1508,13 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit)
 
 static bool save_page_use_compression(RAMState *rs);
 
+static inline void compress_reset_result(CompressParam *param)
+{
+    param->result = RES_NONE;
+    param->block = NULL;
+    param->offset = 0;
+}
+
 static void flush_compressed_data(RAMState *rs)
 {
     MigrationState *ms = migrate_get_current();
@@ -1529,13 +1536,16 @@ static void flush_compressed_data(RAMState *rs)
     for (idx = 0; idx < thread_count; idx++) {
         qemu_mutex_lock(&comp_param[idx].mutex);
         if (!comp_param[idx].quit) {
-            len = qemu_put_qemu_file(ms->to_dst_file, comp_param[idx].file);
+            CompressParam *param = &comp_param[idx];
+            len = qemu_put_qemu_file(ms->to_dst_file, param->file);
+            compress_reset_result(param);
+
             /*
              * it's safe to fetch zero_page without holding comp_done_lock
              * as there is no further request submitted to the thread,
              * i.e, the thread should be waiting for a request at this point.
              */
-            update_compress_thread_counts(&comp_param[idx], len);
+            update_compress_thread_counts(param, len);
         }
         qemu_mutex_unlock(&comp_param[idx].mutex);
     }
@@ -1560,15 +1570,17 @@ static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset)
 retry:
     for (idx = 0; idx < thread_count; idx++) {
         if (comp_param[idx].done) {
-            comp_param[idx].done = false;
-            bytes_xmit = qemu_put_qemu_file(ms->to_dst_file,
-                                            comp_param[idx].file);
-            qemu_mutex_lock(&comp_param[idx].mutex);
-            set_compress_params(&comp_param[idx], block, offset);
-            qemu_cond_signal(&comp_param[idx].cond);
-            qemu_mutex_unlock(&comp_param[idx].mutex);
+            CompressParam *param = &comp_param[idx];
+            qemu_mutex_lock(&param->mutex);
+            param->done = false;
+            bytes_xmit = qemu_put_qemu_file(ms->to_dst_file, param->file);
+            compress_reset_result(param);
+            set_compress_params(param, block, offset);
+
+            update_compress_thread_counts(param, bytes_xmit);
+            qemu_cond_signal(&param->cond);
+            qemu_mutex_unlock(&param->mutex);
             pages = 1;
-            update_compress_thread_counts(&comp_param[idx], bytes_xmit);
             break;
         }
     }
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 14/21] ram.c: Do not call save_page_header() from compress threads
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (12 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 13/21] ram.c: Reset result after sending queued data Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 15/21] ram.c: Call update_compress_thread_counts from compress_send_queued_data Juan Quintela
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

save_page_header() accesses several global variables, so calling it
from multiple threads is pretty ugly.

Instead, call save_page_header() before writing out the compressed
data from the compress buffer to the migration stream.

This also makes the core compress code more independend from ram.c.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index b0b11f37fb..53aba37be9 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1465,17 +1465,13 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
                                            RAMBlock *block, ram_addr_t offset,
                                            uint8_t *source_buf)
 {
-    RAMState *rs = ram_state;
-    PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY];
     uint8_t *p = block->host + offset;
     int ret;
 
-    if (save_zero_page_to_file(pss, f, block, offset)) {
+    if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
         return RES_ZEROPAGE;
     }
 
-    save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE);
-
     /*
      * copy it to a internal buffer to avoid it being modified by VM
      * so that we can catch up the error during compression and
@@ -1515,9 +1511,40 @@ static inline void compress_reset_result(CompressParam *param)
     param->offset = 0;
 }
 
+static int send_queued_data(CompressParam *param)
+{
+    PageSearchStatus *pss = &ram_state->pss[RAM_CHANNEL_PRECOPY];
+    MigrationState *ms = migrate_get_current();
+    QEMUFile *file = ms->to_dst_file;
+    int len = 0;
+
+    RAMBlock *block = param->block;
+    ram_addr_t offset = param->offset;
+
+    if (param->result == RES_NONE) {
+        return 0;
+    }
+
+    assert(block == pss->last_sent_block);
+
+    if (param->result == RES_ZEROPAGE) {
+        len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO);
+        qemu_put_byte(file, 0);
+        len += 1;
+        ram_release_page(block->idstr, offset);
+    } else if (param->result == RES_COMPRESS) {
+        len += save_page_header(pss, file, block,
+                                offset | RAM_SAVE_FLAG_COMPRESS_PAGE);
+        len += qemu_put_qemu_file(file, param->file);
+    } else {
+        abort();
+    }
+
+    return len;
+}
+
 static void flush_compressed_data(RAMState *rs)
 {
-    MigrationState *ms = migrate_get_current();
     int idx, len, thread_count;
 
     if (!save_page_use_compression(rs)) {
@@ -1537,7 +1564,7 @@ static void flush_compressed_data(RAMState *rs)
         qemu_mutex_lock(&comp_param[idx].mutex);
         if (!comp_param[idx].quit) {
             CompressParam *param = &comp_param[idx];
-            len = qemu_put_qemu_file(ms->to_dst_file, param->file);
+            len = send_queued_data(param);
             compress_reset_result(param);
 
             /*
@@ -1563,7 +1590,6 @@ static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset)
 {
     int idx, thread_count, bytes_xmit = -1, pages = -1;
     bool wait = migrate_compress_wait_thread();
-    MigrationState *ms = migrate_get_current();
 
     thread_count = migrate_compress_threads();
     qemu_mutex_lock(&comp_done_lock);
@@ -1573,7 +1599,7 @@ retry:
             CompressParam *param = &comp_param[idx];
             qemu_mutex_lock(&param->mutex);
             param->done = false;
-            bytes_xmit = qemu_put_qemu_file(ms->to_dst_file, param->file);
+            bytes_xmit = send_queued_data(param);
             compress_reset_result(param);
             set_compress_params(param, block, offset);
 
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 15/21] ram.c: Call update_compress_thread_counts from compress_send_queued_data
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (13 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 14/21] ram.c: Do not call save_page_header() from compress threads Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 16/21] ram.c: Remove last ram.c dependency from the core compress code Juan Quintela
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

This makes the core compress code more independend from ram.c.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 53aba37be9..f17f6581ff 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1540,12 +1540,14 @@ static int send_queued_data(CompressParam *param)
         abort();
     }
 
+    update_compress_thread_counts(param, len);
+
     return len;
 }
 
 static void flush_compressed_data(RAMState *rs)
 {
-    int idx, len, thread_count;
+    int idx, thread_count;
 
     if (!save_page_use_compression(rs)) {
         return;
@@ -1564,15 +1566,8 @@ static void flush_compressed_data(RAMState *rs)
         qemu_mutex_lock(&comp_param[idx].mutex);
         if (!comp_param[idx].quit) {
             CompressParam *param = &comp_param[idx];
-            len = send_queued_data(param);
+            send_queued_data(param);
             compress_reset_result(param);
-
-            /*
-             * it's safe to fetch zero_page without holding comp_done_lock
-             * as there is no further request submitted to the thread,
-             * i.e, the thread should be waiting for a request at this point.
-             */
-            update_compress_thread_counts(param, len);
         }
         qemu_mutex_unlock(&comp_param[idx].mutex);
     }
@@ -1588,7 +1583,7 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block,
 
 static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset)
 {
-    int idx, thread_count, bytes_xmit = -1, pages = -1;
+    int idx, thread_count, pages = -1;
     bool wait = migrate_compress_wait_thread();
 
     thread_count = migrate_compress_threads();
@@ -1599,11 +1594,10 @@ retry:
             CompressParam *param = &comp_param[idx];
             qemu_mutex_lock(&param->mutex);
             param->done = false;
-            bytes_xmit = send_queued_data(param);
+            send_queued_data(param);
             compress_reset_result(param);
             set_compress_params(param, block, offset);
 
-            update_compress_thread_counts(param, bytes_xmit);
             qemu_cond_signal(&param->cond);
             qemu_mutex_unlock(&param->mutex);
             pages = 1;
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 16/21] ram.c: Remove last ram.c dependency from the core compress code
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (14 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 15/21] ram.c: Call update_compress_thread_counts from compress_send_queued_data Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:11 ` [PULL 17/21] ram.c: Move core compression code into its own file Juan Quintela
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

Make compression interfaces take send_queued_data() as an argument.
Remove save_page_use_compression() from flush_compressed_data().

This removes the last ram.c dependency from the core compress code.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index f17f6581ff..3671912b58 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1545,13 +1545,10 @@ static int send_queued_data(CompressParam *param)
     return len;
 }
 
-static void flush_compressed_data(RAMState *rs)
+static void flush_compressed_data(int (send_queued_data(CompressParam *)))
 {
     int idx, thread_count;
 
-    if (!save_page_use_compression(rs)) {
-        return;
-    }
     thread_count = migrate_compress_threads();
 
     qemu_mutex_lock(&comp_done_lock);
@@ -1573,6 +1570,15 @@ static void flush_compressed_data(RAMState *rs)
     }
 }
 
+static void ram_flush_compressed_data(RAMState *rs)
+{
+    if (!save_page_use_compression(rs)) {
+        return;
+    }
+
+    flush_compressed_data(send_queued_data);
+}
+
 static inline void set_compress_params(CompressParam *param, RAMBlock *block,
                                        ram_addr_t offset)
 {
@@ -1581,7 +1587,8 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block,
     param->trigger = true;
 }
 
-static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset)
+static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset,
+                                int (send_queued_data(CompressParam *)))
 {
     int idx, thread_count, pages = -1;
     bool wait = migrate_compress_wait_thread();
@@ -1672,7 +1679,7 @@ static int find_dirty_block(RAMState *rs, PageSearchStatus *pss)
              * Also If xbzrle is on, stop using the data compression at this
              * point. In theory, xbzrle can do better than compression.
              */
-            flush_compressed_data(rs);
+            ram_flush_compressed_data(rs);
 
             /* Hit the end of the list */
             pss->block = QLIST_FIRST_RCU(&ram_list.blocks);
@@ -2362,11 +2369,11 @@ static bool save_compress_page(RAMState *rs, PageSearchStatus *pss,
      * much CPU resource.
      */
     if (block != pss->last_sent_block) {
-        flush_compressed_data(rs);
+        ram_flush_compressed_data(rs);
         return false;
     }
 
-    if (compress_page_with_multi_thread(block, offset) > 0) {
+    if (compress_page_with_multi_thread(block, offset, send_queued_data) > 0) {
         return true;
     }
 
@@ -3412,7 +3419,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
              * page is sent in one chunk.
              */
             if (migrate_postcopy_ram()) {
-                flush_compressed_data(rs);
+                ram_flush_compressed_data(rs);
             }
 
             /*
@@ -3507,7 +3514,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
         }
         qemu_mutex_unlock(&rs->bitmap_mutex);
 
-        flush_compressed_data(rs);
+        ram_flush_compressed_data(rs);
         ram_control_after_iterate(f, RAM_CONTROL_FINISH);
     }
 
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 17/21] ram.c: Move core compression code into its own file
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (15 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 16/21] ram.c: Remove last ram.c dependency from the core compress code Juan Quintela
@ 2023-04-28 19:11 ` Juan Quintela
  2023-04-28 19:12 ` [PULL 18/21] ram.c: Move core decompression " Juan Quintela
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

No functional changes intended.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/meson.build    |   5 +-
 migration/ram-compress.c | 274 +++++++++++++++++++++++++++++++++++++++
 migration/ram-compress.h |  65 ++++++++++
 migration/ram.c          | 262 +------------------------------------
 4 files changed, 344 insertions(+), 262 deletions(-)
 create mode 100644 migration/ram-compress.c
 create mode 100644 migration/ram-compress.h

diff --git a/migration/meson.build b/migration/meson.build
index da1897fadf..2090af8e85 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -38,4 +38,7 @@ endif
 softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c'))
 
 specific_ss.add(when: 'CONFIG_SOFTMMU',
-                if_true: files('dirtyrate.c', 'ram.c', 'target.c'))
+                if_true: files('dirtyrate.c',
+                               'ram.c',
+                               'ram-compress.c',
+                               'target.c'))
diff --git a/migration/ram-compress.c b/migration/ram-compress.c
new file mode 100644
index 0000000000..d9bc67d075
--- /dev/null
+++ b/migration/ram-compress.c
@@ -0,0 +1,274 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2011-2015 Red Hat Inc
+ *
+ * Authors:
+ *  Juan Quintela <quintela@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/cutils.h"
+
+#include "ram-compress.h"
+
+#include "qemu/error-report.h"
+#include "migration.h"
+#include "options.h"
+#include "io/channel-null.h"
+#include "exec/ram_addr.h"
+
+CompressionStats compression_counters;
+
+static CompressParam *comp_param;
+static QemuThread *compress_threads;
+/* comp_done_cond is used to wake up the migration thread when
+ * one of the compression threads has finished the compression.
+ * comp_done_lock is used to co-work with comp_done_cond.
+ */
+static QemuMutex comp_done_lock;
+static QemuCond comp_done_cond;
+
+static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
+                                           RAMBlock *block, ram_addr_t offset,
+                                           uint8_t *source_buf);
+
+static void *do_data_compress(void *opaque)
+{
+    CompressParam *param = opaque;
+    RAMBlock *block;
+    ram_addr_t offset;
+    CompressResult result;
+
+    qemu_mutex_lock(&param->mutex);
+    while (!param->quit) {
+        if (param->trigger) {
+            block = param->block;
+            offset = param->offset;
+            param->trigger = false;
+            qemu_mutex_unlock(&param->mutex);
+
+            result = do_compress_ram_page(param->file, &param->stream,
+                                          block, offset, param->originbuf);
+
+            qemu_mutex_lock(&comp_done_lock);
+            param->done = true;
+            param->result = result;
+            qemu_cond_signal(&comp_done_cond);
+            qemu_mutex_unlock(&comp_done_lock);
+
+            qemu_mutex_lock(&param->mutex);
+        } else {
+            qemu_cond_wait(&param->cond, &param->mutex);
+        }
+    }
+    qemu_mutex_unlock(&param->mutex);
+
+    return NULL;
+}
+
+void compress_threads_save_cleanup(void)
+{
+    int i, thread_count;
+
+    if (!migrate_compress() || !comp_param) {
+        return;
+    }
+
+    thread_count = migrate_compress_threads();
+    for (i = 0; i < thread_count; i++) {
+        /*
+         * we use it as a indicator which shows if the thread is
+         * properly init'd or not
+         */
+        if (!comp_param[i].file) {
+            break;
+        }
+
+        qemu_mutex_lock(&comp_param[i].mutex);
+        comp_param[i].quit = true;
+        qemu_cond_signal(&comp_param[i].cond);
+        qemu_mutex_unlock(&comp_param[i].mutex);
+
+        qemu_thread_join(compress_threads + i);
+        qemu_mutex_destroy(&comp_param[i].mutex);
+        qemu_cond_destroy(&comp_param[i].cond);
+        deflateEnd(&comp_param[i].stream);
+        g_free(comp_param[i].originbuf);
+        qemu_fclose(comp_param[i].file);
+        comp_param[i].file = NULL;
+    }
+    qemu_mutex_destroy(&comp_done_lock);
+    qemu_cond_destroy(&comp_done_cond);
+    g_free(compress_threads);
+    g_free(comp_param);
+    compress_threads = NULL;
+    comp_param = NULL;
+}
+
+int compress_threads_save_setup(void)
+{
+    int i, thread_count;
+
+    if (!migrate_compress()) {
+        return 0;
+    }
+    thread_count = migrate_compress_threads();
+    compress_threads = g_new0(QemuThread, thread_count);
+    comp_param = g_new0(CompressParam, thread_count);
+    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);
+        if (!comp_param[i].originbuf) {
+            goto exit;
+        }
+
+        if (deflateInit(&comp_param[i].stream,
+                        migrate_compress_level()) != Z_OK) {
+            g_free(comp_param[i].originbuf);
+            goto exit;
+        }
+
+        /* comp_param[i].file is just used as a dummy buffer to save data,
+         * set its ops to empty.
+         */
+        comp_param[i].file = qemu_file_new_output(
+            QIO_CHANNEL(qio_channel_null_new()));
+        comp_param[i].done = true;
+        comp_param[i].quit = false;
+        qemu_mutex_init(&comp_param[i].mutex);
+        qemu_cond_init(&comp_param[i].cond);
+        qemu_thread_create(compress_threads + i, "compress",
+                           do_data_compress, comp_param + i,
+                           QEMU_THREAD_JOINABLE);
+    }
+    return 0;
+
+exit:
+    compress_threads_save_cleanup();
+    return -1;
+}
+
+static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
+                                           RAMBlock *block, ram_addr_t offset,
+                                           uint8_t *source_buf)
+{
+    uint8_t *p = block->host + offset;
+    int ret;
+
+    if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
+        return RES_ZEROPAGE;
+    }
+
+    /*
+     * copy it to a internal buffer to avoid it being modified by VM
+     * 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);
+    if (ret < 0) {
+        qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
+        error_report("compressed data failed!");
+        return RES_NONE;
+    }
+    return RES_COMPRESS;
+}
+
+static inline void compress_reset_result(CompressParam *param)
+{
+    param->result = RES_NONE;
+    param->block = NULL;
+    param->offset = 0;
+}
+
+void flush_compressed_data(int (send_queued_data(CompressParam *)))
+{
+    int idx, thread_count;
+
+    thread_count = migrate_compress_threads();
+
+    qemu_mutex_lock(&comp_done_lock);
+    for (idx = 0; idx < thread_count; idx++) {
+        while (!comp_param[idx].done) {
+            qemu_cond_wait(&comp_done_cond, &comp_done_lock);
+        }
+    }
+    qemu_mutex_unlock(&comp_done_lock);
+
+    for (idx = 0; idx < thread_count; idx++) {
+        qemu_mutex_lock(&comp_param[idx].mutex);
+        if (!comp_param[idx].quit) {
+            CompressParam *param = &comp_param[idx];
+            send_queued_data(param);
+            compress_reset_result(param);
+        }
+        qemu_mutex_unlock(&comp_param[idx].mutex);
+    }
+}
+
+static inline void set_compress_params(CompressParam *param, RAMBlock *block,
+                                       ram_addr_t offset)
+{
+    param->block = block;
+    param->offset = offset;
+    param->trigger = true;
+}
+
+int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset,
+                                int (send_queued_data(CompressParam *)))
+{
+    int idx, thread_count, pages = -1;
+    bool wait = migrate_compress_wait_thread();
+
+    thread_count = migrate_compress_threads();
+    qemu_mutex_lock(&comp_done_lock);
+retry:
+    for (idx = 0; idx < thread_count; idx++) {
+        if (comp_param[idx].done) {
+            CompressParam *param = &comp_param[idx];
+            qemu_mutex_lock(&param->mutex);
+            param->done = false;
+            send_queued_data(param);
+            compress_reset_result(param);
+            set_compress_params(param, block, offset);
+
+            qemu_cond_signal(&param->cond);
+            qemu_mutex_unlock(&param->mutex);
+            pages = 1;
+            break;
+        }
+    }
+
+    /*
+     * wait for the free thread if the user specifies 'compress-wait-thread',
+     * otherwise we will post the page out in the main thread as normal page.
+     */
+    if (pages < 0 && wait) {
+        qemu_cond_wait(&comp_done_cond, &comp_done_lock);
+        goto retry;
+    }
+    qemu_mutex_unlock(&comp_done_lock);
+
+    return pages;
+}
diff --git a/migration/ram-compress.h b/migration/ram-compress.h
new file mode 100644
index 0000000000..06570a799c
--- /dev/null
+++ b/migration/ram-compress.h
@@ -0,0 +1,65 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2011-2015 Red Hat Inc
+ *
+ * Authors:
+ *  Juan Quintela <quintela@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_MIGRATION_COMPRESS_H
+#define QEMU_MIGRATION_COMPRESS_H
+
+#include "qemu-file.h"
+
+enum CompressResult {
+    RES_NONE = 0,
+    RES_ZEROPAGE = 1,
+    RES_COMPRESS = 2
+};
+typedef enum CompressResult CompressResult;
+
+struct CompressParam {
+    bool done;
+    bool quit;
+    bool trigger;
+    CompressResult result;
+    QEMUFile *file;
+    QemuMutex mutex;
+    QemuCond cond;
+    RAMBlock *block;
+    ram_addr_t offset;
+
+    /* internally used fields */
+    z_stream stream;
+    uint8_t *originbuf;
+};
+typedef struct CompressParam CompressParam;
+
+void compress_threads_save_cleanup(void);
+int compress_threads_save_setup(void);
+
+void flush_compressed_data(int (send_queued_data(CompressParam *)));
+int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset,
+                                int (send_queued_data(CompressParam *)));
+
+#endif
diff --git a/migration/ram.c b/migration/ram.c
index 3671912b58..e4e50f5363 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -32,8 +32,8 @@
 #include "qemu/bitmap.h"
 #include "qemu/madvise.h"
 #include "qemu/main-loop.h"
-#include "io/channel-null.h"
 #include "xbzrle.h"
+#include "ram-compress.h"
 #include "ram.h"
 #include "migration.h"
 #include "migration-stats.h"
@@ -480,32 +480,6 @@ typedef struct MigrationOps MigrationOps;
 
 MigrationOps *migration_ops;
 
-CompressionStats compression_counters;
-
-enum CompressResult {
-    RES_NONE = 0,
-    RES_ZEROPAGE = 1,
-    RES_COMPRESS = 2
-};
-typedef enum CompressResult CompressResult;
-
-struct CompressParam {
-    bool done;
-    bool quit;
-    bool trigger;
-    CompressResult result;
-    QEMUFile *file;
-    QemuMutex mutex;
-    QemuCond cond;
-    RAMBlock *block;
-    ram_addr_t offset;
-
-    /* internally used fields */
-    z_stream stream;
-    uint8_t *originbuf;
-};
-typedef struct CompressParam CompressParam;
-
 struct DecompressParam {
     bool done;
     bool quit;
@@ -518,15 +492,6 @@ struct DecompressParam {
 };
 typedef struct DecompressParam DecompressParam;
 
-static CompressParam *comp_param;
-static QemuThread *compress_threads;
-/* comp_done_cond is used to wake up the migration thread when
- * one of the compression threads has finished the compression.
- * comp_done_lock is used to co-work with comp_done_cond.
- */
-static QemuMutex comp_done_lock;
-static QemuCond comp_done_cond;
-
 static QEMUFile *decomp_file;
 static DecompressParam *decomp_param;
 static QemuThread *decompress_threads;
@@ -535,10 +500,6 @@ static QemuCond decomp_done_cond;
 
 static int ram_save_host_page_urgent(PageSearchStatus *pss);
 
-static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
-                                           RAMBlock *block, ram_addr_t offset,
-                                           uint8_t *source_buf);
-
 /* NOTE: page is the PFN not real ram_addr_t. */
 static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page)
 {
@@ -557,123 +518,6 @@ static bool pss_overlap(PageSearchStatus *pss1, PageSearchStatus *pss2)
         (pss1->host_page_start == pss2->host_page_start);
 }
 
-static void *do_data_compress(void *opaque)
-{
-    CompressParam *param = opaque;
-    RAMBlock *block;
-    ram_addr_t offset;
-    CompressResult result;
-
-    qemu_mutex_lock(&param->mutex);
-    while (!param->quit) {
-        if (param->trigger) {
-            block = param->block;
-            offset = param->offset;
-            param->trigger = false;
-            qemu_mutex_unlock(&param->mutex);
-
-            result = do_compress_ram_page(param->file, &param->stream,
-                                          block, offset, param->originbuf);
-
-            qemu_mutex_lock(&comp_done_lock);
-            param->done = true;
-            param->result = result;
-            qemu_cond_signal(&comp_done_cond);
-            qemu_mutex_unlock(&comp_done_lock);
-
-            qemu_mutex_lock(&param->mutex);
-        } else {
-            qemu_cond_wait(&param->cond, &param->mutex);
-        }
-    }
-    qemu_mutex_unlock(&param->mutex);
-
-    return NULL;
-}
-
-static void compress_threads_save_cleanup(void)
-{
-    int i, thread_count;
-
-    if (!migrate_compress() || !comp_param) {
-        return;
-    }
-
-    thread_count = migrate_compress_threads();
-    for (i = 0; i < thread_count; i++) {
-        /*
-         * we use it as a indicator which shows if the thread is
-         * properly init'd or not
-         */
-        if (!comp_param[i].file) {
-            break;
-        }
-
-        qemu_mutex_lock(&comp_param[i].mutex);
-        comp_param[i].quit = true;
-        qemu_cond_signal(&comp_param[i].cond);
-        qemu_mutex_unlock(&comp_param[i].mutex);
-
-        qemu_thread_join(compress_threads + i);
-        qemu_mutex_destroy(&comp_param[i].mutex);
-        qemu_cond_destroy(&comp_param[i].cond);
-        deflateEnd(&comp_param[i].stream);
-        g_free(comp_param[i].originbuf);
-        qemu_fclose(comp_param[i].file);
-        comp_param[i].file = NULL;
-    }
-    qemu_mutex_destroy(&comp_done_lock);
-    qemu_cond_destroy(&comp_done_cond);
-    g_free(compress_threads);
-    g_free(comp_param);
-    compress_threads = NULL;
-    comp_param = NULL;
-}
-
-static int compress_threads_save_setup(void)
-{
-    int i, thread_count;
-
-    if (!migrate_compress()) {
-        return 0;
-    }
-    thread_count = migrate_compress_threads();
-    compress_threads = g_new0(QemuThread, thread_count);
-    comp_param = g_new0(CompressParam, thread_count);
-    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);
-        if (!comp_param[i].originbuf) {
-            goto exit;
-        }
-
-        if (deflateInit(&comp_param[i].stream,
-                        migrate_compress_level()) != Z_OK) {
-            g_free(comp_param[i].originbuf);
-            goto exit;
-        }
-
-        /* comp_param[i].file is just used as a dummy buffer to save data,
-         * set its ops to empty.
-         */
-        comp_param[i].file = qemu_file_new_output(
-            QIO_CHANNEL(qio_channel_null_new()));
-        comp_param[i].done = true;
-        comp_param[i].quit = false;
-        qemu_mutex_init(&comp_param[i].mutex);
-        qemu_cond_init(&comp_param[i].cond);
-        qemu_thread_create(compress_threads + i, "compress",
-                           do_data_compress, comp_param + i,
-                           QEMU_THREAD_JOINABLE);
-    }
-    return 0;
-
-exit:
-    compress_threads_save_cleanup();
-    return -1;
-}
-
 /**
  * save_page_header: write page header to wire
  *
@@ -1461,32 +1305,6 @@ static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block,
     return 1;
 }
 
-static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
-                                           RAMBlock *block, ram_addr_t offset,
-                                           uint8_t *source_buf)
-{
-    uint8_t *p = block->host + offset;
-    int ret;
-
-    if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
-        return RES_ZEROPAGE;
-    }
-
-    /*
-     * copy it to a internal buffer to avoid it being modified by VM
-     * 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);
-    if (ret < 0) {
-        qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
-        error_report("compressed data failed!");
-        return RES_NONE;
-    }
-    return RES_COMPRESS;
-}
-
 static void
 update_compress_thread_counts(const CompressParam *param, int bytes_xmit)
 {
@@ -1504,13 +1322,6 @@ update_compress_thread_counts(const CompressParam *param, int bytes_xmit)
 
 static bool save_page_use_compression(RAMState *rs);
 
-static inline void compress_reset_result(CompressParam *param)
-{
-    param->result = RES_NONE;
-    param->block = NULL;
-    param->offset = 0;
-}
-
 static int send_queued_data(CompressParam *param)
 {
     PageSearchStatus *pss = &ram_state->pss[RAM_CHANNEL_PRECOPY];
@@ -1545,31 +1356,6 @@ static int send_queued_data(CompressParam *param)
     return len;
 }
 
-static void flush_compressed_data(int (send_queued_data(CompressParam *)))
-{
-    int idx, thread_count;
-
-    thread_count = migrate_compress_threads();
-
-    qemu_mutex_lock(&comp_done_lock);
-    for (idx = 0; idx < thread_count; idx++) {
-        while (!comp_param[idx].done) {
-            qemu_cond_wait(&comp_done_cond, &comp_done_lock);
-        }
-    }
-    qemu_mutex_unlock(&comp_done_lock);
-
-    for (idx = 0; idx < thread_count; idx++) {
-        qemu_mutex_lock(&comp_param[idx].mutex);
-        if (!comp_param[idx].quit) {
-            CompressParam *param = &comp_param[idx];
-            send_queued_data(param);
-            compress_reset_result(param);
-        }
-        qemu_mutex_unlock(&comp_param[idx].mutex);
-    }
-}
-
 static void ram_flush_compressed_data(RAMState *rs)
 {
     if (!save_page_use_compression(rs)) {
@@ -1579,52 +1365,6 @@ static void ram_flush_compressed_data(RAMState *rs)
     flush_compressed_data(send_queued_data);
 }
 
-static inline void set_compress_params(CompressParam *param, RAMBlock *block,
-                                       ram_addr_t offset)
-{
-    param->block = block;
-    param->offset = offset;
-    param->trigger = true;
-}
-
-static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset,
-                                int (send_queued_data(CompressParam *)))
-{
-    int idx, thread_count, pages = -1;
-    bool wait = migrate_compress_wait_thread();
-
-    thread_count = migrate_compress_threads();
-    qemu_mutex_lock(&comp_done_lock);
-retry:
-    for (idx = 0; idx < thread_count; idx++) {
-        if (comp_param[idx].done) {
-            CompressParam *param = &comp_param[idx];
-            qemu_mutex_lock(&param->mutex);
-            param->done = false;
-            send_queued_data(param);
-            compress_reset_result(param);
-            set_compress_params(param, block, offset);
-
-            qemu_cond_signal(&param->cond);
-            qemu_mutex_unlock(&param->mutex);
-            pages = 1;
-            break;
-        }
-    }
-
-    /*
-     * wait for the free thread if the user specifies 'compress-wait-thread',
-     * otherwise we will post the page out in the main thread as normal page.
-     */
-    if (pages < 0 && wait) {
-        qemu_cond_wait(&comp_done_cond, &comp_done_lock);
-        goto retry;
-    }
-    qemu_mutex_unlock(&comp_done_lock);
-
-    return pages;
-}
-
 #define PAGE_ALL_CLEAN 0
 #define PAGE_TRY_AGAIN 1
 #define PAGE_DIRTY_FOUND 2
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 18/21] ram.c: Move core decompression code into its own file
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (16 preceding siblings ...)
  2023-04-28 19:11 ` [PULL 17/21] ram.c: Move core compression code into its own file Juan Quintela
@ 2023-04-28 19:12 ` Juan Quintela
  2023-04-28 19:12 ` [PULL 19/21] ram compress: Assert that the file buffer matches the result Juan Quintela
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub,
	Philippe Mathieu-Daudé

From: Lukas Straub <lukasstraub2@web.de>

No functional changes intended.

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>
---
 migration/ram-compress.c | 203 ++++++++++++++++++++++++++++++++++++++
 migration/ram-compress.h |   5 +
 migration/ram.c          | 204 ---------------------------------------
 3 files changed, 208 insertions(+), 204 deletions(-)

diff --git a/migration/ram-compress.c b/migration/ram-compress.c
index d9bc67d075..c25562f12d 100644
--- a/migration/ram-compress.c
+++ b/migration/ram-compress.c
@@ -48,6 +48,24 @@ static QemuThread *compress_threads;
 static QemuMutex comp_done_lock;
 static QemuCond comp_done_cond;
 
+struct DecompressParam {
+    bool done;
+    bool quit;
+    QemuMutex mutex;
+    QemuCond cond;
+    void *des;
+    uint8_t *compbuf;
+    int len;
+    z_stream stream;
+};
+typedef struct DecompressParam DecompressParam;
+
+static QEMUFile *decomp_file;
+static DecompressParam *decomp_param;
+static QemuThread *decompress_threads;
+static QemuMutex decomp_done_lock;
+static QemuCond decomp_done_cond;
+
 static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
                                            RAMBlock *block, ram_addr_t offset,
                                            uint8_t *source_buf);
@@ -272,3 +290,188 @@ retry:
 
     return pages;
 }
+
+/* return the size after decompression, or negative value on error */
+static int
+qemu_uncompress_data(z_stream *stream, uint8_t *dest, size_t dest_len,
+                     const uint8_t *source, size_t source_len)
+{
+    int err;
+
+    err = inflateReset(stream);
+    if (err != Z_OK) {
+        return -1;
+    }
+
+    stream->avail_in = source_len;
+    stream->next_in = (uint8_t *)source;
+    stream->avail_out = dest_len;
+    stream->next_out = dest;
+
+    err = inflate(stream, Z_NO_FLUSH);
+    if (err != Z_STREAM_END) {
+        return -1;
+    }
+
+    return stream->total_out;
+}
+
+static void *do_data_decompress(void *opaque)
+{
+    DecompressParam *param = opaque;
+    unsigned long pagesize;
+    uint8_t *des;
+    int len, ret;
+
+    qemu_mutex_lock(&param->mutex);
+    while (!param->quit) {
+        if (param->des) {
+            des = param->des;
+            len = param->len;
+            param->des = 0;
+            qemu_mutex_unlock(&param->mutex);
+
+            pagesize = TARGET_PAGE_SIZE;
+
+            ret = qemu_uncompress_data(&param->stream, des, pagesize,
+                                       param->compbuf, len);
+            if (ret < 0 && migrate_get_current()->decompress_error_check) {
+                error_report("decompress data failed");
+                qemu_file_set_error(decomp_file, ret);
+            }
+
+            qemu_mutex_lock(&decomp_done_lock);
+            param->done = true;
+            qemu_cond_signal(&decomp_done_cond);
+            qemu_mutex_unlock(&decomp_done_lock);
+
+            qemu_mutex_lock(&param->mutex);
+        } else {
+            qemu_cond_wait(&param->cond, &param->mutex);
+        }
+    }
+    qemu_mutex_unlock(&param->mutex);
+
+    return NULL;
+}
+
+int wait_for_decompress_done(void)
+{
+    int idx, thread_count;
+
+    if (!migrate_compress()) {
+        return 0;
+    }
+
+    thread_count = migrate_decompress_threads();
+    qemu_mutex_lock(&decomp_done_lock);
+    for (idx = 0; idx < thread_count; idx++) {
+        while (!decomp_param[idx].done) {
+            qemu_cond_wait(&decomp_done_cond, &decomp_done_lock);
+        }
+    }
+    qemu_mutex_unlock(&decomp_done_lock);
+    return qemu_file_get_error(decomp_file);
+}
+
+void compress_threads_load_cleanup(void)
+{
+    int i, thread_count;
+
+    if (!migrate_compress()) {
+        return;
+    }
+    thread_count = migrate_decompress_threads();
+    for (i = 0; i < thread_count; i++) {
+        /*
+         * we use it as a indicator which shows if the thread is
+         * properly init'd or not
+         */
+        if (!decomp_param[i].compbuf) {
+            break;
+        }
+
+        qemu_mutex_lock(&decomp_param[i].mutex);
+        decomp_param[i].quit = true;
+        qemu_cond_signal(&decomp_param[i].cond);
+        qemu_mutex_unlock(&decomp_param[i].mutex);
+    }
+    for (i = 0; i < thread_count; i++) {
+        if (!decomp_param[i].compbuf) {
+            break;
+        }
+
+        qemu_thread_join(decompress_threads + i);
+        qemu_mutex_destroy(&decomp_param[i].mutex);
+        qemu_cond_destroy(&decomp_param[i].cond);
+        inflateEnd(&decomp_param[i].stream);
+        g_free(decomp_param[i].compbuf);
+        decomp_param[i].compbuf = NULL;
+    }
+    g_free(decompress_threads);
+    g_free(decomp_param);
+    decompress_threads = NULL;
+    decomp_param = NULL;
+    decomp_file = NULL;
+}
+
+int compress_threads_load_setup(QEMUFile *f)
+{
+    int i, thread_count;
+
+    if (!migrate_compress()) {
+        return 0;
+    }
+
+    thread_count = migrate_decompress_threads();
+    decompress_threads = g_new0(QemuThread, thread_count);
+    decomp_param = g_new0(DecompressParam, thread_count);
+    qemu_mutex_init(&decomp_done_lock);
+    qemu_cond_init(&decomp_done_cond);
+    decomp_file = f;
+    for (i = 0; i < thread_count; i++) {
+        if (inflateInit(&decomp_param[i].stream) != Z_OK) {
+            goto exit;
+        }
+
+        decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE));
+        qemu_mutex_init(&decomp_param[i].mutex);
+        qemu_cond_init(&decomp_param[i].cond);
+        decomp_param[i].done = true;
+        decomp_param[i].quit = false;
+        qemu_thread_create(decompress_threads + i, "decompress",
+                           do_data_decompress, decomp_param + i,
+                           QEMU_THREAD_JOINABLE);
+    }
+    return 0;
+exit:
+    compress_threads_load_cleanup();
+    return -1;
+}
+
+void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len)
+{
+    int idx, thread_count;
+
+    thread_count = migrate_decompress_threads();
+    QEMU_LOCK_GUARD(&decomp_done_lock);
+    while (true) {
+        for (idx = 0; idx < thread_count; idx++) {
+            if (decomp_param[idx].done) {
+                decomp_param[idx].done = false;
+                qemu_mutex_lock(&decomp_param[idx].mutex);
+                qemu_get_buffer(f, decomp_param[idx].compbuf, len);
+                decomp_param[idx].des = host;
+                decomp_param[idx].len = len;
+                qemu_cond_signal(&decomp_param[idx].cond);
+                qemu_mutex_unlock(&decomp_param[idx].mutex);
+                break;
+            }
+        }
+        if (idx < thread_count) {
+            break;
+        } else {
+            qemu_cond_wait(&decomp_done_cond, &decomp_done_lock);
+        }
+    }
+}
diff --git a/migration/ram-compress.h b/migration/ram-compress.h
index 06570a799c..6f7fe2f472 100644
--- a/migration/ram-compress.h
+++ b/migration/ram-compress.h
@@ -62,4 +62,9 @@ void flush_compressed_data(int (send_queued_data(CompressParam *)));
 int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset,
                                 int (send_queued_data(CompressParam *)));
 
+int wait_for_decompress_done(void);
+void compress_threads_load_cleanup(void);
+int compress_threads_load_setup(QEMUFile *f);
+void decompress_data_with_multi_threads(QEMUFile *f, void *host, int len);
+
 #endif
diff --git a/migration/ram.c b/migration/ram.c
index e4e50f5363..250cb01099 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -480,24 +480,6 @@ typedef struct MigrationOps MigrationOps;
 
 MigrationOps *migration_ops;
 
-struct DecompressParam {
-    bool done;
-    bool quit;
-    QemuMutex mutex;
-    QemuCond cond;
-    void *des;
-    uint8_t *compbuf;
-    int len;
-    z_stream stream;
-};
-typedef struct DecompressParam DecompressParam;
-
-static QEMUFile *decomp_file;
-static DecompressParam *decomp_param;
-static QemuThread *decompress_threads;
-static QemuMutex decomp_done_lock;
-static QemuCond decomp_done_cond;
-
 static int ram_save_host_page_urgent(PageSearchStatus *pss);
 
 /* NOTE: page is the PFN not real ram_addr_t. */
@@ -3465,192 +3447,6 @@ void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
     }
 }
 
-/* return the size after decompression, or negative value on error */
-static int
-qemu_uncompress_data(z_stream *stream, uint8_t *dest, size_t dest_len,
-                     const uint8_t *source, size_t source_len)
-{
-    int err;
-
-    err = inflateReset(stream);
-    if (err != Z_OK) {
-        return -1;
-    }
-
-    stream->avail_in = source_len;
-    stream->next_in = (uint8_t *)source;
-    stream->avail_out = dest_len;
-    stream->next_out = dest;
-
-    err = inflate(stream, Z_NO_FLUSH);
-    if (err != Z_STREAM_END) {
-        return -1;
-    }
-
-    return stream->total_out;
-}
-
-static void *do_data_decompress(void *opaque)
-{
-    DecompressParam *param = opaque;
-    unsigned long pagesize;
-    uint8_t *des;
-    int len, ret;
-
-    qemu_mutex_lock(&param->mutex);
-    while (!param->quit) {
-        if (param->des) {
-            des = param->des;
-            len = param->len;
-            param->des = 0;
-            qemu_mutex_unlock(&param->mutex);
-
-            pagesize = TARGET_PAGE_SIZE;
-
-            ret = qemu_uncompress_data(&param->stream, des, pagesize,
-                                       param->compbuf, len);
-            if (ret < 0 && migrate_get_current()->decompress_error_check) {
-                error_report("decompress data failed");
-                qemu_file_set_error(decomp_file, ret);
-            }
-
-            qemu_mutex_lock(&decomp_done_lock);
-            param->done = true;
-            qemu_cond_signal(&decomp_done_cond);
-            qemu_mutex_unlock(&decomp_done_lock);
-
-            qemu_mutex_lock(&param->mutex);
-        } else {
-            qemu_cond_wait(&param->cond, &param->mutex);
-        }
-    }
-    qemu_mutex_unlock(&param->mutex);
-
-    return NULL;
-}
-
-static int wait_for_decompress_done(void)
-{
-    int idx, thread_count;
-
-    if (!migrate_compress()) {
-        return 0;
-    }
-
-    thread_count = migrate_decompress_threads();
-    qemu_mutex_lock(&decomp_done_lock);
-    for (idx = 0; idx < thread_count; idx++) {
-        while (!decomp_param[idx].done) {
-            qemu_cond_wait(&decomp_done_cond, &decomp_done_lock);
-        }
-    }
-    qemu_mutex_unlock(&decomp_done_lock);
-    return qemu_file_get_error(decomp_file);
-}
-
-static void compress_threads_load_cleanup(void)
-{
-    int i, thread_count;
-
-    if (!migrate_compress()) {
-        return;
-    }
-    thread_count = migrate_decompress_threads();
-    for (i = 0; i < thread_count; i++) {
-        /*
-         * we use it as a indicator which shows if the thread is
-         * properly init'd or not
-         */
-        if (!decomp_param[i].compbuf) {
-            break;
-        }
-
-        qemu_mutex_lock(&decomp_param[i].mutex);
-        decomp_param[i].quit = true;
-        qemu_cond_signal(&decomp_param[i].cond);
-        qemu_mutex_unlock(&decomp_param[i].mutex);
-    }
-    for (i = 0; i < thread_count; i++) {
-        if (!decomp_param[i].compbuf) {
-            break;
-        }
-
-        qemu_thread_join(decompress_threads + i);
-        qemu_mutex_destroy(&decomp_param[i].mutex);
-        qemu_cond_destroy(&decomp_param[i].cond);
-        inflateEnd(&decomp_param[i].stream);
-        g_free(decomp_param[i].compbuf);
-        decomp_param[i].compbuf = NULL;
-    }
-    g_free(decompress_threads);
-    g_free(decomp_param);
-    decompress_threads = NULL;
-    decomp_param = NULL;
-    decomp_file = NULL;
-}
-
-static int compress_threads_load_setup(QEMUFile *f)
-{
-    int i, thread_count;
-
-    if (!migrate_compress()) {
-        return 0;
-    }
-
-    thread_count = migrate_decompress_threads();
-    decompress_threads = g_new0(QemuThread, thread_count);
-    decomp_param = g_new0(DecompressParam, thread_count);
-    qemu_mutex_init(&decomp_done_lock);
-    qemu_cond_init(&decomp_done_cond);
-    decomp_file = f;
-    for (i = 0; i < thread_count; i++) {
-        if (inflateInit(&decomp_param[i].stream) != Z_OK) {
-            goto exit;
-        }
-
-        decomp_param[i].compbuf = g_malloc0(compressBound(TARGET_PAGE_SIZE));
-        qemu_mutex_init(&decomp_param[i].mutex);
-        qemu_cond_init(&decomp_param[i].cond);
-        decomp_param[i].done = true;
-        decomp_param[i].quit = false;
-        qemu_thread_create(decompress_threads + i, "decompress",
-                           do_data_decompress, decomp_param + i,
-                           QEMU_THREAD_JOINABLE);
-    }
-    return 0;
-exit:
-    compress_threads_load_cleanup();
-    return -1;
-}
-
-static void decompress_data_with_multi_threads(QEMUFile *f,
-                                               void *host, int len)
-{
-    int idx, thread_count;
-
-    thread_count = migrate_decompress_threads();
-    QEMU_LOCK_GUARD(&decomp_done_lock);
-    while (true) {
-        for (idx = 0; idx < thread_count; idx++) {
-            if (decomp_param[idx].done) {
-                decomp_param[idx].done = false;
-                qemu_mutex_lock(&decomp_param[idx].mutex);
-                qemu_get_buffer(f, decomp_param[idx].compbuf, len);
-                decomp_param[idx].des = host;
-                decomp_param[idx].len = len;
-                qemu_cond_signal(&decomp_param[idx].cond);
-                qemu_mutex_unlock(&decomp_param[idx].mutex);
-                break;
-            }
-        }
-        if (idx < thread_count) {
-            break;
-        } else {
-            qemu_cond_wait(&decomp_done_cond, &decomp_done_lock);
-        }
-    }
-}
-
 static void colo_init_ram_state(void)
 {
     ram_state_init(&ram_state);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 19/21] ram compress: Assert that the file buffer matches the result
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (17 preceding siblings ...)
  2023-04-28 19:12 ` [PULL 18/21] ram.c: Move core decompression " Juan Quintela
@ 2023-04-28 19:12 ` Juan Quintela
  2023-04-28 19:12 ` [PULL 20/21] ram-compress.c: Make target independent Juan Quintela
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

Before this series, "nothing to send" was handled by the file buffer
being empty. Now it is tracked via param->result.

Assert that the file buffer state matches the result.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c    | 11 +++++++++++
 migration/qemu-file.h    |  1 +
 migration/ram-compress.c |  5 +++++
 migration/ram.c          |  2 ++
 4 files changed, 19 insertions(+)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index ee04240a21..9c1ef8e3f9 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -887,6 +887,17 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src)
     return len;
 }
 
+/*
+ * Check if the writable buffer is empty
+ */
+
+bool qemu_file_buffer_empty(QEMUFile *file)
+{
+    assert(qemu_file_is_writable(file));
+
+    return !file->iovcnt;
+}
+
 /*
  * Get a string whose length is determined by a single preceding byte
  * A preallocated 256 byte buffer must be passed in.
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index d16cd50448..c2d6086a6e 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -113,6 +113,7 @@ size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, s
 ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream,
                                   const uint8_t *p, size_t size);
 int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);
+bool qemu_file_buffer_empty(QEMUFile *file);
 
 /*
  * Note that you can only peek continuous bytes from where the current pointer
diff --git a/migration/ram-compress.c b/migration/ram-compress.c
index c25562f12d..3d2a4a6329 100644
--- a/migration/ram-compress.c
+++ b/migration/ram-compress.c
@@ -194,6 +194,8 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
     uint8_t *p = block->host + offset;
     int ret;
 
+    assert(qemu_file_buffer_empty(f));
+
     if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
         return RES_ZEROPAGE;
     }
@@ -208,6 +210,7 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
     if (ret < 0) {
         qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
         error_report("compressed data failed!");
+        qemu_fflush(f);
         return RES_NONE;
     }
     return RES_COMPRESS;
@@ -239,6 +242,7 @@ void flush_compressed_data(int (send_queued_data(CompressParam *)))
         if (!comp_param[idx].quit) {
             CompressParam *param = &comp_param[idx];
             send_queued_data(param);
+            assert(qemu_file_buffer_empty(param->file));
             compress_reset_result(param);
         }
         qemu_mutex_unlock(&comp_param[idx].mutex);
@@ -268,6 +272,7 @@ retry:
             qemu_mutex_lock(&param->mutex);
             param->done = false;
             send_queued_data(param);
+            assert(qemu_file_buffer_empty(param->file));
             compress_reset_result(param);
             set_compress_params(param, block, offset);
 
diff --git a/migration/ram.c b/migration/ram.c
index 250cb01099..a5bd943cc6 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1321,11 +1321,13 @@ static int send_queued_data(CompressParam *param)
     assert(block == pss->last_sent_block);
 
     if (param->result == RES_ZEROPAGE) {
+        assert(qemu_file_buffer_empty(param->file));
         len += save_page_header(pss, file, block, offset | RAM_SAVE_FLAG_ZERO);
         qemu_put_byte(file, 0);
         len += 1;
         ram_release_page(block->idstr, offset);
     } else if (param->result == RES_COMPRESS) {
+        assert(!qemu_file_buffer_empty(param->file));
         len += save_page_header(pss, file, block,
                                 offset | RAM_SAVE_FLAG_COMPRESS_PAGE);
         len += qemu_put_qemu_file(file, param->file);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 20/21] ram-compress.c: Make target independent
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (18 preceding siblings ...)
  2023-04-28 19:12 ` [PULL 19/21] ram compress: Assert that the file buffer matches the result Juan Quintela
@ 2023-04-28 19:12 ` Juan Quintela
  2023-04-28 19:12 ` [PULL 21/21] migration: Initialize and cleanup decompression in migration.c Juan Quintela
  2023-04-29 18:45 ` [PULL 00/21] Migration 20230428 patches Richard Henderson
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub,
	Philippe Mathieu-Daudé

From: Lukas Straub <lukasstraub2@web.de>

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>
---
 migration/meson.build    |  3 ++-
 migration/ram-compress.c | 17 ++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/migration/meson.build b/migration/meson.build
index 2090af8e85..75de868bb7 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -23,6 +23,8 @@ softmmu_ss.add(files(
   'migration.c',
   'multifd.c',
   'multifd-zlib.c',
+  'multifd-zlib.c',
+  'ram-compress.c',
   'options.c',
   'postcopy-ram.c',
   'savevm.c',
@@ -40,5 +42,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 3d2a4a6329..06254d8c69 100644
--- a/migration/ram-compress.c
+++ b/migration/ram-compress.c
@@ -35,7 +35,8 @@
 #include "migration.h"
 #include "options.h"
 #include "io/channel-null.h"
-#include "exec/ram_addr.h"
+#include "exec/target_page.h"
+#include "exec/ramblock.h"
 
 CompressionStats compression_counters;
 
@@ -156,7 +157,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;
         }
@@ -192,11 +193,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;
     }
 
@@ -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
      * 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!");
@@ -336,7 +338,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);
@@ -439,7 +441,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;
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PULL 21/21] migration: Initialize and cleanup decompression in migration.c
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (19 preceding siblings ...)
  2023-04-28 19:12 ` [PULL 20/21] ram-compress.c: Make target independent Juan Quintela
@ 2023-04-28 19:12 ` Juan Quintela
  2023-04-29 18:45 ` [PULL 00/21] Migration 20230428 patches Richard Henderson
  21 siblings, 0 replies; 35+ messages in thread
From: Juan Quintela @ 2023-04-28 19:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: Leonardo Bras, Juan Quintela, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

From: Lukas Straub <lukasstraub2@web.de>

This fixes compress with colo.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/migration.c | 9 +++++++++
 migration/ram.c       | 5 -----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index feb5ab7493..11f5a2dd6f 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -26,6 +26,7 @@
 #include "sysemu/cpu-throttle.h"
 #include "rdma.h"
 #include "ram.h"
+#include "ram-compress.h"
 #include "migration/global_state.h"
 #include "migration/misc.h"
 #include "migration.h"
@@ -228,6 +229,7 @@ void migration_incoming_state_destroy(void)
     struct MigrationIncomingState *mis = migration_incoming_get_current();
 
     multifd_load_cleanup();
+    compress_threads_load_cleanup();
 
     if (mis->to_src_file) {
         /* Tell source that we are done */
@@ -500,6 +502,12 @@ process_incoming_migration_co(void *opaque)
     Error *local_err = NULL;
 
     assert(mis->from_src_file);
+
+    if (compress_threads_load_setup(mis->from_src_file)) {
+        error_report("Failed to setup decompress threads");
+        goto fail;
+    }
+
     mis->migration_incoming_co = qemu_coroutine_self();
     mis->largest_page_size = qemu_ram_pagesize_largest();
     postcopy_state_set(POSTCOPY_INCOMING_NONE);
@@ -565,6 +573,7 @@ fail:
     qemu_fclose(mis->from_src_file);
 
     multifd_load_cleanup();
+    compress_threads_load_cleanup();
 
     exit(EXIT_FAILURE);
 }
diff --git a/migration/ram.c b/migration/ram.c
index a5bd943cc6..1f664fa071 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3558,10 +3558,6 @@ void colo_release_ram_cache(void)
  */
 static int ram_load_setup(QEMUFile *f, void *opaque)
 {
-    if (compress_threads_load_setup(f)) {
-        return -1;
-    }
-
     xbzrle_load_setup();
     ramblock_recv_map_init();
 
@@ -3577,7 +3573,6 @@ static int ram_load_cleanup(void *opaque)
     }
 
     xbzrle_load_cleanup();
-    compress_threads_load_cleanup();
 
     RAMBLOCK_FOREACH_NOT_IGNORED(rb) {
         g_free(rb->receivedmap);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
                   ` (20 preceding siblings ...)
  2023-04-28 19:12 ` [PULL 21/21] migration: Initialize and cleanup decompression in migration.c Juan Quintela
@ 2023-04-29 18:45 ` Richard Henderson
  2023-04-29 20:14   ` Lukas Straub
  2023-05-02 10:39   ` Juan Quintela
  21 siblings, 2 replies; 35+ messages in thread
From: Richard Henderson @ 2023-04-29 18:45 UTC (permalink / raw)
  To: Juan Quintela, qemu-devel
  Cc: Leonardo Bras, Thomas Huth, Laurent Vivier, Paolo Bonzini,
	Peter Xu

On 4/28/23 20:11, Juan Quintela wrote:
> The following changes since commit 05d50ba2d4668d43a835c5a502efdec9b92646e6:
> 
>    Merge tag 'migration-20230427-pull-request' of https://gitlab.com/juan.quintela/qemu into staging (2023-04-28 08:35:06 +0100)
> 
> are available in the Git repository at:
> 
>    https://gitlab.com/juan.quintela/qemu.git tags/migration-20230428-pull-request
> 
> for you to fetch changes up to 05ecac612ec6a4bdb358e68554b4406ac2c8e25a:
> 
>    migration: Initialize and cleanup decompression in migration.c (2023-04-28 20:54:53 +0200)
> 
> ----------------------------------------------------------------
> Migration Pull request (20230429 vintage)
> 
> Hi
> 
> In this series:
> - compression code cleanup (lukas)
>    nice, nice, nice.
> - drop useless parameters from migration_tls* (juan)
> - first part of remove QEMUFileHooks series (juan)
> 
> Please apply.
> 
> ----------------------------------------------------------------
> 
> Juan Quintela (8):
>    multifd: We already account for this packet on the multifd thread
>    migration: Move ram_stats to its own file migration-stats.[ch]
>    migration: Rename ram_counters to mig_stats
>    migration: Rename RAMStats to MigrationAtomicStats
>    migration/rdma: Split the zero page case from acct_update_position
>    migration/rdma: Unfold last user of acct_update_position()
>    migration: Drop unused parameter for migration_tls_get_creds()
>    migration: Drop unused parameter for migration_tls_client_create()
> 
> Lukas Straub (13):
>    qtest/migration-test.c: Add tests with compress enabled
>    qtest/migration-test.c: Add postcopy tests with compress enabled
>    ram.c: Let the compress threads return a CompressResult enum
>    ram.c: Dont change param->block in the compress thread
>    ram.c: Reset result after sending queued data
>    ram.c: Do not call save_page_header() from compress threads
>    ram.c: Call update_compress_thread_counts from
>      compress_send_queued_data
>    ram.c: Remove last ram.c dependency from the core compress code
>    ram.c: Move core compression code into its own file
>    ram.c: Move core decompression code into its own file
>    ram compress: Assert that the file buffer matches the result
>    ram-compress.c: Make target independent
>    migration: Initialize and cleanup decompression in migration.c

There are a bunch of migration failures in CI:

https://gitlab.com/qemu-project/qemu/-/jobs/4201998343#L375
https://gitlab.com/qemu-project/qemu/-/jobs/4201998342#L428
https://gitlab.com/qemu-project/qemu/-/jobs/4201998340#L459
https://gitlab.com/qemu-project/qemu/-/jobs/4201998336#L4883


r~




^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-04-29 18:45 ` [PULL 00/21] Migration 20230428 patches Richard Henderson
@ 2023-04-29 20:14   ` Lukas Straub
  2023-04-29 22:08     ` Richard Henderson
  2023-05-02 10:39   ` Juan Quintela
  1 sibling, 1 reply; 35+ messages in thread
From: Lukas Straub @ 2023-04-29 20:14 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Juan Quintela, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu

[-- Attachment #1: Type: text/plain, Size: 3023 bytes --]

On Sat, 29 Apr 2023 19:45:07 +0100
Richard Henderson <richard.henderson@linaro.org> wrote:

> On 4/28/23 20:11, Juan Quintela wrote:
> > The following changes since commit 05d50ba2d4668d43a835c5a502efdec9b92646e6:
> > 
> >    Merge tag 'migration-20230427-pull-request' of https://gitlab.com/juan.quintela/qemu into staging (2023-04-28 08:35:06 +0100)
> > 
> > are available in the Git repository at:
> > 
> >    https://gitlab.com/juan.quintela/qemu.git tags/migration-20230428-pull-request
> > 
> > for you to fetch changes up to 05ecac612ec6a4bdb358e68554b4406ac2c8e25a:
> > 
> >    migration: Initialize and cleanup decompression in migration.c (2023-04-28 20:54:53 +0200)
> > 
> > ----------------------------------------------------------------
> > Migration Pull request (20230429 vintage)
> > 
> > Hi
> > 
> > In this series:
> > - compression code cleanup (lukas)
> >    nice, nice, nice.
> > - drop useless parameters from migration_tls* (juan)
> > - first part of remove QEMUFileHooks series (juan)
> > 
> > Please apply.
> > 
> > ----------------------------------------------------------------
> > 
> > Juan Quintela (8):
> >    multifd: We already account for this packet on the multifd thread
> >    migration: Move ram_stats to its own file migration-stats.[ch]
> >    migration: Rename ram_counters to mig_stats
> >    migration: Rename RAMStats to MigrationAtomicStats
> >    migration/rdma: Split the zero page case from acct_update_position
> >    migration/rdma: Unfold last user of acct_update_position()
> >    migration: Drop unused parameter for migration_tls_get_creds()
> >    migration: Drop unused parameter for migration_tls_client_create()
> > 
> > Lukas Straub (13):
> >    qtest/migration-test.c: Add tests with compress enabled
> >    qtest/migration-test.c: Add postcopy tests with compress enabled
> >    ram.c: Let the compress threads return a CompressResult enum
> >    ram.c: Dont change param->block in the compress thread
> >    ram.c: Reset result after sending queued data
> >    ram.c: Do not call save_page_header() from compress threads
> >    ram.c: Call update_compress_thread_counts from
> >      compress_send_queued_data
> >    ram.c: Remove last ram.c dependency from the core compress code
> >    ram.c: Move core compression code into its own file
> >    ram.c: Move core decompression code into its own file
> >    ram compress: Assert that the file buffer matches the result
> >    ram-compress.c: Make target independent
> >    migration: Initialize and cleanup decompression in migration.c  
> 
> There are a bunch of migration failures in CI:
> 
> https://gitlab.com/qemu-project/qemu/-/jobs/4201998343#L375
> https://gitlab.com/qemu-project/qemu/-/jobs/4201998342#L428
> https://gitlab.com/qemu-project/qemu/-/jobs/4201998340#L459
> https://gitlab.com/qemu-project/qemu/-/jobs/4201998336#L4883
> 
> 
> r~

Hmm, it doesn't always fail. Any way to get the testlog from the failed
jobs?

-- 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-04-29 20:14   ` Lukas Straub
@ 2023-04-29 22:08     ` Richard Henderson
  0 siblings, 0 replies; 35+ messages in thread
From: Richard Henderson @ 2023-04-29 22:08 UTC (permalink / raw)
  To: Lukas Straub
  Cc: Juan Quintela, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu

On 4/29/23 21:14, Lukas Straub wrote:
> On Sat, 29 Apr 2023 19:45:07 +0100
> Richard Henderson <richard.henderson@linaro.org> wrote:
> 
>> On 4/28/23 20:11, Juan Quintela wrote:
>>> The following changes since commit 05d50ba2d4668d43a835c5a502efdec9b92646e6:
>>>
>>>     Merge tag 'migration-20230427-pull-request' of https://gitlab.com/juan.quintela/qemu into staging (2023-04-28 08:35:06 +0100)
>>>
>>> are available in the Git repository at:
>>>
>>>     https://gitlab.com/juan.quintela/qemu.git tags/migration-20230428-pull-request
>>>
>>> for you to fetch changes up to 05ecac612ec6a4bdb358e68554b4406ac2c8e25a:
>>>
>>>     migration: Initialize and cleanup decompression in migration.c (2023-04-28 20:54:53 +0200)
>>>
>>> ----------------------------------------------------------------
>>> Migration Pull request (20230429 vintage)
>>>
>>> Hi
>>>
>>> In this series:
>>> - compression code cleanup (lukas)
>>>     nice, nice, nice.
>>> - drop useless parameters from migration_tls* (juan)
>>> - first part of remove QEMUFileHooks series (juan)
>>>
>>> Please apply.
>>>
>>> ----------------------------------------------------------------
>>>
>>> Juan Quintela (8):
>>>     multifd: We already account for this packet on the multifd thread
>>>     migration: Move ram_stats to its own file migration-stats.[ch]
>>>     migration: Rename ram_counters to mig_stats
>>>     migration: Rename RAMStats to MigrationAtomicStats
>>>     migration/rdma: Split the zero page case from acct_update_position
>>>     migration/rdma: Unfold last user of acct_update_position()
>>>     migration: Drop unused parameter for migration_tls_get_creds()
>>>     migration: Drop unused parameter for migration_tls_client_create()
>>>
>>> Lukas Straub (13):
>>>     qtest/migration-test.c: Add tests with compress enabled
>>>     qtest/migration-test.c: Add postcopy tests with compress enabled
>>>     ram.c: Let the compress threads return a CompressResult enum
>>>     ram.c: Dont change param->block in the compress thread
>>>     ram.c: Reset result after sending queued data
>>>     ram.c: Do not call save_page_header() from compress threads
>>>     ram.c: Call update_compress_thread_counts from
>>>       compress_send_queued_data
>>>     ram.c: Remove last ram.c dependency from the core compress code
>>>     ram.c: Move core compression code into its own file
>>>     ram.c: Move core decompression code into its own file
>>>     ram compress: Assert that the file buffer matches the result
>>>     ram-compress.c: Make target independent
>>>     migration: Initialize and cleanup decompression in migration.c
>>
>> There are a bunch of migration failures in CI:
>>
>> https://gitlab.com/qemu-project/qemu/-/jobs/4201998343#L375
>> https://gitlab.com/qemu-project/qemu/-/jobs/4201998342#L428
>> https://gitlab.com/qemu-project/qemu/-/jobs/4201998340#L459
>> https://gitlab.com/qemu-project/qemu/-/jobs/4201998336#L4883
>>
>>
>> r~
> 
> Hmm, it doesn't always fail. Any way to get the testlog from the failed
> jobs?

What you can get from the links above is all I have.
But they're consistent, and new.


r~



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-04-29 18:45 ` [PULL 00/21] Migration 20230428 patches Richard Henderson
  2023-04-29 20:14   ` Lukas Straub
@ 2023-05-02 10:39   ` Juan Quintela
  2023-05-02 10:43     ` Peter Maydell
  2023-05-08  1:06     ` Lukas Straub
  1 sibling, 2 replies; 35+ messages in thread
From: Juan Quintela @ 2023-05-02 10:39 UTC (permalink / raw)
  To: Richard Henderson
  Cc: qemu-devel, Leonardo Bras, Thomas Huth, Laurent Vivier,
	Paolo Bonzini, Peter Xu, Lukas Straub

Richard Henderson <richard.henderson@linaro.org> wrote:
> On 4/28/23 20:11, Juan Quintela wrote:
>> The following changes since commit 05d50ba2d4668d43a835c5a502efdec9b92646e6:
>>    Merge tag 'migration-20230427-pull-request' of
>> https://gitlab.com/juan.quintela/qemu into staging (2023-04-28
>> 08:35:06 +0100)
>> are available in the Git repository at:
>>    https://gitlab.com/juan.quintela/qemu.git
>> tags/migration-20230428-pull-request
>> for you to fetch changes up to
>> 05ecac612ec6a4bdb358e68554b4406ac2c8e25a:
>>    migration: Initialize and cleanup decompression in migration.c
>> (2023-04-28 20:54:53 +0200)
>> ----------------------------------------------------------------
>> Migration Pull request (20230429 vintage)
>> Hi
>> In this series:
>> - compression code cleanup (lukas)
>>    nice, nice, nice.
>> - drop useless parameters from migration_tls* (juan)
>> - first part of remove QEMUFileHooks series (juan)
>> Please apply.
>> ----------------------------------------------------------------
>> Juan Quintela (8):
>>    multifd: We already account for this packet on the multifd thread
>>    migration: Move ram_stats to its own file migration-stats.[ch]
>>    migration: Rename ram_counters to mig_stats
>>    migration: Rename RAMStats to MigrationAtomicStats
>>    migration/rdma: Split the zero page case from acct_update_position
>>    migration/rdma: Unfold last user of acct_update_position()
>>    migration: Drop unused parameter for migration_tls_get_creds()
>>    migration: Drop unused parameter for migration_tls_client_create()
>> Lukas Straub (13):
>>    qtest/migration-test.c: Add tests with compress enabled
>>    qtest/migration-test.c: Add postcopy tests with compress enabled
>>    ram.c: Let the compress threads return a CompressResult enum
>>    ram.c: Dont change param->block in the compress thread
>>    ram.c: Reset result after sending queued data
>>    ram.c: Do not call save_page_header() from compress threads
>>    ram.c: Call update_compress_thread_counts from
>>      compress_send_queued_data
>>    ram.c: Remove last ram.c dependency from the core compress code
>>    ram.c: Move core compression code into its own file
>>    ram.c: Move core decompression code into its own file
>>    ram compress: Assert that the file buffer matches the result
>>    ram-compress.c: Make target independent
>>    migration: Initialize and cleanup decompression in migration.c
>
> There are a bunch of migration failures in CI:
>
> https://gitlab.com/qemu-project/qemu/-/jobs/4201998343#L375

cfi-x86_64

> https://gitlab.com/qemu-project/qemu/-/jobs/4201998342#L428

opensuse aarch64?

> https://gitlab.com/qemu-project/qemu/-/jobs/4201998340#L459

debian i386

> https://gitlab.com/qemu-project/qemu/-/jobs/4201998336#L4883

x86_64 and aarch64 on a s390x host?

Dunno really what is going on here.

It works here: fedora 37 x86_64 host and both:

qemu-system-x86_64 (native kvm)
qemu-system-aarch64 (emulated)

my patches are only code movement and cleanups, so Lukas any clue?

Lukas, I am going to drop the compress code for now and pass the other
patches.  In the meanwhile, I am going to try to setup some machine
where I can run the upstream tests and see if I can reproduce there.
BTW, I would be happy if you double check that I did the rebase
correctly, they didn't apply correctly, but as said, the tests have been
running for two/three days on all my daily testing, so I thought that I
did the things correctly.

Richard, once that we are here, one of the problem that we are having is
that the test is exiting with an abort, so we have no clue what is
happening.  Is there a way to get a backtrace, or at least the number

Later, Juan.



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-02 10:39   ` Juan Quintela
@ 2023-05-02 10:43     ` Peter Maydell
  2023-05-03  9:17       ` Juan Quintela
  2023-05-08  1:06     ` Lukas Straub
  1 sibling, 1 reply; 35+ messages in thread
From: Peter Maydell @ 2023-05-02 10:43 UTC (permalink / raw)
  To: quintela
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu, Lukas Straub,
	Daniel P. Berrange

On Tue, 2 May 2023 at 11:39, Juan Quintela <quintela@redhat.com> wrote:
> Richard, once that we are here, one of the problem that we are having is
> that the test is exiting with an abort, so we have no clue what is
> happening.  Is there a way to get a backtrace, or at least the number

This has been consistently an issue with the migration tests.
As the owner of the tests, if they are not providing you with
the level of detail that you need to diagnose failures, I
think that is something that is in your court to address:
the CI system is always going to only be able to provide
you with what your tests are outputting to the logs.

For the specific case of backtraces from assertion failures,
I think Dan was looking at whether we could put something
together for that. It won't help with segfaults and the like, though.

You should be able to at least get the number of the subtest out of
the logs (either directly in the logs of the job, or else
from the more detailed log file that gets stored as a
job artefact in most cases).

thanks
-- PMM


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-02 10:43     ` Peter Maydell
@ 2023-05-03  9:17       ` Juan Quintela
  2023-05-03 12:57         ` Daniel P. Berrangé
  2023-05-03 12:57         ` Peter Maydell
  0 siblings, 2 replies; 35+ messages in thread
From: Juan Quintela @ 2023-05-03  9:17 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu, Lukas Straub,
	Daniel P. Berrange

Peter Maydell <peter.maydell@linaro.org> wrote:
> On Tue, 2 May 2023 at 11:39, Juan Quintela <quintela@redhat.com> wrote:
>> Richard, once that we are here, one of the problem that we are having is
>> that the test is exiting with an abort, so we have no clue what is
>> happening.  Is there a way to get a backtrace, or at least the number
>
> This has been consistently an issue with the migration tests.
> As the owner of the tests, if they are not providing you with
> the level of detail that you need to diagnose failures, I
> think that is something that is in your court to address:
> the CI system is always going to only be able to provide
> you with what your tests are outputting to the logs.

Right now I would be happy just to see what test it is failing at.

I am doing something wrong, or from the links that I see on richard
email, I am not able to reach anywhere where I can see the full logs.

> For the specific case of backtraces from assertion failures,
> I think Dan was looking at whether we could put something
> together for that. It won't help with segfaults and the like, though.

I am waiting for that O:-)

> You should be able to at least get the number of the subtest out of
> the logs (either directly in the logs of the job, or else
> from the more detailed log file that gets stored as a
> job artefact in most cases).

Also note that the test is stopping in an abort, with no diagnostic
message that I can see.  But I don't see where the abort cames from:

$ grep abort tests/qtest/migration-*
tests/qtest/migration-test.c:    visit_type_SocketAddressList(iv, NULL, &addrs, &error_abort);
tests/qtest/migration-test.c:     * In non-multifd case when client aborts due to mismatched
tests/qtest/migration-test.c:     * In multifd case when client aborts due to mismatched
tests/qtest/migration-test.c:     * to load migration state, and thus just aborts the migration
$

Later, Juan.



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-03  9:17       ` Juan Quintela
@ 2023-05-03 12:57         ` Daniel P. Berrangé
  2023-05-03 12:57         ` Peter Maydell
  1 sibling, 0 replies; 35+ messages in thread
From: Daniel P. Berrangé @ 2023-05-03 12:57 UTC (permalink / raw)
  To: Juan Quintela
  Cc: Peter Maydell, Richard Henderson, qemu-devel, Leonardo Bras,
	Thomas Huth, Laurent Vivier, Paolo Bonzini, Peter Xu,
	Lukas Straub

On Wed, May 03, 2023 at 11:17:33AM +0200, Juan Quintela wrote:
> Peter Maydell <peter.maydell@linaro.org> wrote:
> > On Tue, 2 May 2023 at 11:39, Juan Quintela <quintela@redhat.com> wrote:
> >> Richard, once that we are here, one of the problem that we are having is
> >> that the test is exiting with an abort, so we have no clue what is
> >> happening.  Is there a way to get a backtrace, or at least the number
> >
> > This has been consistently an issue with the migration tests.
> > As the owner of the tests, if they are not providing you with
> > the level of detail that you need to diagnose failures, I
> > think that is something that is in your court to address:
> > the CI system is always going to only be able to provide
> > you with what your tests are outputting to the logs.
> 
> Right now I would be happy just to see what test it is failing at.
> 
> I am doing something wrong, or from the links that I see on richard
> email, I am not able to reach anywhere where I can see the full logs.
> 
> > For the specific case of backtraces from assertion failures,
> > I think Dan was looking at whether we could put something
> > together for that. It won't help with segfaults and the like, though.
> 
> I am waiting for that O:-)

I did have a play, but didn't get anything satisfactory working.
I could only capture a trace from a single thread and the hard
problems that really want traces usually involve multiple threads.
There's really no good substitute for an OS level crash collector
like systemd-coredump or abrtd :-( This is really worth an RFE
to GitLab as a possible enhancement to their shared runners.

> > You should be able to at least get the number of the subtest out of
> > the logs (either directly in the logs of the job, or else
> > from the more detailed log file that gets stored as a
> > job artefact in most cases).
> 
> Also note that the test is stopping in an abort, with no diagnostic
> message that I can see.  But I don't see where the abort cames from:

Any g_assert  failure will result in an abort, so there are many
possibilities.

We should be uploading the testlog.txt from meson test to show what
one asserts, but I've just discovered we're lacking 'when: always'
on our 'artifacts' declarations. So the artifacts are only uploaded
when the job succeeds, which the least useful scenario for our test
logs !

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-03  9:17       ` Juan Quintela
  2023-05-03 12:57         ` Daniel P. Berrangé
@ 2023-05-03 12:57         ` Peter Maydell
  2023-05-03 13:29           ` Juan Quintela
  1 sibling, 1 reply; 35+ messages in thread
From: Peter Maydell @ 2023-05-03 12:57 UTC (permalink / raw)
  To: quintela
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu, Lukas Straub,
	Daniel P. Berrange

On Wed, 3 May 2023 at 10:17, Juan Quintela <quintela@redhat.com> wrote:
>
> Peter Maydell <peter.maydell@linaro.org> wrote:
> > On Tue, 2 May 2023 at 11:39, Juan Quintela <quintela@redhat.com> wrote:
> >> Richard, once that we are here, one of the problem that we are having is
> >> that the test is exiting with an abort, so we have no clue what is
> >> happening.  Is there a way to get a backtrace, or at least the number
> >
> > This has been consistently an issue with the migration tests.
> > As the owner of the tests, if they are not providing you with
> > the level of detail that you need to diagnose failures, I
> > think that is something that is in your court to address:
> > the CI system is always going to only be able to provide
> > you with what your tests are outputting to the logs.
>
> Right now I would be happy just to see what test it is failing at.
>
> I am doing something wrong, or from the links that I see on richard
> email, I am not able to reach anywhere where I can see the full logs.
>
> > For the specific case of backtraces from assertion failures,
> > I think Dan was looking at whether we could put something
> > together for that. It won't help with segfaults and the like, though.
>
> I am waiting for that O:-)
>
> > You should be able to at least get the number of the subtest out of
> > the logs (either directly in the logs of the job, or else
> > from the more detailed log file that gets stored as a
> > job artefact in most cases).
>
> Also note that the test is stopping in an abort, with no diagnostic
> message that I can see.  But I don't see where the abort cames from:

So, as an example I took the check-system-opensuse log:
https://gitlab.com/qemu-project/qemu/-/jobs/4201998342

Use your browser's "search in web page" to look for "SIGABRT":
it'll show you the two errors (as well as the summary at
the bottom of the page which just says the tests aborted).
Here's one:

5/351 qemu:qtest+qtest-x86_64 / qtest-x86_64/migration-test ERROR
246.12s killed by signal 6 SIGABRT
>>> QTEST_QEMU_BINARY=./qemu-system-x86_64 QTEST_QEMU_IMG=./qemu-img MALLOC_PERTURB_=48 QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon G_TEST_DBUS_DAEMON=/builds/qemu-project/qemu/tests/dbus-vmstate-daemon.sh /builds/qemu-project/qemu/build/tests/qtest/migration-test --tap -k
――――――――――――――――――――――――――――――――――――― ✀ ―――――――――――――――――――――――――――――――――――――
stderr:
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
Could not access KVM kernel module: No such file or directory
**
ERROR:../tests/qtest/migration-helpers.c:205:wait_for_migration_status:
assertion failed: (g_test_timer_elapsed() <
MIGRATION_STATUS_WAIT_TIMEOUT)
(test program exited with status code -6)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
▶ 6/351 ERROR:../tests/qtest/migration-helpers.c:205:wait_for_migration_status:
assertion failed: (g_test_timer_elapsed() <
MIGRATION_STATUS_WAIT_TIMEOUT) ERROR
6/351 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test ERROR
221.18s killed by signal 6 SIGABRT

Looks like it failed on a timeout in the test code.

I think there ought to be artefacts from the job which have a
copy of the full log, but I can't find them: not sure if this
is just because the gitlab UI is terrible, or if they really
didn't get generated.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-03 12:57         ` Peter Maydell
@ 2023-05-03 13:29           ` Juan Quintela
  2023-05-03 13:58             ` Peter Maydell
  0 siblings, 1 reply; 35+ messages in thread
From: Juan Quintela @ 2023-05-03 13:29 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu, Lukas Straub,
	Daniel P. Berrange

Peter Maydell <peter.maydell@linaro.org> wrote:
> On Wed, 3 May 2023 at 10:17, Juan Quintela <quintela@redhat.com> wrote:
>>
>> Peter Maydell <peter.maydell@linaro.org> wrote:
>> > On Tue, 2 May 2023 at 11:39, Juan Quintela <quintela@redhat.com> wrote:
>> >> Richard, once that we are here, one of the problem that we are having is
>> >> that the test is exiting with an abort, so we have no clue what is
>> >> happening.  Is there a way to get a backtrace, or at least the number
>> >
>> > This has been consistently an issue with the migration tests.
>> > As the owner of the tests, if they are not providing you with
>> > the level of detail that you need to diagnose failures, I
>> > think that is something that is in your court to address:
>> > the CI system is always going to only be able to provide
>> > you with what your tests are outputting to the logs.
>>
>> Right now I would be happy just to see what test it is failing at.
>>
>> I am doing something wrong, or from the links that I see on richard
>> email, I am not able to reach anywhere where I can see the full logs.
>>
>> > For the specific case of backtraces from assertion failures,
>> > I think Dan was looking at whether we could put something
>> > together for that. It won't help with segfaults and the like, though.
>>
>> I am waiting for that O:-)
>>
>> > You should be able to at least get the number of the subtest out of
>> > the logs (either directly in the logs of the job, or else
>> > from the more detailed log file that gets stored as a
>> > job artefact in most cases).
>>
>> Also note that the test is stopping in an abort, with no diagnostic
>> message that I can see.  But I don't see where the abort cames from:
>
> So, as an example I took the check-system-opensuse log:
> https://gitlab.com/qemu-project/qemu/-/jobs/4201998342
>
> Use your browser's "search in web page" to look for "SIGABRT":
> it'll show you the two errors (as well as the summary at
> the bottom of the page which just says the tests aborted).
> Here's one:
>
> 5/351 qemu:qtest+qtest-x86_64 / qtest-x86_64/migration-test ERROR
> 246.12s killed by signal 6 SIGABRT
>>>> QTEST_QEMU_BINARY=./qemu-system-x86_64 QTEST_QEMU_IMG=./qemu-img
>>> MALLOC_PERTURB_=48
>>> QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon
>>> G_TEST_DBUS_DAEMON=/builds/qemu-project/qemu/tests/dbus-vmstate-daemon.sh
>>> /builds/qemu-project/qemu/build/tests/qtest/migration-test --tap -k
> ――――――――――――――――――――――――――――――――――――― ✀ ―――――――――――――――――――――――――――――――――――――
> stderr:
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> Could not access KVM kernel module: No such file or directory
> **
> ERROR:../tests/qtest/migration-helpers.c:205:wait_for_migration_status:
> assertion failed: (g_test_timer_elapsed() <
> MIGRATION_STATUS_WAIT_TIMEOUT)
> (test program exited with status code -6)
> ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
> ▶ 6/351 ERROR:../tests/qtest/migration-helpers.c:205:wait_for_migration_status:
> assertion failed: (g_test_timer_elapsed() <
> MIGRATION_STATUS_WAIT_TIMEOUT) ERROR
> 6/351 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test ERROR
> 221.18s killed by signal 6 SIGABRT
>
> Looks like it failed on a timeout in the test code.

Thanks.

> I think there ought to be artefacts from the job which have a
> copy of the full log, but I can't find them: not sure if this
> is just because the gitlab UI is terrible, or if they really
> didn't get generated.

So now we are between a rock and a hard place.

We have slowed down the bandwidth for migration test because on non
loaded machines, migration was too fast to need more than one pass.

And we slowed it so much than now we hit the timer that was set at 120
seconds.

So .....

It is going to be interesting.

BTW, what procesor speed do that aarch64 machines have? Or are they so
loaded that they are efectively trashing?

2minutes for a pass looks a bit too much.

Will give a try to get this test done changing when we detect that we
don't move to the completion stage.

Thanks for the explanation on where to find the data.  The other issue
is that whan I really want is to know what test failed.  I can't see a
way to get that info.  According to Daniel answer, we don't upload that
files for tests that fail.

Later, Juan.



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-03 13:29           ` Juan Quintela
@ 2023-05-03 13:58             ` Peter Maydell
  0 siblings, 0 replies; 35+ messages in thread
From: Peter Maydell @ 2023-05-03 13:58 UTC (permalink / raw)
  To: quintela
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu, Lukas Straub,
	Daniel P. Berrange

On Wed, 3 May 2023 at 14:29, Juan Quintela <quintela@redhat.com> wrote:
> So now we are between a rock and a hard place.
>
> We have slowed down the bandwidth for migration test because on non
> loaded machines, migration was too fast to need more than one pass.
>
> And we slowed it so much than now we hit the timer that was set at 120
> seconds.
>
> So .....
>
> It is going to be interesting.
>
> BTW, what procesor speed do that aarch64 machines have? Or are they so
> loaded that they are efectively trashing?

The 4 failures listed in this thread are all jobs running
on Gitlab's standard x86-64 shared runners, not on the
private aarch64 runner.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-02 10:39   ` Juan Quintela
  2023-05-02 10:43     ` Peter Maydell
@ 2023-05-08  1:06     ` Lukas Straub
  2023-05-08  8:12       ` Juan Quintela
  1 sibling, 1 reply; 35+ messages in thread
From: Lukas Straub @ 2023-05-08  1:06 UTC (permalink / raw)
  To: Juan Quintela
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu

[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]

On Tue, 02 May 2023 12:39:12 +0200
Juan Quintela <quintela@redhat.com> wrote:

> [...]
> 
> my patches are only code movement and cleanups, so Lukas any clue?
> 
> Lukas, I am going to drop the compress code for now and pass the other
> patches.  In the meanwhile, I am going to try to setup some machine
> where I can run the upstream tests and see if I can reproduce there.
> BTW, I would be happy if you double check that I did the rebase
> correctly, they didn't apply correctly, but as said, the tests have been
> running for two/three days on all my daily testing, so I thought that I
> did the things correctly.

Hi,
I rebased the series here and got exactly the same files as in this
pull request. And I can't reproduce these failures either.

Maybe you can run the CI just on the newly added compress tests and see
if it already blows up without the refactoring?

Anyway, this series is not so important anymore...

> Richard, once that we are here, one of the problem that we are having is
> that the test is exiting with an abort, so we have no clue what is
> happening.  Is there a way to get a backtrace, or at least the number
> 
> Later, Juan.
> 



-- 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-08  1:06     ` Lukas Straub
@ 2023-05-08  8:12       ` Juan Quintela
  2023-05-08  9:47         ` Lukas Straub
  0 siblings, 1 reply; 35+ messages in thread
From: Juan Quintela @ 2023-05-08  8:12 UTC (permalink / raw)
  To: Lukas Straub
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu

Lukas Straub <lukasstraub2@web.de> wrote:
> On Tue, 02 May 2023 12:39:12 +0200
> Juan Quintela <quintela@redhat.com> wrote:
>
>> [...]
>> 
>> my patches are only code movement and cleanups, so Lukas any clue?
>> 
>> Lukas, I am going to drop the compress code for now and pass the other
>> patches.  In the meanwhile, I am going to try to setup some machine
>> where I can run the upstream tests and see if I can reproduce there.
>> BTW, I would be happy if you double check that I did the rebase
>> correctly, they didn't apply correctly, but as said, the tests have been
>> running for two/three days on all my daily testing, so I thought that I
>> did the things correctly.

Hi

> Hi,
> I rebased the series here and got exactly the same files as in this
> pull request. And I can't reproduce these failures either.

Nice

> Maybe you can run the CI just on the newly added compress tests and see
> if it already blows up without the refactoring?

It does, I don't have to check O:-)

The initial reason that I did the compression code on top of multifd was
that I was not able to get the old compression code to run "reliabely"
on my testing.

> Anyway, this series is not so important anymore...

What about:
- I add the series as they are, because the code is better than what we
  have before (and being in a different file makes it easier to
  deprecate, not compile, ...)
- I just disable the tests until we find something that works.

Richard, Lukas?

Later, Juan.

>> Richard, once that we are here, one of the problem that we are having is
>> that the test is exiting with an abort, so we have no clue what is
>> happening.  Is there a way to get a backtrace, or at least the number
>> 
>> Later, Juan.
>> 



^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PULL 00/21] Migration 20230428 patches
  2023-05-08  8:12       ` Juan Quintela
@ 2023-05-08  9:47         ` Lukas Straub
  0 siblings, 0 replies; 35+ messages in thread
From: Lukas Straub @ 2023-05-08  9:47 UTC (permalink / raw)
  To: Juan Quintela
  Cc: Richard Henderson, qemu-devel, Leonardo Bras, Thomas Huth,
	Laurent Vivier, Paolo Bonzini, Peter Xu

[-- Attachment #1: Type: text/plain, Size: 1987 bytes --]

On Mon, 08 May 2023 10:12:35 +0200
Juan Quintela <quintela@redhat.com> wrote:

> Lukas Straub <lukasstraub2@web.de> wrote:
> > On Tue, 02 May 2023 12:39:12 +0200
> > Juan Quintela <quintela@redhat.com> wrote:
> >
> >> [...]
> >> 
> >> my patches are only code movement and cleanups, so Lukas any clue?
> >> 
> >> Lukas, I am going to drop the compress code for now and pass the other
> >> patches.  In the meanwhile, I am going to try to setup some machine
> >> where I can run the upstream tests and see if I can reproduce there.
> >> BTW, I would be happy if you double check that I did the rebase
> >> correctly, they didn't apply correctly, but as said, the tests have been
> >> running for two/three days on all my daily testing, so I thought that I
> >> did the things correctly.
> 
> Hi
> 
> > Hi,
> > I rebased the series here and got exactly the same files as in this
> > pull request. And I can't reproduce these failures either.
> 
> Nice
> 
> > Maybe you can run the CI just on the newly added compress tests and see
> > if it already blows up without the refactoring?
> 
> It does, I don't have to check O:-)
> 
> The initial reason that I did the compression code on top of multifd was
> that I was not able to get the old compression code to run "reliabely"
> on my testing.
> 
> > Anyway, this series is not so important anymore...
> 
> What about:
> - I add the series as they are, because the code is better than what we
>   have before (and being in a different file makes it easier to
>   deprecate, not compile, ...)
> - I just disable the tests until we find something that works.
> 
> Richard, Lukas?

That is fine with me.

> 
> Later, Juan.
> 
> >> Richard, once that we are here, one of the problem that we are having is
> >> that the test is exiting with an abort, so we have no clue what is
> >> happening.  Is there a way to get a backtrace, or at least the number
> >> 
> >> Later, Juan.
> >> 
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2023-05-08  9:48 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-28 19:11 [PULL 00/21] Migration 20230428 patches Juan Quintela
2023-04-28 19:11 ` [PULL 01/21] multifd: We already account for this packet on the multifd thread Juan Quintela
2023-04-28 19:11 ` [PULL 02/21] migration: Move ram_stats to its own file migration-stats.[ch] Juan Quintela
2023-04-28 19:11 ` [PULL 03/21] migration: Rename ram_counters to mig_stats Juan Quintela
2023-04-28 19:11 ` [PULL 04/21] migration: Rename RAMStats to MigrationAtomicStats Juan Quintela
2023-04-28 19:11 ` [PULL 05/21] migration/rdma: Split the zero page case from acct_update_position Juan Quintela
2023-04-28 19:11 ` [PULL 06/21] migration/rdma: Unfold last user of acct_update_position() Juan Quintela
2023-04-28 19:11 ` [PULL 07/21] migration: Drop unused parameter for migration_tls_get_creds() Juan Quintela
2023-04-28 19:11 ` [PULL 08/21] migration: Drop unused parameter for migration_tls_client_create() Juan Quintela
2023-04-28 19:11 ` [PULL 09/21] qtest/migration-test.c: Add tests with compress enabled Juan Quintela
2023-04-28 19:11 ` [PULL 10/21] qtest/migration-test.c: Add postcopy " Juan Quintela
2023-04-28 19:11 ` [PULL 11/21] ram.c: Let the compress threads return a CompressResult enum Juan Quintela
2023-04-28 19:11 ` [PULL 12/21] ram.c: Dont change param->block in the compress thread Juan Quintela
2023-04-28 19:11 ` [PULL 13/21] ram.c: Reset result after sending queued data Juan Quintela
2023-04-28 19:11 ` [PULL 14/21] ram.c: Do not call save_page_header() from compress threads Juan Quintela
2023-04-28 19:11 ` [PULL 15/21] ram.c: Call update_compress_thread_counts from compress_send_queued_data Juan Quintela
2023-04-28 19:11 ` [PULL 16/21] ram.c: Remove last ram.c dependency from the core compress code Juan Quintela
2023-04-28 19:11 ` [PULL 17/21] ram.c: Move core compression code into its own file Juan Quintela
2023-04-28 19:12 ` [PULL 18/21] ram.c: Move core decompression " Juan Quintela
2023-04-28 19:12 ` [PULL 19/21] ram compress: Assert that the file buffer matches the result Juan Quintela
2023-04-28 19:12 ` [PULL 20/21] ram-compress.c: Make target independent Juan Quintela
2023-04-28 19:12 ` [PULL 21/21] migration: Initialize and cleanup decompression in migration.c Juan Quintela
2023-04-29 18:45 ` [PULL 00/21] Migration 20230428 patches Richard Henderson
2023-04-29 20:14   ` Lukas Straub
2023-04-29 22:08     ` Richard Henderson
2023-05-02 10:39   ` Juan Quintela
2023-05-02 10:43     ` Peter Maydell
2023-05-03  9:17       ` Juan Quintela
2023-05-03 12:57         ` Daniel P. Berrangé
2023-05-03 12:57         ` Peter Maydell
2023-05-03 13:29           ` Juan Quintela
2023-05-03 13:58             ` Peter Maydell
2023-05-08  1:06     ` Lukas Straub
2023-05-08  8:12       ` Juan Quintela
2023-05-08  9:47         ` Lukas Straub

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).