From 5345490b8e0a3c82587fd1ccf30244035cf0b1d5 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 16 May 2023 19:01:55 +0200 Subject: [PATCH] MINOR: clock: provide a function to automatically adjust now_offset Right now there's no way to enforce a specific value of now_ms upon startup in order to compensate for the time it takes to load a config, specifically when dealing with the health check startup. For this we'd need to force the now_offset value to compensate for the last known value of the current date. This patch exposes a function to do exactly this. --- include/haproxy/clock.h | 1 + src/clock.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/haproxy/clock.h b/include/haproxy/clock.h index 8ce41e79e..264363e27 100644 --- a/include/haproxy/clock.h +++ b/include/haproxy/clock.h @@ -48,6 +48,7 @@ char *timeofday_as_iso_us(int pad); uint clock_report_idle(void); void clock_leaving_poll(int timeout, int interrupted); void clock_entering_poll(void); +void clock_adjust_now_offset(void); static inline void clock_update_date(int max_wait, int interrupted) { diff --git a/src/clock.c b/src/clock.c index 7cf71607f..ec2133c8b 100644 --- a/src/clock.c +++ b/src/clock.c @@ -304,6 +304,11 @@ void clock_init_process_date(void) clock_update_date(0, 1); } +void clock_adjust_now_offset(void) +{ + HA_ATOMIC_STORE(&now_offset, now_ns - tv_to_ns(&date)); +} + /* must be called once per thread to initialize their thread-local variables. * Note that other threads might also be initializing and running in parallel. */