From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: aarcange@redhat.com, yamahata@private.email.ne.jp,
quintela@redhat.com, qemu-devel@nongnu.org,
lilei@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 31/46] Postcopy: Rework migration thread for postcopy mode
Date: Thu, 28 Aug 2014 12:04:49 +0100 [thread overview]
Message-ID: <20140828110448.GB2402@work-vm> (raw)
In-Reply-To: <53B7D118.50008@redhat.com>
* Paolo Bonzini (pbonzini@redhat.com) wrote:
Hi Paolo,
Apologies, I realised I hadn't dug into this comment.
> Il 04/07/2014 19:41, Dr. David Alan Gilbert (git) ha scritto:
> >From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> >
> >Switch to postcopy if:
> > 1) There's still a significant amount to transfer
> > 2) Postcopy is enabled
> > 3) It's taken longer than the time set by the parameter.
> >
> >and change the cleanup at the end of migration to match.
> >
> >Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> >---
> > migration.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
> > 1 file changed, 73 insertions(+), 19 deletions(-)
> >
> >diff --git a/migration.c b/migration.c
> >index 0d567ef..c73fcfa 100644
> >--- a/migration.c
> >+++ b/migration.c
> >@@ -982,16 +982,40 @@ static int postcopy_start(MigrationState *ms)
> > static void *migration_thread(void *opaque)
> > {
> > MigrationState *s = opaque;
> >+ /* Used by the bandwidth calcs, updated later */
> > int64_t initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >+ /* Really, the time we started */
> >+ const int64_t initial_time_fixed = initial_time;
> > int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST);
> > int64_t initial_bytes = 0;
> > int64_t max_size = 0;
> > int64_t start_time = initial_time;
> >+ int64_t pc_start_time;
> >+
> > bool old_vm_running = false;
> >+ pc_start_time = s->tunables[MIGRATION_PARAMETER_NAME_X_POSTCOPY_START_TIME];
> >+
> >+ /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */
> >+ enum MigrationPhase current_active_type = MIG_STATE_ACTIVE;
> >
> > qemu_savevm_state_begin(s->file, &s->params);
> >
> >+ if (migrate_postcopy_ram()) {
> >+ /* Now tell the dest that it should open it's end so it can reply */
> >+ qemu_savevm_send_openrp(s->file);
> >+
> >+ /* And ask it to send an ack that will make stuff easier to debug */
> >+ qemu_savevm_send_reqack(s->file, 1);
> >+
> >+ /* Tell the destination that we *might* want to do postcopy later;
> >+ * if the other end can't do postcopy it should fail now, nice and
> >+ * early.
> >+ */
> >+ qemu_savevm_send_postcopy_ram_advise(s->file);
> >+ }
> >+
> > s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
> >+ current_active_type = MIG_STATE_ACTIVE;
> > migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE);
> >
> > DPRINTF("setup complete\n");
> >@@ -1012,37 +1036,66 @@ static void *migration_thread(void *opaque)
> > " nonpost=%" PRIu64 ")\n",
> > pending_size, max_size, pend_post, pend_nonpost);
> > if (pending_size && pending_size >= max_size) {
> >- qemu_savevm_state_iterate(s->file);
> >+ /* Still a significant amount to transfer */
> >+
> >+ current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >+ if (migrate_postcopy_ram() &&
> >+ s->state != MIG_STATE_POSTCOPY_ACTIVE &&
> >+ pend_nonpost == 0 &&
> >+ (current_time >= initial_time_fixed + pc_start_time)) {
> >+
> >+ if (!postcopy_start(s)) {
> >+ current_active_type = MIG_STATE_POSTCOPY_ACTIVE;
> >+ }
> >+
> >+ continue;
> >+ } else {
>
> You don't really need the "else" if you have a continue. However, do you
> need _any_ of the "else" and "continue"? Would the next iteration of the
> "while" loop do anything else but invoking qemu_savevm_state_iterate.
Yes, I've dropped that 'else'; however, I've kept the continue - we're about
3 if's deep here inside the loop and there's a bunch of stuff at the end of
the if's but still inside the loop that I'm not 100% sure I want to run
again at this point (although it's probably OK).
> >+ /* Just another iteration step */
> >+ qemu_savevm_state_iterate(s->file);
> >+ }
> > } else {
> > int ret;
> >
> >- DPRINTF("done iterating\n");
> >- qemu_mutex_lock_iothread();
> >- start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >- qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
> >- old_vm_running = runstate_is_running();
> >-
> >- ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
> >- if (ret >= 0) {
> >- qemu_file_set_rate_limit(s->file, INT64_MAX);
> >- qemu_savevm_state_complete(s->file);
> >- }
> >- qemu_mutex_unlock_iothread();
> >-
> >- if (ret < 0) {
> >- migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
> >- break;
> >+ DPRINTF("done iterating pending size %" PRIu64 "\n",
> >+ pending_size);
> >+
> >+ if (s->state == MIG_STATE_ACTIVE) {
> >+ qemu_mutex_lock_iothread();
> >+ start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >+ qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
> >+ old_vm_running = runstate_is_running();
> >+
> >+ ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
> >+ if (ret >= 0) {
> >+ qemu_file_set_rate_limit(s->file, INT64_MAX);
> >+ qemu_savevm_state_complete(s->file);
> >+ }
> >+ qemu_mutex_unlock_iothread();
> >+ if (ret < 0) {
> >+ migrate_set_state(s, current_active_type,
> >+ MIG_STATE_ERROR);
> >+ break;
> >+ }
>
> I think all this code applies to postcopy as well. Only the body of the
> first "if" must be replaced by qemu_savevm_state_postcopy_complete for
> postcopy.
A lot of this stuff is done, but it's done at the point we transition into
postcopy, not at the end (see postcopy_start). However, I've not
got the wakup_request and old_vm_running check; so I probably need to
think where they should go; what's the purpose of the qemu_system_wakeup_request
there ? it seems to be getting the guest into running state - which is
where I'd assumed it was already.
> >+ } else {
> >+ assert(s->state == MIG_STATE_POSTCOPY_ACTIVE);
>
> This can fail if you get a cancel in the meanwhile. You can replace the "if
> (s->state == MIG_STATE_ACTIVE" by "if (current_active_type ==
> MIG_STATE_ACTIVE)" and remove the assert here. Alternatively:
Ah, thanks - fixed in the next version.
> if (migrate_postcopy_ram()) {
> assert(current_active_type == MIG_STATE_ACTIVE);
> ...
> } else {
> assert(current_active_type == MIG_STATE_POSTCOPY_ACTIVE);
> ...
> }
>
> >+ DPRINTF("postcopy end\n");
> >+
> >+ qemu_savevm_state_postcopy_complete(s->file);
> >+ DPRINTF("postcopy end after complete\n");
> > }
> >
> > if (!qemu_file_get_error(s->file)) {
> >- migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
> >+ migrate_set_state(s, current_active_type,
> >+ MIG_STATE_COMPLETED);
> > break;
> > }
> > }
> > }
> >
> > if (qemu_file_get_error(s->file)) {
> >- migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
> >+ migrate_set_state(s, current_active_type, MIG_STATE_ERROR);
> >+ DPRINTF("migration_thread: file is in error state\n");
> > break;
> > }
> > current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >@@ -1073,6 +1126,7 @@ static void *migration_thread(void *opaque)
> > }
> > }
> >
> >+ DPRINTF("migration_thread: Hit error: case\n");
>
> This dprintf looks weird.
Fixed.
Dave
>
> Paolo
>
> > qemu_mutex_lock_iothread();
> > if (s->state == MIG_STATE_COMPLETED) {
> > int64_t end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> >
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2014-08-28 11:05 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-04 17:41 [Qemu-devel] [PATCH 00/46] Postcopy implementation Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 01/46] qemu_ram_foreach_block: pass up error value, and down the ramblock name Dr. David Alan Gilbert (git)
2014-07-07 15:46 ` Eric Blake
2014-07-07 15:48 ` Dr. David Alan Gilbert
2014-07-04 17:41 ` [Qemu-devel] [PATCH 02/46] Move QEMUFile structure to qemu-file.h Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 03/46] QEMUSizedBuffer/QEMUFile Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 04/46] improve DPRINTF macros, add to savevm Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 05/46] Add qemu_get_counted_string to read a string prefixed by a count byte Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 06/46] Create MigrationIncomingState Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 07/46] Return path: Open a return path on QEMUFile for sockets Dr. David Alan Gilbert (git)
2014-07-05 10:06 ` Paolo Bonzini
2014-07-16 9:37 ` Dr. David Alan Gilbert
2014-07-16 9:50 ` Paolo Bonzini
2014-07-16 11:52 ` Dr. David Alan Gilbert
2014-07-16 12:31 ` Paolo Bonzini
2014-07-16 17:10 ` Dr. David Alan Gilbert
2014-07-17 6:25 ` Paolo Bonzini
2014-07-04 17:41 ` [Qemu-devel] [PATCH 08/46] Return path: socket_writev_buffer: Block even on non-blocking fd's Dr. David Alan Gilbert (git)
2014-07-05 10:07 ` Paolo Bonzini
2014-07-04 17:41 ` [Qemu-devel] [PATCH 09/46] Migration commands Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 10/46] Return path: Control commands Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 11/46] Return path: Send responses from destination to source Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 12/46] Return path: Source handling of return path Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 13/46] qemu_loadvm debug Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 14/46] ram_debug_dump_bitmap: Dump a migration bitmap as text Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 15/46] Rework loadvm path for subloops Dr. David Alan Gilbert (git)
2014-07-05 10:26 ` Paolo Bonzini
2014-07-07 14:35 ` Dr. David Alan Gilbert
2014-07-07 14:53 ` Paolo Bonzini
2014-07-07 15:04 ` Dr. David Alan Gilbert
2014-07-16 9:25 ` Dr. David Alan Gilbert
2014-07-04 17:41 ` [Qemu-devel] [PATCH 16/46] Add migration-capability boolean for postcopy-ram Dr. David Alan Gilbert (git)
2014-07-07 19:41 ` Eric Blake
2014-07-07 20:23 ` Dr. David Alan Gilbert
2014-07-10 16:17 ` Paolo Bonzini
2014-07-10 19:02 ` Dr. David Alan Gilbert
2014-07-04 17:41 ` [Qemu-devel] [PATCH 17/46] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 18/46] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 19/46] migrate_init: Call from savevm Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 20/46] Allow savevm handlers to state whether they could go into postcopy Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 21/46] postcopy: OS support test Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 22/46] Migration parameters: Add qmp/hmp commands for setting/viewing Dr. David Alan Gilbert (git)
2014-07-07 19:50 ` Eric Blake
2014-07-04 17:41 ` [Qemu-devel] [PATCH 23/46] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 24/46] qemu_savevm_state_complete: Postcopy changes Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 25/46] Postcopy: Maintain sentmap during postcopy pre phase Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 26/46] Postcopy page-map-incoming (PMI) structure Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 27/46] postcopy: Add incoming_init/cleanup functions Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 28/46] postcopy: Incoming initialisation Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 29/46] postcopy: ram_enable_notify to switch on userfault Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 30/46] Postcopy: postcopy_start Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 31/46] Postcopy: Rework migration thread for postcopy mode Dr. David Alan Gilbert (git)
2014-07-05 10:19 ` Paolo Bonzini
2014-08-28 11:04 ` Dr. David Alan Gilbert [this message]
2014-08-28 11:23 ` Paolo Bonzini
2014-07-04 17:41 ` [Qemu-devel] [PATCH 32/46] mig fd_connect: open return path Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 33/46] Postcopy: Create a fault handler thread before marking the ram as userfault Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 34/46] Page request: Add MIG_RPCOMM_REQPAGES reverse command Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 35/46] Page request: Process incoming page request Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 36/46] Page request: Consume pages off the post-copy queue Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 37/46] Add assertion to check migration_dirty_pages doesn't go -ve; have seen it happen once but not sure why Dr. David Alan Gilbert (git)
2014-07-11 15:20 ` Eric Blake
2014-07-11 15:41 ` Dr. David Alan Gilbert
2014-07-04 17:41 ` [Qemu-devel] [PATCH 38/46] postcopy_ram.c: place_page and helpers Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 39/46] Postcopy: Use helpers to map pages during migration Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 40/46] qemu_ram_block_from_host Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 41/46] Handle userfault requests (although userfaultfd not done yet) Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 42/46] Start up a postcopy/listener thread ready for incoming page data Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 43/46] postcopy: Wire up loadvm_postcopy_ram_handle_{run, end} commands Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 44/46] postcopy: Use userfaultfd Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 45/46] End of migration for postcopy Dr. David Alan Gilbert (git)
2014-07-04 17:41 ` [Qemu-devel] [PATCH 46/46] Start documenting how postcopy works Dr. David Alan Gilbert (git)
2014-07-05 10:28 ` [Qemu-devel] [PATCH 00/46] Postcopy implementation Paolo Bonzini
2014-07-07 14:02 ` Dr. David Alan Gilbert
2014-07-07 14:35 ` Paolo Bonzini
2014-07-07 14:58 ` Dr. David Alan Gilbert
2014-07-10 11:29 ` Dr. David Alan Gilbert
2014-07-10 12:48 ` Eric Blake
2014-07-10 13:37 ` Dr. David Alan Gilbert
2014-07-10 15:33 ` Andrea Arcangeli
2014-07-10 15:49 ` Dr. David Alan Gilbert
2014-07-11 4:05 ` Sanidhya Kashyap
2014-08-11 15:31 ` Dr. David Alan Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140828110448.GB2402@work-vm \
--to=dgilbert@redhat.com \
--cc=aarcange@redhat.com \
--cc=lilei@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=yamahata@private.email.ne.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).