diff options
author | Juan Quintela <quintela@redhat.com> | 2023-05-15 21:56:58 +0200 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2023-05-18 18:40:51 +0200 |
commit | e1fde0e038bafd0bd05db7d43305b9b2f03c0683 (patch) | |
tree | 14c6f72e2e86867957e62c01ac2ec2363dcbcc58 /migration/qemu-file.c | |
parent | de37f8b9c21e1c6ef98eebb0b05bd83e5867bc6f (diff) |
migration: Move rate_limit_max and rate_limit_used to migration_stats
These way we can make them atomic and use this functions from any
place. I also moved all functions that use rate_limit to
migration-stats.
Functions got renamed, they are not qemu_file anymore.
qemu_file_rate_limit -> migration_rate_exceeded
qemu_file_set_rate_limit -> migration_rate_set
qemu_file_get_rate_limit -> migration_rate_get
qemu_file_reset_rate_limit -> migration_rate_reset
qemu_file_acct_rate_limit -> migration_rate_account.
Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-Id: <20230515195709.63843-6-quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'migration/qemu-file.c')
-rw-r--r-- | migration/qemu-file.c | 52 |
1 files changed, 2 insertions, 50 deletions
diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 3d66c5c512..9c67b52fe0 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -41,17 +41,6 @@ struct QEMUFile { QIOChannel *ioc; bool is_writable; - /* - * Maximum amount of data in bytes to transfer during one - * rate limiting time window - */ - uint64_t rate_limit_max; - /* - * Total amount of data in bytes queued for transfer - * during this rate limiting time window - */ - uint64_t rate_limit_used; - /* The sum of bytes transferred on the wire */ uint64_t total_transferred; @@ -303,7 +292,7 @@ void qemu_fflush(QEMUFile *f) qemu_file_set_error_obj(f, -EIO, local_error); } else { uint64_t size = iov_size(f->iov, f->iovcnt); - qemu_file_acct_rate_limit(f, size); + migration_rate_account(size); f->total_transferred += size; } @@ -356,7 +345,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, int ret = f->hooks->save_page(f, block_offset, offset, size, bytes_sent); if (ret != RAM_SAVE_CONTROL_NOT_SUPP) { - qemu_file_acct_rate_limit(f, size); + migration_rate_account(size); } if (ret != RAM_SAVE_CONTROL_DELAYED && @@ -727,43 +716,6 @@ uint64_t qemu_file_transferred(QEMUFile *f) return f->total_transferred; } -int qemu_file_rate_limit(QEMUFile *f) -{ - if (qemu_file_get_error(f)) { - return 1; - } - if (f->rate_limit_max == RATE_LIMIT_DISABLED) { - return 0; - } - if (f->rate_limit_used > f->rate_limit_max) { - return 1; - } - return 0; -} - -uint64_t qemu_file_get_rate_limit(QEMUFile *f) -{ - return f->rate_limit_max; -} - -void qemu_file_set_rate_limit(QEMUFile *f, uint64_t limit) -{ - /* - * 'limit' is per second. But we check it each 100 miliseconds. - */ - f->rate_limit_max = limit / XFER_LIMIT_RATIO; -} - -void qemu_file_reset_rate_limit(QEMUFile *f) -{ - f->rate_limit_used = 0; -} - -void qemu_file_acct_rate_limit(QEMUFile *f, uint64_t len) -{ - f->rate_limit_used += len; -} - void qemu_put_be16(QEMUFile *f, unsigned int v) { qemu_put_byte(f, v >> 8); |