aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2025-06-13 10:12:14 -0400
committerFabiano Rosas <farosas@suse.de>2025-07-11 10:37:38 -0300
commit4c8a1194852844a1fc07af804579c7cf997e5c4a (patch)
tree620c65a275aa20c1c47bd73e78e755d6f1461a77
parent28a185204ee9a4dd1b0da38c92f2d9326ca590d5 (diff)
downloadqemu-4c8a1194852844a1fc07af804579c7cf997e5c4a.zip
qemu-4c8a1194852844a1fc07af804579c7cf997e5c4a.tar.gz
qemu-4c8a1194852844a1fc07af804579c7cf997e5c4a.tar.bz2
migration/postcopy: Cleanup the total blocktime accounting
The variable vcpu_total_blocktime isn't easy to follow. In reality, it wants to capture the case where all vCPUs are stopped, and now there will be some vCPUs starts running. The name now starts to conflict with vcpu_blocktime_total[], meanwhile it's actually not necessary to have the variable at all: since nobody is touching smp_cpus_down except ourselves, we can safely do the calculation at the end before decrementing smp_cpus_down. Hopefully this makes the logic easier to read, side benefit is we drop one temp var. Reviewed-by: Fabiano Rosas <farosas@suse.de> Link: https://lore.kernel.org/r/20250613141217.474825-12-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de>
-rw-r--r--migration/postcopy-ram.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index bf65d60..fd6c0bd 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -972,7 +972,6 @@ static void mark_postcopy_blocktime_end(uintptr_t addr)
MachineState *ms = MACHINE(qdev_get_machine());
unsigned int smp_cpus = ms->smp.cpus;
int i, affected_cpu = 0;
- bool vcpu_total_blocktime = false;
uint64_t read_vcpu_time, current;
if (!dc) {
@@ -994,20 +993,19 @@ static void mark_postcopy_blocktime_end(uintptr_t addr)
dc->vcpu_addr[i] = 0;
vcpu_blocktime = current - 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
- * page and in that case we shouldn't be here */
- if (!vcpu_total_blocktime && dc->smp_cpus_down == smp_cpus) {
- vcpu_total_blocktime = true;
- }
/* continue cycle, due to one page could affect several vCPUs */
dc->vcpu_blocktime_total[i] += vcpu_blocktime;
}
- dc->smp_cpus_down -= affected_cpu;
- if (vcpu_total_blocktime) {
+ /*
+ * If all vCPUs used to be down, and copying this page would free some
+ * vCPUs, then the system-level blocktime ends here.
+ */
+ if (dc->smp_cpus_down == smp_cpus && affected_cpu) {
dc->total_blocktime += current - dc->last_begin;
}
+ dc->smp_cpus_down -= affected_cpu;
+
trace_mark_postcopy_blocktime_end(addr, dc->total_blocktime,
affected_cpu);
}