Re: [PATCH v2 05/16] migration: Move rate_limit_max and rate_limit_used to migration_stats
On Mon, 2023-05-15 at 21:56 +0200, Juan Quintela wrote: > 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. > > Signed-off-by: Juan Quintela > Reviewed-by: Harsh Prateek Bora > > --- > > s/this/these/ (harsh) > If you have any good suggestion for better names, I am all ears. > Fix missing / XFER_LIMIT_RATIO in migration_rate_set(quintela) > --- > include/migration/qemu-file-types.h | 12 ++- > migration/migration-stats.h | 47 ++ > migration/options.h | 7 > migration/qemu-file.h | 11 -- > hw/ppc/spapr.c | 4 +-- > hw/s390x/s390-stattrib.c| 2 +- > migration/block-dirty-bitmap.c | 2 +- > migration/block.c | 5 +-- > migration/migration-stats.c | 44 > migration/migration.c | 14 > migration/multifd.c | 2 +- > migration/options.c | 7 ++-- > migration/qemu-file.c | 52 ++--- > migration/ram.c | 2 +- > migration/savevm.c | 2 +- > 15 files changed, 124 insertions(+), 89 deletions(-) > > diff --git a/include/migration/qemu-file-types.h > b/include/migration/qemu-file-types.h > index 1436f9ce92..9ba163f333 100644 > --- a/include/migration/qemu-file-types.h > +++ b/include/migration/qemu-file-types.h > @@ -165,6 +165,16 @@ size_t coroutine_mixed_fn > qemu_get_counted_string(QEMUFile *f, char buf[256]); > > void qemu_put_counted_string(QEMUFile *f, const char *name); > > -int qemu_file_rate_limit(QEMUFile *f); > +/** > + * migration_rate_exceeded: Check if we have exceeded rate for this interval > + * > + * Checks if we have already transferred more data that we are allowed > + * in the current interval. > + * > + * @f: QEMUFile used for main migration channel > + * > + * Returns if we should stop sending data for this interval. > + */ > +bool migration_rate_exceeded(QEMUFile *f); > > #endif > diff --git a/migration/migration-stats.h b/migration/migration-stats.h > index 21402af9e4..e39c083245 100644 > --- a/migration/migration-stats.h > +++ b/migration/migration-stats.h > @@ -15,6 +15,12 @@ > > #include "qemu/stats64.h" > > +/* > + * Amount of time to allocate to each "chunk" of bandwidth-throttled > + * data. > + */ > +#define BUFFER_DELAY 100 > + > /* > * If rate_limit_max is 0, there is special code to remove the rate > * limit. > @@ -75,6 +81,14 @@ typedef struct { > * Number of bytes sent during precopy stage. > */ > Stat64 precopy_bytes; > +/* > + * Maximum amount of data we can send in a cycle. > + */ > +Stat64 rate_limit_max; > +/* > + * Amount of data we have sent in the current cycle. > + */ > +Stat64 rate_limit_used; > /* > * How long has the setup stage took. > */ > @@ -100,4 +114,37 @@ extern MigrationAtomicStats mig_stats; > * Returns: Nothing. The time is stored in val. > */ > void migration_time_since(MigrationAtomicStats *stats, int64_t since); > + > +/** > + * migration_rate_account: Increase the number of bytes transferred. > + * > + * Report on a number of bytes the have been transferred that need to > + * be applied to the rate limiting calcuations. s/calcuations/calculations > + * > + * @len: amount of bytes transferred > + */ > +void migration_rate_account(uint64_t len); > + > +/** > + * migration_rate_get: Get the maximum amount that can be transferred. > + * > + * Returns the maximum number of bytes that can be transferred in a cycle. > + */ > +uint64_t migration_rate_get(void); maybe migration_max_rate_get() ? > + > +/** > + * migration_rate_reset: Reset the rate limit counter. > + * > + * This is called when we know we start a new transfer cycle. > + */ > +void migration_rate_reset(void); > + > +/** > + * migration_rate_set: Set the maximum amount that can be transferred. > + * > + * Sets the maximum amount of bytes that can be transferred in one cycle. > + * > + * @new_rate: new maximum amount > + */ > +void migration_rate_set(uint64_t new_rate); maybe migration_max_rate_set() ? > #endif > diff --git a/migration/options.h b/migration/options.h > index 5cca3326d6..45991af3c2 100644 > --- a/migration/options.h > +++ b/migration/options.h > @@ -17,13 +17,6 @@ > #include "hw/qdev-properties.h" > #include "hw/qdev-properties-system.h" > > -/* constants */ > - > -/* Amount of time to allocate to each "chunk" of bandwidth-throttled > - * data. */ > -#define BUFFER_DELAY
Re: [PATCH v2 05/16] migration: Move rate_limit_max and rate_limit_used to migration_stats
On 5/15/23 21:56, Juan Quintela wrote: 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. Signed-off-by: Juan Quintela Reviewed-by: Harsh Prateek Bora Reviewed-by: Cédric Le Goater Thanks, C. --- s/this/these/ (harsh) If you have any good suggestion for better names, I am all ears. Fix missing / XFER_LIMIT_RATIO in migration_rate_set(quintela) --- include/migration/qemu-file-types.h | 12 ++- migration/migration-stats.h | 47 ++ migration/options.h | 7 migration/qemu-file.h | 11 -- hw/ppc/spapr.c | 4 +-- hw/s390x/s390-stattrib.c| 2 +- migration/block-dirty-bitmap.c | 2 +- migration/block.c | 5 +-- migration/migration-stats.c | 44 migration/migration.c | 14 migration/multifd.c | 2 +- migration/options.c | 7 ++-- migration/qemu-file.c | 52 ++--- migration/ram.c | 2 +- migration/savevm.c | 2 +- 15 files changed, 124 insertions(+), 89 deletions(-) diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-file-types.h index 1436f9ce92..9ba163f333 100644 --- a/include/migration/qemu-file-types.h +++ b/include/migration/qemu-file-types.h @@ -165,6 +165,16 @@ size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256]); void qemu_put_counted_string(QEMUFile *f, const char *name); -int qemu_file_rate_limit(QEMUFile *f); +/** + * migration_rate_exceeded: Check if we have exceeded rate for this interval + * + * Checks if we have already transferred more data that we are allowed + * in the current interval. + * + * @f: QEMUFile used for main migration channel + * + * Returns if we should stop sending data for this interval. + */ +bool migration_rate_exceeded(QEMUFile *f); #endif diff --git a/migration/migration-stats.h b/migration/migration-stats.h index 21402af9e4..e39c083245 100644 --- a/migration/migration-stats.h +++ b/migration/migration-stats.h @@ -15,6 +15,12 @@ #include "qemu/stats64.h" +/* + * Amount of time to allocate to each "chunk" of bandwidth-throttled + * data. + */ +#define BUFFER_DELAY 100 + /* * If rate_limit_max is 0, there is special code to remove the rate * limit. @@ -75,6 +81,14 @@ typedef struct { * Number of bytes sent during precopy stage. */ Stat64 precopy_bytes; +/* + * Maximum amount of data we can send in a cycle. + */ +Stat64 rate_limit_max; +/* + * Amount of data we have sent in the current cycle. + */ +Stat64 rate_limit_used; /* * How long has the setup stage took. */ @@ -100,4 +114,37 @@ extern MigrationAtomicStats mig_stats; * Returns: Nothing. The time is stored in val. */ void migration_time_since(MigrationAtomicStats *stats, int64_t since); + +/** + * migration_rate_account: Increase the number of bytes transferred. + * + * Report on a number of bytes the have been transferred that need to + * be applied to the rate limiting calcuations. + * + * @len: amount of bytes transferred + */ +void migration_rate_account(uint64_t len); + +/** + * migration_rate_get: Get the maximum amount that can be transferred. + * + * Returns the maximum number of bytes that can be transferred in a cycle. + */ +uint64_t migration_rate_get(void); + +/** + * migration_rate_reset: Reset the rate limit counter. + * + * This is called when we know we start a new transfer cycle. + */ +void migration_rate_reset(void); + +/** + * migration_rate_set: Set the maximum amount that can be transferred. + * + * Sets the maximum amount of bytes that can be transferred in one cycle. + * + * @new_rate: new maximum amount + */ +void migration_rate_set(uint64_t new_rate); #endif diff --git a/migration/options.h b/migration/options.h index 5cca3326d6..45991af3c2 100644 --- a/migration/options.h +++ b/migration/options.h @@ -17,13 +17,6 @@ #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" -/* constants */ - -/* Amount of time to allocate to each "chunk" of bandwidth-throttled - * data. */ -#define BUFFER_DELAY 100 -#define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY) - /* migration properties */ extern Property migration_properties[]; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index bcc39081f2..e649718492 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -130,17 +130,6 @@ void
[PATCH v2 05/16] 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. Signed-off-by: Juan Quintela Reviewed-by: Harsh Prateek Bora --- s/this/these/ (harsh) If you have any good suggestion for better names, I am all ears. Fix missing / XFER_LIMIT_RATIO in migration_rate_set(quintela) --- include/migration/qemu-file-types.h | 12 ++- migration/migration-stats.h | 47 ++ migration/options.h | 7 migration/qemu-file.h | 11 -- hw/ppc/spapr.c | 4 +-- hw/s390x/s390-stattrib.c| 2 +- migration/block-dirty-bitmap.c | 2 +- migration/block.c | 5 +-- migration/migration-stats.c | 44 migration/migration.c | 14 migration/multifd.c | 2 +- migration/options.c | 7 ++-- migration/qemu-file.c | 52 ++--- migration/ram.c | 2 +- migration/savevm.c | 2 +- 15 files changed, 124 insertions(+), 89 deletions(-) diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-file-types.h index 1436f9ce92..9ba163f333 100644 --- a/include/migration/qemu-file-types.h +++ b/include/migration/qemu-file-types.h @@ -165,6 +165,16 @@ size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256]); void qemu_put_counted_string(QEMUFile *f, const char *name); -int qemu_file_rate_limit(QEMUFile *f); +/** + * migration_rate_exceeded: Check if we have exceeded rate for this interval + * + * Checks if we have already transferred more data that we are allowed + * in the current interval. + * + * @f: QEMUFile used for main migration channel + * + * Returns if we should stop sending data for this interval. + */ +bool migration_rate_exceeded(QEMUFile *f); #endif diff --git a/migration/migration-stats.h b/migration/migration-stats.h index 21402af9e4..e39c083245 100644 --- a/migration/migration-stats.h +++ b/migration/migration-stats.h @@ -15,6 +15,12 @@ #include "qemu/stats64.h" +/* + * Amount of time to allocate to each "chunk" of bandwidth-throttled + * data. + */ +#define BUFFER_DELAY 100 + /* * If rate_limit_max is 0, there is special code to remove the rate * limit. @@ -75,6 +81,14 @@ typedef struct { * Number of bytes sent during precopy stage. */ Stat64 precopy_bytes; +/* + * Maximum amount of data we can send in a cycle. + */ +Stat64 rate_limit_max; +/* + * Amount of data we have sent in the current cycle. + */ +Stat64 rate_limit_used; /* * How long has the setup stage took. */ @@ -100,4 +114,37 @@ extern MigrationAtomicStats mig_stats; * Returns: Nothing. The time is stored in val. */ void migration_time_since(MigrationAtomicStats *stats, int64_t since); + +/** + * migration_rate_account: Increase the number of bytes transferred. + * + * Report on a number of bytes the have been transferred that need to + * be applied to the rate limiting calcuations. + * + * @len: amount of bytes transferred + */ +void migration_rate_account(uint64_t len); + +/** + * migration_rate_get: Get the maximum amount that can be transferred. + * + * Returns the maximum number of bytes that can be transferred in a cycle. + */ +uint64_t migration_rate_get(void); + +/** + * migration_rate_reset: Reset the rate limit counter. + * + * This is called when we know we start a new transfer cycle. + */ +void migration_rate_reset(void); + +/** + * migration_rate_set: Set the maximum amount that can be transferred. + * + * Sets the maximum amount of bytes that can be transferred in one cycle. + * + * @new_rate: new maximum amount + */ +void migration_rate_set(uint64_t new_rate); #endif diff --git a/migration/options.h b/migration/options.h index 5cca3326d6..45991af3c2 100644 --- a/migration/options.h +++ b/migration/options.h @@ -17,13 +17,6 @@ #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" -/* constants */ - -/* Amount of time to allocate to each "chunk" of bandwidth-throttled - * data. */ -#define BUFFER_DELAY 100 -#define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY) - /* migration properties */ extern Property migration_properties[]; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index bcc39081f2..e649718492 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -130,17 +130,6 @@ void qemu_file_skip(QEMUFile *f, int size); * accounting information tracks the total migration traffic. */ void