2023-04-26 19:04:06 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2023-05-15 21:56:58 +02:00
|
|
|
#include "qemu-file.h"
|
2023-05-15 21:57:00 +02:00
|
|
|
#include "trace.h"
|
2023-04-26 19:04:06 +02:00
|
|
|
#include "migration-stats.h"
|
|
|
|
|
2023-04-26 19:40:13 +02:00
|
|
|
MigrationAtomicStats mig_stats;
|
2023-05-15 21:56:58 +02:00
|
|
|
|
|
|
|
bool migration_rate_exceeded(QEMUFile *f)
|
|
|
|
{
|
|
|
|
if (qemu_file_get_error(f)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-11 20:43:55 +02:00
|
|
|
uint64_t rate_limit_max = migration_rate_get();
|
|
|
|
if (rate_limit_max == RATE_LIMIT_DISABLED) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-15 21:57:01 +02:00
|
|
|
uint64_t rate_limit_start = stat64_get(&mig_stats.rate_limit_start);
|
2023-10-25 11:11:12 +02:00
|
|
|
uint64_t rate_limit_current = migration_transferred_bytes();
|
2023-05-15 21:57:01 +02:00
|
|
|
uint64_t rate_limit_used = rate_limit_current - rate_limit_start;
|
2023-05-15 21:56:58 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
/*
|
2023-07-14 13:32:41 +02:00
|
|
|
* 'limit' is per second. But we check it each BUFFER_DELAY milliseconds.
|
2023-05-15 21:56:58 +02:00
|
|
|
*/
|
|
|
|
stat64_set(&mig_stats.rate_limit_max, limit / XFER_LIMIT_RATIO);
|
|
|
|
}
|
|
|
|
|
2023-05-15 21:57:01 +02:00
|
|
|
void migration_rate_reset(QEMUFile *f)
|
2023-05-15 21:56:58 +02:00
|
|
|
{
|
2023-10-25 11:11:12 +02:00
|
|
|
stat64_set(&mig_stats.rate_limit_start, migration_transferred_bytes());
|
2023-05-15 21:56:58 +02:00
|
|
|
}
|
|
|
|
|
2023-10-25 11:11:12 +02:00
|
|
|
uint64_t migration_transferred_bytes(void)
|
2023-05-15 21:56:59 +02:00
|
|
|
{
|
2023-05-15 21:57:00 +02:00
|
|
|
uint64_t multifd = stat64_get(&mig_stats.multifd_bytes);
|
2023-05-15 21:57:03 +02:00
|
|
|
uint64_t rdma = stat64_get(&mig_stats.rdma_bytes);
|
2023-10-25 11:11:09 +02:00
|
|
|
uint64_t qemu_file = stat64_get(&mig_stats.qemu_file_transferred);
|
2023-05-15 21:57:00 +02:00
|
|
|
|
2023-05-15 21:57:03 +02:00
|
|
|
trace_migration_transferred_bytes(qemu_file, multifd, rdma);
|
|
|
|
return qemu_file + multifd + rdma;
|
2023-05-15 21:56:59 +02:00
|
|
|
}
|