[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] ratelimit: restrict the delay time to a non-negative value
From: |
wangliangzz |
Subject: |
[PATCH] ratelimit: restrict the delay time to a non-negative value |
Date: |
Tue, 20 Sep 2022 20:33:50 +0800 |
From: Wang Liang <wangliangzz@inspur.com>
The delay time should never be a negative value.
Signed-off-by: Wang Liang <wangliangzz@inspur.com>
---
include/qemu/ratelimit.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h
index 48bf59e857..c8ea855fc1 100644
--- a/include/qemu/ratelimit.h
+++ b/include/qemu/ratelimit.h
@@ -69,7 +69,7 @@ static inline int64_t ratelimit_calculate_delay(RateLimit
*limit, uint64_t n)
delay_slices = (double)limit->dispatched / limit->slice_quota;
limit->slice_end_time = limit->slice_start_time +
(uint64_t)(delay_slices * limit->slice_ns);
- return limit->slice_end_time - now;
+ return MAX(limit->slice_end_time - now, 0);
}
static inline void ratelimit_init(RateLimit *limit)
--
2.31.1
- [PATCH] ratelimit: restrict the delay time to a non-negative value,
wangliangzz <=