@@ -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