[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v10 11/24] migration: terminate_* can be called for
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH v10 11/24] migration: terminate_* can be called for other threads |
Date: |
Wed, 7 Mar 2018 11:59:57 +0100 |
Once there, make count field to always be accessed with atomic
operations. To make blocking operations, we need to know that the
thread is running, so create a bool to indicate that.
Signed-off-by: Juan Quintela <address@hidden>
---
migration/ram.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 4a56a85d53..977e675f46 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -400,6 +400,7 @@ struct MultiFDSendParams {
QemuThread thread;
QemuSemaphore sem;
QemuMutex mutex;
+ bool running;
bool quit;
};
typedef struct MultiFDSendParams MultiFDSendParams;
@@ -424,7 +425,7 @@ static void terminate_multifd_send_threads(Error *errp)
}
}
- for (i = 0; i < multifd_send_state->count; i++) {
+ for (i = 0; i < migrate_multifd_channels(); i++) {
MultiFDSendParams *p = &multifd_send_state->params[i];
qemu_mutex_lock(&p->mutex);
@@ -443,10 +444,13 @@ int multifd_save_cleanup(Error **errp)
return 0;
}
terminate_multifd_send_threads(NULL);
- for (i = 0; i < multifd_send_state->count; i++) {
+ for (i = 0; i < migrate_multifd_channels(); i++) {
MultiFDSendParams *p = &multifd_send_state->params[i];
- qemu_thread_join(&p->thread);
+ if (p->running) {
+ qemu_thread_join(&p->thread);
+ p->running = false;
+ }
qemu_mutex_destroy(&p->mutex);
qemu_sem_destroy(&p->sem);
g_free(p->name);
@@ -487,7 +491,7 @@ int multifd_save_setup(void)
thread_count = migrate_multifd_channels();
multifd_send_state = g_malloc0(sizeof(*multifd_send_state));
multifd_send_state->params = g_new0(MultiFDSendParams, thread_count);
- multifd_send_state->count = 0;
+ atomic_set(&multifd_send_state->count, 0);
for (i = 0; i < thread_count; i++) {
MultiFDSendParams *p = &multifd_send_state->params[i];
@@ -496,10 +500,11 @@ int multifd_save_setup(void)
p->quit = false;
p->id = i;
p->name = g_strdup_printf("multifdsend_%d", i);
+ p->running = true;
qemu_thread_create(&p->thread, p->name, multifd_send_thread, p,
QEMU_THREAD_JOINABLE);
- multifd_send_state->count++;
+ atomic_inc(&multifd_send_state->count);
}
return 0;
}
@@ -510,6 +515,7 @@ struct MultiFDRecvParams {
QemuThread thread;
QemuSemaphore sem;
QemuMutex mutex;
+ bool running;
bool quit;
};
typedef struct MultiFDRecvParams MultiFDRecvParams;
@@ -534,7 +540,7 @@ static void terminate_multifd_recv_threads(Error *errp)
}
}
- for (i = 0; i < multifd_recv_state->count; i++) {
+ for (i = 0; i < migrate_multifd_channels(); i++) {
MultiFDRecvParams *p = &multifd_recv_state->params[i];
qemu_mutex_lock(&p->mutex);
@@ -553,10 +559,13 @@ int multifd_load_cleanup(Error **errp)
return 0;
}
terminate_multifd_recv_threads(NULL);
- for (i = 0; i < multifd_recv_state->count; i++) {
+ for (i = 0; i < migrate_multifd_channels(); i++) {
MultiFDRecvParams *p = &multifd_recv_state->params[i];
- qemu_thread_join(&p->thread);
+ if (p->running) {
+ qemu_thread_join(&p->thread);
+ p->running = false;
+ }
qemu_mutex_destroy(&p->mutex);
qemu_sem_destroy(&p->sem);
g_free(p->name);
@@ -598,7 +607,7 @@ int multifd_load_setup(void)
thread_count = migrate_multifd_channels();
multifd_recv_state = g_malloc0(sizeof(*multifd_recv_state));
multifd_recv_state->params = g_new0(MultiFDRecvParams, thread_count);
- multifd_recv_state->count = 0;
+ atomic_set(&multifd_recv_state->count, 0);
for (i = 0; i < thread_count; i++) {
MultiFDRecvParams *p = &multifd_recv_state->params[i];
@@ -607,9 +616,10 @@ int multifd_load_setup(void)
p->quit = false;
p->id = i;
p->name = g_strdup_printf("multifdrecv_%d", i);
+ p->running = true;
qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p,
QEMU_THREAD_JOINABLE);
- multifd_recv_state->count++;
+ atomic_inc(&multifd_recv_state->count);
}
return 0;
}
--
2.14.3
- [Qemu-devel] [PATCH v10 04/24] migration: Set the migration tcp port, (continued)
- [Qemu-devel] [PATCH v10 04/24] migration: Set the migration tcp port, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 12/24] migration: Reference counting recv channels correctly, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 03/24] migration: Create tcp_port parameter, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 07/24] [RFH] tests: Add migration compress threads tests, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 06/24] tests: Add basic migration precopy tcp test, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 11/24] migration: terminate_* can be called for other threads,
Juan Quintela <=
- [Qemu-devel] [PATCH v10 14/24] migration: Be sure all recv channels are created, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 01/24] tests: Add migration precopy test, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 10/24] migration: In case of error just end the migration, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 02/24] tests: Add migration xbzrle test, Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 13/24] migration: Introduce multifd_recv_new_channel(), Juan Quintela, 2018/03/07
- [Qemu-devel] [PATCH v10 18/24] migration: Add multifd traces for start/end thread, Juan Quintela, 2018/03/07