[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 11/17] migration: Create thread infrastructure f
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 11/17] migration: Create thread infrastructure for multifd send side |
Date: |
Thu, 26 Jan 2017 13:38:30 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 |
On 23/01/2017 22:32, Juan Quintela wrote:
> We make the locking and the transfer of information specific, even if we
> are still transmiting things through the main thread.
>
> Signed-off-by: Juan Quintela <address@hidden>
> ---
> migration/ram.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 52 insertions(+), 1 deletion(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index c71929e..9d7bc64 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -392,17 +392,25 @@ void migrate_compress_threads_create(void)
> /* Multiple fd's */
>
> struct MultiFDSendParams {
> + /* not changed */
> QemuThread thread;
> QIOChannel *c;
> QemuCond cond;
> QemuMutex mutex;
> + /* protected by param mutex */
> bool quit;
> bool started;
> + uint8_t *address;
> + /* protected by multifd mutex */
> + bool done;
> };
> typedef struct MultiFDSendParams MultiFDSendParams;
>
> static MultiFDSendParams *multifd_send;
>
> +QemuMutex multifd_send_mutex;
> +QemuCond multifd_send_cond;
Having n+1 semaphores instead of n+1 cond/mutex pairs could be more
efficient. See thread-pool.c for an example.
Paolo
> static void *multifd_send_thread(void *opaque)
> {
> MultiFDSendParams *params = opaque;
> @@ -416,7 +424,17 @@ static void *multifd_send_thread(void *opaque)
>
> qemu_mutex_lock(¶ms->mutex);
> while (!params->quit){
> - qemu_cond_wait(¶ms->cond, ¶ms->mutex);
> + if (params->address) {
> + params->address = 0;
> + qemu_mutex_unlock(¶ms->mutex);
> + qemu_mutex_lock(&multifd_send_mutex);
> + params->done = true;
> + qemu_cond_signal(&multifd_send_cond);
> + qemu_mutex_unlock(&multifd_send_mutex);
> + qemu_mutex_lock(¶ms->mutex);
> + } else {
> + qemu_cond_wait(¶ms->cond, ¶ms->mutex);
> + }
> }
> qemu_mutex_unlock(¶ms->mutex);
>
> @@ -464,12 +482,16 @@ void migrate_multifd_send_threads_create(void)
> }
> thread_count = migrate_multifd_threads();
> multifd_send = g_new0(MultiFDSendParams, thread_count);
> + qemu_mutex_init(&multifd_send_mutex);
> + qemu_cond_init(&multifd_send_cond);
> for (i = 0; i < thread_count; i++) {
> char thread_name[15];
> qemu_mutex_init(&multifd_send[i].mutex);
> qemu_cond_init(&multifd_send[i].cond);
> multifd_send[i].quit = false;
> multifd_send[i].started = false;
> + multifd_send[i].done = true;
> + multifd_send[i].address = 0;
> multifd_send[i].c = socket_send_channel_create();
> if(!multifd_send[i].c) {
> error_report("Error creating a send channel");
> @@ -487,6 +509,34 @@ void migrate_multifd_send_threads_create(void)
> }
> }
>
> +static int multifd_send_page(uint8_t *address)
> +{
> + int i, thread_count;
> + bool found = false;
> +
> + thread_count = migrate_multifd_threads();
> + qemu_mutex_lock(&multifd_send_mutex);
> + while (!found) {
> + for (i = 0; i < thread_count; i++) {
> + if (multifd_send[i].done) {
> + multifd_send[i].done = false;
> + found = true;
> + break;
> + }
> + }
> + if (!found) {
> + qemu_cond_wait(&multifd_send_cond, &multifd_send_mutex);
> + }
> + }
> + qemu_mutex_unlock(&multifd_send_mutex);
> + qemu_mutex_lock(&multifd_send[i].mutex);
> + multifd_send[i].address = address;
> + qemu_cond_signal(&multifd_send[i].cond);
> + qemu_mutex_unlock(&multifd_send[i].mutex);
> +
> + return 0;
> +}
> +
> struct MultiFDRecvParams {
> QemuThread thread;
> QIOChannel *c;
> @@ -1015,6 +1065,7 @@ static int ram_multifd_page(QEMUFile *f,
> PageSearchStatus *pss,
> *bytes_transferred +=
> save_page_header(f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE);
> qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
> + multifd_send_page(p);
> *bytes_transferred += TARGET_PAGE_SIZE;
> pages = 1;
> acct_info.norm_pages++;
>
- Re: [Qemu-devel] [PATCH 03/17] migration: Test for disabled features on reception, (continued)
- [Qemu-devel] [PATCH 04/17] migration: Don't create decompression threads if not enabled, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 05/17] migration: Add multifd capability, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 06/17] migration: Create x-multifd-threads parameter, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 07/17] migration: Create x-multifd-group parameter, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 08/17] migration: create multifd migration threads, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 09/17] migration: Start of multiple fd work, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 10/17] migration: create ram_multifd_page, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 11/17] migration: Create thread infrastructure for multifd send side, Juan Quintela, 2017/01/23
- Re: [Qemu-devel] [PATCH 11/17] migration: Create thread infrastructure for multifd send side,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 12/17] migration: really use multiple pages at a time, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 13/17] migration: Send the fd number which we are going to use for this page, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 14/17] migration: Create thread infrastructure for multifd recv side, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 15/17] migration: Test new fd infrastructure, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 16/17] migration: [HACK]Transfer pages over new channels, Juan Quintela, 2017/01/23
- [Qemu-devel] [PATCH 17/17] migration: flush receive queue, Juan Quintela, 2017/01/23
- Re: [Qemu-devel] [PATCH 00/17] multifd v3, no-reply, 2017/01/23