[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/6] migration/multifd: use sync field to synchroniz
From: |
Wei Yang |
Subject: |
[Qemu-devel] [PATCH 3/6] migration/multifd: use sync field to synchronize send threads |
Date: |
Thu, 6 Jun 2019 16:34:58 +0800 |
Add a field in MultiFDSendParams to indicate there is a request to
synchronize send threads.
By doing so, send_thread will just post sem_sync on synchronization
request and channels_ready will not *overflow*.
Signed-off-by: Wei Yang <address@hidden>
---
migration/ram.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index f9e53ac413..9982930392 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -640,6 +640,8 @@ typedef struct {
QemuMutex mutex;
/* is this channel thread running */
bool running;
+ /* should sync this channel */
+ bool sync;
/* should this thread finish */
bool quit;
/* thread has work to do */
@@ -1065,8 +1067,7 @@ static void multifd_send_sync_main(void)
qemu_mutex_lock(&p->mutex);
p->packet_num = multifd_send_state->packet_num++;
- p->flags |= MULTIFD_FLAG_SYNC;
- p->pending_job++;
+ p->sync = true;
qemu_mutex_unlock(&p->mutex);
qemu_sem_post(&p->sem);
}
@@ -1129,10 +1130,27 @@ static void *multifd_send_thread(void *opaque)
p->pending_job--;
qemu_mutex_unlock(&p->mutex);
- if (flags & MULTIFD_FLAG_SYNC) {
- qemu_sem_post(&multifd_send_state->sem_sync);
- }
qemu_sem_post(&multifd_send_state->channels_ready);
+ } else if (p->sync) {
+ uint64_t packet_num = p->packet_num;
+ uint32_t flags = p->flags;
+ assert(!p->pages->used);
+
+ p->flags |= MULTIFD_FLAG_SYNC;
+ multifd_send_fill_packet(p);
+ p->sync = false;
+ qemu_mutex_unlock(&p->mutex);
+
+ trace_multifd_send(p->id, packet_num, 0, flags | MULTIFD_FLAG_SYNC,
+ p->next_packet_size);
+
+ ret = qio_channel_write_all(p->c, (void *)p->packet,
+ p->packet_len, &local_err);
+ if (ret != 0) {
+ break;
+ }
+
+ qemu_sem_post(&multifd_send_state->sem_sync);
} else if (p->quit) {
qemu_mutex_unlock(&p->mutex);
break;
@@ -1196,7 +1214,7 @@ int multifd_save_setup(void)
qemu_mutex_init(&p->mutex);
qemu_sem_init(&p->sem, 0);
- p->quit = false;
+ p->sync = p->quit = false;
p->pending_job = 0;
p->id = i;
p->pages = multifd_pages_init(page_count);
--
2.19.1
- [Qemu-devel] [PATCH 0/6] multifd: a new mechanism for send thread sync, Wei Yang, 2019/06/06
- [Qemu-devel] [PATCH 2/6] migration/multifd: notify channels_ready when send thread starts, Wei Yang, 2019/06/06
- [Qemu-devel] [PATCH 4/6] migration/multifd: used must not be 0 for a pending job, Wei Yang, 2019/06/06
- [Qemu-devel] [PATCH 5/6] migration/multifd: use boolean for pending_job is enough, Wei Yang, 2019/06/06
- [Qemu-devel] [PATCH 3/6] migration/multifd: use sync field to synchronize send threads,
Wei Yang <=
- [Qemu-devel] [PATCH 1/6] migration/multifd: move MultiFDSendParams handling into multifd_send_fill_packet(), Wei Yang, 2019/06/06
- [Qemu-devel] [PATCH 6/6] migration/multifd: there is no spurious wakeup now, Wei Yang, 2019/06/06