From patchwork Thu Aug 28 15:03:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 383904 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 DAF2C140119 for ; Fri, 29 Aug 2014 01:17:55 +1000 (EST) Received: from localhost ([::1]:37255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XN1ST-0005Vy-Vk for incoming@patchwork.ozlabs.org; Thu, 28 Aug 2014 11:17:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XN1GM-0001gq-Tr for qemu-devel@nongnu.org; Thu, 28 Aug 2014 11:05:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XN1GG-0002kH-Nr for qemu-devel@nongnu.org; Thu, 28 Aug 2014 11:05:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XN1GG-0002kB-G7 for qemu-devel@nongnu.org; Thu, 28 Aug 2014 11:05:16 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7SF5CGM018476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 28 Aug 2014 11:05:13 -0400 Received: from dgilbert-t530.home.treblig.org (vpn1-5-132.ams2.redhat.com [10.36.5.132]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7SF44wD003726; Thu, 28 Aug 2014 11:05:11 -0400 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Thu, 28 Aug 2014 16:03:53 +0100 Message-Id: <1409238244-31720-37-git-send-email-dgilbert@redhat.com> In-Reply-To: <1409238244-31720-1-git-send-email-dgilbert@redhat.com> References: <1409238244-31720-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, amit.shah@redhat.com, lilei@linux.vnet.ibm.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH v3 36/47] Page request: Add MIG_RPCOMM_REQPAGES reverse command 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 MIG_RPCOMM_REQPAGES command on Return path for the postcopy destination to request a page from the source. Signed-off-by: Dr. David Alan Gilbert --- include/migration/migration.h | 3 ++ migration.c | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 07e15d7..8e8fdf2 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -45,6 +45,7 @@ enum mig_rpcomm_cmd { MIG_RPCOMM_INVALID = 0, /* Must be 0 */ MIG_RPCOMM_SHUT, /* sibling will not send any more RP messages */ MIG_RPCOMM_ACK, /* data (seq: be32 ) */ + MIG_RPCOMM_REQPAGES, /* data (start: be64, len: be64) */ MIG_RPCOMM_AFTERLASTVALID }; @@ -240,6 +241,8 @@ void migrate_send_rp_shut(MigrationIncomingState *mis, uint32_t value); void migrate_send_rp_ack(MigrationIncomingState *mis, uint32_t value); +void migrate_send_rp_reqpages(MigrationIncomingState *mis, const char* rbname, + ram_addr_t start, ram_addr_t len); void ram_control_before_iterate(QEMUFile *f, uint64_t flags); diff --git a/migration.c b/migration.c index 8ab378f..b8df458 100644 --- a/migration.c +++ b/migration.c @@ -144,6 +144,38 @@ void migrate_send_rp_ack(MigrationIncomingState *mis, migrate_send_rp_message(mis, MIG_RPCOMM_ACK, 4, (uint8_t *)&buf); } +/* Request a range of pages from the source VM at the given + * start address. + * rbname: Name of the RAMBlock to request the page in, if NULL it's the same + * as the last request (a name must have been given previously) + * Start: Address offset within the RB + * Len: Length in bytes required - must be a multiple of pagesize + */ +void migrate_send_rp_reqpages(MigrationIncomingState *mis, const char *rbname, + ram_addr_t start, ram_addr_t len) +{ + uint8_t bufc[16+1+255]; /* start (8 byte), len (8 byte), rbname upto 256 */ + uint64_t *buf64 = (uint64_t *)bufc; + size_t msglen = 16; /* start + len */ + + assert(!(len & 1)); + if (rbname) { + int rbname_len = strlen(rbname); + assert(rbname_len < 256); + + len |= 1; /* Flag to say we've got a name */ + bufc[msglen++] = rbname_len; + memcpy(bufc + msglen, rbname, rbname_len); + msglen += rbname_len; + } + + buf64[0] = (uint64_t)start; + buf64[0] = cpu_to_be64(buf64[0]); + buf64[1] = (uint64_t)len; + buf64[1] = cpu_to_be64(buf64[1]); + migrate_send_rp_message(mis, MIG_RPCOMM_REQPAGES, msglen, bufc); +} + void qemu_start_incoming_migration(const char *uri, Error **errp) { const char *p; @@ -777,6 +809,17 @@ static void source_return_path_bad(MigrationState *s) } /* + * Process a request for pages received on the return path, + * We're allowed to send more than requested (e.g. to round to our page size) + * and we don't need to send pages that have already been sent. + */ +static void migrate_handle_rp_reqpages(MigrationState *ms, const char* rbname, + ram_addr_t start, ram_addr_t len) +{ + DPRINTF("migrate_handle_rp_reqpages: at %zx for len %zx", start, len); +} + +/* * Handles messages sent on the return path towards the source VM * */ @@ -788,6 +831,8 @@ static void *source_return_path_thread(void *opaque) const int max_len = 512; uint8_t buf[max_len]; uint32_t tmp32; + uint64_t tmp64a, tmp64b; + char *tmpstr; int res; DPRINTF("RP: %s entry", __func__); @@ -803,6 +848,11 @@ static void *source_return_path_thread(void *opaque) expected_len = 4; break; + case MIG_RPCOMM_REQPAGES: + /* 16 byte start/len _possibly_ plus an id str */ + expected_len = 16 + 256; + break; + default: error_report("RP: Received invalid cmd 0x%04x length 0x%04x", header_com, header_len); @@ -850,6 +900,30 @@ static void *source_return_path_thread(void *opaque) atomic_xchg(&ms->rp_state.latest_ack, tmp32); break; + case MIG_RPCOMM_REQPAGES: + tmp64a = be64_to_cpup((uint64_t *)buf); /* Start */ + tmp64b = be64_to_cpup(((uint64_t *)buf)+1); /* Len */ + tmpstr = NULL; + if (tmp64b & 1) { + tmp64b -= 1; /* Remove the flag */ + /* Now we expect an idstr */ + tmp32 = buf[16]; /* Length of the following idstr */ + tmpstr = (char *)&buf[17]; + buf[17+tmp32] = '\0'; + expected_len = 16+1+tmp32; + } else { + expected_len = 16; + } + if (header_len != expected_len) { + error_report("RP: Received ReqPage with length %d expecting %d", + header_len, expected_len); + source_return_path_bad(ms); + } + migrate_handle_rp_reqpages(ms, tmpstr, + (ram_addr_t)tmp64a, + (ram_addr_t)tmp64b); + break; + default: /* This shouldn't happen because we should catch this above */ DPRINTF("RP: Bad header_com in dispatch");