From nobody Tue Feb 10 04:55:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=samsung.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520953112807776.0489542197477; Tue, 13 Mar 2018 07:58:32 -0700 (PDT) Received: from localhost ([::1]:40338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evlNo-0007Gl-0U for importer@patchew.org; Tue, 13 Mar 2018 10:58:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evlJV-0003Mw-8s for qemu-devel@nongnu.org; Tue, 13 Mar 2018 10:54:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evlJR-0001Lm-Q5 for qemu-devel@nongnu.org; Tue, 13 Mar 2018 10:54:05 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:45213) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evlJR-0001LF-GP for qemu-devel@nongnu.org; Tue, 13 Mar 2018 10:54:01 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180313145359euoutp016054ae93471c1faed26b560e85c26cb8~bgoytaLiO1996919969euoutp01b; Tue, 13 Mar 2018 14:53:59 +0000 (GMT) Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180313145358eucas1p23a9b9c1f1cbea5a4de5c65b3e22ba344~bgoxxBW5i2044720447eucas1p2C; Tue, 13 Mar 2018 14:53:58 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 4E.8D.10409.606E7AA5; Tue, 13 Mar 2018 14:53:58 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180313145358eucas1p24595ea6cba76b169ffbaa9bf1a90e964~bgoxC0gyz1638116381eucas1p2q; Tue, 13 Mar 2018 14:53:58 +0000 (GMT) Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id D7.3C.04183.506E7AA5; Tue, 13 Mar 2018 14:53:58 +0000 (GMT) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P5J00AR2APOJ400@eusync3.samsung.com>; Tue, 13 Mar 2018 14:53:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180313145359euoutp016054ae93471c1faed26b560e85c26cb8~bgoytaLiO1996919969euoutp01b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1520952839; bh=MmPq2VuWta5WPyGO7fGT3WYQotzvFhwU1KDKpqhVmUM=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=FYRXrRnRaEWr272aEjzX3BxK/EZpO2qp1EGpr1rymMWu5yn4iUom4uWjZsV9uh/4F MBZOep42h6wh9Hr5IRCLV3w4vOWjUBaK3dUoZDsNcxNqU1AbogDBtb8xhK8McaR6is lb0t8tEX+hz+jaQvfKBy7Ta9Eo/XpXAKoZs+iFPA= X-AuditID: cbfec7f5-b5fff700000028a9-7e-5aa7e606d881 From: Alexey Perevalov To: qemu-devel@nongnu.org, dgilbert@redhat.com Date: Tue, 13 Mar 2018 17:53:40 +0300 Message-id: <1520952824-3172-3-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1520952824-3172-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsWy7djP87psz5ZHGcyYL2cx9+55FouVk5cw WfRuu8ducWLTQWaLTw1SFlv2f2O3ON67g8XizpY+JovTNzezO3B6HHixkN3jybXNTB7v911l 8+jbsooxgCWKyyYlNSezLLVI3y6BK2PXjDb2gsUaFa9/X2ZsYNym0MXIySEhYCIxaeoG1i5G Lg4hgRWMEt/2XWSCcD4zSkx7MJcFpmrCvW3sEIlljBIX+t6wQDjdTBKr1u0B6ufgYBMwkNh3 zxbEFBHQk5hwNRKkhFlgI6PEzjvvwQYJC0RLvDswjRXEZhFQlbix6yk7iM0r4CZxaMVpVohl chI3z3Uyg8zhFHCXWNFVAjJHQqCHTWLltDtQNS4S/2Z/Y4ewhSVeHd8CZctIXJ7czQLR0M4o cXfjVVYIZwKjxLrJx5ghquwlTt28ygRiMwvwSUzaNh1sm4QAr0RHmxBEiYfE3etvoZY5Spx+ f58Z4uFZjBIHts9kmcAotYCRYRWjeGppcW56arFxXmq5XnFibnFpXrpecn7uJkZgjJ7+d/zr DsZ9f5IOMQpwMCrx8DJcWB4lxJpYVlyZe4hRgoNZSYQ35wFQiDclsbIqtSg/vqg0J7X4EKM0 B4uSOG+cRl2UkEB6YklqdmpqQWoRTJaJg1OqgXG99tH0NDOzOZctKp8xOk5f+lbu/r8P71/e 1OQ8GB6zq/JY3Ab3lZl5z/PaZv978y3/bejG6cG/V+81nT3PwkDz1kNzXUPfEzeO80p97X9l 2hr4m/G6bYgUQ/BtU8bOjM61G1VV5utO/Hh/6s8i3SsPv7NLdC387Xh/mv/TE9MkOKyazrxS ylFRYinOSDTUYi4qTgQAdklc7s0CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkluLIzCtJLcpLzFFi42I5/e/4VV22Z8ujDBpKLebePc9isXLyEiaL 3m332C1ObDrIbPGpQcpiy/5v7BbHe3ewWNzZ0sdkcfrmZnYHTo8DLxayezy5tpnJ4/2+q2we fVtWMQawRHHZpKTmZJalFunbJXBl7JrRxl6wWKPi9e/LjA2M2xS6GDk5JARMJCbc28bexcjF ISSwhFHi1t+7UE4vk8TEde9Yuhg5ONgEDCT23bMFMUUE9CQmXI0EKWEW2Mgo8WvGXVaQQcIC 0RLvDkwDs1kEVCVu7HrKDmLzCrhJHFpxmhVimZzEzXOdzCBzOAXcJVZ0lYCEhYBKds76yz6B kWcBI8MqRpHU0uLc9NxiI73ixNzi0rx0veT83E2MwADaduznlh2MXe+CDzEKcDAq8fAyXFge JcSaWFZcmXuIUYKDWUmEN+cBUIg3JbGyKrUoP76oNCe1+BCjNAeLkjjveYPKKCGB9MSS1OzU 1ILUIpgsEwenVAMj00L9ORv6elc9kDdcs9B506prq3az7tD5+KaI1/ktm6jH2ZSIy8ldim71 U7R9s7ftNGGSep1U/+rVqh15YhJ5NRl25e5fw9PXHNaqlHTNU2zU9T39o+C/PDtjXuf/ymhe D0sZnsuSJlxCjFGvnTrfPbzz5kx0cONtFgNRzb33ilcIaq6T/qrEUpyRaKjFXFScCABnmlXO HAIAAA== X-CMS-MailID: 20180313145358eucas1p24595ea6cba76b169ffbaa9bf1a90e964 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180313145358eucas1p24595ea6cba76b169ffbaa9bf1a90e964 X-RootMTR: 20180313145358eucas1p24595ea6cba76b169ffbaa9bf1a90e964 References: <1520952824-3172-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 210.118.77.11 Subject: [Qemu-devel] [PATCH v1 2/6] migration: add postcopy blocktime ctx into MigrationIncomingState 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: lvivier@redhat.com, v.kuramshin@samsung.com, quintela@redhat.com, ash.billore@samsung.com, Alexey Perevalov , peterx@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3Dcharmonitor,path=3D/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 Signed-off-by: Alexey Perevalov Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- 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 aa7a884..3ead619 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -22,6 +22,8 @@ #include "hw/qdev.h" #include "io/channel.h" =20 +struct PostcopyBlocktimeContext; + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -61,6 +63,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; }; =20 MigrationIncomingState *migration_incoming_get_current(void); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 032abfb..9144102 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -61,6 +61,54 @@ struct PostcopyDiscardState { #include #include =20 +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 =3D container_of(n, PostcopyBlocktimeCon= text, + exit_notifier); + destroy_blocktime_context(ctx); +} + +static struct PostcopyBlocktimeContext *blocktime_context_new(void) +{ + PostcopyBlocktimeContext *ctx =3D g_new0(PostcopyBlocktimeContext, 1); + ctx->page_fault_vcpu_time =3D g_new0(uint32_t, smp_cpus); + ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); + ctx->vcpu_blocktime =3D g_new0(uint32_t, smp_cpus); + + ctx->exit_notifier.notify =3D migration_exit_cb; + ctx->start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + qemu_add_exit_notifier(&ctx->exit_notifier); + return ctx; +} =20 /** * receive_ufd_features: check userfault fd features, to request only supp= orted @@ -153,6 +201,19 @@ static bool ufd_check_and_apply(int ufd, MigrationInco= mingState *mis) } } =20 +#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 =3D blocktime_context_new(); + } + + asked_features |=3D UFFD_FEATURE_THREAD_ID; + } +#endif + /* * request features, even if asked_features is 0, due to * kernel expects UFFD_API before UFFDIO_REGISTER, per --=20 2.7.4