From nobody Tue Feb 10 22:18:00 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.zoho.com; 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14945962316815.476979660850475; Fri, 12 May 2017 06:37:11 -0700 (PDT) Received: from localhost ([::1]:53854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9Ako-0000tK-Ds for importer@patchew.org; Fri, 12 May 2017 09:37:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9Afj-0005OF-AN for qemu-devel@nongnu.org; Fri, 12 May 2017 09:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9Afe-00072T-AI for qemu-devel@nongnu.org; Fri, 12 May 2017 09:31:55 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:20657) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9Afe-00070o-4j for qemu-devel@nongnu.org; Fri, 12 May 2017 09:31:50 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OPU00IELDL0FO10@mailout1.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 12 May 2017 14:31:48 +0100 (BST) Received: from eusmges2.samsung.com (unknown [203.254.199.241]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170512133148eucas1p1998308b3adc5185aac2044456a392d1b~93w9T1zjR2543425434eucas1p1v; Fri, 12 May 2017 13:31:48 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2.samsung.com (EUCPMTA) with SMTP id 4C.94.04459.349B5195; Fri, 12 May 2017 14:31:48 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170512133147eucas1p1aca0281fc864bf6f3beb610e7ce2695b~93w8uoKvM2731527315eucas1p1B; Fri, 12 May 2017 13:31:47 +0000 (GMT) Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id C0.81.20206.369B5195; Fri, 12 May 2017 14:32:19 +0100 (BST) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OPU00791DKM5L30@eusync1.samsung.com>; Fri, 12 May 2017 14:31:47 +0100 (BST) X-AuditID: cbfec7f1-f796e6d00000116b-7c-5915b943f4f6 From: Alexey Perevalov To: qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:31:23 +0300 Message-id: <1494595886-30912-7-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1494595886-30912-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRmVeSWpSXmKPExsWy7djP87ouO0UjDX5NZbKYe/c8i0Xvtnvs Flfaf7JbbNn/jd3ieO8OFgdWjyfXNjN5vN93lc2jb8sqxgDmKC6blNSczLLUIn27BK6Ml/NP sBa81qp4OfM2awNjo1IXIyeHhICJxK8zU9kgbDGJC/fWA9lcHEICSxkluvfuZIVwPjNKbO28 ygzT0XBsGQtEYhmjxKcXq6CqupkkNjeeBari4GATMJDYd88WpEFEQFLid9dpsGZmgViJt9ev ga0TFkiReLe4gRXEZhFQlfgxEWQ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FhxhNgY6ayCwlmpwPjKC8knhDE0NzS0MjYwsLcyMjJXHeqR+uhAsJpCeWpGanphak FsH0MXFwSjUwXjgcypy1d668/1cG0dnHd1xOXe5d7dy4IFn0Ce/9hZslDhSIuB4s2JW9+8r7 FRclHs47nVHl+Z25pT7056nT7s97jJs7/yUc0elpmHmOYdrEn6t1y6wjt1hfnHO1UqFj+6yt Wpu3bJS1Wtc9ZZuP6cqyql8veC67bX3n4ue2Xn3GmkX3ii1LmJRYijMSDbWYi4oTATsOspNo AgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170512133147eucas1p1aca0281fc864bf6f3beb610e7ce2695b X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG+yCvOyEseyghOyekBtTZW5pb3IgRW5naW5lZXI=?= X-Global-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG1NhbXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1NA==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170512133147eucas1p1aca0281fc864bf6f3beb610e7ce2695b X-RootMTR: 20170512133147eucas1p1aca0281fc864bf6f3beb610e7ce2695b References: <1494595886-30912-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 210.118.77.11 Subject: [Qemu-devel] [PATCH V5 6/9] migration: add postcopy vcpu blocktime context 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: i.maximets@samsung.com, dgilbert@redhat.com, peterx@redhat.com, a.perevalov@samsung.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: 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 when this feature is provided by kernel. PostcopyBlocktimeContext is incapsulated inside postcopy-ram.c, due to it's 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 capabiltiy (Patch for documentation will at the tail of 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 Signed-off-by: Alexey Perevalov --- include/migration/migration.h | 8 +++++ migration/postcopy-ram.c | 76 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 84 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 82bbcd8..7e69a2d 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -83,6 +83,8 @@ typedef enum { POSTCOPY_INCOMING_END } PostcopyState; =20 +struct PostcopyBlocktimeContext; + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -123,6 +125,12 @@ struct MigrationIncomingState { =20 /* See savevm.c */ LoadStateEntry_Head loadvm_handlers; + + /* + * 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 c96d5f5..a1f1705 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -60,6 +60,73 @@ struct PostcopyDiscardState { #include #include =20 +typedef struct PostcopyBlocktimeContext { + /* time when page fault initiated per vCPU */ + int64_t *page_fault_vcpu_time; + /* page address per vCPU */ + uint64_t *vcpu_addr; + int64_t total_blocktime; + /* blocktime per vCPU */ + int64_t *vcpu_blocktime; + /* point in time when last page fault was initiated */ + int64_t last_begin; + /* number of vCPU are suspended */ + int smp_cpus_down; + + /* + * Handler for exit event, necessary for + * releasing whole blocktime_ctx + */ + Notifier exit_notifier; + /* + * Handler for postcopy event, necessary for + * releasing unnecessary part of blocktime_ctx + */ + Notifier postcopy_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 postcopy_migration_cb(Notifier *n, void *data) +{ + PostcopyBlocktimeContext *ctx =3D container_of(n, PostcopyBlocktimeCon= text, + postcopy_notifier); + MigrationState *s =3D data; + if (migration_has_finished(s) || migration_has_failed(s)) { + g_free(ctx->page_fault_vcpu_time); + /* g_free is NULL robust */ + ctx->page_fault_vcpu_time =3D NULL; + g_free(ctx->vcpu_addr); + ctx->vcpu_addr =3D NULL; + } +} + +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(int64_t, smp_cpus); + ctx->vcpu_addr =3D g_new0(uint64_t, smp_cpus); + ctx->vcpu_blocktime =3D g_new0(int64_t, smp_cpus); + + ctx->exit_notifier.notify =3D migration_exit_cb; + ctx->postcopy_notifier.notify =3D postcopy_migration_cb; + qemu_add_exit_notifier(&ctx->exit_notifier); + add_migration_state_change_notifier(&ctx->postcopy_notifier); + return ctx; +} =20 /* * Check userfault fd features, to request only supported features in @@ -134,6 +201,15 @@ static bool ufd_check_and_apply(int ufd, MigrationInco= mingState *mis) return false; } =20 +#ifdef UFFD_FEATURE_THREAD_ID + if (migrate_postcopy_blocktime() && mis && + UFFD_FEATURE_THREAD_ID & supported_features) { + /* kernel supports that feature */ + 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 1.9.1