qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ratelimit: restrict the delay time to a non-negative value
@ 2022-09-20 12:33 wangliangzz
  2022-09-20 13:18 ` Alberto Garcia
  0 siblings, 1 reply; 7+ messages in thread
From: wangliangzz @ 2022-09-20 12:33 UTC (permalink / raw)
  To: qemu-devel, qemu-block, wangliangzz
  Cc: pbonzini, stefanha, silbe, berto, Wang Liang

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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-23  7:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 12:33 [PATCH] ratelimit: restrict the delay time to a non-negative value wangliangzz
2022-09-20 13:18 ` Alberto Garcia
2022-09-21  1:47   ` Wang Liang
2022-09-21  4:53     ` Markus Armbruster
2022-09-21  6:26       ` Wang Liang
2022-09-21  8:17     ` Alberto Garcia
2022-09-23  7:14       ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).