From: Willy Tarreau Date: Fri, 27 Aug 2021 21:16:58 +0000 (+0200) Subject: BUG/MINOR: time: fix idle time computation for long sleeps X-Git-Tag: v2.5-dev5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e365aa28d4f30b3d98118ab460c856d3aa72c75e;p=thirdparty%2Fhaproxy.git BUG/MINOR: time: fix idle time computation for long sleeps In 2.4 we extended the max poll time from 1s to 60s with commit 4f59d3861 ("MINOR: time: increase the minimum wakeup interval to 60s"). This had the consequence that the calculation of the idle time percentage may overflow during the multiply by 100 if the thread had slept 43s or more. Let's change this to a 64 bit computation. This will have no performance impact since this is done at most twice per second. This should fix github issue #1366. This must be backported to 2.4. --- diff --git a/include/haproxy/time.h b/include/haproxy/time.h index a556af2a50..4a3feb5df7 100644 --- a/include/haproxy/time.h +++ b/include/haproxy/time.h @@ -577,7 +577,7 @@ static inline void measure_idle() if (samp_time < 500000) return; - ti->idle_pct = (100 * idle_time + samp_time / 2) / samp_time; + ti->idle_pct = (100ULL * idle_time + samp_time / 2) / samp_time; idle_time = samp_time = 0; }