From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dave@treblig.org>,
peterx@redhat.com, Alexey Perevalov <a.perevalov@samsung.com>,
Fabiano Rosas <farosas@suse.de>,
Juraj Marcin <jmarcin@redhat.com>
Subject: [PATCH 06/13] migration/postcopy: Bring blocktime layer to us level
Date: Tue, 27 May 2025 19:12:41 -0400 [thread overview]
Message-ID: <20250527231248.1279174-7-peterx@redhat.com> (raw)
In-Reply-To: <20250527231248.1279174-1-peterx@redhat.com>
With 64-bit fields, it is trivial. The caution is when exposing any values
in QMP, it was still declared with milliseconds (ms). Hence it's needed to
do the convertion when exporting the values to existing QMP queries.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/postcopy-ram.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index c6ae4b650c..5cbc7aa77e 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -110,6 +110,7 @@ void postcopy_thread_create(MigrationIncomingState *mis,
#include <sys/eventfd.h>
#include <linux/userfaultfd.h>
+/* All the time records are in unit of microseconds (us) */
typedef struct PostcopyBlocktimeContext {
/* time when page fault initiated per vCPU */
uint64_t *vcpu_blocktime_start;
@@ -168,7 +169,8 @@ static uint32List *get_vcpu_blocktime_list(PostcopyBlocktimeContext *ctx)
int i;
for (i = ms->smp.cpus - 1; i >= 0; i--) {
- QAPI_LIST_PREPEND(list, (uint32_t)ctx->vcpu_blocktime_total[i]);
+ QAPI_LIST_PREPEND(
+ list, (uint32_t)(ctx->vcpu_blocktime_total[i] / 1000));
}
return list;
@@ -191,7 +193,7 @@ void fill_destination_postcopy_migration_info(MigrationInfo *info)
}
info->has_postcopy_blocktime = true;
- info->postcopy_blocktime = (uint32_t)bc->total_blocktime;
+ info->postcopy_blocktime = (uint32_t)(bc->total_blocktime / 1000);
info->has_postcopy_vcpu_blocktime = true;
info->postcopy_vcpu_blocktime = get_vcpu_blocktime_list(bc);
}
@@ -816,9 +818,9 @@ static int get_mem_fault_cpu_index(uint32_t pid)
return -1;
}
-static uint64_t get_low_time_offset(void)
+static uint64_t get_current_us(void)
{
- return (uint64_t)qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+ return (uint64_t)qemu_clock_get_us(QEMU_CLOCK_REALTIME);
}
/*
@@ -835,7 +837,7 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid,
int cpu;
MigrationIncomingState *mis = migration_incoming_get_current();
PostcopyBlocktimeContext *dc = mis->blocktime_ctx;
- uint64_t low_time_offset;
+ uint64_t current_us;
if (!dc || ptid == 0) {
return;
@@ -845,13 +847,13 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid,
return;
}
- low_time_offset = get_low_time_offset();
+ current_us = get_current_us();
if (dc->vcpu_addr[cpu] == 0) {
dc->smp_cpus_down++;
}
- dc->last_begin = low_time_offset;
- dc->vcpu_blocktime_start[cpu] = low_time_offset;
+ dc->last_begin = current_us;
+ dc->vcpu_blocktime_start[cpu] = current_us;
dc->vcpu_addr[cpu] = addr;
/*
@@ -899,13 +901,13 @@ static void mark_postcopy_blocktime_end(uintptr_t addr)
unsigned int smp_cpus = ms->smp.cpus;
int i, affected_cpu = 0;
bool vcpu_total_blocktime = false;
- uint64_t read_vcpu_time, low_time_offset;
+ uint64_t read_vcpu_time, current_us;
if (!dc) {
return;
}
- low_time_offset = get_low_time_offset();
+ current_us = get_current_us();
/* lookup cpu, to clear it,
* that algorithm looks straightforward, but it's not
* optimal, more optimal algorithm is keeping tree or hash
@@ -918,7 +920,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr)
continue;
}
dc->vcpu_addr[i] = 0;
- vcpu_blocktime = low_time_offset - read_vcpu_time;
+ vcpu_blocktime = current_us - read_vcpu_time;
affected_cpu += 1;
/* we need to know is that mark_postcopy_end was due to
* faulted page, another possible case it's prefetched
@@ -932,7 +934,7 @@ static void mark_postcopy_blocktime_end(uintptr_t addr)
dc->smp_cpus_down -= affected_cpu;
if (vcpu_total_blocktime) {
- dc->total_blocktime += low_time_offset - dc->last_begin;
+ dc->total_blocktime += current_us - dc->last_begin;
}
trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime,
affected_cpu);
--
2.49.0
next prev parent reply other threads:[~2025-05-27 23:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 23:12 [PATCH 00/13] migration/postcopy: Blocktime tracking overhaul Peter Xu
2025-05-27 23:12 ` [PATCH 01/13] migration: Add option to set postcopy-blocktime Peter Xu
2025-06-02 16:50 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 02/13] migration/postcopy: Push blocktime start/end into page req mutex Peter Xu
2025-06-02 17:46 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 03/13] migration/postcopy: Drop all atomic ops in blocktime feature Peter Xu
2025-06-02 18:00 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 04/13] migration/postcopy: Make all blocktime vars 64bits Peter Xu
2025-06-02 20:42 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 05/13] migration/postcopy: Drop PostcopyBlocktimeContext.start_time Peter Xu
2025-06-03 15:52 ` Fabiano Rosas
2025-06-03 15:55 ` Fabiano Rosas
2025-05-27 23:12 ` Peter Xu [this message]
2025-06-03 15:54 ` [PATCH 06/13] migration/postcopy: Bring blocktime layer to us level Fabiano Rosas
2025-05-27 23:12 ` [PATCH 07/13] migration/postcopy: Add blocktime fault counts per-vcpu Peter Xu
2025-06-03 15:59 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 08/13] migration/postcopy: Report fault latencies in blocktime Peter Xu
2025-06-02 9:26 ` Markus Armbruster
2025-06-02 16:29 ` Peter Xu
2025-06-03 16:07 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 09/13] migration/postcopy: Initialize blocktime context only until listen Peter Xu
2025-06-03 16:08 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 10/13] migration/postcopy: Cache the tid->vcpu mapping for blocktime Peter Xu
2025-06-03 16:20 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 11/13] migration/postcopy: Cleanup the total blocktime accounting Peter Xu
2025-06-03 16:22 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 12/13] migration/postcopy: Optimize blocktime fault tracking with hashtable Peter Xu
2025-06-03 16:44 ` Fabiano Rosas
2025-05-27 23:12 ` [PATCH 13/13] migration/postcopy: blocktime allows track / report non-vCPU faults Peter Xu
2025-06-03 16:50 ` Fabiano Rosas
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=20250527231248.1279174-7-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=a.perevalov@samsung.com \
--cc=dave@treblig.org \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).