[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/10] ratelimit: treat zero speed as unlimited
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PULL 01/10] ratelimit: treat zero speed as unlimited |
Date: |
Fri, 25 Jun 2021 15:59:57 +0300 |
From: Paolo Bonzini <pbonzini@redhat.com>
Both users of RateLimit, block-copy.c and blockjob.c, treat
a speed of zero as unlimited, while RateLimit treats it as
"as slow as possible". The latter is nicer from the code
point of view but pretty useless, so disable rate limiting
if a speed of zero is provided.
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20210614081130.22134-2-eesposit@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
include/qemu/ratelimit.h | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h
index 003ea6d5a3..48bf59e857 100644
--- a/include/qemu/ratelimit.h
+++ b/include/qemu/ratelimit.h
@@ -43,7 +43,11 @@ static inline int64_t ratelimit_calculate_delay(RateLimit
*limit, uint64_t n)
double delay_slices;
QEMU_LOCK_GUARD(&limit->lock);
- assert(limit->slice_quota && limit->slice_ns);
+ if (!limit->slice_quota) {
+ /* Throttling disabled. */
+ return 0;
+ }
+ assert(limit->slice_ns);
if (limit->slice_end_time < now) {
/* Previous, possibly extended, time slice finished; reset the
@@ -83,7 +87,11 @@ static inline void ratelimit_set_speed(RateLimit *limit,
uint64_t speed,
{
QEMU_LOCK_GUARD(&limit->lock);
limit->slice_ns = slice_ns;
- limit->slice_quota = MAX(((double)speed * slice_ns) / 1000000000ULL, 1);
+ if (speed == 0) {
+ limit->slice_quota = 0;
+ } else {
+ limit->slice_quota = MAX(((double)speed * slice_ns) / 1000000000ULL,
1);
+ }
}
#endif
--
2.29.2
- [PULL 00/10] Block Jobs patches, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 01/10] ratelimit: treat zero speed as unlimited,
Vladimir Sementsov-Ogievskiy <=
- [PULL 04/10] progressmeter: protect with a mutex, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 08/10] block-copy: move progress_set_remaining in block_copy_task_end, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 03/10] blockjob: let ratelimit handle a speed of 0, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 05/10] co-shared-resource: protect with a mutex, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 07/10] block-copy: streamline choice of copy_range vs. read/write, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 09/10] block-copy: add CoMutex lock, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 02/10] block-copy: let ratelimit handle a speed of 0, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 06/10] block-copy: small refactor in block_copy_task_entry and block_copy_common, Vladimir Sementsov-Ogievskiy, 2021/06/25
- [PULL 10/10] block-copy: atomic .cancelled and .finished fields in BlockCopyCallState, Vladimir Sementsov-Ogievskiy, 2021/06/25
- Re: [PULL 00/10] Block Jobs patches, Peter Maydell, 2021/06/28