mirror of
https://github.com/qemu/qemu.git
synced 2024-11-24 03:13:44 +08:00
60c7981aa3
In migration rate limiting atomic operations are used to read the rate limit variables and transferred bytes and they are expensive. Check first if rate_limit_max is equal to RATE_LIMIT_DISABLED and return false immediately if so. Note that with this patch we will also will stop flushing by not calling qemu_fflush() from migration_transferred_bytes() if the migration rate is not exceeded. This should be fine since migration thread calls in the loop migration_update_counters from migration_rate_limit() that calls the migration_transferred_bytes() and flushes there. Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com> Message-ID: <20231011184358.97349-2-elena.ufimtseva@oracle.com>
71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
/*
|
|
* Migration stats
|
|
*
|
|
* Copyright (c) 2012-2023 Red Hat Inc
|
|
*
|
|
* Authors:
|
|
* Juan Quintela <quintela@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/stats64.h"
|
|
#include "qemu-file.h"
|
|
#include "trace.h"
|
|
#include "migration-stats.h"
|
|
|
|
MigrationAtomicStats mig_stats;
|
|
|
|
bool migration_rate_exceeded(QEMUFile *f)
|
|
{
|
|
if (qemu_file_get_error(f)) {
|
|
return true;
|
|
}
|
|
|
|
uint64_t rate_limit_max = migration_rate_get();
|
|
if (rate_limit_max == RATE_LIMIT_DISABLED) {
|
|
return false;
|
|
}
|
|
|
|
uint64_t rate_limit_start = stat64_get(&mig_stats.rate_limit_start);
|
|
uint64_t rate_limit_current = migration_transferred_bytes(f);
|
|
uint64_t rate_limit_used = rate_limit_current - rate_limit_start;
|
|
|
|
if (rate_limit_max > 0 && rate_limit_used > rate_limit_max) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
uint64_t migration_rate_get(void)
|
|
{
|
|
return stat64_get(&mig_stats.rate_limit_max);
|
|
}
|
|
|
|
#define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY)
|
|
|
|
void migration_rate_set(uint64_t limit)
|
|
{
|
|
/*
|
|
* 'limit' is per second. But we check it each BUFFER_DELAY milliseconds.
|
|
*/
|
|
stat64_set(&mig_stats.rate_limit_max, limit / XFER_LIMIT_RATIO);
|
|
}
|
|
|
|
void migration_rate_reset(QEMUFile *f)
|
|
{
|
|
stat64_set(&mig_stats.rate_limit_start, migration_transferred_bytes(f));
|
|
}
|
|
|
|
uint64_t migration_transferred_bytes(QEMUFile *f)
|
|
{
|
|
uint64_t multifd = stat64_get(&mig_stats.multifd_bytes);
|
|
uint64_t rdma = stat64_get(&mig_stats.rdma_bytes);
|
|
uint64_t qemu_file = qemu_file_transferred(f);
|
|
|
|
trace_migration_transferred_bytes(qemu_file, multifd, rdma);
|
|
return qemu_file + multifd + rdma;
|
|
}
|