From patchwork Tue Nov 10 14:25:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 542449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1DD00140323 for ; Wed, 11 Nov 2015 02:09:04 +1100 (AEDT) Received: from localhost ([::1]:60851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwAXd-0003Lj-O1 for incoming@patchwork.ozlabs.org; Tue, 10 Nov 2015 10:09:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zw9sM-0003eu-Pv for qemu-devel@nongnu.org; Tue, 10 Nov 2015 09:26:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zw9sL-0000p2-5B for qemu-devel@nongnu.org; Tue, 10 Nov 2015 09:26:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43424) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zw9sK-0000oy-Tl for qemu-devel@nongnu.org; Tue, 10 Nov 2015 09:26:21 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id A193D8E22F for ; Tue, 10 Nov 2015 14:26:20 +0000 (UTC) Received: from trasno.mitica (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAAEPk8o030601; Tue, 10 Nov 2015 09:26:19 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 10 Nov 2015 15:25:09 +0100 Message-Id: <1447165546-27784-21-git-send-email-quintela@redhat.com> In-Reply-To: <1447165546-27784-1-git-send-email-quintela@redhat.com> References: <1447165546-27784-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, dgilbert@redhat.com Subject: [Qemu-devel] [PULL 20/57] Return path: Send responses from destination to source X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Dr. David Alan Gilbert" Add migrate_send_rp_message to send a message from destination to source along the return path. (It uses a mutex to let it be called from multiple threads) Add migrate_send_rp_shut to send a 'shut' message to indicate the destination is finished with the RP. Add migrate_send_rp_ack to send a 'PONG' message in response to a PING Use it in the MSG_RP_PING handler Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Amit Shah Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/migration/migration.h | 19 ++++++++++++++++++ migration/migration.c | 45 +++++++++++++++++++++++++++++++++++++++++++ migration/savevm.c | 2 +- trace-events | 1 + 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 98a6d07..3ce3fda 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -43,12 +43,22 @@ struct MigrationParams { bool shared; }; +/* Messages sent on the return path from destination to source */ +enum mig_rp_message_type { + MIG_RP_MSG_INVALID = 0, /* Must be 0 */ + MIG_RP_MSG_SHUT, /* sibling will not send any more RP messages */ + MIG_RP_MSG_PONG, /* Response to a PING; data (seq: be32 ) */ + + MIG_RP_MSG_MAX +}; + typedef QLIST_HEAD(, LoadStateEntry) LoadStateEntry_Head; /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; QEMUFile *to_src_file; + QemuMutex rp_mutex; /* We send replies from multiple threads */ /* See savevm.c */ LoadStateEntry_Head loadvm_handlers; @@ -181,6 +191,15 @@ int migrate_compress_threads(void); int migrate_decompress_threads(void); bool migrate_use_events(void); +/* Sending on the return path - generic and then for each message type */ +void migrate_send_rp_message(MigrationIncomingState *mis, + enum mig_rp_message_type message_type, + uint16_t len, void *data); +void migrate_send_rp_shut(MigrationIncomingState *mis, + uint32_t value); +void migrate_send_rp_pong(MigrationIncomingState *mis, + uint32_t value); + void ram_control_before_iterate(QEMUFile *f, uint64_t flags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data); diff --git a/migration/migration.c b/migration/migration.c index bb7dcb9..8380e2f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -97,6 +97,7 @@ MigrationIncomingState *migration_incoming_state_new(QEMUFile* f) mis_current = g_new0(MigrationIncomingState, 1); mis_current->from_src_file = f; QLIST_INIT(&mis_current->loadvm_handlers); + qemu_mutex_init(&mis_current->rp_mutex); return mis_current; } @@ -344,6 +345,50 @@ void process_incoming_migration(QEMUFile *f) qemu_coroutine_enter(co, f); } +/* + * Send a message on the return channel back to the source + * of the migration. + */ +void migrate_send_rp_message(MigrationIncomingState *mis, + enum mig_rp_message_type message_type, + uint16_t len, void *data) +{ + trace_migrate_send_rp_message((int)message_type, len); + qemu_mutex_lock(&mis->rp_mutex); + qemu_put_be16(mis->to_src_file, (unsigned int)message_type); + qemu_put_be16(mis->to_src_file, len); + qemu_put_buffer(mis->to_src_file, data, len); + qemu_fflush(mis->to_src_file); + qemu_mutex_unlock(&mis->rp_mutex); +} + +/* + * Send a 'SHUT' message on the return channel with the given value + * to indicate that we've finished with the RP. Non-0 value indicates + * error. + */ +void migrate_send_rp_shut(MigrationIncomingState *mis, + uint32_t value) +{ + uint32_t buf; + + buf = cpu_to_be32(value); + migrate_send_rp_message(mis, MIG_RP_MSG_SHUT, sizeof(buf), &buf); +} + +/* + * Send a 'PONG' message on the return channel with the given value + * (normally in response to a 'PING') + */ +void migrate_send_rp_pong(MigrationIncomingState *mis, + uint32_t value) +{ + uint32_t buf; + + buf = cpu_to_be32(value); + migrate_send_rp_message(mis, MIG_RP_MSG_PONG, sizeof(buf), &buf); +} + /* amount of nanoseconds we are willing to wait for migration to be down. * the choice of nanoseconds is because it is the maximum resolution that * get_clock() can achieve. It is an internal measure. All user-visible diff --git a/migration/savevm.c b/migration/savevm.c index d47c55b..1ffe7b0 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1103,7 +1103,7 @@ static int loadvm_process_command(QEMUFile *f) tmp32); return -1; } - /* migrate_send_rp_pong(mis, tmp32); TODO: gets added later */ + migrate_send_rp_pong(mis, tmp32); break; } diff --git a/trace-events b/trace-events index 500f1e3..ca5909b 100644 --- a/trace-events +++ b/trace-events @@ -1431,6 +1431,7 @@ migrate_fd_cleanup(void) "" migrate_fd_error(void) "" migrate_fd_cancel(void) "" migrate_pending(uint64_t size, uint64_t max) "pending size %" PRIu64 " max %" PRIu64 +migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 migrate_state_too_big(void) "" migrate_global_state_post_load(const char *state) "loaded state: %s"