MINOR: time: also provide a global, monotonic global_now_ms timer
authorWilly Tarreau <w@1wt.eu>
Tue, 23 Mar 2021 07:45:42 +0000 (08:45 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 31 Mar 2021 07:41:42 +0000 (09:41 +0200)
commitd0fbbb909ebbf80ba60e61444377a0761a3edc13
tree7646faba91a245a8ffd39b38a16f609955231bd3
parent529bae594e9e80406151717d22118f9062ab9d43
MINOR: time: also provide a global, monotonic global_now_ms timer

The period-based freq counters need the global date in milliseconds,
so better calculate it and expose it rather than letting all call
places incorrectly retrieve it.

Here what we do is that we maintain a new globally monotonic timer,
global_now_ms, which ought to be very close to the global_now one,
but maintains the monotonic approach of now_ms between all threads
in that global_now_ms is always ahead of any now_ms.

This patch is made simple to ease backporting (it will be needed for
a subsequent fix), but it also opens the way to some simplifications
on the time handling: instead of computing the local time and trying
to force it to the global one, we should soon be able to proceed in
the opposite way, that is computing the new global time an making the
local one just the latest snapshot of it. This will bring the benefit
of making sure that the global time is always ahead of the local one.

(cherry picked from commit 6064b34be0e761de881a5bfca287d01f69122602)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 3a9bc55350e18a92538ffa7295a204420fdba683)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 29d0329b8af90af42d37007c8c89872203fba1a3)
[wt: minor adjustments to includes (common/ instead of haproxy/)]
Signed-off-by: Willy Tarreau <w@1wt.eu>
include/common/time.h
src/time.c