]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: clock: opportunistically use CLOCK_MONOTONIC for the internal time
authorWilly Tarreau <w@1wt.eu>
Sun, 8 Sep 2024 18:13:53 +0000 (18:13 +0000)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Sep 2024 07:08:10 +0000 (09:08 +0200)
commit4150851ce5be04f170e828d8e045e72a73628994
treea680e10d20bf44143ba014108435db227f426a34
parentf793845f4af346159878b4c74e40537a5fedac55
MEDIUM: clock: opportunistically use CLOCK_MONOTONIC for the internal time

We already collect CLOCK_MONOTONIC when it's available when leaving the
poller, but it's only used for profiling. The functions that return it
set the value to zero when it's not available, so we can use that to
detect if it works or not. The idea is that if the monotonic time is
non-zero, it is ticking and usable, then we use if for now_ns, otherwise
we use the corrected date. We continue to apply the now_offset to the
returned value because it helps forcing an early time wrap-around.

Proceeding like this presents two benefits:
  - on systems supporting this, the time is much more robust against
    time changes
  - when it works, it saves us from having to go through the time
    correction code, which is usually cheap, but better avoided anyway.

Note that idle time calculation continues to rely on the wall-clock
time.
src/clock.c