From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Juan Quintela <quintela@redhat.com>,
Fabiano Rosas <farosas@suse.de>,
peterx@redhat.com
Subject: [PATCH RFC 6/7] migration: Split multifd pending_job into two booleans
Date: Sun, 22 Oct 2023 16:12:10 -0400 [thread overview]
Message-ID: <20231022201211.452861-7-peterx@redhat.com> (raw)
In-Reply-To: <20231022201211.452861-1-peterx@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/multifd.h | 16 ++++++++++------
migration/multifd.c | 33 +++++++++++++++++++++++----------
2 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/migration/multifd.h b/migration/multifd.h
index 2acf400085..ddee7b8d8a 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -101,12 +101,16 @@ typedef struct {
uint32_t flags;
/* global number of generated multifd packets */
uint64_t packet_num;
- /* thread has work to do */
- int pending_job;
- /* array of pages to sent.
- * The owner of 'pages' depends of 'pending_job' value:
- * pending_job == 0 -> migration_thread can use it.
- * pending_job != 0 -> multifd_channel can use it.
+ /* thread has a request to sync all data */
+ bool pending_sync;
+ /* thread has something to send */
+ bool pending_job;
+ /*
+ * Array of pages to sent. The owner of 'pages' depends of
+ * 'pending_job' value:
+ *
+ * - true -> multifd_channel owns it.
+ * - false -> migration_thread owns it.
*/
MultiFDPages_t *pages;
diff --git a/migration/multifd.c b/migration/multifd.c
index 8140520843..fe8d746ff9 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -425,7 +425,7 @@ static int multifd_send_pages(QEMUFile *f)
p = &multifd_send_state->params[i];
qemu_mutex_lock(&p->mutex);
if (!p->pending_job) {
- p->pending_job++;
+ p->pending_job = true;
next_channel = (i + 1) % migrate_multifd_channels();
break;
}
@@ -615,8 +615,7 @@ int multifd_send_sync_main(QEMUFile *f)
qemu_mutex_lock(&p->mutex);
p->packet_num = multifd_send_state->packet_num++;
- p->flags |= MULTIFD_FLAG_SYNC;
- p->pending_job++;
+ p->pending_sync = true;
qemu_mutex_unlock(&p->mutex);
qemu_sem_post(&p->sem);
}
@@ -747,8 +746,6 @@ static void *multifd_send_thread(void *opaque)
qemu_mutex_lock(&p->mutex);
if (p->pending_job) {
- bool need_sync = p->flags & MULTIFD_FLAG_SYNC;
-
if (!multifd_send_prepare(p, &local_err)) {
assert(local_err);
qemu_mutex_unlock(&p->mutex);
@@ -764,12 +761,27 @@ static void *multifd_send_thread(void *opaque)
qemu_mutex_lock(&p->mutex);
/* Send successful, mark the task completed */
- p->pending_job--;
+ p->pending_job = false;
+
+ } else if (p->pending_sync) {
+ p->flags |= MULTIFD_FLAG_SYNC;
+
+ if (!multifd_send_prepare(p, &local_err)) {
+ assert(local_err);
+ qemu_mutex_unlock(&p->mutex);
+ goto out;
+ }
- /* If this is a sync task, we need one more kick */
- if (need_sync) {
- qemu_sem_post(&p->sem_sync);
+ /* Send the packets without mutex */
+ qemu_mutex_unlock(&p->mutex);
+ if (!multifd_do_send(p, &local_err)) {
+ assert(local_err);
+ goto out;
}
+ qemu_mutex_lock(&p->mutex);
+
+ qemu_sem_post(&p->sem_sync);
+ p->pending_sync = false;
}
qemu_mutex_unlock(&p->mutex);
}
@@ -932,7 +944,8 @@ int multifd_save_setup(Error **errp)
qemu_mutex_init(&p->mutex);
qemu_sem_init(&p->sem, 0);
qemu_sem_init(&p->sem_sync, 0);
- p->pending_job = 0;
+ p->pending_job = false;
+ p->pending_sync = false;
p->id = i;
p->pages = multifd_pages_init(page_count);
p->packet_len = sizeof(MultiFDPacket_t)
--
2.41.0
next prev parent reply other threads:[~2023-10-22 20:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-22 20:12 [PATCH RFC 0/7] migration/multifd: quit unitifications and separate sync packet Peter Xu
2023-10-22 20:12 ` [PATCH RFC 1/7] migration: Drop stale comment for multifd zero copy Peter Xu
2023-10-23 14:16 ` Fabiano Rosas
2023-10-22 20:12 ` [PATCH RFC 2/7] migration: Fix error leak in multifd_tls_outgoing_handshake() Peter Xu
2023-10-23 14:17 ` Fabiano Rosas
2023-10-22 20:12 ` [PATCH RFC 3/7] migration: multifd_send_kick_main() Peter Xu
2023-10-23 14:43 ` Fabiano Rosas
2023-11-08 22:49 ` Fabiano Rosas
2023-11-09 16:50 ` Peter Xu
2023-11-09 17:00 ` Fabiano Rosas
2023-10-22 20:12 ` [PATCH RFC 4/7] migration: Drop MultiFDSendParams.quit and cleanup error paths Peter Xu
2023-10-23 14:42 ` Fabiano Rosas
2023-10-23 14:53 ` Peter Xu
2023-10-23 15:35 ` Fabiano Rosas
2023-10-23 15:54 ` Peter Xu
2023-10-22 20:12 ` [PATCH RFC 5/7] migration: Modulize multifd send threads with a few helpers Peter Xu
2023-10-22 20:12 ` Peter Xu [this message]
2023-10-23 15:15 ` [PATCH RFC 6/7] migration: Split multifd pending_job into two booleans Fabiano Rosas
2023-10-23 15:52 ` Peter Xu
2023-10-22 20:12 ` [PATCH RFC 7/7] migration: Further unify paths for multifd normal or sync requests Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231022201211.452861-7-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.