Skip to content

Commit

Permalink
migration/multifd: Compute transferred bytes correctly
Browse files Browse the repository at this point in the history
In the past, we had to put the in the main thread all the operations
related with sizes due to qemu_file not beeing thread safe.  As now
all counters are atomic, we can update the counters just after the
do the write.  As an aditional bonus, we are able to use the right
value for the compression methods.  Right now we were assuming that
there were no compression at all.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Message-Id: <20230515195709.63843-17-quintela@redhat.com>
  • Loading branch information
Juan Quintela committed May 18, 2023
1 parent bd7ceaf commit cbec7eb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions migration/multifd.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,20 @@ void multifd_register_ops(int method, MultiFDMethods *ops)
static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp)
{
MultiFDInit_t msg = {};
size_t size = sizeof(msg);
int ret;

msg.magic = cpu_to_be32(MULTIFD_MAGIC);
msg.version = cpu_to_be32(MULTIFD_VERSION);
msg.id = p->id;
memcpy(msg.uuid, &qemu_uuid.data, sizeof(msg.uuid));

ret = qio_channel_write_all(p->c, (char *)&msg, sizeof(msg), errp);
ret = qio_channel_write_all(p->c, (char *)&msg, size, errp);
if (ret != 0) {
return -1;
}
stat64_add(&mig_stats.multifd_bytes, size);
stat64_add(&mig_stats.transferred, size);
return 0;
}

Expand Down Expand Up @@ -395,7 +398,6 @@ static int multifd_send_pages(QEMUFile *f)
static int next_channel;
MultiFDSendParams *p = NULL; /* make happy gcc */
MultiFDPages_t *pages = multifd_send_state->pages;
uint64_t transferred;

if (qatomic_read(&multifd_send_state->exiting)) {
return -1;
Expand Down Expand Up @@ -430,10 +432,7 @@ static int multifd_send_pages(QEMUFile *f)
p->packet_num = multifd_send_state->packet_num++;
multifd_send_state->pages = p->pages;
p->pages = pages;
transferred = ((uint64_t) pages->num) * p->page_size + p->packet_len;
qemu_mutex_unlock(&p->mutex);
stat64_add(&mig_stats.transferred, transferred);
stat64_add(&mig_stats.multifd_bytes, transferred);
qemu_sem_post(&p->sem);

return 1;
Expand Down Expand Up @@ -715,6 +714,8 @@ static void *multifd_send_thread(void *opaque)
if (ret != 0) {
break;
}
stat64_add(&mig_stats.multifd_bytes, p->packet_len);
stat64_add(&mig_stats.transferred, p->packet_len);
} else {
/* Send header using the same writev call */
p->iov[0].iov_len = p->packet_len;
Expand All @@ -727,6 +728,8 @@ static void *multifd_send_thread(void *opaque)
break;
}

stat64_add(&mig_stats.multifd_bytes, p->next_packet_size);
stat64_add(&mig_stats.transferred, p->next_packet_size);
qemu_mutex_lock(&p->mutex);
p->pending_job--;
qemu_mutex_unlock(&p->mutex);
Expand Down

0 comments on commit cbec7eb

Please sign in to comment.