From patchwork Wed Apr 20 14:44:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 8890741 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 211AB9F39A for ; Wed, 20 Apr 2016 14:51:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 50B19201C0 for ; Wed, 20 Apr 2016 14:51:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 54E2020165 for ; Wed, 20 Apr 2016 14:51:31 +0000 (UTC) Received: from localhost ([::1]:50609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astTW-0004IC-JG for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Apr 2016 10:51:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astNB-0006Wk-8I for qemu-devel@nongnu.org; Wed, 20 Apr 2016 10:45:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1astN7-0002fG-WB for qemu-devel@nongnu.org; Wed, 20 Apr 2016 10:44:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astN7-0002fC-Ok for qemu-devel@nongnu.org; Wed, 20 Apr 2016 10:44:53 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F34462640 for ; Wed, 20 Apr 2016 14:44:53 +0000 (UTC) Received: from emacs.mitica (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3KEigqs020907; Wed, 20 Apr 2016 10:44:52 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 20 Apr 2016 16:44:34 +0200 Message-Id: <1461163481-11439-7-git-send-email-quintela@redhat.com> In-Reply-To: <1461163481-11439-1-git-send-email-quintela@redhat.com> References: <1461163481-11439-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Apr 2016 14:44:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/13] migration: create multifd migration threads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amit.shah@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Creation of the threads, nothing inside yet. Signed-off-by: Juan Quintela --- include/migration/migration.h | 4 ++ migration/migration.c | 6 ++ migration/ram.c | 148 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 19d535d..9f94c75 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -220,6 +220,10 @@ bool migration_in_postcopy_after_devices(MigrationState *); MigrationState *migrate_get_current(void); int migrate_multifd_threads(void); +void migrate_multifd_send_threads_create(void); +void migrate_multifd_send_threads_join(void); +void migrate_multifd_recv_threads_create(void); +void migrate_multifd_recv_threads_join(void); void migrate_compress_threads_create(void); void migrate_compress_threads_join(void); diff --git a/migration/migration.c b/migration/migration.c index 29e43ff..b3ad36b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -335,6 +335,7 @@ static void process_incoming_migration_bh(void *opaque) MIGRATION_STATUS_FAILED); error_report_err(local_err); migrate_decompress_threads_join(); + migrate_multifd_recv_threads_join(); exit(EXIT_FAILURE); } @@ -359,6 +360,7 @@ static void process_incoming_migration_bh(void *opaque) runstate_set(global_state_get_runstate()); } migrate_decompress_threads_join(); + migrate_multifd_recv_threads_join(); /* * This must happen after any state changes since as soon as an external * observer sees this event they might start to prod at the VM assuming @@ -412,6 +414,7 @@ static void process_incoming_migration_co(void *opaque) MIGRATION_STATUS_FAILED); error_report("load of migration failed: %s", strerror(-ret)); migrate_decompress_threads_join(); + migrate_multifd_recv_threads_join(); exit(EXIT_FAILURE); } @@ -426,6 +429,7 @@ void process_incoming_migration(QEMUFile *f) assert(fd != -1); migrate_decompress_threads_create(); + migrate_multifd_recv_threads_create(); qemu_set_nonblock(fd); qemu_coroutine_enter(co, f); } @@ -844,6 +848,7 @@ static void migrate_fd_cleanup(void *opaque) qemu_mutex_lock_iothread(); migrate_compress_threads_join(); + migrate_multifd_send_threads_join(); qemu_fclose(s->to_dst_file); s->to_dst_file = NULL; } @@ -1825,6 +1830,7 @@ void migrate_fd_connect(MigrationState *s) } migrate_compress_threads_create(); + migrate_multifd_send_threads_create(); qemu_thread_create(&s->thread, "migration", migration_thread, s, QEMU_THREAD_JOINABLE); s->migration_thread_running = true; diff --git a/migration/ram.c b/migration/ram.c index 648362c..6139f7c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -390,6 +390,154 @@ void migrate_compress_threads_create(void) } } +/* Multiple fd's */ + +struct MultiFDSendParams { + QemuThread thread; + QemuCond cond; + QemuMutex mutex; + bool quit; +}; +typedef struct MultiFDSendParams MultiFDSendParams; + +static MultiFDSendParams *multifd_send; + +static void *multifd_send_thread(void *opaque) +{ + MultiFDSendParams *params = opaque; + + qemu_mutex_lock(¶ms->mutex); + while (!params->quit){ + qemu_cond_wait(¶ms->cond, ¶ms->mutex); + } + qemu_mutex_unlock(¶ms->mutex); + + return NULL; +} + +static void terminate_multifd_send_threads(void) +{ + int i, thread_count; + + thread_count = migrate_multifd_threads(); + for (i = 0; i < thread_count; i++) { + qemu_mutex_lock(&multifd_send[i].mutex); + multifd_send[i].quit = true; + qemu_cond_signal(&multifd_send[i].cond); + qemu_mutex_unlock(&multifd_send[i].mutex); + } +} + +void migrate_multifd_send_threads_join(void) +{ + int i, thread_count; + + if (!migrate_multifd()){ + return; + } + terminate_multifd_send_threads(); + thread_count = migrate_multifd_threads(); + for (i = 0; i < thread_count; i++) { + qemu_thread_join(&multifd_send[i].thread); + qemu_mutex_destroy(&multifd_send[i].mutex); + qemu_cond_destroy(&multifd_send[i].cond); + } + g_free(multifd_send); + multifd_send = NULL; +} + +void migrate_multifd_send_threads_create(void) +{ + int i, thread_count; + + if (!migrate_multifd()){ + return; + } + thread_count = migrate_multifd_threads(); + multifd_send = g_new0(MultiFDSendParams, thread_count); + for (i = 0; i < thread_count; i++) { + qemu_mutex_init(&multifd_send[i].mutex); + qemu_cond_init(&multifd_send[i].cond); + multifd_send[i].quit = false; + qemu_thread_create(&multifd_send[i].thread, "multifd_send", + multifd_send_thread, &multifd_send[i], + QEMU_THREAD_JOINABLE); + } +} + +struct MultiFDRecvParams { + QemuThread thread; + QemuCond cond; + QemuMutex mutex; + bool quit; +}; +typedef struct MultiFDRecvParams MultiFDRecvParams; + +static MultiFDRecvParams *multifd_recv; + +static void *multifd_recv_thread(void *opaque) +{ + MultiFDSendParams *params = opaque; + + qemu_mutex_lock(¶ms->mutex); + while (!params->quit){ + qemu_cond_wait(¶ms->cond, ¶ms->mutex); + } + qemu_mutex_unlock(¶ms->mutex); + + return NULL; +} + +static void terminate_multifd_recv_threads(void) +{ + int i, thread_count; + + thread_count = migrate_multifd_threads(); + for (i = 0; i < thread_count; i++) { + qemu_mutex_lock(&multifd_recv[i].mutex); + multifd_recv[i].quit = true; + qemu_cond_signal(&multifd_recv[i].cond); + qemu_mutex_unlock(&multifd_recv[i].mutex); + } +} + +void migrate_multifd_recv_threads_join(void) +{ + int i, thread_count; + + if (!migrate_multifd()){ + return; + } + terminate_multifd_recv_threads(); + thread_count = migrate_multifd_threads(); + for (i = 0; i < thread_count; i++) { + qemu_thread_join(&multifd_recv[i].thread); + qemu_mutex_destroy(&multifd_recv[i].mutex); + qemu_cond_destroy(&multifd_recv[i].cond); + } + g_free(multifd_recv); + multifd_recv = NULL; +} + +void migrate_multifd_recv_threads_create(void) +{ + int i, thread_count; + + if (!migrate_multifd()){ + return; + } + thread_count = migrate_multifd_threads(); + multifd_recv = g_new0(MultiFDRecvParams, thread_count); + for (i = 0; i < thread_count; i++) { + qemu_mutex_init(&multifd_recv[i].mutex); + qemu_cond_init(&multifd_recv[i].cond); + multifd_recv[i].quit = false; + qemu_thread_create(&multifd_recv[i].thread, "multifd_recv", + multifd_recv_thread, &multifd_recv[i], + QEMU_THREAD_JOINABLE); + } +} + /** * save_page_header: Write page header to wire *