qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, quintela@redhat.com, peterx@redhat.com,
	a.perevalov@samsung.com, xiaoguangrong@tencent.com
Subject: [Qemu-devel] [PULL 02/16] migration: add postcopy blocktime ctx into MigrationIncomingState
Date: Wed, 25 Apr 2018 21:03:12 +0100	[thread overview]
Message-ID: <20180425200326.72337-3-dgilbert@redhat.com> (raw)
In-Reply-To: <20180425200326.72337-1-dgilbert@redhat.com>

From: Alexey Perevalov <a.perevalov@samsung.com>

This patch adds request to kernel space for UFFD_FEATURE_THREAD_ID, in
case this feature is provided by kernel.

PostcopyBlocktimeContext is encapsulated inside postcopy-ram.c,
due to it being a postcopy-only feature.
Also it defines PostcopyBlocktimeContext's instance live time.
Information from PostcopyBlocktimeContext instance will be provided
much after postcopy migration end, instance of PostcopyBlocktimeContext
will live till QEMU exit, but part of it (vcpu_addr,
page_fault_vcpu_time) used only during calculation, will be released
when postcopy ended or failed.

To enable postcopy blocktime calculation on destination, need to
request proper compatibility (Patch for documentation will be at the
tail of the patch set).

As an example following command enable that capability, assume QEMU was
started with
-chardev socket,id=charmonitor,path=/var/lib/migrate-vm-monitor.sock
option to control it

[root@host]#printf "{\"execute\" : \"qmp_capabilities\"}\r\n \
{\"execute\": \"migrate-set-capabilities\" , \"arguments\":   {
\"capabilities\": [ { \"capability\": \"postcopy-blocktime\", \"state\":
true } ] } }" | nc -U /var/lib/migrate-vm-monitor.sock

Or just with HMP
(qemu) migrate_set_capability postcopy-blocktime on

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-Id: <1521742647-25550-3-git-send-email-a.perevalov@samsung.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/migration.h    |  8 ++++++
 migration/postcopy-ram.c | 61 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/migration/migration.h b/migration/migration.h
index 46a50bc789..6d9aaeb480 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -22,6 +22,8 @@
 #include "hw/qdev.h"
 #include "io/channel.h"
 
+struct PostcopyBlocktimeContext;
+
 /* State for the incoming migration */
 struct MigrationIncomingState {
     QEMUFile *from_src_file;
@@ -65,6 +67,12 @@ struct MigrationIncomingState {
     /* The coroutine we should enter (back) after failover */
     Coroutine *migration_incoming_co;
     QemuSemaphore colo_incoming_sem;
+
+    /*
+     * PostcopyBlocktimeContext to keep information for postcopy
+     * live migration, to calculate vCPU block time
+     * */
+    struct PostcopyBlocktimeContext *blocktime_ctx;
 };
 
 MigrationIncomingState *migration_incoming_get_current(void);
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 4a0b33b373..eddba05b57 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -90,6 +90,54 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp)
 #include <sys/eventfd.h>
 #include <linux/userfaultfd.h>
 
+typedef struct PostcopyBlocktimeContext {
+    /* time when page fault initiated per vCPU */
+    uint32_t *page_fault_vcpu_time;
+    /* page address per vCPU */
+    uintptr_t *vcpu_addr;
+    uint32_t total_blocktime;
+    /* blocktime per vCPU */
+    uint32_t *vcpu_blocktime;
+    /* point in time when last page fault was initiated */
+    uint32_t last_begin;
+    /* number of vCPU are suspended */
+    int smp_cpus_down;
+    uint64_t start_time;
+
+    /*
+     * Handler for exit event, necessary for
+     * releasing whole blocktime_ctx
+     */
+    Notifier exit_notifier;
+} PostcopyBlocktimeContext;
+
+static void destroy_blocktime_context(struct PostcopyBlocktimeContext *ctx)
+{
+    g_free(ctx->page_fault_vcpu_time);
+    g_free(ctx->vcpu_addr);
+    g_free(ctx->vcpu_blocktime);
+    g_free(ctx);
+}
+
+static void migration_exit_cb(Notifier *n, void *data)
+{
+    PostcopyBlocktimeContext *ctx = container_of(n, PostcopyBlocktimeContext,
+                                                 exit_notifier);
+    destroy_blocktime_context(ctx);
+}
+
+static struct PostcopyBlocktimeContext *blocktime_context_new(void)
+{
+    PostcopyBlocktimeContext *ctx = g_new0(PostcopyBlocktimeContext, 1);
+    ctx->page_fault_vcpu_time = g_new0(uint32_t, smp_cpus);
+    ctx->vcpu_addr = g_new0(uintptr_t, smp_cpus);
+    ctx->vcpu_blocktime = g_new0(uint32_t, smp_cpus);
+
+    ctx->exit_notifier.notify = migration_exit_cb;
+    ctx->start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+    qemu_add_exit_notifier(&ctx->exit_notifier);
+    return ctx;
+}
 
 /**
  * receive_ufd_features: check userfault fd features, to request only supported
@@ -182,6 +230,19 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
         }
     }
 
+#ifdef UFFD_FEATURE_THREAD_ID
+    if (migrate_postcopy_blocktime() && mis &&
+        UFFD_FEATURE_THREAD_ID & supported_features) {
+        /* kernel supports that feature */
+        /* don't create blocktime_context if it exists */
+        if (!mis->blocktime_ctx) {
+            mis->blocktime_ctx = blocktime_context_new();
+        }
+
+        asked_features |= UFFD_FEATURE_THREAD_ID;
+    }
+#endif
+
     /*
      * request features, even if asked_features is 0, due to
      * kernel expects UFFD_API before UFFDIO_REGISTER, per
-- 
2.17.0

  parent reply	other threads:[~2018-04-25 20:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-25 20:03 [Qemu-devel] [PULL 00/16] migration queue Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 01/16] migration: introduce postcopy-blocktime capability Dr. David Alan Gilbert (git)
2018-04-25 20:34   ` Eric Blake
2018-04-26 12:24     ` Dr. David Alan Gilbert
2018-04-25 20:03 ` Dr. David Alan Gilbert (git) [this message]
2018-04-25 20:03 ` [Qemu-devel] [PULL 03/16] migration: calculate vCPU blocktime on dst side Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 04/16] migration: postcopy_blocktime documentation Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 05/16] migration: add blocktime calculation into migration-test Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 06/16] migration: add postcopy total blocktime into query-migrate Dr. David Alan Gilbert (git)
2018-04-25 20:37   ` Eric Blake
2018-04-26 12:28     ` Dr. David Alan Gilbert
2018-04-25 20:03 ` [Qemu-devel] [PULL 07/16] migration: stop compressing page in migration thread Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 08/16] migration: stop compression to allocate and free memory frequently Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 09/16] migration: stop decompression " Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 10/16] migration: detect compression and decompression errors Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 11/16] migration: introduce control_save_page() Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 12/16] migration: move some code to ram_save_host_page Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 13/16] migration: move calling control_save_page to the common place Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 14/16] migration: move calling save_zero_page " Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 15/16] migration: introduce save_normal_page() Dr. David Alan Gilbert (git)
2018-04-25 20:03 ` [Qemu-devel] [PULL 16/16] migration: remove ram_save_compressed_page() Dr. David Alan Gilbert (git)
2018-04-26 10:57 ` [Qemu-devel] [PULL 00/16] migration queue Peter Maydell

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=20180425200326.72337-3-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=a.perevalov@samsung.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=xiaoguangrong@tencent.com \
    /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).