]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async/Timeout: always round up 60265/head
authorMax Kellermann <max.kellermann@ionos.com>
Fri, 11 Oct 2024 14:15:28 +0000 (16:15 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Tue, 22 Oct 2024 10:22:09 +0000 (12:22 +0200)
Currently, we always round down, which has a bad side effect: when a
timer comes closer, we have lots of early wakeups, and eventually
we'll run into a busy loop (timeout=0) when the timeout is less than
one millisecond; the process will remain this busy loop for one
millisecond, wasting lots of CPU time.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/msg/async/Timeout.h

index b47bcec8447634c216e383c4ff1039471559baed..b8df1b4076198c31cd3c45f042d2e3f40006a270 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef CEPH_MSG_TIMEOUT_H
 #define CEPH_MSG_TIMEOUT_H
 
+#include "include/intarith.h" // for div_round_up()
+
 #include <time.h> // for struct timeval
 
 /**
@@ -28,7 +30,8 @@
 constexpr int
 timeout_to_milliseconds(const struct timeval &tv) noexcept
 {
-  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+  /* round up to the next millisecond so we don't wake up too early */
+  return tv.tv_sec * 1000 + div_round_up(tv.tv_usec, 1000);
 }
 
 /**